Fix for motor duty cycle not obeying direction

motor-and-encoder
ZodiusInfuser 2022-05-10 18:34:59 +01:00
rodzic 71f0ea76ed
commit b26d13bab1
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -31,7 +31,7 @@ namespace motor {
}
float MotorState::get_duty() const {
return last_enabled_duty;
return (motor_direction == NORMAL_DIR) ? last_enabled_duty : 0.0f - last_enabled_duty;
}
float MotorState::get_deadzoned_duty() const {
@ -47,6 +47,10 @@ namespace motor {
}
float MotorState::set_duty_with_return(float duty) {
// Invert provided speed if the motor direction is reversed
if(motor_direction == REVERSED_DIR)
duty = 0.0f - duty;
// Clamp the duty between the hard limits
last_enabled_duty = CLAMP(duty, -1.0f, 1.0f);