Skip to content

Hyundai: delay cancel button send#3305

Merged
sshane merged 14 commits intocommaai:masterfrom
sunnypilot:cancel-car-specific
Apr 22, 2026
Merged

Hyundai: delay cancel button send#3305
sshane merged 14 commits intocommaai:masterfrom
sunnypilot:cancel-car-specific

Conversation

@sunnyhaibin
Copy link
Copy Markdown
Contributor

@sunnyhaibin sunnyhaibin commented Apr 7, 2026

Description

  • Closes Hyundai: ACC error message when brake is used instead of pause button (2023 Ioniq 5 HDA2) #2770
  • On some HKG CAN and CAN FD non-CANFD_ALT_BUTTONS models, the cancel button bit (CF_Clu_CruiseSwState / CRUISE_BUTTONS = 4) is a pause/resume toggle, not a dedicated cancel. When the driver brakes to disengage, openpilot fires this bit ~17 ms later while factory SCC is still mid-transition, triggering the "SCC Conditions Not Met" alert.
  • carcontroller now delays the cancel button send by CANCEL_BUTTON_DELAY_FRAMES = 10 (~100 ms) using a cancel_counter pattern, same approach GM uses for its ECM soft-disable fault (thanks @sshane !). This lets factory SCC disengage naturally on brake press before OP ever sends the toggle.
  • The button still fires as a fallback if CC.cruiseControl.cancel remains asserted past the delay, such as factory SCC failed to disengage on brake for any other reason. Force-cancel remains fully functional.
  • Measured brake -> SCC-disengage latency on 161 HKG segments:
    • median 31 ms
    • p90 49 ms
    • p99/max 100 ms
    • 100% of brake-triggered disengages complete within 100 ms.

Validation

  • Dongle ID: 79f534ddd71804c0
  • Route: 00000015--738e5913fc/0
Before After
79f534ddd71804c0/00000011--ecef752f2c 79f534ddd71804c0/00000015--738e5913fc
before_79f534ddd71804c0_00000011_ecef752f2c after_79f534ddd71804c0_00000015_738e5913fc
IMG_3059.mov
IMG_3057.mov

@github-actions github-actions Bot added car related to opendbc/car/ hyundai labels Apr 7, 2026
@sunnyhaibin sunnyhaibin changed the title Hyundai: prioritize brake over pause/cancel button for factory SCC fo… Hyundai: prioritize brake over pause/cancel button for factory SCC force-disengage Apr 7, 2026
@sunnyhaibin sunnyhaibin changed the title Hyundai: prioritize brake over pause/cancel button for factory SCC force-disengage Hyundai: prioritize brake press over pause/cancel button for force-disengage Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

Car behavior report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

Testing 260 segments for: HYUNDAI_AZERA_HEV_6TH_GEN, HYUNDAI_ELANTRA_GT_I30, HYUNDAI_ELANTRA_2021, HYUNDAI_ELANTRA_HEV_2021, HYUNDAI_GENESIS, HYUNDAI_IONIQ, HYUNDAI_IONIQ_HEV_2022, HYUNDAI_IONIQ_EV_2020, HYUNDAI_IONIQ_PHEV_2019, HYUNDAI_IONIQ_PHEV, HYUNDAI_KONA_2022, HYUNDAI_KONA_EV, HYUNDAI_KONA_EV_2022, HYUNDAI_KONA_EV_2ND_GEN, HYUNDAI_SANTA_FE, HYUNDAI_SANTA_FE_2022, HYUNDAI_SANTA_FE_HEV_2022, HYUNDAI_SANTA_FE_PHEV_2022, HYUNDAI_SONATA, HYUNDAI_SONATA_LF, HYUNDAI_STARIA_4TH_GEN, HYUNDAI_PALISADE, HYUNDAI_SONATA_HYBRID, HYUNDAI_IONIQ_5, HYUNDAI_IONIQ_6, HYUNDAI_TUCSON_4TH_GEN, HYUNDAI_SANTA_CRUZ_1ST_GEN, HYUNDAI_CUSTIN_1ST_GEN

