Skip to content

Commit

Permalink
Detect the Absence of Devices during the Initialization of the Main C…
Browse files Browse the repository at this point in the history
…ontroller and Notify the SFT (#264)

* Bug fixed: incorrect `mark_device()` logic. (#263)

* Bug fixed: incorrect `mark_device()` logic. (#263)

* Added absence of devices detection. (#263)
  • Loading branch information
ATATC authored Jul 6, 2024
1 parent 51211d4 commit 08cdfea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
9 changes: 4 additions & 5 deletions leads/sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from leads.registry import require_context


def mark_device(device: Device, system: str, *related: str) -> None:
if hasattr(device, "__device_system__"):
setattr(device, "__device_system__", getattr(device, "__device_system__") + related)
setattr(device, "__device_system__", [system, *related])
def mark_device(device: Device, system: str, *related: str, append: bool = True) -> None:
setattr(device, "__sft_marker__", getattr(device, "__sft_marker__") + [system, *related] if append and hasattr(
device, "__sft_marker__") else [system, *related])


def read_device_marker(device: Device) -> list[str] | None:
return getattr(device, "__device_system__") if hasattr(device, "__device_system__") else None
return getattr(device, "__sft_marker__") if hasattr(device, "__sft_marker__") else None


class SystemFailureTracer(object):
Expand Down
2 changes: 1 addition & 1 deletion leads_vec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def on_recover(e: SuspensionEvent) -> None:
layout = [
["m1", "m2", "m3"],
["left", "time_lap", "hazard", "right"],
["battery_fault", "brake_fault", "esc_fault", "gps_fault", "motor_fault", "wsc_fault"],
["battery_fault", "brake_fault", "esc_fault", "gps_fault", "light_fault", "motor_fault", "wsc_fault"],
[*map(lambda s: f"{s.lower()}_status", SystemLiteral), "comm_status"],
list(map(lambda s: s.lower(), SystemLiteral)),
["esc"]
Expand Down
30 changes: 28 additions & 2 deletions leads_vec/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from leads import device, controller, MAIN_CONTROLLER, LEFT_FRONT_WHEEL_SPEED_SENSOR, RIGHT_FRONT_WHEEL_SPEED_SENSOR, \
Controller, CENTER_REAR_WHEEL_SPEED_SENSOR, require_config, mark_device, ODOMETER, GPS_RECEIVER, \
ConcurrentOdometer, LEFT_INDICATOR, RIGHT_INDICATOR, VOLTAGE_SENSOR, DataContainer, get_device, has_device, \
FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA, REAR_VIEW_CAMERA, VisualDataContainer, BRAKE_INDICATOR
FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA, REAR_VIEW_CAMERA, VisualDataContainer, BRAKE_INDICATOR, \
SFT, read_device_marker, has_controller
from leads_arduino import ArduinoMicro, WheelSpeedSensor, VoltageSensor
from leads_gui import Config
from leads_raspberry_pi import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition
Expand All @@ -24,6 +25,26 @@

@controller(MAIN_CONTROLLER)
class VeCController(Controller):
@override
def initialize(self, *parent_tags: str) -> None:
super().initialize(*parent_tags)
if not has_controller("pc"):
mark_device(self, "POWER", "BATT", "MOTOR", "BRAKE")
if not has_controller("wsc"):
mark_device(self, "WSC", "ESC")
if not has_device(ODOMETER):
mark_device(self, "WSC")
if not has_device(GPS_RECEIVER):
mark_device(self, "GPS")
if not has_device(BRAKE_INDICATOR):
mark_device(self, "LIGHT")
if not has_device(LEFT_INDICATOR):
mark_device(self, "LIGHT")
if not has_device(RIGHT_INDICATOR):
mark_device(self, "LIGHT")
if read_device_marker(self):
SFT.fail(self, RuntimeError("Unexpected system integrity"))

@override
def read(self) -> DataContainer:
general = {
Expand Down Expand Up @@ -51,7 +72,7 @@ def read(self) -> DataContainer:
class PowerController(ArduinoMicro):
@override
def initialize(self, *parent_tags: str) -> None:
mark_device(self, "POWER", "BATT", "MOTOR")
mark_device(self, "POWER", "BATT", "MOTOR", "BRAKE")
super().initialize(*parent_tags)

@override
Expand Down Expand Up @@ -89,6 +110,11 @@ def read(self) -> dict[str, float]:

@device(ODOMETER, MAIN_CONTROLLER)
class AverageOdometer(ConcurrentOdometer):
@override
def initialize(self, *parent_tags: str) -> None:
mark_device(self, "WSC")
super().initialize(*parent_tags)

@override
def read(self) -> float:
return super().read() / 3
Expand Down

0 comments on commit 08cdfea

Please sign in to comment.