From a77b3845e0d0f380e84d7ac364b80319d89b4d29 Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Mon, 30 Oct 2023 13:22:42 -0500 Subject: [PATCH] documentation, stripped out unused functionality. --- hardware_main/src/main.rs | 6 +++--- independent_logic/src/line_drawing.rs | 14 +++++++++----- independent_logic/src/tilt_compensation.rs | 4 +--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/hardware_main/src/main.rs b/hardware_main/src/main.rs index 8c88f7b..685e480 100644 --- a/hardware_main/src/main.rs +++ b/hardware_main/src/main.rs @@ -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); diff --git a/independent_logic/src/line_drawing.rs b/independent_logic/src/line_drawing.rs index 9847782..d34c765 100644 --- a/independent_logic/src/line_drawing.rs +++ b/independent_logic/src/line_drawing.rs @@ -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 { 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 From } } +/// 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. diff --git a/independent_logic/src/tilt_compensation.rs b/independent_logic/src/tilt_compensation.rs index 423680f..fae117b 100644 --- a/independent_logic/src/tilt_compensation.rs +++ b/independent_logic/src/tilt_compensation.rs @@ -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(