From 0b363ed8e791a37c6d49688d2ed943a7ae35e108 Mon Sep 17 00:00:00 2001 From: Gabe Venberg Date: Fri, 27 Oct 2023 11:46:03 -0500 Subject: [PATCH] code cleanup. --- src/calibration.rs | 10 +++++----- src/led.rs | 1 + src/line_drawing.rs | 12 ++++++++---- src/tilt_compensation.rs | 4 +++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/calibration.rs b/src/calibration.rs index 35ad5ba..0b0a6e7 100644 --- a/src/calibration.rs +++ b/src/calibration.rs @@ -59,7 +59,7 @@ where E: Debug, { let data = get_data(sensor, display, timer); - return calibrate(&data); + calibrate(&data) } fn get_data( @@ -124,7 +124,7 @@ where } display.show(timer, leds, 200); } - return data; + data } fn difference_square(a: Measurement, b: Measurement) -> f32 { @@ -164,9 +164,9 @@ fn calibrate(data: &[Measurement]) -> Calibration { center.z += point.z; } - center.x = center.x / data.len() as i32; - center.y = center.y / data.len() as i32; - center.z = center.z / data.len() as i32; + center.x /= data.len() as i32; + center.y /= data.len() as i32; + center.z /= data.len() as i32; let mut current = center; let mut score = measure_score(current, data); diff --git a/src/led.rs b/src/led.rs index 97d670a..0efea88 100644 --- a/src/led.rs +++ b/src/led.rs @@ -13,6 +13,7 @@ pub enum Direction { NorthWest, } +//forward is towards usb port const NORTH: [[u8; 5]; 5] = [ [0, 0, 1, 0, 0], [0, 1, 1, 1, 0], diff --git a/src/line_drawing.rs b/src/line_drawing.rs index 06ad04d..d03db08 100644 --- a/src/line_drawing.rs +++ b/src/line_drawing.rs @@ -1,6 +1,6 @@ use core::mem::swap; -pub struct Point { +struct Point { x: isize, y: isize, } @@ -9,7 +9,7 @@ impl Point { /// converts a point (representing a point on a 4 quadrant grid) into a upoint (representing a /// point on a 1 quadrant grid with the origin in the bottom-left corner). Returns none if /// the resulting point would have either number negative. - pub fn to_upoint(&self, zero_coord: &UPoint) -> Option { + fn to_upoint(&self, zero_coord: &UPoint) -> Option { Some(UPoint { x: zero_coord.x.checked_add_signed(self.x)?, y: zero_coord.y.checked_add_signed(self.y)?, @@ -17,7 +17,7 @@ impl Point { } } -pub struct UPoint { +struct UPoint { x: usize, y: usize, } @@ -33,7 +33,7 @@ impl UPoint { } } -pub fn draw_line( +fn draw_line( mut p0: Point, mut p1: Point, matrix: &mut [[u8; X]; Y], @@ -70,3 +70,7 @@ pub fn draw_line( } } } + +fn heading_to_sector(sectors: u8, heading: f32) -> u8 { + todo!() +} diff --git a/src/tilt_compensation.rs b/src/tilt_compensation.rs index 644ee4e..5dce79e 100644 --- a/src/tilt_compensation.rs +++ b/src/tilt_compensation.rs @@ -14,7 +14,8 @@ pub struct NedMeasurement { pub z: f32, } -//theta=0 at north, pi/-pi at south, pi/2 at east, and -pi/2 at west +//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) pub struct Heading(pub f32); /// board has forward in the -y direction and right in the -x direction, and down in the -z. (SWU), algs for tilt compensation @@ -57,6 +58,7 @@ pub fn calc_tilt_calibrated_measurement( } } +//0 is the top sector and positive is clockwise, negative is counterclockwise. pub fn heading_from_measurement(measurement: NedMeasurement) -> Heading { Heading(atan2f(-measurement.y, measurement.x)) }