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
2324from openpilot .sunnypilot .modeld .runners import ModelRunner , Runtime
2425from openpilot .sunnypilot .modeld .parse_model_outputs import Parser
2526from openpilot .sunnypilot .modeld .fill_model_msg import fill_model_msg , fill_pose_msg , PublishState
2627from openpilot .sunnypilot .modeld .constants import ModelConstants , Plan
2728from 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
3031
3132
3233PROCESS_NAME = "selfdrive.modeld.modeld_snpe"
@@ -48,7 +49,7 @@ def __init__(self, vipc=None):
4849 if vipc is not None :
4950 self .frame_id , self .timestamp_sof , self .timestamp_eof = vipc .frame_id , vipc .timestamp_sof , vipc .timestamp_eof
5051
51- class ModelState :
52+ class ModelState ( ModelStateBase ) :
5253 frame : ModelFrame
5354 wide_frame : ModelFrame
5455 inputs : dict [str , np .ndarray ]
@@ -57,6 +58,7 @@ class ModelState:
5758 model : ModelRunner
5859
5960 def __init__ (self , context : CLContext ):
61+ ModelStateBase .__init__ (self )
6062 self .frame = ModelFrame (context )
6163 self .wide_frame = ModelFrame (context )
6264 self .prev_desire = np .zeros (ModelConstants .DESIRE_LEN , dtype = np .float32 )
@@ -202,8 +204,6 @@ def main(demo=False):
202204
203205 cloudlog .info ("modeld got CarParams: %s" , CP .brand )
204206
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,8 +248,9 @@ def main(demo=False):
248248 v_ego = sm ["carState" ].vEgo
249249 is_rhd = sm ["driverMonitoringState" ].isRHD
250250 frame_id = sm ["roadCameraState" ].frameId
251- steer_delay = modeld_lagd .lagd_main (CP , sm , model )
252-
251+ if sm .frame % 60 == 0 :
252+ model .lat_delay = get_lat_delay (params , sm ["liveDelay" ].lateralDelay )
253+ lat_delay = model .lat_delay + model .LAT_SMOOTH_SECONDS
253254 if sm .updated ["liveCalibration" ] and sm .seen ['roadCameraState' ] and sm .seen ['deviceState' ]:
254255 device_from_calib_euler = np .array (sm ["liveCalibration" ].rpyCalib , dtype = np .float32 )
255256 dc = DEVICE_CAMERAS [(str (sm ['deviceState' ].deviceType ), str (sm ['roadCameraState' ].sensor ))]
@@ -283,7 +284,7 @@ def main(demo=False):
283284 }
284285
285286 if "lateral_control_params" in model .inputs .keys ():
286- inputs ['lateral_control_params' ] = np .array ([max (v_ego , 0. ), steer_delay ], dtype = np .float32 )
287+ inputs ['lateral_control_params' ] = np .array ([max (v_ego , 0. ), lat_delay ], dtype = np .float32 )
287288
288289 if "driving_style" in model .inputs .keys ():
289290 inputs ['driving_style' ] = np .array ([1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ], dtype = np .float32 )
@@ -306,7 +307,7 @@ def main(demo=False):
306307 action = model .get_action_from_model (model_output , prev_action , long_delay + DT_MDL )
307308 fill_model_msg (drivingdata_send , modelv2_send , model_output , action , publish_state , meta_main .frame_id , meta_extra .frame_id , frame_id ,
308309 frame_drop_ratio , meta_main .timestamp_eof , model_execution_time , live_calib_seen ,
309- v_ego , steer_delay , model .meta )
310+ v_ego , lat_delay , model .meta )
310311
311312 desire_state = modelv2_send .modelV2 .meta .desireState
312313 l_lane_change_prob = desire_state [log .Desire .laneChangeLeft ]
0 commit comments