diff --git a/arduino/leads b/arduino/leads index b2dc01f..84105d1 160000 --- a/arduino/leads +++ b/arduino/leads @@ -1 +1 @@ -Subproject commit b2dc01f5f1e07f122a26f5bc18f56dabebd35cf5 +Subproject commit 84105d10adc6e1e62c8c6b90528f3adef56eb60c diff --git a/arduino/leads_vec_wsc/leads_vec_wsc.ino b/arduino/leads_vec_wsc/leads_vec_wsc.ino index 6b1b6ce..c6e1b49 100644 --- a/arduino/leads_vec_wsc/leads_vec_wsc.ino +++ b/arduino/leads_vec_wsc/leads_vec_wsc.ino @@ -12,7 +12,7 @@ WheelSpeedSensor RFWSS{ArrayList(PIN_RFWSS, 1), [](float ws) {returnFloat(P WheelSpeedSensor LRWSS{ArrayList(PIN_LRWSS, 1), [](float ws) {returnFloat(P, LEFT_REAR_WHEEL_SPEED_SENSOR, ws);}}; WheelSpeedSensor RRWSS{ArrayList(PIN_RRWSS, 1), [](float ws) {returnFloat(P, RIGHT_REAR_WHEEL_SPEED_SENSOR, ws);}}; WheelSpeedSensor CRWSS{ArrayList(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(); diff --git a/leads/data_persistence/core.py b/leads/data_persistence/core.py index 3b7956e..6ac6f8b 100644 --- a/leads/data_persistence/core.py +++ b/leads/data_persistence/core.py @@ -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) diff --git a/leads_arduino/accelerometer.py b/leads_arduino/accelerometer.py index 8733e59..812571a 100644 --- a/leads_arduino/accelerometer.py +++ b/leads_arduino/accelerometer.py @@ -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): @@ -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) diff --git a/leads_vec/devices.py b/leads_vec/devices.py index 7f3b004..da2e74b 100644 --- a/leads_vec/devices.py +++ b/leads_vec/devices.py @@ -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 @@ -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) @@ -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) @@ -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