@ -11,7 +11,29 @@ from opendbc.can.packer import CANPacker
VisualAlert = car . CarControl . HUDControl . VisualAlert
# TODO: not clear this does anything useful
def compute_gb_honda_bosch ( accel , speed ) :
#TODO returns 0s, is unused
return 0.0 , 0.0
def compute_gb_honda_nidec ( accel , speed ) :
creep_brake = 0.0
creep_speed = 2.3
creep_brake_value = 0.15
if speed < creep_speed :
creep_brake = ( creep_speed - speed ) / creep_speed * creep_brake_value
gb = float ( accel ) / 4.8 - creep_brake
return clip ( gb , 0.0 , 1.0 ) , clip ( - gb , 0.0 , 1.0 )
def compute_gas_brake ( accel , speed , fingerprint ) :
if fingerprint in HONDA_BOSCH :
return compute_gb_honda_bosch ( accel , speed )
else :
return compute_gb_honda_nidec ( accel , speed )
#TODO not clear this does anything useful
def actuator_hystereses ( brake , braking , brake_steady , v_ego , car_fingerprint ) :
# hyst params
brake_hyst_on = 0.02 # to activate brakes exceed this value
@ -94,8 +116,15 @@ class CarController():
P = self . params
if enabled :
accel = actuators . accel
gas , brake = compute_gas_brake ( actuators . accel , CS . out . vEgo , CS . CP . carFingerprint )
else :
accel = 0.0
gas , brake = 0.0 , 0.0
# *** apply brake hysteresis ***
brake , self . braking , self . brake_steady = actuator_hystereses ( actuators . brake , self . braking , self . brake_steady , CS . out . vEgo , CS . CP . carFingerprint )
pre_limit_ brake, self . braking , self . brake_steady = actuator_hystereses ( brake , self . braking , self . brake_steady , CS . out . vEgo , CS . CP . carFingerprint )
# *** no output if not enabled ***
if not enabled and CS . out . cruiseState . enabled :
@ -107,7 +136,7 @@ class CarController():
pcm_cancel_cmd = pcm_cancel_cmd and CS . CP . pcmCruise
# *** rate limit after the enable check ***
self . brake_last = rate_limit ( brake , self . brake_last , - 2. , DT_CTRL )
self . brake_last = rate_limit ( pre_limit_ brake, self . brake_last , - 2. , DT_CTRL )
# vehicle hud display, wait for one update from 10Hz 0x304 msg
if hud_show_lanes :
@ -147,18 +176,13 @@ class CarController():
lkas_active , CS . CP . carFingerprint , idx , CS . CP . openpilotLongitudinalControl ) )
accel = actuators . gas - actuators . brake
# TODO: pass in LoC.long_control_state and use that to decide starting/stoppping
stopping = accel < 0 and CS . out . vEgo < 0.3
starting = accel > 0 and CS . out . vEgo < 0.3
# Prevent rolling backwards
accel = - 1.0 if stopping else accel
if CS . CP . carFingerprint in HONDA_BOSCH :
apply_accel = interp ( accel , P . BOSCH_ACCEL_LOOKUP_BP , P . BOSCH_ACCEL_LOOKUP_V )
else :
apply_accel = interp ( accel , P . NIDEC_ACCEL_LOOKUP_BP , P . NIDEC_ACCEL_LOOKUP_V )
accel = - 4.0 if stopping else accel
# wind brake from air resistance decel at high speed
wind_brake = interp ( CS . out . vEgo , [ 0.0 , 2.3 , 35.0 ] , [ 0.001 , 0.002 , 0.15 ] )
@ -167,14 +191,15 @@ class CarController():
pcm_accel = int ( clip ( pcm_accel , 0 , 1 ) * 0xc6 )
else :
max_accel = interp ( CS . out . vEgo , P . NIDEC_MAX_ACCEL_BP , P . NIDEC_MAX_ACCEL_V )
pcm_accel = int ( clip ( apply_accel / max_accel , 0.0 , 1.0 ) * 0xc6 )
# TODO this 1.44 is just to maintain previous behavior
pcm_accel = int ( clip ( ( accel / 1.44 ) / max_accel , 0.0 , 1.0 ) * 0xc6 )
pcm_speed_BP = [ - wind_brake ,
- wind_brake * ( 3 / 4 ) ,
0.0 ]
pcm_speed_V = [ 0.0 ,
clip ( CS . out . vEgo + apply_a ccel / 2.0 - 2.0 , 0.0 , 100.0 ) ,
clip ( CS . out . vEgo + apply_a ccel / 2.0 + 2.0 , 0.0 , 100.0 ) ]
pcm_speed = interp ( accel , pcm_speed_BP , pcm_speed_V )
clip ( CS . out . vEgo + accel / 2.0 - 2.0 , 0.0 , 100.0 ) ,
clip ( CS . out . vEgo + accel / 2.0 + 2.0 , 0.0 , 100.0 ) ]
pcm_speed = interp ( - brake , pcm_speed_BP , pcm_speed_V )
if not CS . CP . openpilotLongitudinalControl :
if ( frame % 2 ) == 0 :
@ -193,8 +218,8 @@ class CarController():
ts = frame * DT_CTRL
if CS . CP . carFingerprint in HONDA_BOSCH :
apply _gas = interp ( accel , P . BOSCH_GAS_LOOKUP_BP , P . BOSCH_GAS_LOOKUP_V )
can_sends . extend ( hondacan . create_acc_commands ( self . packer , enabled , apply_a ccel , apply _gas, idx , stopping , starting , CS . CP . carFingerprint ) )
bosch _gas = interp ( accel , P . BOSCH_GAS_LOOKUP_BP , P . BOSCH_GAS_LOOKUP_V )
can_sends . extend ( hondacan . create_acc_commands ( self . packer , enabled , accel , bosch _gas, idx , stopping , starting , CS . CP . carFingerprint ) )
else :
apply_brake = clip ( self . brake_last - wind_brake , 0.0 , 1.0 )
@ -209,7 +234,7 @@ class CarController():
gas_mult = interp ( CS . out . vEgo , [ 0. , 10. ] , [ 0.4 , 1.0 ] )
# send exactly zero if apply_gas is zero. Interceptor will send the max between read value and apply_gas.
# This prevents unexpected pedal range rescaling
apply_gas = clip ( gas_mult * actuators . gas , 0. , 1. )
apply_gas = clip ( gas_mult * gas , 0. , 1. )
can_sends . append ( create_gas_command ( self . packer , apply_gas , idx ) )
hud = HUDData ( int ( pcm_accel ) , int ( round ( hud_v_cruise ) ) , hud_car ,