Skip to content

Toyota: Add SECOC longitudinal control#1385

Merged
jyoung8607 merged 109 commits intocommaai:masterfrom
chrispypatt:secoc-long
Sep 29, 2025
Merged

Toyota: Add SECOC longitudinal control#1385
jyoung8607 merged 109 commits intocommaai:masterfrom
chrispypatt:secoc-long

Conversation

@chrispypatt
Copy link
Copy Markdown
Contributor

@chrispypatt chrispypatt commented Oct 18, 2024

DBC:

  • Add counter for secoc acc messages like the other secoc messages
  • Add new acc message creation for second ACCEL_CMD
  • Remove SECOC openpilotLongitudinalControl disable

Safety:

Creates a SECOC variant of common long messages. This is basically a copy of the TOYOTA_COMMON_LONG_TX_MSGS but:

swapped TOYOTA_COMMON_TX_MSGS for TOYOTA_COMMON_SECOC_TX_MSGS
added a the new secoc acc command address 0x183

@chrispypatt chrispypatt force-pushed the secoc-long branch 2 times, most recently from 745b551 to 848f074 Compare October 18, 2024 17:53
Copy link
Copy Markdown
Collaborator

@jyoung8607 jyoung8607 left a comment

Choose a reason for hiding this comment

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

Long term I'd like to clean up the SecOC message wrapping convention, but that's a separate refactor that we don't need to get into for this PR.

For development purposes we've gotten away with setting the accel value in both ACC control messages, but before we merge we need to match stock actuation behavior: always set zero/inactive acceleration in ACC_CONTROL, and only send the true accel in ACC_CONTROL_2. There are checks in commaai/panda#2072 to ensure this correct behavior.

Aside from that, LGTM.

@nelsonjchen
Copy link
Copy Markdown
Contributor

Just passing a Discord Link here to some of the chatter on the state of the PR:

Nov 21: "Well the mutation tests are failing so something seems wrong functionally. But I would also say my attempt at supporting two acc commands in the tests is a bit gross"

https://discord.com/channels/469524606043160576/905950538816978974/1309380353261174847

@chrispypatt chrispypatt marked this pull request as ready for review December 11, 2024 02:22
@chrispypatt
Copy link
Copy Markdown
Contributor Author

@sshane @jyoung8607 I just resolved some merge conflicts w/ master and have updated my branch. Any feedback or discussion around my previous questions would be appreciated.

@GaganBhat
Copy link
Copy Markdown

Hi, @sshane Is there a process to get a review on this PR? Thank you!

@yuzisee
Copy link
Copy Markdown

yuzisee commented Aug 5, 2025

Good news! Sounds like it's on Jason's radar https://discord.com/channels/469524606043160576/1184981830714261604/1400183941515972830 so for now we need to be patient 🙂

@dobromirmontauk
Copy link
Copy Markdown

So excited for this!

@jyoung8607
Copy link
Copy Markdown
Collaborator

jyoung8607 commented Aug 27, 2025

Rebased.

I think the car port and safety code are basically okay, but we have to figure out a better way to run the accel tests. We can't hack up the common tests like that. Can you try doing it with inheritance instead?

Something like this in the base classes:

  def _accel_msg_835(self, accel, cancel_req=0):
    values = {"ACCEL_CMD": accel, "CANCEL_REQ": cancel_req}
    return self.packer.make_can_msg_panda("ACC_CONTROL", 0, values)

  def _accel_msg_387(self, accel):
    values = {"ACCEL_CMD": accel}
    return self.packer.make_can_msg_panda("ACC_CONTROL_2", 0, values)

Then in the non-SecOC cases:

  def _accel_msg(self, accel):
    return self._accel_msg_835(accel)

And in the SecOC cases:

  def _accel_msg(self, accel):
    return self._accel_msg_387(accel)

  def test_835_actuation_blocked(self, stock_longitudinal: bool = True):
    """
    For SecOC cars, longitudinal acceleration must be sent in ACC_CONTROL_2, but all other ACC
    data remains in ACC_CONTROL. Verify no actuation is sent via ACC_CONTROL.
    """
    (the same as test_acc_cancel but should_tx = accel == self.INACTIVE_ACCEL)

