From b68cfbb332af7ae9182f2806bc7b8dc46e6c8bc0 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 13 Oct 2023 23:27:04 -0700 Subject: [PATCH] cleanup old sm pm args (#30241) * cleanup sm pm * fix controlsd * fix --- selfdrive/controls/controlsd.py | 36 ++++++++++++---------------- selfdrive/controls/plannerd.py | 15 +++++------- selfdrive/locationd/laikad.py | 5 ++-- selfdrive/locationd/paramsd.py | 8 +++---- selfdrive/locationd/torqued.py | 9 +++---- selfdrive/monitoring/dmonitoringd.py | 13 ++++------ selfdrive/navd/navd.py | 8 +++---- system/micd.py | 11 ++++----- 8 files changed, 41 insertions(+), 64 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 4f3b6a912899af..d800d895d36b00 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -56,39 +56,33 @@ class Controls: - def __init__(self, sm=None, pm=None, can_sock=None, CI=None): + def __init__(self, CI=None): config_realtime_process(4, Priority.CTRL_HIGH) # Ensure the current branch is cached, otherwise the first iteration of controlsd lags self.branch = get_short_branch("") # Setup sockets - self.pm = pm - if self.pm is None: - self.pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState', - 'carControl', 'carEvents', 'carParams']) + self.pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState', + 'carControl', 'carEvents', 'carParams']) self.sensor_packets = ["accelerometer", "gyroscope"] self.camera_packets = ["roadCameraState", "driverCameraState", "wideRoadCameraState"] - self.can_sock = can_sock - if can_sock is None: - can_timeout = None if os.environ.get('NO_CAN_TIMEOUT', False) else 20 - self.can_sock = messaging.sub_sock('can', timeout=can_timeout) + can_timeout = None if os.environ.get('NO_CAN_TIMEOUT', False) else 20 + self.can_sock = messaging.sub_sock('can', timeout=can_timeout) self.log_sock = messaging.sub_sock('androidLog') self.params = Params() - self.sm = sm - if self.sm is None: - ignore = self.sensor_packets + ['testJoystick'] - if SIMULATION: - ignore += ['driverCameraState', 'managerState'] - self.sm = messaging.SubMaster(['deviceState', 'pandaStates', 'peripheralState', 'modelV2', 'liveCalibration', - 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman', - 'managerState', 'liveParameters', 'radarState', 'liveTorqueParameters', - 'testJoystick'] + self.camera_packets + self.sensor_packets, - ignore_alive=ignore, ignore_avg_freq=['radarState', 'testJoystick']) + ignore = self.sensor_packets + ['testJoystick'] + if SIMULATION: + ignore += ['driverCameraState', 'managerState'] + self.sm = messaging.SubMaster(['deviceState', 'pandaStates', 'peripheralState', 'modelV2', 'liveCalibration', + 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman', + 'managerState', 'liveParameters', 'radarState', 'liveTorqueParameters', + 'testJoystick'] + self.camera_packets + self.sensor_packets, + ignore_alive=ignore, ignore_avg_freq=['radarState', 'testJoystick']) if CI is None: # wait for one pandaState and one CAN packet @@ -879,8 +873,8 @@ def controlsd_thread(self): self.prof.display() -def main(sm=None, pm=None, logcan=None): - controls = Controls(sm, pm, logcan) +def main(): + controls = Controls() controls.controlsd_thread() diff --git a/selfdrive/controls/plannerd.py b/selfdrive/controls/plannerd.py index 2b23a0440e6f62..ed1a2fa09a2247 100755 --- a/selfdrive/controls/plannerd.py +++ b/selfdrive/controls/plannerd.py @@ -27,7 +27,7 @@ def publish_ui_plan(sm, pm, lateral_planner, longitudinal_planner): uiPlan.accel = longitudinal_planner.a_desired_trajectory_full.tolist() pm.send('uiPlan', ui_send) -def plannerd_thread(sm=None, pm=None): +def plannerd_thread(): config_realtime_process(5, Priority.CTRL_LOW) cloudlog.info("plannerd is waiting for CarParams") @@ -41,12 +41,9 @@ def plannerd_thread(sm=None, pm=None): longitudinal_planner = LongitudinalPlanner(CP) lateral_planner = LateralPlanner(CP, debug=debug_mode) - if sm is None: - sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2'], - poll=['radarState', 'modelV2'], ignore_avg_freq=['radarState']) - - if pm is None: - pm = messaging.PubMaster(['longitudinalPlan', 'lateralPlan', 'uiPlan']) + pm = messaging.PubMaster(['longitudinalPlan', 'lateralPlan', 'uiPlan']) + sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2'], + poll=['radarState', 'modelV2'], ignore_avg_freq=['radarState']) while True: sm.update() @@ -58,8 +55,8 @@ def plannerd_thread(sm=None, pm=None): longitudinal_planner.publish(sm, pm) publish_ui_plan(sm, pm, lateral_planner, longitudinal_planner) -def main(sm=None, pm=None): - plannerd_thread(sm, pm) +def main(): + plannerd_thread() if __name__ == "__main__": diff --git a/selfdrive/locationd/laikad.py b/selfdrive/locationd/laikad.py index f00595618e9913..10c0e4a7b0882b 100755 --- a/selfdrive/locationd/laikad.py +++ b/selfdrive/locationd/laikad.py @@ -440,7 +440,7 @@ def clear_tmp_cache(): os.mkdir(Paths.download_cache_root()) -def main(sm=None, pm=None): +def main(): #clear_tmp_cache() use_qcom = not Params().get_bool("UbloxAvailable") @@ -449,8 +449,7 @@ def main(sm=None, pm=None): else: raw_name = "ubloxGnss" raw_gnss_sock = messaging.sub_sock(raw_name, conflate=False) - if pm is None: - pm = messaging.PubMaster(['gnssMeasurements']) + pm = messaging.PubMaster(['gnssMeasurements']) # disable until set as main gps source, to better analyze startup time # TODO ensure low CPU usage before enabling diff --git a/selfdrive/locationd/paramsd.py b/selfdrive/locationd/paramsd.py index 93a5b47f280b85..0e779c9e3e596c 100755 --- a/selfdrive/locationd/paramsd.py +++ b/selfdrive/locationd/paramsd.py @@ -117,16 +117,14 @@ def check_valid_with_hysteresis(current_valid: bool, val: float, threshold: floa return current_valid -def main(sm=None, pm=None): +def main(): config_realtime_process([0, 1, 2, 3], 5) DEBUG = bool(int(os.getenv("DEBUG", "0"))) REPLAY = bool(int(os.getenv("REPLAY", "0"))) - if sm is None: - sm = messaging.SubMaster(['liveLocationKalman', 'carState'], poll=['liveLocationKalman']) - if pm is None: - pm = messaging.PubMaster(['liveParameters']) + pm = messaging.PubMaster(['liveParameters']) + 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 719651bcb1b18d..829f8db417697a 100755 --- a/selfdrive/locationd/torqued.py +++ b/selfdrive/locationd/torqued.py @@ -218,14 +218,11 @@ def get_msg(self, valid=True, with_points=False): return msg -def main(sm=None, pm=None): +def main(): config_realtime_process([0, 1, 2, 3], 5) - if sm is None: - sm = messaging.SubMaster(['carControl', 'carState', 'liveLocationKalman'], poll=['liveLocationKalman']) - - if pm is None: - pm = messaging.PubMaster(['liveTorqueParameters']) + pm = messaging.PubMaster(['liveTorqueParameters']) + 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/monitoring/dmonitoringd.py b/selfdrive/monitoring/dmonitoringd.py index c7cff88f3e5421..ff2ee71e745062 100755 --- a/selfdrive/monitoring/dmonitoringd.py +++ b/selfdrive/monitoring/dmonitoringd.py @@ -10,15 +10,12 @@ from openpilot.selfdrive.monitoring.driver_monitor import DriverStatus -def dmonitoringd_thread(sm=None, pm=None): +def dmonitoringd_thread(): gc.disable() set_realtime_priority(2) - if pm is None: - pm = messaging.PubMaster(['driverMonitoringState']) - - if sm is None: - sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll=['driverStateV2']) + pm = messaging.PubMaster(['driverMonitoringState']) + sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll=['driverStateV2']) driver_status = DriverStatus(rhd_saved=Params().get_bool("IsRhdDetected")) @@ -89,8 +86,8 @@ def dmonitoringd_thread(sm=None, pm=None): driver_status.wheel_on_right == (driver_status.wheelpos_learner.filtered_stat.M > driver_status.settings._WHEELPOS_THRESHOLD)): put_bool_nonblocking("IsRhdDetected", driver_status.wheel_on_right) -def main(sm=None, pm=None): - dmonitoringd_thread(sm, pm) +def main(): + dmonitoringd_thread() if __name__ == '__main__': diff --git a/selfdrive/navd/navd.py b/selfdrive/navd/navd.py index 0ccd1f144b5d13..da2b8c06b9558c 100755 --- a/selfdrive/navd/navd.py +++ b/selfdrive/navd/navd.py @@ -344,11 +344,9 @@ def should_recompute(self): # TODO: Check for going wrong way in segment -def main(sm=None, pm=None): - if sm is None: - sm = messaging.SubMaster(['liveLocationKalman', 'managerState']) - if pm is None: - pm = messaging.PubMaster(['navInstruction', 'navRoute']) +def main(): + pm = messaging.PubMaster(['navInstruction', 'navRoute']) + sm = messaging.SubMaster(['liveLocationKalman', 'managerState']) rk = Ratekeeper(1.0) route_engine = RouteEngine(sm, pm) diff --git a/system/micd.py b/system/micd.py index c7af1b0ad2ef90..72f3b8b4904f17 100755 --- a/system/micd.py +++ b/system/micd.py @@ -40,9 +40,9 @@ def apply_a_weighting(measurements: np.ndarray) -> np.ndarray: class Mic: - def __init__(self, pm): - self.pm = pm + def __init__(self): self.rk = Ratekeeper(RATE) + self.pm = messaging.PubMaster(['microphone']) self.measurements = np.empty(0) @@ -93,11 +93,8 @@ def micd_thread(self): self.update() -def main(pm=None): - if pm is None: - pm = messaging.PubMaster(['microphone']) - - mic = Mic(pm) +def main(): + mic = Mic() mic.micd_thread()