@ -16,7 +16,7 @@ from system.version import get_short_branch
from selfdrive . boardd . boardd import can_list_to_can_capnp
from selfdrive . boardd . boardd import can_list_to_can_capnp
from selfdrive . car . car_helpers import get_car , get_startup_event , get_one_can
from selfdrive . car . car_helpers import get_car , get_startup_event , get_one_can
from selfdrive . controls . lib . lane_planner import CAMERA_OFFSET
from selfdrive . controls . lib . lane_planner import CAMERA_OFFSET
from selfdrive . controls . lib . drive_helpers import update_v_cruise , initialize_v_cruise
from selfdrive . controls . lib . drive_helpers import V_CRUISE_INITIAL , update_v_cruise , initialize_v_cruise
from selfdrive . controls . lib . drive_helpers import get_lag_adjusted_curvature
from selfdrive . controls . lib . drive_helpers import get_lag_adjusted_curvature
from selfdrive . controls . lib . latcontrol import LatControl
from selfdrive . controls . lib . latcontrol import LatControl
from selfdrive . controls . lib . longcontrol import LongControl
from selfdrive . controls . lib . longcontrol import LongControl
@ -50,6 +50,7 @@ LaneChangeState = log.LateralPlan.LaneChangeState
LaneChangeDirection = log . LateralPlan . LaneChangeDirection
LaneChangeDirection = log . LateralPlan . LaneChangeDirection
EventName = car . CarEvent . EventName
EventName = car . CarEvent . EventName
ButtonEvent = car . CarState . ButtonEvent
ButtonEvent = car . CarState . ButtonEvent
ButtonType = car . CarState . ButtonEvent . Type
SafetyModel = car . CarParams . SafetyModel
SafetyModel = car . CarParams . SafetyModel
IGNORED_SAFETY_MODES = ( SafetyModel . silent , SafetyModel . noOutput )
IGNORED_SAFETY_MODES = ( SafetyModel . silent , SafetyModel . noOutput )
@ -162,8 +163,8 @@ class Controls:
self . active = False
self . active = False
self . can_rcv_error = False
self . can_rcv_error = False
self . soft_disable_timer = 0
self . soft_disable_timer = 0
self . v_cruise_kph = 255
self . v_cruise_kph = V_CRUISE_INITIAL
self . v_cruise_cluster_kph = 255
self . v_cruise_cluster_kph = V_CRUISE_INITIAL
self . v_cruise_kph_last = 0
self . v_cruise_kph_last = 0
self . mismatch_counter = 0
self . mismatch_counter = 0
self . cruise_mismatch_counter = 0
self . cruise_mismatch_counter = 0
@ -228,6 +229,11 @@ class Controls:
self . events . add ( EventName . controlsInitializing )
self . events . add ( EventName . controlsInitializing )
return
return
# Block resume if cruise never previously enabled
resume_pressed = any ( be . type in ( ButtonType . accelCruise , ButtonType . resumeCruise ) for be in CS . buttonEvents )
if not self . CP . pcmCruise and self . v_cruise_kph == V_CRUISE_INITIAL and resume_pressed :
self . events . add ( EventName . resumeBlocked )
# Disable on rising edge of accelerator or brake. Also disable on brake when speed > 0
# Disable on rising edge of accelerator or brake. Also disable on brake when speed > 0
if ( CS . gasPressed and not self . CS_prev . gasPressed and self . disengage_on_accelerator ) or \
if ( CS . gasPressed and not self . CS_prev . gasPressed and self . disengage_on_accelerator ) or \
( CS . brakePressed and ( not self . CS_prev . brakePressed or not CS . standstill ) ) :
( CS . brakePressed and ( not self . CS_prev . brakePressed or not CS . standstill ) ) :
@ -460,18 +466,18 @@ class Controls:
self . v_cruise_kph_last = self . v_cruise_kph
self . v_cruise_kph_last = self . v_cruise_kph
# if stock cruise is completely disabled, then we can use our own set speed logic
if CS . cruiseState . available :
if not self . CP . pcmCruise :
# if stock cruise is completely disabled, then we can use our own set speed logic
self . v_cruise_kph = update_v_cruise ( self . v_cruise_kph , CS . vEgo , CS . gasPressed , CS . buttonEvents ,
if not self . CP . pcmCruise :
self . button_timers , self . enabled , self . is_metric )
self . v_cruise_kph = update_v_cruise ( self . v_cruise_kph , CS . vEgo , CS . gasPressed , CS . buttonEvents ,
self . v_cruise_cluster_kph = self . v_cruise_kph
self . button_timers , self . enabled , self . is_metric )
else :
self . v_cruise_cluster_kph = self . v_cruise_kph
if CS . cruis eState . availabl e:
els e :
self . v_cruise_kph = CS . cruiseState . speed * CV . MS_TO_KPH
self . v_cruise_kph = CS . cruiseState . speed * CV . MS_TO_KPH
self . v_cruise_cluster_kph = CS . cruiseState . speedCluster * CV . MS_TO_KPH
self . v_cruise_cluster_kph = CS . cruiseState . speedCluster * CV . MS_TO_KPH
else :
else :
self . v_cruise_kph = 0
self . v_cruise_kph = V_CRUISE_INITIAL
self . v_cruise_cluster_kph = 0
self . v_cruise_cluster_kph = V_CRUISE_INITIAL
# decrement the soft disable timer at every step, as it's reset on
# decrement the soft disable timer at every step, as it's reset on
# entrance in SOFT_DISABLING state
# entrance in SOFT_DISABLING state