Skip to content

Commit

Permalink
SubMaster: Don't check alive when SIMULATION env variable is set
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed May 5, 2021
1 parent 9d83b15 commit bab2f2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 16 additions & 12 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def update_msgs(self, cur_time: float, msgs: List[capnp.lib.capnp._DynamicStruct
self.updated[s] = True

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):
and (s not in self.ignore_average_freq):
self.recv_dts[s].append(cur_time - self.rcv_time[s])

self.rcv_time[s] = cur_time
Expand All @@ -200,19 +200,23 @@ def update_msgs(self, cur_time: float, msgs: List[capnp.lib.capnp._DynamicStruct
self.logMonoTime[s] = msg.logMonoTime
self.valid[s] = msg.valid

for s in self.data:
# arbitrary small number to avoid float comparison. If freq is 0, we can skip the check
if self.freq[s] > 1e-5:
# alive if delay is within 10x the expected frequency
self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s])

# 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:
if SIMULATION:
self.alive[s] = True

if not SIMULATION:
for s in self.data:
# arbitrary small number to avoid float comparison. If freq is 0, we can skip the check
if self.freq[s] > 1e-5:
# alive if delay is within 10x the expected frequency
self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s])

# 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

def all_alive(self, service_list=None) -> bool:
if service_list is None: # check all
service_list = self.alive.keys()
Expand Down
13 changes: 10 additions & 3 deletions messaging/socketmaster.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <time.h>
#include <assert.h>
#include <stdlib.h>
#include <string>

#include "services.h"
#include "messaging.h"

const bool SIMULATION = (getenv("SIMULATION") != nullptr) && (std::string(getenv("SIMULATION")) == "1");

static inline uint64_t nanos_since_boot() {
struct timespec t;
clock_gettime(CLOCK_BOOTTIME, &t);
Expand Down Expand Up @@ -103,11 +107,14 @@ void SubMaster::update_msgs(uint64_t current_time, std::vector<std::pair<std::st
m->rcv_time = current_time;
m->rcv_frame = frame;
m->valid = m->event.getValid();
if (SIMULATION) m->alive = true;
}

for (auto &kv : messages_) {
SubMessage *m = kv.second;
m->alive = (m->freq <= (1e-5) || ((current_time - m->rcv_time) * (1e-9)) < (10.0 / m->freq));
if (!SIMULATION) {
for (auto &kv : messages_) {
SubMessage *m = kv.second;
m->alive = (m->freq <= (1e-5) || ((current_time - m->rcv_time) * (1e-9)) < (10.0 / m->freq));
}
}
}

Expand Down

0 comments on commit bab2f2b

Please sign in to comment.