From c803eddb33c05ac8e8704df90bf854e3dda600b3 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 8 Apr 2021 18:04:11 +0200 Subject: [PATCH] add list for average frequency ignore (#132) * add list for averge frequency ignore * not simulation * cleanup --- messaging/__init__.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/messaging/__init__.py b/messaging/__init__.py index 0eb926f79f68c1..a1f20ed93fe1bf 100644 --- a/messaging/__init__.py +++ b/messaging/__init__.py @@ -131,7 +131,8 @@ def recv_one_retry(sock: SubSocket) -> capnp.lib.capnp._DynamicStructReader: class SubMaster(): def __init__(self, services: List[str], poll: Optional[List[str]] = None, - ignore_alive: Optional[List[str]] = None, check_average_freq: bool = True, addr: str = "127.0.0.1"): + ignore_alive: Optional[List[str]] = None, ignore_avg_freq: Optional[List[str]] = None, + addr: str = "127.0.0.1"): self.frame = -1 self.updated = {s: False for s in services} self.rcv_time = {s: 0. for s in services} @@ -143,16 +144,13 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None, self.data = {} self.valid = {} self.logMonoTime = {} - self.check_average_freq = check_average_freq and (not SIMULATION) self.poller = Poller() self.non_polled_services = [s for s in services if poll is not None and len(poll) and s not in poll] - if ignore_alive is not None: - self.ignore_alive = ignore_alive - else: - self.ignore_alive = [] + self.ignore_average_freq = [] if ignore_avg_freq is None else ignore_avg_freq + self.ignore_alive = [] if ignore_alive is None else ignore_alive for s in services: if addr is not None: @@ -192,7 +190,8 @@ def update_msgs(self, cur_time: float, msgs: List[capnp.lib.capnp._DynamicStruct s = msg.which() self.updated[s] = True - if self.check_average_freq and self.rcv_time[s] > 1e-5 and self.freq[s] > 1e-5 and (s not in self.non_polled_services): + if self.rcv_time[s] > 1e-5 and self.freq[s] > 1e-5 and (s not in self.non_polled_services) \ + and (s not in self.ignore_average_freq) and (not SIMULATION): self.recv_dts[s].append(cur_time - self.rcv_time[s]) self.rcv_time[s] = cur_time @@ -207,11 +206,10 @@ def update_msgs(self, cur_time: float, msgs: List[capnp.lib.capnp._DynamicStruct # alive if delay is within 10x the expected frequency self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s]) - if self.check_average_freq: - # alive if average frequency is higher than 90% of expected frequency - avg_dt = sum(self.recv_dts[s]) / AVG_FREQ_HISTORY - expected_dt = 1 / (self.freq[s] * 0.90) - self.alive[s] = self.alive[s] and (avg_dt < expected_dt) + # alive if average frequency is higher than 90% of expected frequency + avg_dt = sum(self.recv_dts[s]) / AVG_FREQ_HISTORY + expected_dt = 1 / (self.freq[s] * 0.90) + self.alive[s] = self.alive[s] and (avg_dt < expected_dt) else: self.alive[s] = True