Skip to content

Commit

Permalink
add list for average frequency ignore (commaai#132)
Browse files Browse the repository at this point in the history
* add list for averge frequency ignore

* not simulation

* cleanup
  • Loading branch information
pd0wm authored Apr 8, 2021
1 parent 5980517 commit c803edd
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit c803edd

Please sign in to comment.