Add single steering/throttle grpc methods, add bounds checks to set servo value

This commit is contained in:
Piv
2022-10-02 15:44:38 +10:30
parent de0e3e3243
commit 3daa815710
2 changed files with 20 additions and 6 deletions

View File

@@ -123,7 +123,14 @@ impl<T: SerialPort> Servo for Esp32SerialPwmServo<T> {
}
fn set_value(&mut self, value: f64) {
self.value = value;
let mut temp_value = value;
// TODO: Panic when out of bounds?
if temp_value < -1. {
temp_value = -1.;
} else if temp_value > 1. {
temp_value = 1.;
}
self.value = temp_value;
let bytes_written = self
.serial_port
.write(&[self.channel, ((value + 1.) / 2. * 255.) as u8]);
@@ -150,9 +157,8 @@ impl<T: Servo> ServoVehicle<T> {
}
impl<T: Servo> Vehicle for ServoVehicle<T> {
// TODO: Set duty cycle correctly
fn get_throttle(&self) -> f64 {
unimplemented!()
self.throttle_servo.get_value()
}
fn set_throttle(&mut self, throttle: f64) {
@@ -160,7 +166,7 @@ impl<T: Servo> Vehicle for ServoVehicle<T> {
}
fn get_steering(&self) -> f64 {
unimplemented!()
self.steering_servo.get_value()
}
fn set_steering(&mut self, steering: f64) {