From b3cf76c623ba14fc5141cdbedd907119648780f9 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 12 Sep 2023 02:16:38 -0700 Subject: [PATCH 01/19] bump pandaStates to 10Hz --- cereal | 2 +- selfdrive/boardd/boardd.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cereal b/cereal index 4b334f6f10877e..283799bee3d28c 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 4b334f6f10877e4a666b23983de2d27934ebf3b1 +Subproject commit 283799bee3d28cddc5aa87180ee26c1b0fb307ff diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index b64a81296ea5d6..4f298cbe1669a0 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -472,8 +472,8 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { LOGD("start panda state thread"); - // run at 2hz - RateKeeper rk("panda_state_thread", 2); + // run at 10hz + RateKeeper rk("panda_state_thread", 10); while (!do_exit && check_all_connected(pandas)) { // send out peripheralState From 8769682bf6febbdb0d47766dc153c282ae162137 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 12 Sep 2023 02:19:11 -0700 Subject: [PATCH 02/19] run thermald at 2 Hz --- selfdrive/thermald/thermald.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 32cfe11c39b7f3..38515dd1cfaf48 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -33,7 +33,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_TIMEOUT = int(1000 * 1.5 * DT_TRML) # 1.5x the expected pandaState frequency +PANDA_STATES_TIMEOUT = int(100 * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -210,6 +210,10 @@ def thermald_thread(end_event, hw_queue) -> None: while not end_event.is_set(): sm.update(PANDA_STATES_TIMEOUT) + # Run at 2Hz + if sm.frame % 5 != 0: + continue + pandaStates = sm['pandaStates'] peripheralState = sm['peripheralState'] peripheral_panda_present = peripheralState.pandaType != log.PandaState.PandaType.unknown From 82017201f397f35c3ae225f42949b5f3d39a46f7 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 12 Sep 2023 02:22:42 -0700 Subject: [PATCH 03/19] use service list for freq --- cereal | 2 +- selfdrive/thermald/thermald.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cereal b/cereal index 283799bee3d28c..8c4c2222140694 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 283799bee3d28cddc5aa87180ee26c1b0fb307ff +Subproject commit 8c4c2222140694347617a99f7e9ec8cfa012019a diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 38515dd1cfaf48..db32b8ce5b3c65 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -13,6 +13,7 @@ import cereal.messaging as messaging from cereal import log +from cereal.services import SERVICE_LIST from openpilot.common.dict_helpers import strip_deprecated_keys from openpilot.common.time import MIN_DATE from openpilot.common.filter_simple import FirstOrderFilter @@ -33,7 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_TIMEOUT = int(100 * 1.5) # 1.5x the expected pandaState frequency +PANDA_STATES_TIMEOUT = int(1000 / SERVICE_LIST['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', From 4a9d8ef79574fe2d4dbb5f55a0717efda845c27f Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 12 Sep 2023 02:23:54 -0700 Subject: [PATCH 04/19] even better --- selfdrive/thermald/thermald.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index db32b8ce5b3c65..beb059c560e6c5 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -34,7 +34,8 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_TIMEOUT = int(1000 / SERVICE_LIST['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency +PANDA_STATES_FREQUENCY = SERVICE_LIST['pandaStates'].frequency +PANDA_STATES_TIMEOUT = round(1000 / PANDA_STATES_FREQUENCY * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -212,7 +213,7 @@ def thermald_thread(end_event, hw_queue) -> None: sm.update(PANDA_STATES_TIMEOUT) # Run at 2Hz - if sm.frame % 5 != 0: + if sm.frame % round(PANDA_STATES_FREQUENCY / 2) != 0: continue pandaStates = sm['pandaStates'] From e06d70a82919f8add75a628388d478922897e3dc Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 12 Sep 2023 04:05:30 -0700 Subject: [PATCH 05/19] fix import --- cereal | 2 +- selfdrive/athena/athenad.py | 4 ++-- selfdrive/controls/lib/events.py | 4 ++-- selfdrive/debug/check_lag.py | 4 ++-- selfdrive/debug/count_events.py | 6 +++--- selfdrive/debug/dump.py | 4 ++-- selfdrive/debug/internal/qlog_size.py | 4 ++-- selfdrive/locationd/test/test_locationd.py | 6 +++--- selfdrive/test/process_replay/process_replay.py | 6 +++--- selfdrive/test/profiling/lib.py | 4 ++-- selfdrive/test/test_onroad.py | 6 +++--- system/camerad/test/test_camerad.py | 6 +++--- system/hardware/tici/tests/test_power_draw.py | 4 ++-- system/loggerd/tests/test_loggerd.py | 12 ++++++------ system/sensord/tests/test_pigeond.py | 6 +++--- system/sensord/tests/test_sensord.py | 4 ++-- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cereal b/cereal index 8c4c2222140694..841798768d00d2 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 8c4c2222140694347617a99f7e9ec8cfa012019a +Subproject commit 841798768d00d2e15b4fab41c15a293f5e2a6458 diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 899605d989dbf4..82c00b3bf200ae 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -29,7 +29,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.api import Api from openpilot.common.basedir import PERSIST from openpilot.common.file_helpers import CallbackReader @@ -309,7 +309,7 @@ def _do_upload(upload_item: UploadItem, callback: Optional[Callable] = None) -> # security: user should be able to request any message from their car @dispatcher.add_method def getMessage(service: str, timeout: int = 1000) -> dict: - if service is None or service not in service_list: + if service is None or service not in SERVICE_LIST: raise Exception("invalid service") socket = messaging.sub_sock(service, timeout=timeout) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index 81e55e6bbcced4..a00b8277def491 100755 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -969,7 +969,7 @@ def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, if __name__ == '__main__': # print all alerts by type and priority - from cereal.services import service_list + from cereal.services import SERVICE_LIST from collections import defaultdict, OrderedDict event_names = {v: k for k, v in EventName.schema.enumerants.items()} @@ -977,7 +977,7 @@ def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, CP = car.CarParams.new_message() CS = car.CarState.new_message() - sm = messaging.SubMaster(list(service_list.keys())) + sm = messaging.SubMaster(list(SERVICE_LIST.keys())) for i, alerts in EVENTS.items(): for et, alert in alerts.items(): diff --git a/selfdrive/debug/check_lag.py b/selfdrive/debug/check_lag.py index 141156db913934..72d11d6eda5e1d 100755 --- a/selfdrive/debug/check_lag.py +++ b/selfdrive/debug/check_lag.py @@ -2,7 +2,7 @@ from typing import Dict import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICE_LIST TO_CHECK = ['carState'] @@ -20,7 +20,7 @@ t = sm.logMonoTime[s] / 1e9 if s in prev_t: - expected = 1.0 / (service_list[s].frequency) + expected = 1.0 / (SERVICE_LIST[s].frequency) dt = t - prev_t[s] if dt > 10 * expected: print(t, s, dt) diff --git a/selfdrive/debug/count_events.py b/selfdrive/debug/count_events.py index a8af5e6fe9d51b..a148996d94a58a 100755 --- a/selfdrive/debug/count_events.py +++ b/selfdrive/debug/count_events.py @@ -7,7 +7,7 @@ from tqdm import tqdm from typing import List, Tuple, cast -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.tools.lib.route import Route from openpilot.tools.lib.logreader import LogReader @@ -17,7 +17,7 @@ cnt_valid: Counter = Counter() cnt_events: Counter = Counter() - cams = [s for s in service_list if s.endswith('CameraState')] + cams = [s for s in SERVICE_LIST if s.endswith('CameraState')] cnt_cameras = dict.fromkeys(cams, 0) alerts: List[Tuple[float, str]] = [] @@ -62,7 +62,7 @@ print("\n") print("Cameras") for k, v in cnt_cameras.items(): - s = service_list[k] + s = SERVICE_LIST[k] expected_frames = int(s.frequency * duration / cast(float, s.decimation)) print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected") diff --git a/selfdrive/debug/dump.py b/selfdrive/debug/dump.py index 8436fbd0b07111..db18f4c6228e0a 100755 --- a/selfdrive/debug/dump.py +++ b/selfdrive/debug/dump.py @@ -8,7 +8,7 @@ from hexdump import hexdump from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST codecs.register_error("strict", codecs.backslashreplace_errors) @@ -31,7 +31,7 @@ poller = messaging.Poller() - for m in args.socket if len(args.socket) > 0 else service_list: + for m in args.socket if len(args.socket) > 0 else SERVICE_LIST: messaging.sub_sock(m, poller, addr=args.addr) values = None diff --git a/selfdrive/debug/internal/qlog_size.py b/selfdrive/debug/internal/qlog_size.py index 9b7f3695258b8f..b51cb3af2fc145 100755 --- a/selfdrive/debug/internal/qlog_size.py +++ b/selfdrive/debug/internal/qlog_size.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.route import Route @@ -49,7 +49,7 @@ def make_pie(msgs, typ): msgs_by_type[m.which()].append(m.as_builder().to_bytes()) qlog_by_type = defaultdict(list) - for name, service in service_list.items(): + for name, service in SERVICE_LIST.items(): if service.decimation is None: continue diff --git a/selfdrive/locationd/test/test_locationd.py b/selfdrive/locationd/test/test_locationd.py index 99047c37f306a9..707fdd743f7de0 100755 --- a/selfdrive/locationd/test/test_locationd.py +++ b/selfdrive/locationd/test/test_locationd.py @@ -6,7 +6,7 @@ import capnp import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.params import Params from openpilot.common.transformations.coordinates import ecef2geodetic @@ -74,8 +74,8 @@ def test_params_gps(self): msgs = [] for sec in range(65): for name in self.LLD_MSGS: - for j in range(int(service_list[name].frequency)): - msgs.append(self.get_msg(name, int((sec + j / service_list[name].frequency) * 1e9))) + for j in range(int(SERVICE_LIST[name].frequency)): + msgs.append(self.get_msg(name, int((sec + j / SERVICE_LIST[name].frequency) * 1e9))) for msg in sorted(msgs, key=lambda x: x.logMonoTime): self.pm.send(msg.which(), msg) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index eb49d0dedb751f..753262af12bae3 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -14,7 +14,7 @@ import cereal.messaging as messaging from cereal import car -from cereal.services import service_list +from cereal.services import SERVICE_LIST from cereal.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name from openpilot.common.params import Params from openpilot.common.prefix import OpenpilotPrefix @@ -364,7 +364,7 @@ def controlsd_rcv_callback(msg, cfg, frame): socks = [ s for s in cfg.subs if - frame % int(service_list[msg.which()].frequency / service_list[s].frequency) == 0 + frame % int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency) == 0 ] if "sendcan" in socks and (frame - 1) < 2000: socks.remove("sendcan") @@ -428,7 +428,7 @@ def __call__(self, msg, cfg, frame): resp_sockets = [ s for s in cfg.subs - if frame % max(1, int(service_list[msg.which()].frequency / service_list[s].frequency)) == 0 + if frame % max(1, int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency)) == 0 ] return bool(len(resp_sockets)) diff --git a/selfdrive/test/profiling/lib.py b/selfdrive/test/profiling/lib.py index 843bf52211b6f5..7f3b0126fffd49 100644 --- a/selfdrive/test/profiling/lib.py +++ b/selfdrive/test/profiling/lib.py @@ -1,5 +1,5 @@ from collections import defaultdict, deque -from cereal.services import service_list +from cereal.services import SERVICE_LIST import cereal.messaging as messaging import capnp @@ -67,7 +67,7 @@ def __init__(self, msgs, trigger, services, check_averag_freq=False): self.msgs = list(reversed(self.msgs)) for s in services: - self.freq[s] = service_list[s].frequency + self.freq[s] = SERVICE_LIST[s].frequency try: data = messaging.new_message(s) except capnp.lib.capnp.KjException: diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 553ef1afa61f1b..894ab15c1257ae 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -13,7 +13,7 @@ from cereal import car import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.basedir import BASEDIR from openpilot.common.timeout import Timeout from openpilot.common.params import Params @@ -179,7 +179,7 @@ def test_service_frequencies(self): continue with self.subTest(service=s): - assert len(msgs) >= math.floor(service_list[s].frequency*55) + assert len(msgs) >= math.floor(SERVICE_LIST[s].frequency*55) def test_cloudlog_size(self): msgs = [m for m in self.lr if m.which() == 'logMessage'] @@ -356,7 +356,7 @@ def test_timings(self): raise Exception(f"missing {s}") ts = np.diff(msgs) / 1e9 - dt = 1 / service_list[s].frequency + dt = 1 / SERVICE_LIST[s].frequency try: np.testing.assert_allclose(np.mean(ts), dt, rtol=0.03, err_msg=f"{s} - failed mean timing check") diff --git a/system/camerad/test/test_camerad.py b/system/camerad/test/test_camerad.py index b2aca850d1fa58..b680c1df67446d 100755 --- a/system/camerad/test/test_camerad.py +++ b/system/camerad/test/test_camerad.py @@ -6,7 +6,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.system.hardware import TICI @@ -43,10 +43,10 @@ def setUpClass(cls): for cam, msgs in cls.logs.items(): if cls.sensor_type is None: cls.sensor_type = getattr(msgs[0], msgs[0].which()).sensor.raw - expected_frames = service_list[cam].frequency * TEST_TIMESPAN + expected_frames = SERVICE_LIST[cam].frequency * TEST_TIMESPAN assert expected_frames*0.95 < len(msgs) < expected_frames*1.05, f"unexpected frame count {cam}: {expected_frames=}, got {len(msgs)}" - dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/service_list[cam].frequency) + dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/SERVICE_LIST[cam].frequency) assert (dts < FRAME_DELTA_TOLERANCE[cls.sensor_type]).all(), f"{cam} dts(ms) out of spec: max diff {dts.max()}, 99 percentile {np.percentile(dts, 99)}" for m in msgs: diff --git a/system/hardware/tici/tests/test_power_draw.py b/system/hardware/tici/tests/test_power_draw.py index fbca95f6f6b11c..1409e43cfbc52c 100755 --- a/system/hardware/tici/tests/test_power_draw.py +++ b/system/hardware/tici/tests/test_power_draw.py @@ -8,7 +8,7 @@ from typing import List import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.system.hardware import HARDWARE, TICI from openpilot.system.hardware.tici.power_monitor import get_power from openpilot.selfdrive.manager.process_config import managed_processes @@ -91,7 +91,7 @@ def test_camera_procs(self): cur = used[proc.name] expected = proc.power msgs_received = sum(msg_counts[msg] for msg in proc.msgs) - msgs_expected = int(sum(SAMPLE_TIME * service_list[msg].frequency for msg in proc.msgs)) + msgs_expected = int(sum(SAMPLE_TIME * SERVICE_LIST[msg].frequency for msg in proc.msgs)) tab.append([proc.name, round(expected, 2), round(cur, 2), msgs_expected, msgs_received]) with self.subTest(proc=proc.name): self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol)) diff --git a/system/loggerd/tests/test_loggerd.py b/system/loggerd/tests/test_loggerd.py index 3ea29b0d827d11..9d7d3fa7bd99ba 100755 --- a/system/loggerd/tests/test_loggerd.py +++ b/system/loggerd/tests/test_loggerd.py @@ -12,7 +12,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params from openpilot.common.timeout import Timeout @@ -27,8 +27,8 @@ SentinelType = log.Sentinel.SentinelType -CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in service_list - and service_list[f].should_log and "encode" not in f.lower()] +CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in SERVICE_LIST + and SERVICE_LIST[f].should_log and "encode" not in f.lower()] class TestLoggerd(unittest.TestCase): @@ -219,8 +219,8 @@ def test_bootlog(self): self.assertEqual(expected_val, bootlog_val) def test_qlog(self): - qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is not None] - no_qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is None] + qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is not None] + no_qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is None] services = random.sample(qlog_services, random.randint(2, min(10, len(qlog_services)))) + \ random.sample(no_qlog_services, random.randint(2, min(10, len(no_qlog_services)))) @@ -245,7 +245,7 @@ def test_qlog(self): self.assertEqual(recv_cnt, 0, f"got {recv_cnt} {s} msgs in qlog") else: # check logged message count matches decimation - expected_cnt = (len(msgs) - 1) // service_list[s].decimation + 1 + expected_cnt = (len(msgs) - 1) // SERVICE_LIST[s].decimation + 1 self.assertEqual(recv_cnt, expected_cnt, f"expected {expected_cnt} msgs for {s}, got {recv_cnt}") def test_rlog(self): diff --git a/system/sensord/tests/test_pigeond.py b/system/sensord/tests/test_pigeond.py index 90cbf063406348..b23afcb07c737b 100755 --- a/system/sensord/tests/test_pigeond.py +++ b/system/sensord/tests/test_pigeond.py @@ -3,7 +3,7 @@ import unittest import cereal.messaging as messaging -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.gpio import gpio_read from openpilot.selfdrive.test.helpers import with_processes from openpilot.selfdrive.manager.process_config import managed_processes @@ -26,10 +26,10 @@ def test_frequency(self): sm = messaging.SubMaster(['ubloxRaw']) # setup time - for _ in range(int(5 * service_list['ubloxRaw'].frequency)): + for _ in range(int(5 * SERVICE_LIST['ubloxRaw'].frequency)): sm.update() - for _ in range(int(10 * service_list['ubloxRaw'].frequency)): + for _ in range(int(10 * SERVICE_LIST['ubloxRaw'].frequency)): sm.update() assert sm.all_checks() diff --git a/system/sensord/tests/test_sensord.py b/system/sensord/tests/test_sensord.py index ccdce3b4e53b19..555d613e510420 100755 --- a/system/sensord/tests/test_sensord.py +++ b/system/sensord/tests/test_sensord.py @@ -7,7 +7,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.gpio import get_irqs_for_action from openpilot.common.timeout import Timeout from openpilot.system.hardware import TICI @@ -172,7 +172,7 @@ def test_sensor_frequency(self): for s, msgs in self.events.items(): with self.subTest(sensor=s): freq = len(msgs) / self.sample_secs - ef = service_list[s].frequency + ef = SERVICE_LIST[s].frequency assert ef*0.85 <= freq <= ef*1.15 def test_logmonottime_timestamp_diff(self): From 7a11d9a810dff4bc3b6d5adea1b8ae658f26e2fc Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 14:26:28 -0700 Subject: [PATCH 06/19] use DT_TRML --- selfdrive/thermald/thermald.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index beb059c560e6c5..6733aeb31633e1 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -213,7 +213,7 @@ def thermald_thread(end_event, hw_queue) -> None: sm.update(PANDA_STATES_TIMEOUT) # Run at 2Hz - if sm.frame % round(PANDA_STATES_FREQUENCY / 2) != 0: + if sm.frame % round(PANDA_STATES_FREQUENCY * DT_TRML) != 0: continue pandaStates = sm['pandaStates'] From 6c12ed15653dfb65fbc9d3a5af27c4edf92a89e2 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 17:06:11 -0700 Subject: [PATCH 07/19] revert service list --- cereal | 2 +- selfdrive/athena/athenad.py | 4 ++-- selfdrive/controls/lib/events.py | 4 ++-- selfdrive/debug/check_lag.py | 4 ++-- selfdrive/debug/count_events.py | 6 +++--- selfdrive/debug/dump.py | 4 ++-- selfdrive/debug/internal/qlog_size.py | 4 ++-- selfdrive/locationd/test/test_locationd.py | 6 +++--- selfdrive/test/process_replay/process_replay.py | 6 +++--- selfdrive/test/profiling/lib.py | 4 ++-- selfdrive/test/test_onroad.py | 6 +++--- selfdrive/thermald/thermald.py | 4 ++-- system/camerad/test/test_camerad.py | 6 +++--- system/hardware/tici/tests/test_power_draw.py | 4 ++-- system/loggerd/tests/test_loggerd.py | 12 ++++++------ system/sensord/tests/test_pigeond.py | 6 +++--- system/sensord/tests/test_sensord.py | 4 ++-- 17 files changed, 43 insertions(+), 43 deletions(-) diff --git a/cereal b/cereal index 841798768d00d2..e017685d0fe560 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 841798768d00d2e15b4fab41c15a293f5e2a6458 +Subproject commit e017685d0fe56082b2e34147e9258e35965c1d6e diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 82c00b3bf200ae..899605d989dbf4 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -29,7 +29,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.api import Api from openpilot.common.basedir import PERSIST from openpilot.common.file_helpers import CallbackReader @@ -309,7 +309,7 @@ def _do_upload(upload_item: UploadItem, callback: Optional[Callable] = None) -> # security: user should be able to request any message from their car @dispatcher.add_method def getMessage(service: str, timeout: int = 1000) -> dict: - if service is None or service not in SERVICE_LIST: + if service is None or service not in service_list: raise Exception("invalid service") socket = messaging.sub_sock(service, timeout=timeout) diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index a00b8277def491..81e55e6bbcced4 100755 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -969,7 +969,7 @@ def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, if __name__ == '__main__': # print all alerts by type and priority - from cereal.services import SERVICE_LIST + from cereal.services import service_list from collections import defaultdict, OrderedDict event_names = {v: k for k, v in EventName.schema.enumerants.items()} @@ -977,7 +977,7 @@ def joystick_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, CP = car.CarParams.new_message() CS = car.CarState.new_message() - sm = messaging.SubMaster(list(SERVICE_LIST.keys())) + sm = messaging.SubMaster(list(service_list.keys())) for i, alerts in EVENTS.items(): for et, alert in alerts.items(): diff --git a/selfdrive/debug/check_lag.py b/selfdrive/debug/check_lag.py index 72d11d6eda5e1d..141156db913934 100755 --- a/selfdrive/debug/check_lag.py +++ b/selfdrive/debug/check_lag.py @@ -2,7 +2,7 @@ from typing import Dict import cereal.messaging as messaging -from cereal.services import SERVICE_LIST +from cereal.services import service_list TO_CHECK = ['carState'] @@ -20,7 +20,7 @@ t = sm.logMonoTime[s] / 1e9 if s in prev_t: - expected = 1.0 / (SERVICE_LIST[s].frequency) + expected = 1.0 / (service_list[s].frequency) dt = t - prev_t[s] if dt > 10 * expected: print(t, s, dt) diff --git a/selfdrive/debug/count_events.py b/selfdrive/debug/count_events.py index a148996d94a58a..a8af5e6fe9d51b 100755 --- a/selfdrive/debug/count_events.py +++ b/selfdrive/debug/count_events.py @@ -7,7 +7,7 @@ from tqdm import tqdm from typing import List, Tuple, cast -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.tools.lib.route import Route from openpilot.tools.lib.logreader import LogReader @@ -17,7 +17,7 @@ cnt_valid: Counter = Counter() cnt_events: Counter = Counter() - cams = [s for s in SERVICE_LIST if s.endswith('CameraState')] + cams = [s for s in service_list if s.endswith('CameraState')] cnt_cameras = dict.fromkeys(cams, 0) alerts: List[Tuple[float, str]] = [] @@ -62,7 +62,7 @@ print("\n") print("Cameras") for k, v in cnt_cameras.items(): - s = SERVICE_LIST[k] + s = service_list[k] expected_frames = int(s.frequency * duration / cast(float, s.decimation)) print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected") diff --git a/selfdrive/debug/dump.py b/selfdrive/debug/dump.py index db18f4c6228e0a..8436fbd0b07111 100755 --- a/selfdrive/debug/dump.py +++ b/selfdrive/debug/dump.py @@ -8,7 +8,7 @@ from hexdump import hexdump from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list codecs.register_error("strict", codecs.backslashreplace_errors) @@ -31,7 +31,7 @@ poller = messaging.Poller() - for m in args.socket if len(args.socket) > 0 else SERVICE_LIST: + for m in args.socket if len(args.socket) > 0 else service_list: messaging.sub_sock(m, poller, addr=args.addr) values = None diff --git a/selfdrive/debug/internal/qlog_size.py b/selfdrive/debug/internal/qlog_size.py index b51cb3af2fc145..9b7f3695258b8f 100755 --- a/selfdrive/debug/internal/qlog_size.py +++ b/selfdrive/debug/internal/qlog_size.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.route import Route @@ -49,7 +49,7 @@ def make_pie(msgs, typ): msgs_by_type[m.which()].append(m.as_builder().to_bytes()) qlog_by_type = defaultdict(list) - for name, service in SERVICE_LIST.items(): + for name, service in service_list.items(): if service.decimation is None: continue diff --git a/selfdrive/locationd/test/test_locationd.py b/selfdrive/locationd/test/test_locationd.py index 707fdd743f7de0..99047c37f306a9 100755 --- a/selfdrive/locationd/test/test_locationd.py +++ b/selfdrive/locationd/test/test_locationd.py @@ -6,7 +6,7 @@ import capnp import cereal.messaging as messaging -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.params import Params from openpilot.common.transformations.coordinates import ecef2geodetic @@ -74,8 +74,8 @@ def test_params_gps(self): msgs = [] for sec in range(65): for name in self.LLD_MSGS: - for j in range(int(SERVICE_LIST[name].frequency)): - msgs.append(self.get_msg(name, int((sec + j / SERVICE_LIST[name].frequency) * 1e9))) + for j in range(int(service_list[name].frequency)): + msgs.append(self.get_msg(name, int((sec + j / service_list[name].frequency) * 1e9))) for msg in sorted(msgs, key=lambda x: x.logMonoTime): self.pm.send(msg.which(), msg) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 753262af12bae3..eb49d0dedb751f 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -14,7 +14,7 @@ import cereal.messaging as messaging from cereal import car -from cereal.services import SERVICE_LIST +from cereal.services import service_list from cereal.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name from openpilot.common.params import Params from openpilot.common.prefix import OpenpilotPrefix @@ -364,7 +364,7 @@ def controlsd_rcv_callback(msg, cfg, frame): socks = [ s for s in cfg.subs if - frame % int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency) == 0 + frame % int(service_list[msg.which()].frequency / service_list[s].frequency) == 0 ] if "sendcan" in socks and (frame - 1) < 2000: socks.remove("sendcan") @@ -428,7 +428,7 @@ def __call__(self, msg, cfg, frame): resp_sockets = [ s for s in cfg.subs - if frame % max(1, int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency)) == 0 + if frame % max(1, int(service_list[msg.which()].frequency / service_list[s].frequency)) == 0 ] return bool(len(resp_sockets)) diff --git a/selfdrive/test/profiling/lib.py b/selfdrive/test/profiling/lib.py index 7f3b0126fffd49..843bf52211b6f5 100644 --- a/selfdrive/test/profiling/lib.py +++ b/selfdrive/test/profiling/lib.py @@ -1,5 +1,5 @@ from collections import defaultdict, deque -from cereal.services import SERVICE_LIST +from cereal.services import service_list import cereal.messaging as messaging import capnp @@ -67,7 +67,7 @@ def __init__(self, msgs, trigger, services, check_averag_freq=False): self.msgs = list(reversed(self.msgs)) for s in services: - self.freq[s] = SERVICE_LIST[s].frequency + self.freq[s] = service_list[s].frequency try: data = messaging.new_message(s) except capnp.lib.capnp.KjException: diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 894ab15c1257ae..553ef1afa61f1b 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -13,7 +13,7 @@ from cereal import car import cereal.messaging as messaging -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.basedir import BASEDIR from openpilot.common.timeout import Timeout from openpilot.common.params import Params @@ -179,7 +179,7 @@ def test_service_frequencies(self): continue with self.subTest(service=s): - assert len(msgs) >= math.floor(SERVICE_LIST[s].frequency*55) + assert len(msgs) >= math.floor(service_list[s].frequency*55) def test_cloudlog_size(self): msgs = [m for m in self.lr if m.which() == 'logMessage'] @@ -356,7 +356,7 @@ def test_timings(self): raise Exception(f"missing {s}") ts = np.diff(msgs) / 1e9 - dt = 1 / SERVICE_LIST[s].frequency + dt = 1 / service_list[s].frequency try: np.testing.assert_allclose(np.mean(ts), dt, rtol=0.03, err_msg=f"{s} - failed mean timing check") diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 6733aeb31633e1..51ddc5319b12f7 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -13,7 +13,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.dict_helpers import strip_deprecated_keys from openpilot.common.time import MIN_DATE from openpilot.common.filter_simple import FirstOrderFilter @@ -34,7 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_FREQUENCY = SERVICE_LIST['pandaStates'].frequency +PANDA_STATES_FREQUENCY = service_list['pandaStates'].frequency PANDA_STATES_TIMEOUT = round(1000 / PANDA_STATES_FREQUENCY * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) diff --git a/system/camerad/test/test_camerad.py b/system/camerad/test/test_camerad.py index b680c1df67446d..b2aca850d1fa58 100755 --- a/system/camerad/test/test_camerad.py +++ b/system/camerad/test/test_camerad.py @@ -6,7 +6,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.system.hardware import TICI @@ -43,10 +43,10 @@ def setUpClass(cls): for cam, msgs in cls.logs.items(): if cls.sensor_type is None: cls.sensor_type = getattr(msgs[0], msgs[0].which()).sensor.raw - expected_frames = SERVICE_LIST[cam].frequency * TEST_TIMESPAN + expected_frames = service_list[cam].frequency * TEST_TIMESPAN assert expected_frames*0.95 < len(msgs) < expected_frames*1.05, f"unexpected frame count {cam}: {expected_frames=}, got {len(msgs)}" - dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/SERVICE_LIST[cam].frequency) + dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/service_list[cam].frequency) assert (dts < FRAME_DELTA_TOLERANCE[cls.sensor_type]).all(), f"{cam} dts(ms) out of spec: max diff {dts.max()}, 99 percentile {np.percentile(dts, 99)}" for m in msgs: diff --git a/system/hardware/tici/tests/test_power_draw.py b/system/hardware/tici/tests/test_power_draw.py index 1409e43cfbc52c..fbca95f6f6b11c 100755 --- a/system/hardware/tici/tests/test_power_draw.py +++ b/system/hardware/tici/tests/test_power_draw.py @@ -8,7 +8,7 @@ from typing import List import cereal.messaging as messaging -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.system.hardware import HARDWARE, TICI from openpilot.system.hardware.tici.power_monitor import get_power from openpilot.selfdrive.manager.process_config import managed_processes @@ -91,7 +91,7 @@ def test_camera_procs(self): cur = used[proc.name] expected = proc.power msgs_received = sum(msg_counts[msg] for msg in proc.msgs) - msgs_expected = int(sum(SAMPLE_TIME * SERVICE_LIST[msg].frequency for msg in proc.msgs)) + msgs_expected = int(sum(SAMPLE_TIME * service_list[msg].frequency for msg in proc.msgs)) tab.append([proc.name, round(expected, 2), round(cur, 2), msgs_expected, msgs_received]) with self.subTest(proc=proc.name): self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol)) diff --git a/system/loggerd/tests/test_loggerd.py b/system/loggerd/tests/test_loggerd.py index 9d7d3fa7bd99ba..3ea29b0d827d11 100755 --- a/system/loggerd/tests/test_loggerd.py +++ b/system/loggerd/tests/test_loggerd.py @@ -12,7 +12,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params from openpilot.common.timeout import Timeout @@ -27,8 +27,8 @@ SentinelType = log.Sentinel.SentinelType -CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in SERVICE_LIST - and SERVICE_LIST[f].should_log and "encode" not in f.lower()] +CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in service_list + and service_list[f].should_log and "encode" not in f.lower()] class TestLoggerd(unittest.TestCase): @@ -219,8 +219,8 @@ def test_bootlog(self): self.assertEqual(expected_val, bootlog_val) def test_qlog(self): - qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is not None] - no_qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is None] + qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is not None] + no_qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is None] services = random.sample(qlog_services, random.randint(2, min(10, len(qlog_services)))) + \ random.sample(no_qlog_services, random.randint(2, min(10, len(no_qlog_services)))) @@ -245,7 +245,7 @@ def test_qlog(self): self.assertEqual(recv_cnt, 0, f"got {recv_cnt} {s} msgs in qlog") else: # check logged message count matches decimation - expected_cnt = (len(msgs) - 1) // SERVICE_LIST[s].decimation + 1 + expected_cnt = (len(msgs) - 1) // service_list[s].decimation + 1 self.assertEqual(recv_cnt, expected_cnt, f"expected {expected_cnt} msgs for {s}, got {recv_cnt}") def test_rlog(self): diff --git a/system/sensord/tests/test_pigeond.py b/system/sensord/tests/test_pigeond.py index b23afcb07c737b..90cbf063406348 100755 --- a/system/sensord/tests/test_pigeond.py +++ b/system/sensord/tests/test_pigeond.py @@ -3,7 +3,7 @@ import unittest import cereal.messaging as messaging -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.gpio import gpio_read from openpilot.selfdrive.test.helpers import with_processes from openpilot.selfdrive.manager.process_config import managed_processes @@ -26,10 +26,10 @@ def test_frequency(self): sm = messaging.SubMaster(['ubloxRaw']) # setup time - for _ in range(int(5 * SERVICE_LIST['ubloxRaw'].frequency)): + for _ in range(int(5 * service_list['ubloxRaw'].frequency)): sm.update() - for _ in range(int(10 * SERVICE_LIST['ubloxRaw'].frequency)): + for _ in range(int(10 * service_list['ubloxRaw'].frequency)): sm.update() assert sm.all_checks() diff --git a/system/sensord/tests/test_sensord.py b/system/sensord/tests/test_sensord.py index 555d613e510420..ccdce3b4e53b19 100755 --- a/system/sensord/tests/test_sensord.py +++ b/system/sensord/tests/test_sensord.py @@ -7,7 +7,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import SERVICE_LIST +from cereal.services import service_list from openpilot.common.gpio import get_irqs_for_action from openpilot.common.timeout import Timeout from openpilot.system.hardware import TICI @@ -172,7 +172,7 @@ def test_sensor_frequency(self): for s, msgs in self.events.items(): with self.subTest(sensor=s): freq = len(msgs) / self.sample_secs - ef = SERVICE_LIST[s].frequency + ef = service_list[s].frequency assert ef*0.85 <= freq <= ef*1.15 def test_logmonottime_timestamp_diff(self): From 7ffbd511263e925752b1044b1b871dd121401eeb Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 17:17:22 -0700 Subject: [PATCH 08/19] bump cereal --- cereal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cereal b/cereal index e017685d0fe560..abf03ffdec592e 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit e017685d0fe56082b2e34147e9258e35965c1d6e +Subproject commit abf03ffdec592e8b7a1c0d77e23fddb9e9b2ddd5 From ddeaef2738ab3012fd47c976e5d2a70da82f0f16 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 17:18:12 -0700 Subject: [PATCH 09/19] no inter --- selfdrive/thermald/thermald.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 51ddc5319b12f7..97a0c08c030f1c 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -34,8 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_FREQUENCY = service_list['pandaStates'].frequency -PANDA_STATES_TIMEOUT = round(1000 / PANDA_STATES_FREQUENCY * 1.5) # 1.5x the expected pandaState frequency +PANDA_STATES_TIMEOUT = round(1000 / service_list['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -213,7 +212,7 @@ def thermald_thread(end_event, hw_queue) -> None: sm.update(PANDA_STATES_TIMEOUT) # Run at 2Hz - if sm.frame % round(PANDA_STATES_FREQUENCY * DT_TRML) != 0: + if sm.frame % round(service_list['pandaStates'].frequency * DT_TRML) != 0: continue pandaStates = sm['pandaStates'] From 233d9eb6f4c241024e9813512207e7e340224640 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 17:25:39 -0700 Subject: [PATCH 10/19] not sure why 5hz before --- tools/sim/lib/simulated_sensors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/sim/lib/simulated_sensors.py b/tools/sim/lib/simulated_sensors.py index dd55c02f02d3ef..0274c8453418ce 100644 --- a/tools/sim/lib/simulated_sensors.py +++ b/tools/sim/lib/simulated_sensors.py @@ -1,6 +1,7 @@ import time from cereal import log +from cereal.services import service_list import cereal.messaging as messaging from openpilot.common.params import Params @@ -120,8 +121,8 @@ def update(self, simulator_state: 'SimulatorState', world: 'World'): self.send_fake_driver_monitoring() self.last_dmon_update = now - if (now - self.last_perp_update) > 0.25: + if (now - self.last_perp_update) > (1 / service_list['peripheralState']): self.send_peripheral_state() self.last_perp_update = now - self.send_camera_images(world) \ No newline at end of file + self.send_camera_images(world) From 89ed0d65380df93777895d6b9e0859a8311664c4 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 18:50:09 -0700 Subject: [PATCH 11/19] revert --- tools/sim/lib/simulated_sensors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sim/lib/simulated_sensors.py b/tools/sim/lib/simulated_sensors.py index 0274c8453418ce..f9d0e6d23cdd77 100644 --- a/tools/sim/lib/simulated_sensors.py +++ b/tools/sim/lib/simulated_sensors.py @@ -125,4 +125,4 @@ def update(self, simulator_state: 'SimulatorState', world: 'World'): self.send_peripheral_state() self.last_perp_update = now - self.send_camera_images(world) + self.send_camera_images(world) \ No newline at end of file From 2c99c19eb111a2553090f4242161b81c2f7f5408 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 19:05:42 -0700 Subject: [PATCH 12/19] revert peripheral --- cereal | 2 +- selfdrive/boardd/boardd.cc | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cereal b/cereal index abf03ffdec592e..9ede52e835f2e6 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit abf03ffdec592e8b7a1c0d77e23fddb9e9b2ddd5 +Subproject commit 9ede52e835f2e6b7c263218592fc7deb20ff436f diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 4f298cbe1669a0..4d241f2e2f5e1e 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -476,8 +476,11 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { RateKeeper rk("panda_state_thread", 10); while (!do_exit && check_all_connected(pandas)) { - // send out peripheralState - send_peripheral_state(&pm, peripheral_panda); + if (sm.frame % 5 == 0) { + // send out peripheralState at 2Hz + send_peripheral_state(&pm, peripheral_panda); + } + auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); if (!ignition_opt) { From 5eecb83e070dd51b550a47f3e0e7a1600b8da4e4 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 19:10:01 -0700 Subject: [PATCH 13/19] poll on peripheralState after pandaStates --- selfdrive/boardd/boardd.cc | 4 ++-- selfdrive/thermald/thermald.py | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 4d241f2e2f5e1e..cad2305cdec7b7 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -476,13 +476,13 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { RateKeeper rk("panda_state_thread", 10); while (!do_exit && check_all_connected(pandas)) { + auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); + if (sm.frame % 5 == 0) { // send out peripheralState at 2Hz send_peripheral_state(&pm, peripheral_panda); } - auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); - if (!ignition_opt) { LOGE("Failed to get ignition_opt"); rk.keepTime(); diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 97a0c08c030f1c..bad5318b0fecac 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -34,7 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_TIMEOUT = round(1000 / service_list['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency +PERIPHERAL_STATE_TIMEOUT = round(1000 / service_list['peripheralState'].frequency * 1.5) # 1.5x the expected peripheralState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -168,7 +168,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=["peripheralState"]) count = 0 @@ -209,11 +209,7 @@ def thermald_thread(end_event, hw_queue) -> None: fan_controller = None while not end_event.is_set(): - sm.update(PANDA_STATES_TIMEOUT) - - # Run at 2Hz - if sm.frame % round(service_list['pandaStates'].frequency * DT_TRML) != 0: - continue + sm.update(PERIPHERAL_STATE_TIMEOUT) pandaStates = sm['pandaStates'] peripheralState = sm['peripheralState'] From 6effedf9adaea0ce9957533360184ebd00c4f564 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 19:10:22 -0700 Subject: [PATCH 14/19] Revert "poll on peripheralState" This reverts commit 5eecb83e070dd51b550a47f3e0e7a1600b8da4e4. --- selfdrive/boardd/boardd.cc | 4 ++-- selfdrive/thermald/thermald.py | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index cad2305cdec7b7..4d241f2e2f5e1e 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -476,13 +476,13 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { RateKeeper rk("panda_state_thread", 10); while (!do_exit && check_all_connected(pandas)) { - auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); - if (sm.frame % 5 == 0) { // send out peripheralState at 2Hz send_peripheral_state(&pm, peripheral_panda); } + auto ignition_opt = send_panda_states(&pm, pandas, spoofing_started); + if (!ignition_opt) { LOGE("Failed to get ignition_opt"); rk.keepTime(); diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index bad5318b0fecac..97a0c08c030f1c 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -34,7 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PERIPHERAL_STATE_TIMEOUT = round(1000 / service_list['peripheralState'].frequency * 1.5) # 1.5x the expected peripheralState frequency +PANDA_STATES_TIMEOUT = round(1000 / service_list['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -168,7 +168,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=["peripheralState"]) + sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates"], poll=["pandaStates"]) count = 0 @@ -209,7 +209,11 @@ def thermald_thread(end_event, hw_queue) -> None: fan_controller = None while not end_event.is_set(): - sm.update(PERIPHERAL_STATE_TIMEOUT) + sm.update(PANDA_STATES_TIMEOUT) + + # Run at 2Hz + if sm.frame % round(service_list['pandaStates'].frequency * DT_TRML) != 0: + continue pandaStates = sm['pandaStates'] peripheralState = sm['peripheralState'] From 19832f38ec86ff18ce718ce2d90c4a5269f6d47d Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 15 Sep 2023 19:14:15 -0700 Subject: [PATCH 15/19] revert this --- tools/sim/lib/simulated_sensors.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/sim/lib/simulated_sensors.py b/tools/sim/lib/simulated_sensors.py index f9d0e6d23cdd77..dd55c02f02d3ef 100644 --- a/tools/sim/lib/simulated_sensors.py +++ b/tools/sim/lib/simulated_sensors.py @@ -1,7 +1,6 @@ import time from cereal import log -from cereal.services import service_list import cereal.messaging as messaging from openpilot.common.params import Params @@ -121,7 +120,7 @@ def update(self, simulator_state: 'SimulatorState', world: 'World'): self.send_fake_driver_monitoring() self.last_dmon_update = now - if (now - self.last_perp_update) > (1 / service_list['peripheralState']): + if (now - self.last_perp_update) > 0.25: self.send_peripheral_state() self.last_perp_update = now From 5a39f2526297a8df8acc967b037ab71129bc72f3 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 16:03:08 -0700 Subject: [PATCH 16/19] bump --- cereal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cereal b/cereal index 9ede52e835f2e6..95485f268cacb1 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 9ede52e835f2e6b7c263218592fc7deb20ff436f +Subproject commit 95485f268cacb16186163744224c9dd8644ecd49 From af4dc5917a67dbbf23943b2a323ba878f7ec1490 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 17:42:40 -0700 Subject: [PATCH 17/19] cmt --- selfdrive/boardd/boardd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 4d241f2e2f5e1e..0ec33c1a2760b2 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -476,8 +476,8 @@ void panda_state_thread(std::vector pandas, bool spoofing_started) { RateKeeper rk("panda_state_thread", 10); while (!do_exit && check_all_connected(pandas)) { + // send out peripheralState at 2Hz if (sm.frame % 5 == 0) { - // send out peripheralState at 2Hz send_peripheral_state(&pm, peripheral_panda); } From b4f89856b8a64caa4197f2910a67c14ee8dbc530 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 18:27:37 -0700 Subject: [PATCH 18/19] fix --- selfdrive/thermald/thermald.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 97a0c08c030f1c..3ccb9349e112b4 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -13,7 +13,7 @@ import cereal.messaging as messaging from cereal import log -from cereal.services import service_list +from cereal.services import SERVICE_LIST from openpilot.common.dict_helpers import strip_deprecated_keys from openpilot.common.time import MIN_DATE from openpilot.common.filter_simple import FirstOrderFilter @@ -34,7 +34,7 @@ CURRENT_TAU = 15. # 15s time constant TEMP_TAU = 5. # 5s time constant DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -PANDA_STATES_TIMEOUT = round(1000 / service_list['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency +PANDA_STATES_TIMEOUT = round(1000 / SERVICE_LIST['pandaStates'].frequency * 1.5) # 1.5x the expected pandaState frequency ThermalBand = namedtuple("ThermalBand", ['min_temp', 'max_temp']) HardwareState = namedtuple("HardwareState", ['network_type', 'network_info', 'network_strength', 'network_stats', @@ -212,7 +212,7 @@ def thermald_thread(end_event, hw_queue) -> None: sm.update(PANDA_STATES_TIMEOUT) # Run at 2Hz - if sm.frame % round(service_list['pandaStates'].frequency * DT_TRML) != 0: + if sm.frame % round(SERVICE_LIST['pandaStates'].frequency * DT_TRML) != 0: continue pandaStates = sm['pandaStates'] From 7d9297df03ce8a96dac3d4783dd2502f29f6efe4 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Thu, 21 Sep 2023 18:27:59 -0700 Subject: [PATCH 19/19] bump to master --- cereal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cereal b/cereal index cd493fe2d58491..6bd65e7c7f2692 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit cd493fe2d5849165815abe5fbb058a1d832e6c8f +Subproject commit 6bd65e7c7f2692d15a9b6cc97bad9345f9089c4d