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

Sync: commaai/opendbc:master into sunnypilot/opendbc:master-new #71

Merged
merged 59 commits into from
Mar 9, 2025

Conversation

devtekve
Copy link

@devtekve devtekve commented Mar 9, 2025

Summary by Sourcery

Refactor safety checks and update car values for improved accuracy and maintainability. This includes changes to Ford, Rivian, Hyundai, and other car models, focusing on CAN message handling, steering limits, and firmware matching.

Bug Fixes:

  • Fixes issues with counter and checksum checks in various safety configurations.
  • Corrects steering angle measurements and rate limits for Ford CAN FD.
  • Addresses potential ACC faults and longitudinal control issues in Rivian and Hyundai models.
  • Fixes VIN matching logic for Volkswagen MEB platform.
  • Fixes steering angle measurements for Toyota LTA.
  • Fixes wheel speed measurements for Hyundai CAN-FD

Enhancements:

  • Improves steering angle and torque limits for Ford, Nissan, and Toyota.
  • Enhances CAN message handling and filtering for Rivian, Hyundai, and GM.
  • Updates firmware matching logic for Volkswagen and Rivian.
  • Refactors Ford steering limits to account for lateral acceleration.
  • Adds support for canceling stock ACC in Rivian.
  • Improves steering rate fault prevention for Toyota and Subaru.
  • Updates wheel speed measurements for Hyundai CAN-FD

Tests:

  • Adds tests for Rivian custom fuzzy fingerprinting.
  • Adds tests for max lateral acceleration for Ford CAN FD.
  • Updates tests for steering angle measurements for Toyota LTA.
  • Updates tests for wheel speed measurements for Hyundai CAN-FD

sunnyhaibin and others added 30 commits February 28, 2025 02:40
* reimplement

* use average wheel speed

* fix factor with eEgoRaw

* Revert "fix factor with eEgoRaw"

This reverts commit 35f3624.

* Revert "use average wheel speed"

This reverts commit ec4e9c1.

* revert to previous

* mutation again ugh

* mutation you got to be kidding me

* nice, this passes test models now

---------

Co-authored-by: Shane Smiskol <[email protected]>
* test test_angle_cmd_when_enabled above max angle and set them

* nissan is too high

* clean up

* more
* Hyundai CAN FD: Steering API updates

* comments

* comments

* keep it for now

* not used

* should use DBC spec

* consistent

---------

Co-authored-by: Shane Smiskol <[email protected]>
* struct to prevent forgetting something and make more organized

* use it

* move all over

* clean up

* rm
Revert "Hyundai CAN FD: ADAS steering API updates (commaai#1873)"

This reverts commit 2a75806.
* restart

* fix

* missing

* remove stuff we don't use

* huh

* fix

* fix fix fix

* we haven't seen LKAS with angle yet

* this is missing from the new message

* ...

* more explicit

* flip

* import
…#1890)

* Update replay_drive.py

* warn

* no true

* tqdm too
Use gcovr instead of gcov to support exclusion markers.

This also replaces lcov, since gcov has far fewer dependencies,
can be installed via uv (and looks better if anything).
* curvature safety: limit to ISO max

* .

* cmt

* implement in carcontroller

* MISRAAAAAA

* use ~average road roll

* stash

* clean up

* compiles

* fix safety replay for ford can fd

* always init

* stash

* fix replay

* fix that

* safety doesn't consider rate limits when clipping max curvature

consider: at the max curvature limit and user gas overrides heavily, max curvature limit might drop quicker than the safet rate limit will allow for

* don't limit for CAN

* do tests (need to clean up)

* stash

* rm

* clean up tests

* fix that

* smaller

* fix capnp error

* because we allow tolerance on the error limiting, we need the same type of tolerance on the max accel curvature to not block

* fix a test

* fix another

* consistent naming

* debugging

* debug

* remove

* stash

* clean up

* clean up

* minor

* and this

* space

* misra

* doesn't matter here

* safety mutation test fix

* misra false positive?

* rename

* ah good catch, these are equivalent

* comment

* clean up

* rename like safety

* fix

* simpler

* not needed
* debug

* remove debugging

* huh
* fixup

* test

* bye copilot

* rev

* fix

* fix

* test again

* revert

* need
* Only run tx hooks on msgs in safety_config.tx_msgs.

* 'fix' tests

* retrigger checks bc timeouts

* not hit

* formatting

* add back

---------

Co-authored-by: Shane Smiskol <[email protected]>
these are the same
* no tron (2010)

* switch to actual ACC message

* switch to camera

