Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions selfdrive/car/car_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def __init__(self, CP: structs.CarParams):
self.no_steer_warning = False
self.silent_steer_warning = True

@staticmethod
def add_if_below_engage_speed(speed: float, threshold: float, events: Events):
if speed < threshold:
events.add(EventName.belowEngageSpeed)

def update(self, CS: car.CarState, CS_prev: car.CarState, CC: car.CarControl):
extra_gears = BRAND_EXTRA_GEARS.get(self.CP.brand, None)

Expand All @@ -67,18 +72,16 @@ def update(self, CS: car.CarState, CS_prev: car.CarState, CC: car.CarControl):
elif self.CP.brand == 'honda':
events = self.create_common_events(CS, CS_prev, extra_gears=extra_gears, pcm_enable=False)

if self.CP.pcmCruise and CS.vEgo < self.CP.minEnableSpeed:
events.add(EventName.belowEngageSpeed)

if self.CP.pcmCruise:
CarSpecificEvents.add_if_below_engage_speed(CS.vEgo, self.CP.minEnableSpeed, events)
# we engage when pcm is active (rising edge)
if CS.cruiseState.enabled and not CS_prev.cruiseState.enabled:
events.add(EventName.pcmEnable)
elif not CS.cruiseState.enabled and (CC.actuators.accel >= 0. or not self.CP.openpilotLongitudinalControl):
# it can happen that car cruise disables while comma system is enabled: need to
# keep braking if needed or if the speed is very low
if CS.vEgo < self.CP.minEnableSpeed + 2.:
# non loud alert if cruise disables below 25mph as expected (+ a little margin)
# non-loud alert if cruise disables below 25mph as expected (+ a little margin)
events.add(EventName.speedTooLow)
else:
events.add(EventName.cruiseDisabled)
Expand All @@ -93,32 +96,29 @@ def update(self, CS: car.CarState, CS_prev: car.CarState, CC: car.CarControl):
# Only can leave standstill when planner wants to move
if CS.cruiseState.standstill and not CS.brakePressed and CC.cruiseControl.resume:
events.add(EventName.resumeRequired)
if CS.vEgo < self.CP.minEnableSpeed:
events.add(EventName.belowEngageSpeed)
if CC.actuators.accel > 0.3:
# some margin on the actuator to not false trigger cancellation while stopping
events.add(EventName.speedTooLow)
if CS.vEgo < 0.001:
# while in standstill, send a user alert
events.add(EventName.manualRestart)
CarSpecificEvents.add_if_below_engage_speed(CS.vEgo, self.CP.minEnableSpeed, events)
if CC.actuators.accel > 0.3:
# some margin on the actuator to not false trigger cancellation while stopping
events.add(EventName.speedTooLow)
if CS.vEgo < 0.001:
# while in standstill, send a user alert
events.add(EventName.manualRestart)

elif self.CP.brand == 'gm':
events = self.create_common_events(CS, CS_prev, extra_gears=extra_gears, pcm_enable=self.CP.pcmCruise)

# Enabling at a standstill with brake is allowed
# TODO: verify 17 Volt can enable for the first time at a stop and allow for all GMs
if CS.vEgo < self.CP.minEnableSpeed and not (CS.standstill and CS.brake >= 20 and
self.CP.networkLocation == NetworkLocation.fwdCamera):
events.add(EventName.belowEngageSpeed)
if not (CS.standstill and CS.brake >= 20 and self.CP.networkLocation == NetworkLocation.fwdCamera):
CarSpecificEvents.add_if_below_engage_speed(CS.vEgo, self.CP.minEnableSpeed, events)
if CS.cruiseState.standstill:
events.add(EventName.resumeRequired)

elif self.CP.brand == 'volkswagen':
events = self.create_common_events(CS, CS_prev, extra_gears=extra_gears, pcm_enable=self.CP.pcmCruise)

if self.CP.openpilotLongitudinalControl:
if CS.vEgo < self.CP.minEnableSpeed + 0.5:
events.add(EventName.belowEngageSpeed)
CarSpecificEvents.add_if_below_engage_speed(CS.vEgo, (self.CP.minEnableSpeed + 0.5), events)
if CC.enabled and CS.vEgo < self.CP.minEnableSpeed:
events.add(EventName.speedTooLow)

Expand Down