Skip to content

Ford: add safety code for LCA vehicles #966

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

Merged
merged 23 commits into from
Jul 23, 2022

Conversation

incognitojam
Copy link
Collaborator

@incognitojam incognitojam commented Jun 12, 2022

Safety code for the LCA vehicles (support added in commaai/openpilot#23331)

Currently this does not include any rate limit checks.

@adeebshihadeh
Copy link
Contributor

Ready for a review? I'm cool merging this behind the ALLOW_DEBUG flag until we've got the first port.

@adeebshihadeh adeebshihadeh added the car safety vehicle-specific safety code label Jun 12, 2022
@incognitojam
Copy link
Collaborator Author

Sure!

@incognitojam
Copy link
Collaborator Author

Your review comments disappeared but I've made those changes anyway

Comment on lines 25 to 27
{.msg = {{MSG_ENG_BRAKE_DATA, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{MSG_ENG_VEHICLE_SP_THROTTLE2, 0, 8, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{MSG_ENG_VEHICLE_SP_THROTTLE, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}},
Copy link
Contributor

Choose a reason for hiding this comment

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

these don't have any counters or checksums?

Copy link
Collaborator Author

@incognitojam incognitojam Jul 21, 2022

Choose a reason for hiding this comment

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

Oh I missed this, ApedPos_Pc_ActlArb has a checksum and counter in MSG_ENG_VEHICLE_SP_THROTTLE...

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm cool merging this as-is and adding counter/checksum handling in a follow up PR if you want

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure!

Comment on lines 99 to 104
bool violation = 0U != (GET_BYTE(to_send, 0) |
(GET_BYTE(to_send, 1) & 0xFEU) |
GET_BYTE(to_send, 2) |
GET_BYTE(to_send, 3) |
GET_BYTE(to_send, 4) |
GET_BYTE(to_send, 5));
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be cleaned up with GET_BYTES_04

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried switching it to GET_BYTES_04(to_send) & 0xFEU but then we would be allowing some other button presses to get through

def _user_brake_msg(self, brake: bool):
# brake pedal and cruise state share same message, so we have to send
# the other signal too
enable: bool = self.safety.get_controls_allowed()
Copy link
Contributor

Choose a reason for hiding this comment

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

this type annoation shouldn't be necessary. can we annotate the return type of safety.get_controls_allowed() instead?

Copy link
Collaborator Author

@incognitojam incognitojam Jul 22, 2022

Choose a reason for hiding this comment

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

I've added a whole set of type hints which I think is a good start
I couldn't find any way to get CFFI to generate them? not really sure how that would work

@adeebshihadeh
Copy link
Contributor

Once those comments are address and the tests pass, this should be good to merge.

@adeebshihadeh adeebshihadeh merged commit 3a17c2e into commaai:master Jul 23, 2022
@incognitojam incognitojam deleted the ford-curvature branch July 24, 2022 08:33
incognitojam added a commit to incognitojam/panda that referenced this pull request Jul 24, 2022
* Ford: add CAN messages and signal definitions

* Ford: implement safety hooks

* Ford: add safety unit tests

* Use standstill signal

* Rename bus

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify brake pressed

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Ford LKAS msg helper

* Simplify button violation check

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify LKAS action check

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Tidy up tests

* Use standstill signal for tests

* Misra fix

* Unused definition

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify signal bit shifting

* Remove type hints

* Add panda safety type hints

* Fix vehicle moving signal

* Fix button checks

* Fix steer allowed tests

* Fix standstill threshold in tests

* Maybe this works?

* More button tests

* Revert "Simplify button violation check"

This reverts commit c649626.

Co-authored-by: Adeeb Shihadeh <[email protected]>
mlocoteta pushed a commit to mlocoteta/panda that referenced this pull request Apr 29, 2023
* Ford: add CAN messages and signal definitions

* Ford: implement safety hooks

* Ford: add safety unit tests

* Use standstill signal

* Rename bus

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify brake pressed

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Ford LKAS msg helper

* Simplify button violation check

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify LKAS action check

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Tidy up tests

* Use standstill signal for tests

* Misra fix

* Unused definition

Co-authored-by: Adeeb Shihadeh <[email protected]>

* Simplify signal bit shifting

* Remove type hints

* Add panda safety type hints

* Fix vehicle moving signal

* Fix button checks

* Fix steer allowed tests

* Fix standstill threshold in tests

* Maybe this works?

* More button tests

* Revert "Simplify button violation check"

This reverts commit c649626.

Co-authored-by: Adeeb Shihadeh <[email protected]>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants