Skip to content

mazda: add alpha longitudinal support - #460

Draft
yummydirtx wants to merge 2 commits into
sunnypilot:masterfrom
yummydirtx:mazda-longitudinal-squashed
Draft

mazda: add alpha longitudinal support#460
yummydirtx wants to merge 2 commits into
sunnypilot:masterfrom
yummydirtx:mazda-longitudinal-squashed

Conversation

@yummydirtx

Copy link
Copy Markdown

This pull request adds support for full alpha longitudinal on the Mazda CX-5. The method I used to achieve this involved poisoning the stock radar unit by placing it in "programming" session and sending "tester-present" messages to hold it in that state, and then essentially emulating that radar unit enough to prevent a full malfunction that would disable the ability to trigger MRCC. It is important to note that doing this necessarily disables AEB braking, and as of the current state of these changes, triggers a few malfunctions to show on the dash. None of these impair car function, and across many test drives, alpha longitudinal has worked without triggering errors or exhibiting any unusual unsafe behavior.

This is my first contribution to this project, and, clearly, it's a large one in size, so I welcome any and all critiques or suggestions that need to be addressed before merging all this.

The following is Copilot's summary of my changes (reviewed by me):

Longitudinal Control Integration and Logic:

  • Added support for openpilot-managed longitudinal control, including logic for synthetic stop-and-go/HOLD, resume handling, and synthetic ACC message generation in carcontroller.py. This includes new state variables and careful management of transitions between stopping, holding, and starting, as well as handling both physical and virtual resume requests. [1] [2] [3] [4]

Cruise State and Button Event Handling:

  • Refined parsing and reporting of cruise control button events (including main, cancel, accel, decel, and distance) to support both stock and openpilot longitudinal control. Updated cruise state detection to use radar signals when in openpilot longitudinal mode, ensuring accurate availability and engagement status. [1] [2] [3]

Car Interface and Parameters:

  • Updated interface.py to enable openpilot longitudinal control only for supported models (CX-5 2022), set appropriate car parameters (starting state, accel values, actuator delay, PID tuning), and configure the safety model accordingly. [1] [2] [3]

Radar Session Management:

  • Added initialization and deinitialization hooks to enter/exit radar programming session when openpilot longitudinal control is enabled, ensuring proper radar behavior during take-over and handoff.

These changes collectively enable a robust openpilot longitudinal control experience on supported Mazda vehicles, with careful handling of state transitions, user inputs, and compatibility with stock systems.

Validation

Copilot AI review requested due to automatic review settings April 23, 2026 06:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds alpha longitudinal (openpilot-managed ACC) support for Mazda CX-5 2022 by holding the stock radar in a diagnostic session and emulating the key radar-owned cruise frames so MRCC remains usable under openpilot longitudinal control.

Changes:

  • Introduce Mazda longitudinal message synthesis (CRZ_INFO/CRZ_CTRL) + radar “tester present”/session management.
  • Update Mazda interface/carstate/controller logic to support alpha-long cruise state, buttons, stop/go hold, and resume behavior.
  • Extend Panda safety mode + safety tests/DBC to allow and validate new longitudinal-related TX/RX paths.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
opendbc/safety/tests/test_mazda.py Adds a Mazda longitudinal safety test variant and updates PCM status sourcing for long mode.
opendbc/safety/tests/common.py Adjusts cross-mode TX-hook comparison to account for Mazda long-mode TX superset.
opendbc/safety/modes/mazda.h Adds a Mazda longitudinal safety param, new allowed TX (0x21b/0x21c/0x764), and longitudinal safety checks.
opendbc/dbc/mazda_2017.dbc Refines CRZ_CTRL/CRZ_INFO signal definitions needed for message synthesis/parsing.
opendbc/car/mazda/longitudinal.py New module implementing CRZ_INFO/CRZ_CTRL synthesis and radar UDS session helpers.
opendbc/car/mazda/interface.py Gates openpilot longitudinal to CX-5 2022, sets tuning/params, and enters radar programming session on init.
opendbc/car/mazda/carstate.py Updates cruise availability/enabled logic for radar-suppressed mode; expands button event parsing.
opendbc/car/mazda/carcontroller.py Implements stop/go hold + resume state machine and sends synthetic longitudinal + tester-present frames.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opendbc/safety/modes/mazda.h
Comment thread opendbc/safety/tests/test_mazda.py Outdated
Comment thread opendbc/car/mazda/longitudinal.py
@yummydirtx
yummydirtx marked this pull request as draft April 23, 2026 19:20
@yummydirtx

Copy link
Copy Markdown
Author

Marked this as a draft while I prepare a submission to commaai/opendbc as suggested by sunnyhaibin

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.

2 participants