Add Adjustable Speed Limiter (ASL) support for "Gen2" Mazda 3 2019+#40
Closed
ckesoglou wants to merge 3 commits into
Closed
Add Adjustable Speed Limiter (ASL) support for "Gen2" Mazda 3 2019+#40ckesoglou wants to merge 3 commits into
ckesoglou wants to merge 3 commits into
Conversation
|
Please submit your pull request to the "MAKE-PRS-HERE" branch. |
|
Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Car Bugfix
Background
The Adjustable Speed Limiter (ASL) is a feature on some Mazda models (commonly on European & Australian spec) that allows you to set a maximum speed for driving. When enabled, the car will prevent you from accelerating beyond the set speed even if the accelerator / gas pedal is depressed. This is a separate feature from the Mazda Radar Cruise Control (MRCC). Importantly, the ASL does not apply any acceleration nor brake force on its own and the driver remains in control; instead, it simply begins to reduce the drivers acceleration / gas input as you approach the limit, stopping all acceleration as the limit is reached.
The bug (unintended acceleration)
On the
MoreTore/openpilot mazda-frogpilot branch, there is a serious bug when using the ASL with openpilot enabled. When ASL main is on and a speed is set, the car will accelerate on its own to reach the set speed, as though it was the MRCC feature. Unlike MRCC though, the ASL will not disengage when the brake pedal is pressed and therefore the car will continue to rev up and attempt to accelerate despite the driver braking. The comma has no visual feedback of engagement when this occurs (no AOL nor longitudinal control, only grey borders).Why?
I'm not familiar enough with the codebase to know for certain, but this LLM generated explanation (after giving it example route logs) seems correct.
LLM bug explanation
1. Openpilot always re-transmits the stock ACC command, even when disengaged.
In
selfdrive/car/mazda/carcontroller.py:164, every cycle (50 Hz) openpilot unconditionally repacksCS.acc(the stockACCmessage read off the car) and forwards it to bus 2:This happens regardless of
CC.longActive— i.e. even when openpilot isn't commanding longitudinal at all.2. The repacker zeroes out any bit not declared in the DBC.
mazdacan.create_acc_cmd(selfdrive/car/mazda/mazdacan.py:231) callspacker.make_can_msg("ACC", 2, values), which builds a fresh 8-byte payload and only writes the signals enumerated asSG_inopendbc/mazda_2019.dbc:469-488. Every other bit on the wire gets zeroed. The Mazda DBC is reverse-engineered and incomplete, so unmapped bits in the original frame are silently dropped.3. The ASL and full ACC share the same CAN message (
544 / ACC) but use different bits to distinguish modes.Logs show:
ACC_ENABLED=1, plus a discriminator bit set,CRZ_STATE >= 2ACC_ENABLED=1, discriminator bit NOT set,CRZ_STATE=0, butACCEL_CMDis populated for limiter purposesThe discriminator bit lives in the unmapped region of the DBC.
4. After repack, the limiter frame looks like a full ACC command.
When openpilot repacks the ASL frame:
ACC_ENABLED=1is preserved (mapped in DBC)ACCEL_CMDis preserved (mapped in DBC)CHECKSUMis recomputed → frame is accepted as validResult: the downstream ECU on bus 2 reads "ACC engaged with this ACCEL_CMD" and the car accelerates.
Solution
Unintended acceleration bug fix
SG_ SPEED_LIMITER_ACTIVEand the surrounding bits to theACCdefinition inopendbc/mazda_2019.dbc(commit deb6b5a)Add logic so that ASL main on enables always on lateral
SPEED_LIMITER_MAINto a newACC_STATEdefinition inopendbc/mazda_2019.dbc(commit 6d35dd3).cruiseState.availableandcruiseState.nonAdaptiveto true (commit 53d2fd1).Verification
How I tested the bug fix:
opendbc/mazda_2019.dbcchanges.opendbc/mazda_2019.dbc&car/mazda/carstate.py).Routes
Hosted on stable.konik.ai
Running MoreTore/openpilot mazda-frogpilot:
30d187bca2a78435_00000033--00210b309d30d187bca2a78435_000001ef--75ef031da4(parts 0, 1 & 2)Running ckesoglou/openpilot mazda-frogpilot-asl-aol:
30d187bca2a78435_00000003--8ed7edd049--0