@ -73,7 +73,7 @@ def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None, body_dbc=None) -> Dict[str, st
return { ' pt ' : pt_dbc , ' radar ' : radar_dbc , ' chassis ' : chassis_dbc , ' body ' : body_dbc }
def apply_st d_steer_torque_limits ( apply_torque , apply_torque_last , driver_torque , LIMITS ) :
def apply_driver _steer_torque_limits ( apply_torque , apply_torque_last , driver_torque , LIMITS ) :
# limits due to driver torque
driver_max_torque = LIMITS . STEER_MAX + ( LIMITS . STEER_DRIVER_ALLOWANCE + driver_torque * LIMITS . STEER_DRIVER_FACTOR ) * LIMITS . STEER_DRIVER_MULTIPLIER
@ -93,24 +93,32 @@ def apply_std_steer_torque_limits(apply_torque, apply_torque_last, driver_torque
return int ( round ( float ( apply_torque ) ) )
def apply_toyota_steer_torque_limits ( apply_torque , apply_torque_last , motor_torque , LIMITS ) :
# limits due to comparison of commanded torque VS motor reported torque
max_lim = min ( max ( motor_torque + LIMITS . STEER_ERROR_MAX , LIMITS . STEER_ERROR_MAX ) , LIMITS . STEER_MAX )
min_lim = max ( min ( motor_torque - LIMITS . STEER_ERROR_MAX , - LIMITS . STEER_ERROR_MAX ) , - LIMITS . STEER_MAX )
def apply_dist_to_meas_limits ( val , val_last , val_meas ,
STEER_DELTA_UP , STEER_DELTA_DOWN ,
STEER_ERROR_MAX , STEER_MAX ) :
# limits due to comparison of commanded val VS measured val (torque/angle/curvature)
max_lim = min ( max ( val_meas + STEER_ERROR_MAX , STEER_ERROR_MAX ) , STEER_MAX )
min_lim = max ( min ( val_meas - STEER_ERROR_MAX , - STEER_ERROR_MAX ) , - STEER_MAX )
apply_torque = clip ( apply_torque , min_lim , max_lim )
v al = clip ( v al, min_lim , max_lim )
# slow rate if steer torque increases in magnitude
if app ly_torque _last > 0 :
app ly_torque = clip ( app ly_torque ,
max ( app ly_torque _last - LIMITS . STEER_DELTA_DOWN , - LIMITS . STEER_DELTA_UP ) ,
app ly_torque _last + LIMITS . STEER_DELTA_UP )
# slow rate if val increases in magnitude
if v al_last > 0 :
v al = clip ( v al,
max ( v al_last - STEER_DELTA_DOWN , - STEER_DELTA_UP ) ,
v al_last + STEER_DELTA_UP )
else :
app ly_torque = clip ( app ly_torque ,
app ly_torque _last - LIMITS . STEER_DELTA_UP ,
min ( app ly_torque _last + LIMITS . STEER_DELTA_DOWN , LIMITS . STEER_DELTA_UP ) )
v al = clip ( v al,
v al_last - STEER_DELTA_UP ,
min ( v al_last + STEER_DELTA_DOWN , STEER_DELTA_UP ) )
return int ( round ( float ( apply_torque ) ) )
return float ( val )
def apply_meas_steer_torque_limits ( apply_torque , apply_torque_last , motor_torque , LIMITS ) :
return int ( round ( apply_dist_to_meas_limits ( apply_torque , apply_torque_last , motor_torque ,
LIMITS . STEER_DELTA_UP , LIMITS . STEER_DELTA_DOWN ,
LIMITS . STEER_ERROR_MAX , LIMITS . STEER_MAX ) ) )
def apply_std_steer_angle_limits ( apply_angle , apply_angle_last , v_ego , LIMITS ) :