Skip to content

Commit

Permalink
GM fix 'Controls Failed' on resuming after cycling main cruise switch (
Browse files Browse the repository at this point in the history
…commaai#255)

* Update car.capnp

* Update interface.py

* Update controlsd.py

* Update drive_helpers.py

* Update driver_monitor.py

* Update driver_monitor.py
  • Loading branch information
dibble9012 authored and kegman committed Dec 25, 2019
1 parent 3ec5362 commit 17f92b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct CarEvent @0x9b1657f34caf3ad3 {
immediateDisable @6 :Bool;
preEnable @7 :Bool;
permanent @8 :Bool;
resetVCruise @9 :Bool;

enum EventName @0xbaa8c5d505f727de {
# TODO: copy from error list
Expand Down
9 changes: 8 additions & 1 deletion selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,18 @@ def update(self, c, can_strings):
# handle button presses
for b in ret.buttonEvents:
# do enable on both accel and decel buttons
if b.type in [ButtonType.accelCruise, ButtonType.decelCruise] and not b.pressed:
# The ECM will fault if resume triggers an enable while speed is set to 0
if b.type == ButtonType.accelCruise and c.hudControl.setSpeed > 0 and c.hudControl.setSpeed < 70 and not b.pressed:
events.append(create_event('buttonEnable', [ET.ENABLE]))
if b.type == ButtonType.decelCruise and not b.pressed:
events.append(create_event('buttonEnable', [ET.ENABLE]))
# do disable on button down
if b.type == ButtonType.cancel and b.pressed:
events.append(create_event('buttonCancel', [ET.USER_DISABLE]))
# The ECM independently tracks a ‘speed is set’ state that is reset on main off.
# To keep controlsd in sync with the ECM state, generate a RESET_V_CRUISE event on main cruise presses.
if b.type == ButtonType.altButton3 and b.pressed:
events.append(create_event('buttonCancel', [ET.RESET_V_CRUISE, ET.USER_DISABLE]))

ret.events = events

Expand Down
4 changes: 4 additions & 0 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def state_transition(frame, CS, CP, state, events, soft_disable_timer, v_cruise_
# decrease the soft disable timer at every step, as it's reset on
# entrance in SOFT_DISABLING state
soft_disable_timer = max(0, soft_disable_timer - 1)

# Reset v_cruise_kph to 0
if get_events(events, [ET.RESET_V_CRUISE]):
v_cruise_kph = 0

# DISABLED
if state == State.disabled:
Expand Down
1 change: 1 addition & 0 deletions selfdrive/controls/lib/drive_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class EventTypes:
SOFT_DISABLE = 'softDisable'
IMMEDIATE_DISABLE = 'immediateDisable'
PERMANENT = 'permanent'
RESET_V_CRUISE = 'resetVCruise'


def create_event(name, types):
Expand Down

0 comments on commit 17f92b6

Please sign in to comment.