* add logging
…p fail (commaai#1919)

add checkout check to prevent opendbc bump fail
* add VDM fault signal

* fix
Aniurm and others added 16 commits March 6, 2025 01:33
…e test speed (commaai#1930)

* Replace @parameterized.expand with @pytest.mark.parametrize for faster test collection

This change reduces the opendbc/car/tests/ collection time to ~0.4s.

* clean up

---------

Co-authored-by: Shane Smiskol <[email protected]>
so far only tesla has been seen being able to set to 0
* Update interface.py

* Update fingerprints.py

* Revert "Update interface.py"

This reverts commit a2abbc0.
* Update fingerprints.py

* 2020 confirmed!

* should be fine

---------

Co-authored-by: Jason Young <[email protected]>
* parse vin

* Update opendbc/car/vin.py
* TODO: cant pass down due to circular imports

* revert

* screw it, we can split vin.py and vin_query.py later. this is nicer

* Revert "screw it, we can split vin.py and vin_query.py later. this is nicer"

This reverts commit 9ddab33.
* add match_fw_to_car_fuzzy

* remove comment

* fix dbc

* format

* don't remove...

* parse_vin function

* test caught bug

* safe string accessing

---------

Co-authored-by: Shane Smiskol <[email protected]>
* this is what we want

* rm old

* and now counter

* need this

* toyota

* subaru's good

* Tesla and Chrysler

* Ford

* do some find and replace

* do the rest

* clean up

* remove this

* rm

* not broken but bad

* this was wrong!
* set FWD_BUS_LOOKUP to most common

* this is always assumed to be a number, test models tests mismatches

* clean up

* and this
…aster-new

# Conflicts:
#	opendbc/car/hyundai/hyundaicanfd.py
#	opendbc/car/rivian/carcontroller.py
#	opendbc/safety/tests/common.py
#	opendbc/safety/tests/test_chrysler.py
#	opendbc/safety/tests/test_hyundai_canfd.py
Copy link

sourcery-ai bot commented Mar 9, 2025

Reviewer's Guide by Sourcery

This pull request includes several updates to improve car support, safety, and testing. It adds VIN fuzzy matching for Rivian cars, CAN FD support for Hyundai cars, and lateral acceleration limiting for Ford CAN FD vehicles. It also updates safety RX checks to ignore checksum and counter for various car models, updates safety replay to initialize segments correctly and improve logging, and updates safety tests to use assertEqual instead of assertTrue and assertFalse.

Sequence diagram for Rivian ACC cancel

sequenceDiagram
    participant CarController
    participant CarState
    participant CANPacker

    CarController->CarState: CC.cruiseControl.cancel = True
    CarController->CANPacker: create_adas_status(vdm_adas_status, interface_status)
    activate CANPacker
    CANPacker->CarState: VDM_AdasInterfaceStatus = 1 (frames < 5), 0 (frames >= 5)
    CarController->CANPacker: create_adas_status(vdm_adas_status, interface_status)
    deactivate CANPacker
    CarController->CarState: CC.cruiseControl.cancel = False
    CarController->CANPacker: create_adas_status(vdm_adas_status, interface_status)
    activate CANPacker
    CANPacker->CarState: VDM_AdasInterfaceStatus = None
    deactivate CANPacker
Loading

Sequence diagram for Ford curvature limits

sequenceDiagram
    participant CarController
    participant CarState
    participant apply_ford_curvature_limits

    CarController->CarState: actuators.curvature, CS.out.vEgoRaw, CC.latActive
    CarController->apply_ford_curvature_limits: apply_ford_curvature_limits(actuators.curvature, current_curvature, CS.out.vEgoRaw, CC.latActive, CP)
    activate apply_ford_curvature_limits
    apply_ford_curvature_limits->apply_ford_curvature_limits: apply_std_steer_angle_limits(apply_curvature, v_ego_raw, steering_angle, lat_active, ANGLE_LIMITS)
    apply_ford_curvature_limits->apply_ford_curvature_limits: Limit curvature based on lateral acceleration (CANFD)
    deactivate apply_ford_curvature_limits
Loading

Updated class diagram for RivianPlatformConfig

classDiagram
    class RivianPlatformConfig {
        DbcDict dbc_dict
        set[WMI] wmis
        set[ModelLine] lines
        set[ModelYear] years
    }
Loading

File-Level Changes

Change Details Files
Refactors Ford steering limits to use a macro and adds lateral acceleration limiting for CAN FD.
  • Introduces a FORD_LIMITS macro to define steering limits based on lateral acceleration.
  • Adds angle_is_curvature flag to AngleSteeringLimits struct to indicate curvature-based limits.
  • Implements lateral acceleration limiting for Ford CAN FD vehicles.
  • Updates steer_angle_cmd_checks to include lateral acceleration checks.
  • Defines FORD_CANFD_STEERING_LIMITS with angle_is_curvature set to true.
  • Uses FORD_CANFD_STEERING_LIMITS for safety checks on FORD_LateralMotionControl2 messages.
opendbc/safety/safety/safety_ford.h
opendbc/safety/tests/test_ford.py
Updates Rivian safety to block stock ACC messages when longitudinal control is enabled and fixes cruise control checks.
  • Blocks VDM_AdasSts messages on bus 0 when longitudinal control is enabled.
  • Updates cruise control checks to use feature_status instead of a single bit.
  • Removes longitudinal control check in rivian_tx_hook.
  • Adds VDM_AdasSts to the list of transmitted messages.
  • Adds ignore_checksum and ignore_counter to Rivian RX checks.
  • Adds a test for VDM_AdasSts message transmission.
  • Removes LONGITUDINAL flag from TestRivianLongitudinalSafety.
opendbc/safety/safety/safety_rivian.h
opendbc/safety/tests/test_rivian.py
Adds VIN fuzzy matching for Rivian cars.
  • Adds RivianPlatformConfig dataclass to include WMI, model line, and model year.
  • Adds match_fw_to_car_fuzzy function to match firmware to Rivian cars based on VIN.
  • Adds WMI, ModelLine, and ModelYear enums for Rivian VIN decoding.
  • Adds a test case for Rivian VIN fuzzy matching.
opendbc/car/rivian/values.py
opendbc/car/rivian/tests/test_rivian.py
opendbc/car/vin.py
Adds support for canceling stock ACC on Rivian cars.
  • Adds create_adas_status function to create VDM_AdasSts messages.
  • Adds logic to RivianCarController to send VDM_AdasSts messages for ACC cancellation.
  • Adds vdm_adas_status to CarState to store the last received VDM_AdasSts message.
opendbc/car/rivian/riviancan.py
opendbc/car/rivian/carcontroller.py
opendbc/car/rivian/carstate.py
Adds CAN FD support for Hyundai cars.
  • Adds CANFD_LKA_STEERING and CANFD_LKA_STEERING_ALT flags to HyundaiFlags.
  • Adds logic to create_steering_messages to handle CAN FD steering messages.
  • Adds logic to create_acc_control to handle CAN FD ACC messages.
  • Adds CANFD_ALT_BUTTONS flag to HyundaiFlags.
  • Adds logic to create_button_messages to handle CAN FD button messages.
  • Updates RX checks in safety_hyundai_canfd.h to remove checksum checks and add ignore flags.
  • Adds a test case for ACC cancel message transmission.
opendbc/car/hyundai/values.py
opendbc/car/hyundai/hyundaicanfd.py
opendbc/car/hyundai/carcontroller.py
opendbc/safety/safety/safety_hyundai_canfd.h
opendbc/safety/tests/test_hyundai_canfd.py
Updates safety RX checks to ignore checksum and counter for various car models.
  • Adds ignore_checksum and ignore_counter fields to CanMsgCheck struct.
  • Updates RX checks in safety_honda.h, safety_chrysler.h, safety_gm.h, safety_toyota.h, safety_volkswagen_mqb.h, safety_volkswagen_pq.h, safety_subaru.h, safety_tesla.h, and safety_mazda.h to ignore checksum and counter checks for certain messages.
opendbc/safety/safety_declarations.h
opendbc/safety/safety/safety_honda.h
opendbc/safety/safety/safety_chrysler.h
opendbc/safety/safety/safety_gm.h
opendbc/safety/safety/safety_toyota.h
opendbc/safety/safety/safety_volkswagen_mqb.h
opendbc/safety/safety/safety_volkswagen_pq.h
opendbc/safety/safety/safety_subaru.h
opendbc/safety/safety/safety_tesla.h
opendbc/safety/safety/safety_mazda.h
Updates Ford car controller to limit curvature based on lateral acceleration for CAN FD vehicles.
  • Adds apply_ford_curvature_limits function to limit curvature based on lateral acceleration.
  • Updates CarController.update to use apply_ford_curvature_limits for CAN FD vehicles.
  • Adds MAX_LATERAL_ACCEL constant for lateral acceleration limit.
  • Adds ANGLE_LIMITS to CarControllerParams.
opendbc/car/ford/carcontroller.py
Updates Toyota car controller to use ANGLE_LIMITS.
  • Adds ANGLE_LIMITS to CarControllerParams.
  • Updates CarController.update to use ANGLE_LIMITS.
opendbc/car/toyota/carcontroller.py
opendbc/car/toyota/values.py
Updates Nissan car controller to use ANGLE_LIMITS.
  • Adds ANGLE_LIMITS to CarControllerParams.
  • Updates CarController.update to use ANGLE_LIMITS.
opendbc/car/nissan/carcontroller.py
opendbc/car/nissan/values.py
Updates Tesla car controller to use ANGLE_LIMITS.
  • Adds ANGLE_LIMITS to CarControllerParams.
  • Updates CarController.update to use ANGLE_LIMITS.
opendbc/car/tesla/carcontroller.py
opendbc/car/tesla/values.py
Updates safety replay to initialize segments correctly and improve logging.
  • Updates init_segment to print a message when no steering messages are found.
  • Updates replay_drive to sort messages by logMonoTime.
  • Updates replay_drive to use tqdm for progress bar.
  • Updates replay_drive to pass a list of messages to replay_drive instead of a LogReader.
opendbc/safety/tests/safety_replay/helpers.py
opendbc/safety/tests/safety_replay/replay_drive.py
Updates safety tests to remove FWD_BUS_LOOKUP and add STANDSTILL_THRESHOLD where missing.
  • Removes FWD_BUS_LOOKUP from various safety tests.
  • Adds STANDSTILL_THRESHOLD to TestRivianSafetyBase.
  • Adds FWD_BUS_LOOKUP = {} to TestDefaultRxHookBase.
  • Adds FWD_BUS_LOOKUP = {} to TestBody.
  • Adds FWD_BUS_LOOKUP = {} to TestElm327.
opendbc/safety/tests/test_rivian.py
opendbc/safety/tests/test_defaults.py
opendbc/safety/tests/test_body.py
opendbc/safety/tests/test_elm327.py
Updates safety tests to use assertEqual instead of assertTrue and assertFalse.
  • Updates various safety tests to use assertEqual instead of assertTrue and assertFalse.
opendbc/safety/tests/test_ford.py
opendbc/safety/tests/test_hyundai_canfd.py
opendbc/safety/tests/test_rivian.py
opendbc/safety/tests/test_toyota.py
Updates safety tests to use pytest.mark.parametrize instead of parameterized.expand.
  • Updates test_fw_fingerprint.py and test_can_fingerprint.py to use pytest.mark.parametrize instead of parameterized.expand.
opendbc/car/tests/test_fw_fingerprint.py
opendbc/car/tests/test_can_fingerprint.py
Updates test.sh to use gcovr for coverage reports.
  • Updates test.sh to use gcovr for coverage reports.
  • Removes old coverage report generation code.
opendbc/safety/tests/test.sh
Updates CARS.md to remove Under review status.
  • Updates CARS.md to remove Under review status for Ford F-150, Mustang Mach-E, and Ranger.
docs/CARS.md
Updates CARS_template.md to include SupportType.
  • Updates CARS_template.md to include SupportType.
opendbc/car/docs.py
opendbc/car/CARS_template.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

* Fix get_params_for_docs call to use correct parameters

Updated the function call to match the required arguments by removing the redundant 'model' parameter. This ensures compatibility with the function definition and prevents potential errors.

* Add _tx_acc_state_msg method and standardize PT_BUS usage

Introduce the _tx_acc_state_msg method in Hyundai safety tests to handle ACC state messaging. Replace hardcoded bus values with the self.PT_BUS variable for consistency and maintainability across SCC_CONTROL messages.

* Add MADS heartbeat engaged state validation test

Introduce a new test function `test_heartbeat_engaged_mads_check` to verify the behavior of MADS heartbeat engagement logic under varying conditions. This ensures correct state transitions and validates robustness against mismatched heartbeat signals.

* Increase timeout for safety mutation tests to 60 minutes

Extended the timeout for the entire safety mutation tests workflow and its individual steps from 20 and 10 minutes respectively to 60 minutes. This change ensures that longer-running tests complete successfully without premature termination.
@devtekve devtekve marked this pull request as ready for review March 9, 2025 10:23
@devtekve
Copy link
Author

devtekve commented Mar 9, 2025

Note: The safety mutation failure is expected
commaai#1852 (comment)
image

Copy link

@rav4kumar rav4kumar left a comment

Choose a reason for hiding this comment

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

tested

@devtekve devtekve merged commit eb21f61 into master-new Mar 9, 2025
7 checks passed
@devtekve devtekve deleted the sync-20250309 branch March 9, 2025 19:46
sunnyhaibin added a commit that referenced this pull request Mar 9, 2025
sunnyhaibin added a commit that referenced this pull request Mar 9, 2025
@sunnyhaibin sunnyhaibin restored the sync-20250309 branch March 9, 2025 19:52
@devtekve devtekve deleted the sync-20250309 branch March 9, 2025 20:09
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.