2020from openpilot .selfdrive .controls .lib .desire_helper import DesireHelper
2121from openpilot .selfdrive .controls .lib .drive_helpers import get_accel_from_plan , smooth_value
2222
23- from openpilot .sunnypilot .livedelay .helpers import get_lat_delay
2423from openpilot .sunnypilot .modeld .runners import ModelRunner , Runtime
2524from openpilot .sunnypilot .modeld .parse_model_outputs import Parser
2625from openpilot .sunnypilot .modeld .fill_model_msg import fill_model_msg , fill_pose_msg , PublishState
2726from openpilot .sunnypilot .modeld .constants import ModelConstants , Plan
2827from openpilot .sunnypilot .models .helpers import get_active_bundle , get_model_path , load_metadata , prepare_inputs , load_meta_constants
28+ from openpilot .sunnypilot .livedelay .lagd_toggle import LagdToggle
2929from openpilot .sunnypilot .modeld .models .commonmodel_pyx import ModelFrame , CLContext
30- from openpilot .sunnypilot .modeld .modeld_base import ModelStateBase
3130
3231
3332PROCESS_NAME = "selfdrive.modeld.modeld_snpe"
@@ -49,7 +48,7 @@ def __init__(self, vipc=None):
4948 if vipc is not None :
5049 self .frame_id , self .timestamp_sof , self .timestamp_eof = vipc .frame_id , vipc .timestamp_sof , vipc .timestamp_eof
5150
52- class ModelState ( ModelStateBase ) :
51+ class ModelState :
5352 frame : ModelFrame
5453 wide_frame : ModelFrame
5554 inputs : dict [str , np .ndarray ]
@@ -58,7 +57,6 @@ class ModelState(ModelStateBase):
5857 model : ModelRunner
5958
6059 def __init__ (self , context : CLContext ):
61- ModelStateBase .__init__ (self )
6260 self .frame = ModelFrame (context )
6361 self .wide_frame = ModelFrame (context )
6462 self .prev_desire = np .zeros (ModelConstants .DESIRE_LEN , dtype = np .float32 )
@@ -204,6 +202,8 @@ def main(demo=False):
204202
205203 cloudlog .info ("modeld got CarParams: %s" , CP .brand )
206204
205+ modeld_lagd = LagdToggle ()
206+
207207 # Enable lagd support for sunnypilot modeld
208208 long_delay = CP .longitudinalActuatorDelay + model .LONG_SMOOTH_SECONDS
209209 prev_action = log .ModelDataV2 .Action ()
@@ -248,7 +248,7 @@ def main(demo=False):
248248 v_ego = sm ["carState" ].vEgo
249249 is_rhd = sm ["driverMonitoringState" ].isRHD
250250 frame_id = sm ["roadCameraState" ].frameId
251- model . lat_delay = get_lat_delay ( params , model . lat_delay , sm . updated [ "liveDelay" ]) + model . LAT_SMOOTH_SECONDS
251+ steer_delay = modeld_lagd . lagd_main ( CP , sm , model )
252252
253253 if sm .updated ["liveCalibration" ] and sm .seen ['roadCameraState' ] and sm .seen ['deviceState' ]:
254254 device_from_calib_euler = np .array (sm ["liveCalibration" ].rpyCalib , dtype = np .float32 )
@@ -283,7 +283,7 @@ def main(demo=False):
283283 }
284284
285285 if "lateral_control_params" in model .inputs .keys ():
286- inputs ['lateral_control_params' ] = np .array ([max (v_ego , 0. ), model . lat_delay ], dtype = np .float32 )
286+ inputs ['lateral_control_params' ] = np .array ([max (v_ego , 0. ), steer_delay ], dtype = np .float32 )
287287
288288 if "driving_style" in model .inputs .keys ():
289289 inputs ['driving_style' ] = np .array ([1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ], dtype = np .float32 )
@@ -306,7 +306,7 @@ def main(demo=False):
306306 action = model .get_action_from_model (model_output , prev_action , long_delay + DT_MDL )
307307 fill_model_msg (drivingdata_send , modelv2_send , model_output , action , publish_state , meta_main .frame_id , meta_extra .frame_id , frame_id ,
308308 frame_drop_ratio , meta_main .timestamp_eof , model_execution_time , live_calib_seen ,
309- v_ego , model . lat_delay , model .meta )
309+ v_ego , steer_delay , model .meta )
310310
311311 desire_state = modelv2_send .modelV2 .meta .desireState
312312 l_lane_change_prob = desire_state [log .Desire .laneChangeLeft ]
0 commit comments