@ -1,11 +1,8 @@
from collections import deque
from cereal import car , log
import cereal . messaging as messaging
from opendbc . car import DT_CTRL , structs
from opendbc . car . interfaces import MAX_CTRL_SPEED
from opendbc . car . volkswagen . values import CarControllerParams as VWCarControllerParams
from opendbc . car . hyundai . interface import ENABLE_BUTTONS as HYUNDAI_ENABLE_BUTTONS
from opendbc . car . hyundai . carstate import PREV_BUTTON_SAMPLES as HYUNDAI_PREV_BUTTON_SAMPLES
from openpilot . selfdrive . selfdrived . events import Events
@ -39,8 +36,6 @@ class CarSpecificEvents:
self . no_steer_warning = False
self . silent_steer_warning = True
self . cruise_buttons : deque = deque ( [ ] , maxlen = HYUNDAI_PREV_BUTTON_SAMPLES )
def update ( self , CS : car . CarState , CS_prev : car . CarState , CC : car . CarControl ) :
if self . CP . brand in ( ' body ' , ' mock ' ) :
events = Events ( )
@ -136,12 +131,8 @@ class CarSpecificEvents:
# events.add(EventName.steerTimeLimit)
elif self . CP . brand == ' hyundai ' :
# On some newer model years, the CANCEL button acts as a pause/resume button based on the PCM state
# To avoid re-engaging when openpilot cancels, check user engagement intention via buttons
# Main button also can trigger an engagement on these cars
self . cruise_buttons . append ( any ( ev . type in HYUNDAI_ENABLE_BUTTONS for ev in CS . buttonEvents ) )
events = self . create_common_events ( CS , CS_prev , extra_gears = ( GearShifter . sport , GearShifter . manumatic ) ,
pcm_enable = self . CP . pcmCruise , allow_enable = any ( self . cruise_buttons ) , allow_ button_cancel = False )
pcm_enable = self . CP . pcmCruise , allow_button_cancel = False )
# low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s)
if CS . vEgo < ( self . CP . minSteerSpeed + 2. ) and self . CP . minSteerSpeed > 10. :
@ -157,7 +148,7 @@ class CarSpecificEvents:
return events
def create_common_events ( self , CS : structs . CarState , CS_prev : car . CarState , extra_gears = None , pcm_enable = True ,
allow_enable = True , allow_ button_cancel = True ) :
allow_button_cancel = True ) :
events = Events ( )
if CS . doorOpen :
@ -236,7 +227,7 @@ class CarSpecificEvents:
# we engage when pcm is active (rising edge)
# enabling can optionally be blocked by the car interface
if pcm_enable :
if CS . cruiseState . enabled and not CS_prev . cruiseState . enabled and allow_e nable:
if CS . cruiseState . enabled and not CS_prev . cruiseState . enabled and not CS . blockPcmE nable:
events . add ( EventName . pcmEnable )
elif not CS . cruiseState . enabled :
events . add ( EventName . pcmDisable )