documentation, stripped out unused functionality.

This commit is contained in:
Gabe Venberg 2023-10-30 13:22:42 -05:00
parent f859ea683e
commit a77b3845e0
3 changed files with 13 additions and 11 deletions

View file

@ -116,7 +116,7 @@ fn main() -> ! {
/// need forward in +x and right in +y (this is known as the NED (north, east, down) cordinate
/// system)
/// also converts to f32
pub fn swd_to_ned(measurement: Measurement) -> NedMeasurement {
pub fn enu_to_ned(measurement: Measurement) -> NedMeasurement {
NedMeasurement {
x: -measurement.y as f32,
y: -measurement.x as f32,
@ -136,8 +136,8 @@ fn calc_heading(
let mag_data = calibration::calibrated_measurement(mag_data, mag_calibration);
let acel_data = sensor.accel_data().unwrap();
let mut ned_mag_data = swd_to_ned(mag_data);
let ned_acel_data = swd_to_ned(acel_data);
let mut ned_mag_data = enu_to_ned(mag_data);
let ned_acel_data = enu_to_ned(acel_data);
let attitude = calc_attitude(&ned_acel_data);

View file

@ -5,6 +5,7 @@ use core::{
#[cfg(test)]
use std::dbg;
/// a signed point in 2d space
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Point {
pub x: isize,
@ -23,6 +24,7 @@ impl Point {
}
}
/// an unsigned point in 2d space
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UPoint {
pub x: usize,
@ -42,7 +44,7 @@ impl UPoint {
}
/// A matrix that allows negative co-oordinates. Will panic if referencing out of bounds, just like
/// a nomral matrix.
/// a normal 2d array.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FourQuadrantMatrix<const X: usize, const Y: usize, T> {
matrix: [[T; X]; Y],
@ -56,6 +58,8 @@ where
T: Copy,
T: Default,
{
/// generates a new FourQuadrantMatrix with a given zero point (the point in the underlying 2d
/// array considered to be (0,0))
pub fn new(zero_coord: UPoint) -> FourQuadrantMatrix<{ X }, { Y }, T> {
FourQuadrantMatrix {
matrix: [[T::default(); X]; Y],
@ -77,6 +81,7 @@ where
self.max_point
}
/// makes sure a point is in bounds and if not, brings it in bounds.
pub fn bound_point(&self, point: &mut Point) {
if point.x > self.max_point.x {
point.x = self.max_point.x
@ -95,12 +100,14 @@ where
}
}
/// checks if the point is in bounds.
pub fn is_in_bounds(&self, point: &Point) -> bool {
point.x <= self.max_point.x
&& point.y <= self.max_point.y
&& point.x >= self.min_point.x
&& point.y >= self.min_point.y
}
/// fills the matrix with the Ts default value.
pub fn reset_matrix(&mut self) {
self.matrix = [[T::default(); X]; Y];
}
@ -132,13 +139,10 @@ impl<T, const X: usize, const Y: usize> From<FourQuadrantMatrix<{ X }, { Y }, T>
}
}
/// a line segment in 2d space, described by its two endpoints
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Line(pub Point, pub Point);
//no boxes here!
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ULine(pub UPoint, pub UPoint);
/// Renders a line into a matrix of pixels.
/// Will not attempt to mutate outside bounds of the matrix, so it is safe to draw lines that
/// extend past its edges.

View file

@ -13,8 +13,7 @@ pub struct NedMeasurement {
pub z: f32,
}
//theta=0 at north, pi/-pi at south, pi/2 at east, and -pi/2 at west (desired)
//theta=0 at south, pi/-pi at north, pi/2 at east, and -pi/2 at west (current)
///theta=0 at north, pi/-pi at south, pi/2 at east, and -pi/2 at west
pub struct Heading(pub f32);
pub fn calc_attitude(measurement: &NedMeasurement) -> Attitude {
@ -22,7 +21,6 @@ pub fn calc_attitude(measurement: &NedMeasurement) -> Attitude {
let roll = atan2f(measurement.y, measurement.z);
let pitch = atanf(-measurement.x / (measurement.y * sinf(roll) + measurement.z * cosf(roll)));
Attitude { pitch, roll }
// Attitude { pitch: 0.0, roll: 0.0 }
}
pub fn calc_tilt_calibrated_measurement(