opendbc icon indicating copy to clipboard operation
opendbc copied to clipboard

Toyota: Add SECOC longitudinal control

Open chrispypatt opened this issue 1 year ago • 13 comments

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 avatar Oct 18 '24 00:10 chrispypatt

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

nelsonjchen avatar Dec 03 '24 15:12 nelsonjchen

Confirmed that the RAV4 Prime does camera ACC like the other TSS2 camera ACC. Radar tracks are able to be parsed with toyota_tss2_adas:

  • https://streamable.com/1278ih
  • https://streamable.com/wq3icy

No need to disable radar to achieve openpilot longitudinal with this car.

41ba5b181f29435d/0000007b--edfe81ecc8

sunnyhaibin avatar Jan 23 '25 15:01 sunnyhaibin

Radar points do look unusually sparse, especially with cars off to the side

sshane avatar Jan 30 '25 21:01 sshane

Is that something I can control? If so do you have advice on where to start? I just learned tsk radar worked out of the box when sunny dug into it. So not sure what I'd be looking for.

Is that an issue that would block getting this merged?

chrispypatt avatar Jan 31 '25 03:01 chrispypatt

@sshane have you had a chance to look at my questions above?

Also, how can we get this merged? It's been open for several months and there are a lot of TSK users who have been running this on various forks. Is there something needed to move this forward?

chrispypatt avatar Feb 15 '25 15:02 chrispypatt

@sshane I moved the safety code from https://github.com/commaai/panda/pull/2061 here as requested. Mutation tests are timing out since I synced with master - before I applied my changes from that other PR. Is this a known issue?

chrispypatt avatar Feb 20 '25 04:02 chrispypatt

It should pass if you rebase

sshane avatar Feb 20 '25 06:02 sshane

I really hope this gets merged before 0.9.8

calvinpark avatar Feb 27 '25 07:02 calvinpark

@sshane Just synced with master and tests are now passing. Do you have any feedback for this PR?

@jyoung8607 can you re-review?

Anything here that is blocking us from getting it merged?

chrispypatt avatar Feb 27 '25 16:02 chrispypatt

@jyoung8607 @sshane I replaced the route with one with logs and just resolved some merge conflicts. Anything else you guys want changed or are things looking good?

chrispypatt avatar Mar 11 '25 00:03 chrispypatt

@jyoung8607 @sshane, I just synced with master again fixing merge conflicts. Please let me know if there is any suggestions/blockers on getting this merged.

chrispypatt avatar Mar 12 '25 13:03 chrispypatt

Radar points do look unusually sparse, especially with cars off to the side

@sshane I am looking into this, I think I maybe see what you are saying. I compared my route 41ba5b181f29435d/00000001--e3ae76382f with the SECOC Sienna right below it in routes.py 8bfb000e03b2a257/00000004--f9eee5f52e. Mine was not as active/full of data points. Is that what you were seeing?

chrispypatt avatar Apr 03 '25 02:04 chrispypatt

@sshane I grabbed screenshots from the route I added for this PR and other recent routes. Are the points I'm seeing not expected? I compared with a few other secoc and non-secoc vehicles and didn't see any big differences. My routes seem to be showing all the cars and some objects in frame.

Screenshot 2025-04-02 at 11 51 44 PM
Screenshot 2025-04-02 at 11 52 15 PM
Screenshot 2025-04-02 at 11 55 00 PM
Screenshot 2025-04-02 at 11 55 57 PM
Screenshot 2025-04-02 at 11 57 01 PM

chrispypatt avatar Apr 03 '25 05:04 chrispypatt

@sshane @adeebshihadeh @jyoung8607 FYI I recently updated this PR with safety changes and test fixes after noticing the Yaris secoc route was failing with this code.

The route is now passing after removing assumptions that all secoc vehicles support long.

Are there any other fixes or suggestions any of you have to get this merged?

chrispypatt avatar Apr 19 '25 16:04 chrispypatt

Thank you for your work on this @chrispypatt ! Is this the only PR outstanding before we can mainline Toyota Long control to the official nightly-dev channel?

GaganBhat avatar May 18 '25 18:05 GaganBhat

@GaganBhat yep once this gets merged OP dev branches will support Toyota secoc long

chrispypatt avatar May 18 '25 22:05 chrispypatt

Awesome! @sshane @adeebshihadeh @jyoung8607 Are there any other changes needed here (apart from a rebase / conflict resolution) prior to being able to merge?

This Toyota long support from @chrispypatt has been in-use for many model years now on Sunnypilot with great results and feedback from the community. Would love to get it mainlined.

GaganBhat avatar May 19 '25 06:05 GaganBhat

I would love to see this merged in!

paul-kline avatar Jul 03 '25 00:07 paul-kline

@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.

chrispypatt avatar Jul 03 '25 03:07 chrispypatt

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

GaganBhat avatar Jul 26 '25 17:07 GaganBhat

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 🙂

yuzisee avatar Aug 05 '25 02:08 yuzisee

So excited for this!

dobromirmontauk avatar Aug 25 '25 02:08 dobromirmontauk

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.

jyoung8607 avatar Aug 27 '25 05:08 jyoung8607

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

chrispypatt avatar Aug 27 '25 20:08 chrispypatt

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 avatar Sep 22 '25 04:09 chrispypatt

LGTM pending comma review due to safety code changes.

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

adeebshihadeh avatar Sep 29 '25 16:09 adeebshihadeh

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

GaganBhat avatar Sep 29 '25 20:09 GaganBhat