Also tweak test_acc_cancel to always call _accel_msg_835 instead of _accel_msg.

I started to do this myself but hadn't settled on how to juggle the existing classes, figured you could try.

Copy link
Copy Markdown
Collaborator

@jyoung8607 jyoung8607 left a comment

Choose a reason for hiding this comment

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

Tests need work. Left some untested ideas in an earlier comment.

@chrispypatt
Copy link
Copy Markdown
Contributor Author

Sounds good I can take a stab at it. My time is a bit more limited ATM.

@jyoung8607 jyoung8607 marked this pull request as draft September 4, 2025 18:19
@chrispypatt chrispypatt force-pushed the secoc-long branch 2 times, most recently from b2e4904 to eabcf67 Compare September 22, 2025 04:29
@chrispypatt
Copy link
Copy Markdown
Contributor Author

chrispypatt commented Sep 22, 2025

should_tx = accel == self.INACTIVE_ACCEL

I couldn't get this exactly to work and had to follow how test_acc_cancel is implemented using should_tx = np.isclose(accel, self.INACTIVE_ACCEL, atol=0.0001) due to FP errors in comparing small floats.

But otherwise, @jyoung8607 I really like your suggestion. It's much cleaner than my previous implementation.

@chrispypatt chrispypatt marked this pull request as ready for review September 22, 2025 04:35
Copy link
Copy Markdown
Collaborator

@jyoung8607 jyoung8607 left a comment

Choose a reason for hiding this comment

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

LGTM pending comma review due to safety code changes.

@jyoung8607 jyoung8607 requested review from adeebshihadeh and removed request for adeebshihadeh and sshane September 29, 2025 15:59
@adeebshihadeh
Copy link
Copy Markdown
Contributor

LGTM pending comma review due to safety code changes.

Since it's behind ALLOW_DEBUG, you're good to merge safety changes.

@jyoung8607 jyoung8607 merged commit 4d93a55 into commaai:master Sep 29, 2025
10 checks passed
@GaganBhat
Copy link
Copy Markdown

Thank you for working on this @chrispypatt !! Awesome to see this merged.

@jyoung8607 jyoung8607 mentioned this pull request Sep 29, 2025
gadhadar pushed a commit to qzwf/opendbc that referenced this pull request Oct 14, 2025
* Add secoc ACC command

* Remove commented out secoc long disable code

* Add Toyota 2021 SecOC route

* Send 0 accel for ACC_CONTROL to match stock

* Update opendbc/car/toyota/carcontroller.py

Co-authored-by: Jason Young <46612682+jyoung8607@users.noreply.github.com>

* Add new ACC steering wheel message for SecOC cars. Update distance_button with the new message.

* Add new DBC file for Toyota SecOC cars.

* Update Toyota Rav4 Prime and 4th Gen Sienna to use SecOC DBC file.

* Update carstate.py l

* dont save button state on secoc

Co-authored-by: Jason Wen <haibin.wen3@gmail.com>

* Update opendbc/car/toyota/carstate.py

Co-authored-by: Jason Wen <haibin.wen3@gmail.com>

* Remove unreachable code

* Move secoc safety to opendbc

* Update R4P SecOC route

* Build safety with -Wextra

* safety: relay malfunction config (commaai#1959)

* Do Toyota relay malfunction config

* clean up

* not needed

* rm this

* rm

* fix

* great name (rename after commaai#1954)

* do gm

* need this since we will dynamically block it

* subie

* some more brands

* Ford

* Chrysler

* Hyundai

* huge oof hyundai

* toyota & vw

* fix

* tesla

* 0x194 isn't on Honda Bosch

* Honda: we can check bus 1 for 0xe4

* misra

* static

* ugh need this

* correct

* nl

* like

* space

* Hyundai: dashcam FCEV (commaai#1973)

* Disable FCEV

* coverage

* fixme

* misra

misra

* Hyundai CAN FD: Accurate hybrid powertrain detection (commaai#1891)

* Hyundai CAN FD: Accurate hybrid  powertrain detection

* label message names

* use 0xFA

* Tesla: Autopilot enabled signal (commaai#1978)

* new Tesla signals

* consistent

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* Tesla: fix incorrect DBC msg length (commaai#1980)

actually DBC is wrong

* Subaru Pre-Global: fix missing rx checks (commaai#1982)

passes tm

* Honda Nidec: missing brake command rx check (commaai#1981)

* missing honda rx nidec brake command

* misra

* move up

* Honda safety: only test alt brake for alt brake param

split from commaai#1903

* safety tests: remove redundant test skips (commaai#1983)

remove useless skiptests

* GM safety: add missing regen rx check (commaai#1984)

* from pr

* forgot

* fix test

* cleaner

* misra

* Fingerprint: 2022 Civic Si (commaai#1952)

* 2022 Civic Si

* fix

* Hyundai CAN FD safety: more clear what is common (commaai#1986)

* more clear what is common

* here too

* Hyundai CANFD safety tests: common safety param combinations (commaai#1987)

clean this up

* Hyundai CAN FD safety: replace alt buttons live detection with param (commaai#1985)

* alt buttons needs to be checked with the param

* flip

* do tests

* Hyundai safety: add missing rx checks (commaai#1989)

* add torque driver addr check and always check buttons (for interaction)

* fix

* safety: rename allowed

less confusing next to `safety_allowed`

* safety: only run rx hooks on whitelisted msgs (commaai#1903)

* don't run rx hook on non-allowed messages

* better name

* fix toyota (bug w/ secoc)

* looks like honda is broken

* rivian is also bad! (missing EPAS_SystemStatus)

* misra so far

rivian is also bad!

* nissan is fine

* tesla is also borked

* mazda's good

* subaru's fine

* gm broke

* ford's good

* chrysler's good

* vw is good

* hyundai is broky, canfd is good

* Fix Rivian

* revert these

* do relay malfunction check on all addresses

* Found a Tesla bug

* fix subaru pg

* body

* rm

* Fix Honda

* stash

* fix Hyundai

* fix

* Hyundai: buttons are used always (for interaction)

* revert tesla

* body: we don't rx _torque_cmd_msg

* Revert "body: we don't rx _torque_cmd_msg"

This reverts commit 2f973f6.

* simpler

* GM EV param for correct rxchecks

* no need

* might read better

* rm extras

* fix hyundai

* we weren't testing lfa (non-hda2), alt buttons, long

* fix

* tested

* rm

* not needed

* clean up

* that too

* .

* Hyundai: Fix FCEV RX check and move out of dashcam (commaai#1974)

* Revert "Hyundai: dashcam FCEV (commaai#1973)"

This reverts commit 6254215.

* Hyundai: Fix FCEV RX check and move out of dashcam

* less duplication

* line

* same

* add missing test

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* HKG: spas remove unused frame param (commaai#1966)

spas remove unused frame param

* Added FW for Mazda CX5 2025 (commaai#1911)

Add other CX-5 2025 FP fw

* Hyundai CAN FD: Fix steering messages in safety replay (commaai#1975)

* Hyundai: split car controller by CAN FD (commaai#1990)

* split main can sends part

* use_clu11 was confusing

* better

* bet

* clean up

* Toyota: add static rx check for alt brake (commaai#1991)

rx check for alt brake

* whoops bad pull

* PR suggestions

* Remove unnecessary parens

* PR suggestions

* Fix some logical errors

* Fix tester present test

* Update safety for non-op long secoc

* Update tests

* Update safety

* Update tests

* whitespace adjustment for clarity

* PR suggestions

---------

Co-authored-by: Jason Young <46612682+jyoung8607@users.noreply.github.com>
Co-authored-by: PenitentTangent2401 <klabuschagne@kd9atp.com>
Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: Lukas <61192133+lukasloetkolben@users.noreply.github.com>
Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com>
Co-authored-by: royjr <royjr96@gmail.com>
Co-authored-by: kenhuang14 <97474725+kenhuang14@users.noreply.github.com>
Co-authored-by: Warren Togami <wtogami@gmail.com>
Co-authored-by: Jason Young <jyoung8607@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

car safety vehicle-specific safety code car related to opendbc/car/ toyota

Projects

None yet

Development

Successfully merging this pull request may close these issues.