From 06a42a27bda90dcf29d524a375be5297f961597f Mon Sep 17 00:00:00 2001 From: ATATC Date: Fri, 16 Feb 2024 09:50:05 -0500 Subject: [PATCH] Breaking changes: wheel speed sensor now takes in argument `wheel_diameter` instead of `wheel_radius` but was actually the circumference. --- leads_arduino/wheel_speed_sensor.py | 11 ++++++----- leads_vec/controller.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/leads_arduino/wheel_speed_sensor.py b/leads_arduino/wheel_speed_sensor.py index 8ad0cc42..644aca51 100644 --- a/leads_arduino/wheel_speed_sensor.py +++ b/leads_arduino/wheel_speed_sensor.py @@ -1,21 +1,22 @@ +from math import pi as _pi from time import time as _time from leads import Device as _Device -def rpm2kmh(rpm: float, wheel_radius: float) -> float: - return rpm * wheel_radius * .0006 +def rpm2kmh(rpm: float, wheel_circumference: float) -> float: + return rpm * wheel_circumference * .0006 class WheelSpeedSensor(_Device): - def __init__(self, wheel_radius: float) -> None: + def __init__(self, wheel_diameter: int | float) -> None: super().__init__() - self._wheel_radius: float = wheel_radius + self._wheel_circumference: float = wheel_diameter * 2.54 * _pi self._wheel_speed: int | float = 0 self._last_valid: float = 0 def update(self, data: int | float) -> None: - self._wheel_speed = rpm2kmh(data, self._wheel_radius) + self._wheel_speed = rpm2kmh(data, self._wheel_circumference) self._last_valid = _time() def read(self) -> float: diff --git a/leads_vec/controller.py b/leads_vec/controller.py index 16db2f5d..0a0abe28 100644 --- a/leads_vec/controller.py +++ b/leads_vec/controller.py @@ -12,8 +12,8 @@ config = get_config(Config) BAUD_RATE: int = config.get("baud_rate", 9600) WHEEL_SPEED_CONTROLLER_PORT: str = config.get("wheel_speed_controller_port", "COM3") -FRONT_WHEEL_RADIUS: float = config.get("front_wheel_radius", 159.5) # 20 inches -REAR_WHEEL_RADIUS: float = config.get("rear_wheel_radius", 159.5) # 20 inches +FRONT_WHEEL_DIAMETER: float = config.get("front_wheel_diameter", 20) # 20 inches +REAR_WHEEL_DIAMETER: float = config.get("rear_wheel_diameter", 20) # 20 inches THROTTLE_PEDAL_PIN: int = config.get("throttle_pedal_pin", 2) BRAKE_PEDAL_PIN: int = config.get("brake_pedal_pin", 3) VOLTAGE_SENSOR_PIN: int = config.get("voltage_sensor_pin", 4) @@ -62,9 +62,9 @@ def read(self) -> [float, float, float, _Optional[float]]: RIGHT_FRONT_WHEEL_SPEED_SENSOR, CENTER_REAR_WHEEL_SPEED_SENSOR ), WHEEL_SPEED_CONTROLLER, [ - (FRONT_WHEEL_RADIUS,), - (FRONT_WHEEL_RADIUS,), - (REAR_WHEEL_RADIUS,) + (FRONT_WHEEL_DIAMETER,), + (FRONT_WHEEL_DIAMETER,), + (REAR_WHEEL_DIAMETER,) ] ) if config.srw_mode else ( ( @@ -73,10 +73,10 @@ def read(self) -> [float, float, float, _Optional[float]]: LEFT_REAR_WHEEL_SPEED_SENSOR, RIGHT_REAR_WHEEL_SPEED_SENSOR ), WHEEL_SPEED_CONTROLLER, [ - (FRONT_WHEEL_RADIUS,), - (FRONT_WHEEL_RADIUS,), - (REAR_WHEEL_RADIUS,), - (REAR_WHEEL_RADIUS,) + (FRONT_WHEEL_DIAMETER,), + (FRONT_WHEEL_DIAMETER,), + (REAR_WHEEL_DIAMETER,), + (REAR_WHEEL_DIAMETER,) ] ))) class WheelSpeedSensors(WheelSpeedSensor):