@@ -96,17 +96,17 @@ def initialize_v_cruise(v_ego, buttonEvents, v_cruise_last):
96
96
return int (round (clip (v_ego * CV .MS_TO_KPH , V_CRUISE_ENABLE_MIN , V_CRUISE_MAX )))
97
97
98
98
99
- def get_lag_adjusted_curvature (CP , v_ego , psis , curvatures , curvature_rates ):
100
- if len (psis ) != CONTROL_N :
101
- psis = [0.0 for i in range (CONTROL_N )]
102
- curvatures = [0.0 for i in range (CONTROL_N )]
103
- curvature_rates = [0.0 for i in range (CONTROL_N )]
104
-
99
+ def get_lag_adjusted_curvature (CP , v_ego , psis , curvatures , curvature_rates , t_since_plan ):
105
100
# TODO this needs more thought, use .2s extra for now to estimate other delays
106
101
delay = CP .steerActuatorDelay + .2
107
- current_curvature = curvatures [0 ]
108
- psi = interp (delay , T_IDXS [:CONTROL_N ], psis )
109
- desired_curvature_rate = curvature_rates [0 ]
102
+ if len (psis ) == CONTROL_N :
103
+ psi = interp (delay + t_since_plan , T_IDXS [:CONTROL_N ], psis )
104
+ current_curvature = interp (t_since_plan , T_IDXS [:CONTROL_N ], curvatures )
105
+ desired_curvature_rate = interp (t_since_plan , T_IDXS [:CONTROL_N ], curvature_rates )
106
+ else :
107
+ psi = 0.0
108
+ current_curvature = 0.0
109
+ desired_curvature_rate = 0.0
110
110
111
111
# MPC can plan to turn the wheel and turn back before t_delay. This means
112
112
# in high delay cases some corrections never even get commanded. So just use
@@ -116,9 +116,9 @@ def get_lag_adjusted_curvature(CP, v_ego, psis, curvatures, curvature_rates):
116
116
117
117
max_curvature_rate = interp (v_ego , MAX_CURVATURE_RATE_SPEEDS , MAX_CURVATURE_RATES )
118
118
safe_desired_curvature_rate = clip (desired_curvature_rate ,
119
- - max_curvature_rate ,
120
- max_curvature_rate )
119
+ - max_curvature_rate ,
120
+ max_curvature_rate )
121
121
safe_desired_curvature = clip (desired_curvature ,
122
- current_curvature - max_curvature_rate * DT_MDL ,
123
- current_curvature + max_curvature_rate * DT_MDL )
122
+ current_curvature - max_curvature_rate * DT_MDL ,
123
+ current_curvature + max_curvature_rate * DT_MDL )
124
124
return safe_desired_curvature , safe_desired_curvature_rate
0 commit comments