From bc1b0660e1643fe0e62cd62b6dec9e12b5d6bdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Wed, 25 Mar 2026 14:35:34 -0700 Subject: [PATCH 1/8] Frame delay --- selfdrive/modeld/modeld.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index bff59366d6ec4c..dd2244929ec5ba 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -388,7 +388,8 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - action = get_action_from_model(model_output, prev_action, lat_delay + DT_MDL, long_delay + DT_MDL, v_ego) + frame_delay = modelv2_send.logMonoTime - meta_main.timestamp_eof + action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + DT_MDL, v_ego) prev_action = action fill_model_msg(drivingdata_send, modelv2_send, model_output, action, publish_state, meta_main.frame_id, meta_extra.frame_id, frame_id, From e16bee26c7163d1deb32312214339c6b077194ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Wed, 25 Mar 2026 14:39:02 -0700 Subject: [PATCH 2/8] Multiply --- selfdrive/modeld/modeld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index dd2244929ec5ba..cf4c1856a7f868 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -388,7 +388,7 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - frame_delay = modelv2_send.logMonoTime - meta_main.timestamp_eof + frame_delay = (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + DT_MDL, v_ego) prev_action = action fill_model_msg(drivingdata_send, modelv2_send, model_output, action, From 4a0fc4cff674cc886bc4cf460e2671aec132c4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Wed, 25 Mar 2026 14:48:30 -0700 Subject: [PATCH 3/8] If replay --- selfdrive/modeld/modeld.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index cf4c1856a7f868..1e000a2a29a0fe 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -33,6 +33,7 @@ PROCESS_NAME = "selfdrive.modeld.modeld" SEND_RAW_PRED = os.getenv('SEND_RAW_PRED') +REPLAY = bool(int(os.getenv('REPLAY', '0'))) VISION_PKL_PATH = Path(__file__).parent / 'models/driving_vision_tinygrad.pkl' POLICY_PKL_PATH = Path(__file__).parent / 'models/driving_policy_tinygrad.pkl' @@ -388,7 +389,7 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - frame_delay = (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 + frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + DT_MDL, v_ego) prev_action = action fill_model_msg(drivingdata_send, modelv2_send, model_output, action, From 46830546ec4f8ef62650c0c81fdc48f4f6619616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Wed, 25 Mar 2026 14:52:59 -0700 Subject: [PATCH 4/8] For long too --- selfdrive/modeld/modeld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 1e000a2a29a0fe..3fa0f90ad246cd 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -390,7 +390,7 @@ def main(demo=False): posenet_send = messaging.new_message('cameraOdometry') frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 - action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + DT_MDL, v_ego) + action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + frame_delay + DT_MDL, v_ego) prev_action = action fill_model_msg(drivingdata_send, modelv2_send, model_output, action, publish_state, meta_main.frame_id, meta_extra.frame_id, frame_id, From 5e76e9574237bedd6962d249f8e96ccde786a02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Tue, 31 Mar 2026 12:05:36 -0700 Subject: [PATCH 5/8] DT_MDL / 2 --- selfdrive/modeld/modeld.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 3fa0f90ad246cd..18a3aa50452b04 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -389,8 +389,9 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 - action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + DT_MDL, long_delay + frame_delay + DT_MDL, v_ego) + frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 # compensate for the time passed since the frame was captured + action_delay = DT_MDL / 2 # middle of the interval between model output (current state) and next frame (expected state) + action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + action_delay, long_delay + frame_delay + action_delay, v_ego) prev_action = action fill_model_msg(drivingdata_send, modelv2_send, model_output, action, publish_state, meta_main.frame_id, meta_extra.frame_id, frame_id, From 4b8ffd68e580e5380616f6e3ede7085b0c576733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Tue, 31 Mar 2026 12:43:59 -0700 Subject: [PATCH 6/8] Shorten comment --- selfdrive/modeld/modeld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 18a3aa50452b04..e60ef4eabf0620 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -389,7 +389,7 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 # compensate for the time passed since the frame was captured + frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 # compensate for time passed since the frame was captured action_delay = DT_MDL / 2 # middle of the interval between model output (current state) and next frame (expected state) action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + action_delay, long_delay + frame_delay + action_delay, v_ego) prev_action = action From 7bc8db157b847725970cce5ace77aacf32a58001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Mon, 6 Apr 2026 13:57:45 -0700 Subject: [PATCH 7/8] Just 50ms --- selfdrive/modeld/modeld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index e60ef4eabf0620..9d1638452f0ee9 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -389,7 +389,7 @@ def main(demo=False): drivingdata_send = messaging.new_message('drivingModelData') posenet_send = messaging.new_message('cameraOdometry') - frame_delay = DT_MDL if REPLAY else (modelv2_send.logMonoTime - meta_main.timestamp_eof) * 1e-9 # compensate for time passed since the frame was captured + frame_delay = DT_MDL # compensate for time passed since the frame was captured: current_time - timestamp_eof is 50ms on average action_delay = DT_MDL / 2 # middle of the interval between model output (current state) and next frame (expected state) action = get_action_from_model(model_output, prev_action, lat_delay + frame_delay + action_delay, long_delay + frame_delay + action_delay, v_ego) prev_action = action From 621ca34f595c83f94fe1240dbe7db5ea3beb521b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Mon, 6 Apr 2026 14:00:53 -0700 Subject: [PATCH 8/8] Remove REPLAY const --- selfdrive/modeld/modeld.py | 1 - 1 file changed, 1 deletion(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 9d1638452f0ee9..22ab943199cf45 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -33,7 +33,6 @@ PROCESS_NAME = "selfdrive.modeld.modeld" SEND_RAW_PRED = os.getenv('SEND_RAW_PRED') -REPLAY = bool(int(os.getenv('REPLAY', '0'))) VISION_PKL_PATH = Path(__file__).parent / 'models/driving_vision_tinygrad.pkl' POLICY_PKL_PATH = Path(__file__).parent / 'models/driving_policy_tinygrad.pkl'