Skip to content

Commit

Permalink
Merge branch 'main' into 401
Browse files Browse the repository at this point in the history
Signed-off-by: Tianhao (Terry) Fu <[email protected]>
  • Loading branch information
ATATC authored Sep 27, 2024
2 parents e4f7f2e + 329ee6d commit 86ef1db
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion arduino/leads
2 changes: 1 addition & 1 deletion arduino/leads_vec_wsc/leads_vec_wsc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WheelSpeedSensor RFWSS{ArrayList<int>(PIN_RFWSS, 1), [](float ws) {returnFloat(P
WheelSpeedSensor LRWSS{ArrayList<int>(PIN_LRWSS, 1), [](float ws) {returnFloat(P, LEFT_REAR_WHEEL_SPEED_SENSOR, ws);}};
WheelSpeedSensor RRWSS{ArrayList<int>(PIN_RRWSS, 1), [](float ws) {returnFloat(P, RIGHT_REAR_WHEEL_SPEED_SENSOR, ws);}};
WheelSpeedSensor CRWSS{ArrayList<int>(PIN_CRWSS, 1), [](float ws) {returnFloat(P, CENTER_REAR_WHEEL_SPEED_SENSOR, ws);}};
Accelerometer ACCL{[](Acceleration acceleration) {returnString(acceleration.toString());}};
Accelerometer ACCL{[](Acceleration acceleration) {returnString(P, ACCELEROMETER, acceleration.toString());}};

void setup() {
P.initializeAsRoot();
Expand Down
4 changes: 2 additions & 2 deletions leads/data_persistence/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from leads.types import Compressor as _Compressor, VisualHeader as _VisualHeader, \
VisualHeaderFull as _VisualHeaderFull, DefaultHeaderFull as _DefaultHeaderFull, DefaultHeader as _DefaultHeader
from ._computational import array as _array, norm as _norm, read_csv as _read_csv, DataFrame as _DataFrame, \
TextFileReader as _TextFileReader, sum_up as _sum_up, diff as _diff
from ._computational import mean as _mean, array as _array, norm as _norm, read_csv as _read_csv, \
DataFrame as _DataFrame, TextFileReader as _TextFileReader

T = _TypeVar("T", bound=_SupportsFloat)

Expand Down
17 changes: 14 additions & 3 deletions leads_arduino/accelerometer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from dataclasses import dataclass as _dataclass
from typing import override as _override

from leads import Device as _Device
from leads import Device as _Device, Serializable as _Serializable


@_dataclass
class Acceleration(_Serializable):
yaw: float
pitch: float
roll: float
forward_acceleration: float
lateral_acceleration: float
vertical_acceleration: float


class Accelerometer(_Device):
Expand All @@ -18,5 +29,5 @@ def update(self, data: str) -> None:
self._yaw, self._pitch, self._roll, self._fa, self._la, self._va = tuple(map(float, data.split(',')))

@_override
def read(self) -> tuple[float, float, float, float, float, float]:
return self._yaw, self._pitch, self._roll, self._fa, self._la, self._va
def read(self) -> Acceleration:
return Acceleration(self._yaw, self._pitch, self._roll, self._fa, self._la, self._va)
20 changes: 15 additions & 5 deletions leads_vec/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Controller, CENTER_REAR_WHEEL_SPEED_SENSOR, require_config, mark_device, ODOMETER, GPS_RECEIVER, \
ConcurrentOdometer, LEFT_INDICATOR, RIGHT_INDICATOR, VOLTAGE_SENSOR, DataContainer, has_device, \
FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA, REAR_VIEW_CAMERA, VisualDataContainer, BRAKE_INDICATOR, \
SFT, read_device_marker, has_controller, POWER_CONTROLLER, WHEEL_SPEED_CONTROLLER
from leads_arduino import ArduinoMicro, WheelSpeedSensor, VoltageSensor
SFT, read_device_marker, has_controller, POWER_CONTROLLER, WHEEL_SPEED_CONTROLLER, ACCELEROMETER
from leads_arduino import ArduinoMicro, WheelSpeedSensor, VoltageSensor, Accelerometer
from leads_gpio import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition
from leads_vec.config import Config
from leads_video import Base64Camera, get_camera
Expand Down Expand Up @@ -57,7 +57,9 @@ def read(self) -> DataContainer:
"longitude": gps[3],
**self.device(POWER_CONTROLLER).read()
}
wsc = {"speed": gps[0]} if GPS_ONLY else self.device(WHEEL_SPEED_CONTROLLER).read()
wsc = self.device(WHEEL_SPEED_CONTROLLER).read()
if GPS_ONLY:
wsc["speed"] = gps[1]
visual = {}
if has_device(FRONT_VIEW_CAMERA):
cam = get_camera(FRONT_VIEW_CAMERA, Base64Camera)
Expand Down Expand Up @@ -113,9 +115,9 @@ def initialize(self, *parent_tags: str) -> None:
def read(self) -> dict[str, float]:
lfws = self.device(LEFT_FRONT_WHEEL_SPEED_SENSOR).read()
rfws = self.device(RIGHT_FRONT_WHEEL_SPEED_SENSOR).read()
front_wheel_speed = (lfws + rfws) * .5
return {"speed": min(lfws, rfws, rws := self.device(CENTER_REAR_WHEEL_SPEED_SENSOR).read()),
"front_wheel_speed": front_wheel_speed, "rear_wheel_speed": rws}
"front_wheel_speed": (lfws + rfws) * .5, "rear_wheel_speed": rws,
**self.device(ACCELEROMETER).read().to_dict()}


@device(ODOMETER, MAIN_CONTROLLER)
Expand All @@ -141,6 +143,14 @@ def initialize(self, *parent_tags: str) -> None:
super().initialize(*parent_tags)


@device(ACCELEROMETER, WHEEL_SPEED_CONTROLLER)
class Accele(Accelerometer):
@override
def initialize(self, *parent_tags: str) -> None:
mark_device(self, "WSC", "ESC")
super().initialize(*parent_tags)


@device(GPS_RECEIVER, MAIN_CONTROLLER, (GPS_RECEIVER_PORT,))
class GPS(NMEAGPSReceiver):
@override
Expand Down

0 comments on commit 86ef1db

Please sign in to comment.