Skip to content

Commit

Permalink
Breaking changes: wheel speed sensor now takes in argument `wheel_dia…
Browse files Browse the repository at this point in the history
…meter` instead of `wheel_radius` but was actually the circumference.
  • Loading branch information
ATATC committed Feb 16, 2024
1 parent ae3c1c0 commit 06a42a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
11 changes: 6 additions & 5 deletions leads_arduino/wheel_speed_sensor.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
18 changes: 9 additions & 9 deletions leads_vec/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
(
Expand All @@ -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):
Expand Down

0 comments on commit 06a42a2

Please sign in to comment.