Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect the Absence of Devices during the Initialization of the Main Controller and Notify the SFT #264

Merged
merged 3 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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