From 011f1820c478a985cf55a1330c8d63506facdb28 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 10 May 2024 17:10:31 -0700 Subject: [PATCH] more final ordering, and make polling on/off test repeatable --- selfdrive/car/card.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index d10108724a..2ecdda0b54 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -23,8 +23,11 @@ class Car: CI: CarInterfaceBase def __init__(self, CI=None): + self.POLL = True + self.can_sock = messaging.sub_sock('can', timeout=20) - self.sm = messaging.SubMaster(['pandaStates', 'carControl', 'controlsState']) + self.sm = messaging.SubMaster(['pandaStates', 'carControl', 'controlsState'], + poll='carControl' if self.POLL else None) self.pm = messaging.PubMaster(['sendcan', 'carState', 'carParams', 'carOutput']) self.can_rcv_timeout_counter = 0 # consecutive timeout count @@ -85,7 +88,8 @@ class Car: can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True) CS = self.CI.update(self.CC_prev, can_strs) - self.sm.update(0) + if not self.POLL: + self.sm.update(0) can_rcv_valid = len(can_strs) > 0 @@ -129,6 +133,10 @@ class Car: self.pm.send('carState', cs_send) cloudlog.timestamp('Sent carState') + if self.POLL: + # wait for latest carControl + self.sm.update(20) + def controls_update(self, CS: car.CarState, CC: car.CarControl): """control update loop, driven by carControl""" @@ -146,14 +154,14 @@ class Car: CS = self.state_update() cloudlog.timestamp("State updated") + self.state_publish(CS) + cloudlog.timestamp("State published") + controlsState = self.sm['controlsState'] if controlsState.initialized and not self.controlsState_prev.initialized: self.CI.init(self.CP, self.can_sock, self.pm.sock['sendcan']) cloudlog.timestamp("Initialized") - self.state_publish(CS) - cloudlog.timestamp("State published") - if not self.CP.passive and controlsState.initialized: self.controls_update(CS, self.sm['carControl']) cloudlog.timestamp("Controls updated")