Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toyota: 2021+ RAV4 Prime #2042

Merged
merged 33 commits into from
Oct 4, 2024
Merged

Conversation

jyoung8607
Copy link
Collaborator

@jyoung8607 jyoung8607 commented Sep 26, 2024

Supersedes #1841.

  • Message naming struct cleanup, similar to Chrysler later
  • Consolidate alt flags if possible
  • Add unit tests for new flags flags consolidated
  • Check if any of the new messages have checksum that can be verified by the panda
  • Ensure blocking 0x131 from camera doesn't affect any existing Toyotas (or just put behind flag) put behind flag

@jyoung8607 jyoung8607 marked this pull request as ready for review October 2, 2024 00:55
tests/safety/test_toyota.py Outdated Show resolved Hide resolved
python/__init__.py Outdated Show resolved Hide resolved
board/safety/safety_toyota.h Outdated Show resolved Hide resolved
board/safety/safety_toyota.h Outdated Show resolved Hide resolved
@@ -203,6 +226,19 @@ static bool toyota_tx_hook(const CANPacket_t *to_send) {
}
}

// SecOC cars block any form of LTA actuation for now
if (toyota_secoc && (addr == 0x131)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would now label these three blocks with message names (ideally we make a struct that we can use instead of addresses soon)

Copy link
Collaborator Author

@jyoung8607 jyoung8607 Oct 2, 2024

Choose a reason for hiding this comment

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

Do you mean trailing comments, like // STEERING_LTA_2.STEER_REQUEST?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comments, I'm assuming that's what you were looking for if we're deferring an overall refactor of the entire safety to use message naming macros.

python/__init__.py Outdated Show resolved Hide resolved
Comment on lines 347 to 349
def _lta_msg(self, req, req2, angle_cmd, torque_wind_down=100):
values = {"STEER_REQUEST": req, "STEER_REQUEST_2": req2, "STEER_ANGLE_CMD": angle_cmd}
return self.packer.make_can_msg_panda("STEERING_LTA_2", 0, values)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we still use STEERING_LTA, do we no longer test that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do send both. Both are present on the car, not sure why. Your point is correct. Reverted to Draft, I'll fix up the tests in the AM to verify no-actuation on both.

Copy link
Contributor

@sshane sshane Oct 2, 2024

Choose a reason for hiding this comment

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

Did we ever check what the stock system uses? We were able to send LKA on some 2023 RAV4 but because the stock system used LTA for lane keeping (not just centering) we chose to switch off the unused API.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly the stock system uses the LTA for lane keep steering, but the torque message works fine too. So it's like most TSS2 cars in this regard.

They split up the LTA message into two parts, the old one which contains a bunch of values and flags (with no space for a MAC), and a new one that contains just the actual requested steering angle + a SecOC MAC. They did something similar for longitudinal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now testing both messages, thanks for spotting that!

Verified by breaking the 0x191 check offline:

bool steer_control_enabled = lta_request; //|| lta_request2;

Which was properly picked up by both normal and SecOC tests:

FAILED test_toyota.py::TestToyotaSecOcSafety::test_lta_steer_cmd - AssertionError: False != True : req=0 req2=1 angle=0.0 torque_wind_down=0
FAILED test_toyota.py::TestToyotaStockLongitudinalTorque::test_lta_steer_cmd - AssertionError: False != True : req=0 req2=1 angle=0.0 torque_wind_down=0
FAILED test_toyota.py::TestToyotaSafetyTorque::test_lta_steer_cmd - AssertionError: False != True : req=0 req2=1 angle=0.0 torque_wind_down=0

Copy link
Contributor

@sshane sshane Oct 2, 2024

Choose a reason for hiding this comment

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

@adeebshihadeh do you want to merge this with LKA when we specifically didn't want to merge LKA for the new RAV4s which don't use it but could? commaai/openpilot#29978 for reference.

Copy link
Collaborator Author

@jyoung8607 jyoung8607 Oct 2, 2024

Choose a reason for hiding this comment

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

It's probably possible to switch to LTA, the SecOC part should just carry over. However, it will take multiple round-trips with test owners to plot how the stock camera drives the two LTA messages in tandem and then replicate, test, and validate safety for that behavior.

I don't have a preference on whether to make the switch, the comma openpilot team knows more depth and breadth of Toyota history than I do. If we do want to make the switch, my preference is to ship what we have and create an issue to track migrating to LTA.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly the stock system uses the LTA for lane keep steering, but the torque message works fine too. So it's like most TSS2 cars in this regard.

Sorry, forgot lane keep is what you should call the safety nudges to put you back in the lane, not lane centering. I did not check what the stock system uses for LKA.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

Verified the stock system actuates on both STEERING_LKA (torque) and STEERING_LTA_2 (angle) depending on conditions.

@jyoung8607 jyoung8607 marked this pull request as draft October 2, 2024 06:32
Comment on lines 232 to 235
int lta_angle_msb = GET_BYTE(to_send, 2); // STEERING_LTA_2.STEER_ANGLE_CMD (MSB)
int lta_angle_lsb = GET_BYTE(to_send, 3); // STEERING_LTA_2.STEER_ANGLE_CMD (LSB)

bool actuation = lta_request || lta_request2 || (lta_angle_msb != 0) || (lta_angle_lsb != 0);
Copy link
Collaborator Author

@jyoung8607 jyoung8607 Oct 2, 2024

Choose a reason for hiding this comment

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

Just a note for review: I originally wrote this to build lta_angle, like the other LTA message. Unfortunately the mutation test doesn't like it. We never have actuation via this path, so the angle is never valid while non-zero, so the mutation test sees it can introduce faults in the bit-shift operation without consequence.

@jyoung8607 jyoung8607 marked this pull request as ready for review October 2, 2024 19:11
@jyoung8607 jyoung8607 requested a review from sshane October 2, 2024 19:11
Copy link
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.

Looks much cleaner!

board/safety/safety_toyota.h Show resolved Hide resolved
board/safety/safety_toyota.h Outdated Show resolved Hide resolved
@jyoung8607 jyoung8607 requested a review from sshane October 3, 2024 22:15
@adeebshihadeh adeebshihadeh merged commit abdc418 into commaai:master Oct 4, 2024
9 checks passed
@jyoung8607 jyoung8607 deleted the toyota-secoc branch October 4, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants