From 279d2c3b2319bab73bbc9ed103911b6df3b0dc02 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 12 Feb 2024 10:11:37 -0800 Subject: [PATCH] SubMaster: improve service aliveness checks (#31391) * bump cereal * fix * fixes * single poll * bump * bump --------- Co-authored-by: Comma Device --- cereal | 2 +- selfdrive/controls/controlsd.py | 4 +++- selfdrive/controls/plannerd.py | 3 +-- selfdrive/locationd/calibrationd.py | 2 +- selfdrive/locationd/paramsd.py | 2 +- selfdrive/locationd/torqued.py | 2 +- selfdrive/manager/manager.py | 4 ++-- selfdrive/monitoring/dmonitoringd.py | 2 +- selfdrive/thermald/thermald.py | 2 +- system/webrtc/tests/test_webrtcd.py | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cereal b/cereal index e2811732e6..9b573c2be3 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit e2811732e6d4865a1e7430810a318a161afc5b4f +Subproject commit 9b573c2be34b638ff462648308d3c7075d0ff174 diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index a75addc3bf..4af584a9d2 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -80,7 +80,8 @@ class Controls: 'driverMonitoringState', 'longitudinalPlan', 'liveLocationKalman', 'managerState', 'liveParameters', 'radarState', 'liveTorqueParameters', 'testJoystick'] + self.camera_packets + self.sensor_packets, - ignore_alive=ignore, ignore_avg_freq=['radarState', 'testJoystick'], ignore_valid=['testJoystick', ]) + ignore_alive=ignore, ignore_avg_freq=ignore+['radarState', 'testJoystick'], ignore_valid=['testJoystick', ], + frequency=int(1/DT_CTRL)) if CI is None: # wait for one pandaState and one CAN packet @@ -452,6 +453,7 @@ class Controls: invalid=[s for s, valid in self.sm.valid.items() if not valid], not_alive=[s for s, alive in self.sm.alive.items() if not alive], not_freq_ok=[s for s, freq_ok in self.sm.freq_ok.items() if not freq_ok], + error=True, ) # Check for CAN timeout diff --git a/selfdrive/controls/plannerd.py b/selfdrive/controls/plannerd.py index 5ab4894424..eeeeda050e 100755 --- a/selfdrive/controls/plannerd.py +++ b/selfdrive/controls/plannerd.py @@ -29,11 +29,10 @@ def plannerd_thread(): longitudinal_planner = LongitudinalPlanner(CP) pm = messaging.PubMaster(['longitudinalPlan', 'uiPlan']) sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2'], - poll=['radarState', 'modelV2'], ignore_avg_freq=['radarState']) + poll='modelV2', ignore_avg_freq=['radarState']) while True: sm.update() - if sm.updated['modelV2']: longitudinal_planner.update(sm) longitudinal_planner.publish(sm, pm) diff --git a/selfdrive/locationd/calibrationd.py b/selfdrive/locationd/calibrationd.py index 06be9f031a..da1c4ec37b 100755 --- a/selfdrive/locationd/calibrationd.py +++ b/selfdrive/locationd/calibrationd.py @@ -260,7 +260,7 @@ def main() -> NoReturn: set_realtime_priority(1) pm = messaging.PubMaster(['liveCalibration']) - sm = messaging.SubMaster(['cameraOdometry', 'carState', 'carParams'], poll=['cameraOdometry']) + sm = messaging.SubMaster(['cameraOdometry', 'carState', 'carParams'], poll='cameraOdometry') calibrator = Calibrator(param_put=True) diff --git a/selfdrive/locationd/paramsd.py b/selfdrive/locationd/paramsd.py index 183a8666e8..d124eb5f05 100755 --- a/selfdrive/locationd/paramsd.py +++ b/selfdrive/locationd/paramsd.py @@ -124,7 +124,7 @@ def main(): REPLAY = bool(int(os.getenv("REPLAY", "0"))) pm = messaging.PubMaster(['liveParameters']) - sm = messaging.SubMaster(['liveLocationKalman', 'carState'], poll=['liveLocationKalman']) + sm = messaging.SubMaster(['liveLocationKalman', 'carState'], poll='liveLocationKalman') params_reader = Params() # wait for stats about the car to come in from controls diff --git a/selfdrive/locationd/torqued.py b/selfdrive/locationd/torqued.py index f2c0248afa..51418f9c1e 100755 --- a/selfdrive/locationd/torqued.py +++ b/selfdrive/locationd/torqued.py @@ -218,7 +218,7 @@ def main(demo=False): config_realtime_process([0, 1, 2, 3], 5) pm = messaging.PubMaster(['liveTorqueParameters']) - sm = messaging.SubMaster(['carControl', 'carState', 'liveLocationKalman'], poll=['liveLocationKalman']) + sm = messaging.SubMaster(['carControl', 'carState', 'liveLocationKalman'], poll='liveLocationKalman') params = Params() with car.CarParams.from_bytes(params.get("CarParams", block=True)) as CP: diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index ddc1200cbc..50ba73f18c 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -127,7 +127,7 @@ def manager_thread() -> None: ignore.append("pandad") ignore += [x for x in os.getenv("BLOCK", "").split(",") if len(x) > 0] - sm = messaging.SubMaster(['deviceState', 'carParams'], poll=['deviceState']) + sm = messaging.SubMaster(['deviceState', 'carParams'], poll='deviceState') pm = messaging.PubMaster(['managerState']) write_onroad_params(False, params) @@ -136,7 +136,7 @@ def manager_thread() -> None: started_prev = False while True: - sm.update() + sm.update(1000) started = sm['deviceState'].started diff --git a/selfdrive/monitoring/dmonitoringd.py b/selfdrive/monitoring/dmonitoringd.py index 8e68c0e3bc..579e79093f 100755 --- a/selfdrive/monitoring/dmonitoringd.py +++ b/selfdrive/monitoring/dmonitoringd.py @@ -15,7 +15,7 @@ def dmonitoringd_thread(): params = Params() pm = messaging.PubMaster(['driverMonitoringState']) - sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll=['driverStateV2']) + sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll='driverStateV2') driver_status = DriverStatus(rhd_saved=params.get_bool("IsRhdDetected")) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index abe686903b..bfca2ccabb 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -166,7 +166,7 @@ def hw_state_thread(end_event, hw_queue): def thermald_thread(end_event, hw_queue) -> None: pm = messaging.PubMaster(['deviceState']) - sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates"], poll=["pandaStates"]) + sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates"], poll="pandaStates") count = 0 diff --git a/system/webrtc/tests/test_webrtcd.py b/system/webrtc/tests/test_webrtcd.py index b48bf6bc19..e92958cc92 100755 --- a/system/webrtc/tests/test_webrtcd.py +++ b/system/webrtc/tests/test_webrtcd.py @@ -24,7 +24,7 @@ class TestWebrtcdProc(unittest.IsolatedAsyncioTestCase): async def test_webrtcd(self): mock_request = MagicMock() async def connect(offer): - body = {'sdp': offer.sdp, 'cameras': offer.video, 'bridge_services_in': [], 'bridge_services_out': []} + body = {'sdp': offer.sdp, 'cameras': offer.video, 'bridge_services_in': [], 'bridge_services_out': ['carState']} mock_request.json.side_effect = AsyncMock(return_value=body) response = await get_stream(mock_request) response_json = json.loads(response.text)