✅ 0 changed, 260 passed, 0 errors

Comment thread opendbc/car/hyundai/carcontroller.py Outdated
@sunnyhaibin sunnyhaibin marked this pull request as ready for review April 7, 2026 05:13
@sunnyhaibin sunnyhaibin changed the title Hyundai: prioritize brake press over pause/cancel button for force-disengage Hyundai: delay cancel button send prior force disengage Apr 7, 2026
@sunnyhaibin sunnyhaibin force-pushed the cancel-car-specific branch from 05c7819 to 45c15aa Compare April 7, 2026 05:21
@sunnyhaibin
Copy link
Copy Markdown
Contributor Author

sunnyhaibin commented Apr 7, 2026

Before After
79f534ddd71804c0/00000011--ecef752f2c 79f534ddd71804c0/00000015--738e5913fc
before_79f534ddd71804c0_00000011_ecef752f2c after_79f534ddd71804c0_00000015_738e5913fc
IMG_3059.mov
IMG_3057.mov

@sunnyhaibin
Copy link
Copy Markdown
Contributor Author

sunnyhaibin commented Apr 18, 2026

@sshane please let me know if there's anything else you'd want to see on this. I have been driving on this for 2 weeks and have no issue with it. Thanks!

Comment thread opendbc/car/hyundai/carcontroller.py Outdated
Comment on lines +144 to +146
# Delayed cancel: on newer CAN models, CF_Clu_CruiseSwState=4 is a pause/resume toggle (not a true cancel).
# Waiting CANCEL_BUTTON_DELAY_FRAMES lets factory SCC disengage naturally on brake press within its ~100 ms
# latency, and this branch acts as a fallback if SCC fails to disengage for any other reason.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove these 2 if the top describes it

Copy link
Copy Markdown
Contributor

@sshane sshane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches GM, LGTM. This may eliminate or reduce Toyota beep, I'm not totally sure it's not just a conflict when braking. Can you make a generic function that GM and this can re-use? Or at least put up a temp commit so I can check it out?

@sunnyhaibin
Copy link
Copy Markdown
Contributor Author

sunnyhaibin commented Apr 18, 2026

@sshane removed duplicated comments per review. Ready to merge.

This may eliminate or reduce Toyota beep, I'm not totally sure it's not just a conflict when braking. Can you make a generic function that GM and this can re-use? Or at least put up a temp commit so I can check it out?

I opened a draft PR here. Added Toyota in there for now for easier testing. Will split once it's confirmed to work.

nayan8teen added a commit to nayan8teen/opendbc that referenced this pull request Apr 19, 2026
Comment on lines 211 to 213
if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS:
can_sends.append(hyundaicanfd.create_acc_cancel(self.packer, self.CP, self.CAN, CS.cruise_info))
self.last_button_frame = self.frame
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't these cars have the same problem? It's just a message name difference?

Copy link
Copy Markdown
Contributor

@sshane sshane Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nvm we send ACC message. Why can't we always send ACC message? No comment explaining why. Example of early complexity harming future work

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unifying this is the kind of stuff I want to do before new ports

MAX_ANGLE_FRAMES = 89
MAX_ANGLE_CONSECUTIVE_FRAMES = 2

# On some HKG CAN and CAN FD non-CANFD_ALT_BUTTONS, the cancel button (CF_Clu_CruiseSwState / CRUISE_BUTTONS = 4) is
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging now, but can you update this comment after when we figure out if we can unify CC with the CAN FD alt and non alt buttons?

@sshane sshane changed the title Hyundai: delay cancel button send prior force disengage Hyundai: delay cancel button send Apr 22, 2026
@sshane sshane merged commit 480cde8 into commaai:master Apr 22, 2026
13 checks passed
@sshane sshane deleted the cancel-car-specific branch April 22, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

car related to opendbc/car/ hyundai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hyundai: ACC error message when brake is used instead of pause button (2023 Ioniq 5 HDA2)

2 participants