Skip to content

Commit d8dd5bc

Browse files
committed
log frameAge in modelData
1 parent 397c797 commit d8dd5bc

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

cereal

selfdrive/controls/controlsd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def update_events(self, CS):
227227
self.events.add(EventName.relayMalfunction)
228228
if self.sm['plan'].fcw:
229229
self.events.add(EventName.fcw)
230-
if (self.sm['frame'].frameId - self.sm['model'].frameId) > 1:
230+
if self.sm['model'].frameAge > 1:
231231
self.events.add(EventName.modeldLagging)
232232

233233
# Only allow engagement with brake pressed when stopped behind another stopped car

selfdrive/modeld/modeld.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ int main(int argc, char **argv) {
214214
model_transform, NULL, vec_desire);
215215
mt2 = millis_since_boot();
216216

217-
model_publish(pm, extra.frame_id, frame_id, model_buf, extra.timestamp_eof);
218-
posenet_publish(pm, extra.frame_id, frame_id, model_buf, extra.timestamp_eof);
217+
model_publish(pm, extra.frame_id, frame_id, sm.allAliveAndValid(), model_buf, extra.timestamp_eof);
218+
posenet_publish(pm, extra.frame_id, frame_id, sm.allAliveAndValid(), model_buf, extra.timestamp_eof);
219219

220220
LOGD("model process: %.2fms, from last %.2fms, vipc_frame_id %zu, frame_id, %zu", mt2-mt1, mt1-last, extra.frame_id, frame_id);
221221
last = mt1;

selfdrive/modeld/models/driving.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void fill_longi(cereal::ModelData::LongitudinalData::Builder longi, const float
245245
longi.setAccelerations(accel);
246246
}
247247

248-
void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
248+
void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id, bool sm_alive_valid,
249249
const ModelDataRaw &net_outputs, uint64_t timestamp_eof) {
250250
// make msg
251251
capnp::MallocMessageBuilder msg;
@@ -256,6 +256,9 @@ void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
256256
framed.setFrameId(vipc_frame_id);
257257
framed.setTimestampEof(timestamp_eof);
258258

259+
//
260+
framed.setFrameAge((frame_id > vipc_frame_id) ? frame_id - vipc_frame_id : 0);
261+
259262
auto lpath = framed.initPath();
260263
fill_path(lpath, net_outputs.path, false, 0);
261264
auto left_lane = framed.initLeftLane();
@@ -290,13 +293,13 @@ void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
290293

291294
auto meta = framed.initMeta();
292295
fill_meta(meta, net_outputs.meta);
293-
event.setValid(frame_id < vipc_frame_id + MAX_FRAME_AGE);
296+
event.setValid((frame_id < vipc_frame_id + MAX_FRAME_AGE) && sm_alive_valid);
294297

295298
pm.send("model", msg);
296299
}
297300

298-
void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
299-
const ModelDataRaw &net_outputs, uint64_t timestamp_eof) {
301+
void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id, bool sm_alive_valid,
302+
const ModelDataRaw &net_outputs, uint64_t timestamp_eof) {
300303
capnp::MallocMessageBuilder msg;
301304
cereal::Event::Builder event = msg.initRoot<cereal::Event>();
302305
event.setLogMonoTime(nanos_since_boot());
@@ -326,7 +329,7 @@ void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
326329

327330
posenetd.setTimestampEof(timestamp_eof);
328331
posenetd.setFrameId(vipc_frame_id);
329-
event.setValid(frame_id < vipc_frame_id + MAX_FRAME_AGE);
332+
event.setValid((frame_id < vipc_frame_id + MAX_FRAME_AGE) && sm_alive_valid);
330333

331334
pm.send("cameraOdometry", msg);
332335
}

selfdrive/modeld/models/driving.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q,
7373
void model_free(ModelState* s);
7474
void poly_fit(float *in_pts, float *in_stds, float *out);
7575

76-
void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
77-
const ModelDataRaw &data, uint64_t timestamp_eof);
78-
void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id,
76+
void model_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id, bool sm_alive_valid,
7977
const ModelDataRaw &data, uint64_t timestamp_eof);
78+
void posenet_publish(PubMaster &pm, uint32_t vipc_frame_id, uint32_t frame_id, bool sm_alive_valid,
79+
const ModelDataRaw &data, uint64_t timestamp_eof);
8080
#endif

0 commit comments

Comments
 (0)