@ -71,19 +71,19 @@ class LongControl():
self . pid . reset ( )
self . v_pid = v_pid
def update ( self , active , v_ego , brake_pressed , standstill , cruise_standstill , v_cruise , v_target , v_target_future , a_target , CP ) :
def update ( self , active , CS , v_target , v_target_future , a_target , CP ) :
""" Update longitudinal control. This updates the state machine and runs a PID loop """
# Actuation limits
gas_max = interp ( v_e go, CP . gasMaxBP , CP . gasMaxV )
brake_max = interp ( v_e go, CP . brakeMaxBP , CP . brakeMaxV )
gas_max = interp ( CS . vE go, CP . gasMaxBP , CP . gasMaxV )
brake_max = interp ( CS . vE go, CP . brakeMaxBP , CP . brakeMaxV )
# Update state machine
output_gb = self . last_output_gb
self . long_control_state = long_control_state_trans ( active , self . long_control_state , v_e go,
self . long_control_state = long_control_state_trans ( active , self . long_control_state , CS . vE go,
v_target_future , self . v_pid , output_gb ,
brake_pressed , cruise_ standstill)
CS . brakePressed , CS . cruiseState . standstill )
v_ego_pid = max ( v_e go, MIN_CAN_SPEED ) # Without this we get jumps, CAN bus reports 0 when speed < 0.3
v_ego_pid = max ( CS . vE go, MIN_CAN_SPEED ) # Without this we get jumps, CAN bus reports 0 when speed < 0.3
if self . long_control_state == LongCtrlState . off :
self . v_pid = v_ego_pid
@ -98,7 +98,7 @@ class LongControl():
# Toyota starts braking more when it thinks you want to stop
# Freeze the integrator so we don't accelerate to compensate, and don't allow positive acceleration
prevent_overshoot = not CP . stoppingControl and v_e go < 1.5 and v_target_future < 0.7
prevent_overshoot = not CP . stoppingControl and CS . vE go < 1.5 and v_target_future < 0.7
deadzone = interp ( v_ego_pid , CP . longitudinalTuning . deadzoneBP , CP . longitudinalTuning . deadzoneV )
output_gb = self . pid . update ( self . v_pid , v_ego_pid , speed = v_ego_pid , deadzone = deadzone , feedforward = a_target , freeze_integrator = prevent_overshoot )
@ -109,18 +109,18 @@ class LongControl():
# Intention is to stop, switch to a different brake control until we stop
elif self . long_control_state == LongCtrlState . stopping :
# Keep applying brakes until the car is stopped
if not standstill or output_gb > - BRAKE_STOPPING_TARGET :
if not CS . standstill or output_gb > - BRAKE_STOPPING_TARGET :
output_gb - = STOPPING_BRAKE_RATE / RATE
output_gb = clip ( output_gb , - brake_max , gas_max )
self . v_pid = v_e go
self . v_pid = CS . vE go
self . pid . reset ( )
# Intention is to move again, release brake fast before handing control to PID
elif self . long_control_state == LongCtrlState . starting :
if output_gb < - 0.2 :
output_gb + = STARTING_BRAKE_RATE / RATE
self . v_pid = v_e go
self . v_pid = CS . vE go
self . pid . reset ( )
self . last_output_gb = output_gb