Skip to content

Add Adjustable Speed Limiter (ASL) support for "Gen2" Mazda 3 2019+#40

Closed
ckesoglou wants to merge 3 commits into
MoreTore:mazda-frogpilotfrom
ckesoglou:mazda-frogpilot-asl-aol
Closed

Add Adjustable Speed Limiter (ASL) support for "Gen2" Mazda 3 2019+#40
ckesoglou wants to merge 3 commits into
MoreTore:mazda-frogpilotfrom
ckesoglou:mazda-frogpilot-asl-aol

Conversation

@ckesoglou
Copy link
Copy Markdown

@ckesoglou ckesoglou commented May 31, 2026

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 repacks CS.acc (the stock ACC message read off the car) and forwards it to bus 2:

can_sends.append(mazdacan.create_acc_cmd(self, self.packer, CS.acc, hold, resume))

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) calls packer.make_can_msg("ACC", 2, values), which builds a fresh 8-byte payload and only writes the signals enumerated as SG_ in opendbc/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:

  • Full ACC engaged: ACC_ENABLED=1, plus a discriminator bit set, CRZ_STATE >= 2
  • ASL active only: ACC_ENABLED=1, discriminator bit NOT set, CRZ_STATE=0, but ACCEL_CMD is populated for limiter purposes

The 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=1 is preserved (mapped in DBC)
  • ACCEL_CMD is preserved (mapped in DBC)
  • The ASL/ACC discriminator bit is dropped to 0 (not in DBC)
  • CHECKSUM is recomputed → frame is accepted as valid

Result: the downstream ECU on bus 2 reads "ACC engaged with this ACCEL_CMD" and the car accelerates.

Solution

Unintended acceleration bug fix

  • Added SG_ SPEED_LIMITER_ACTIVE and the surrounding bits to the ACC definition in opendbc/mazda_2019.dbc (commit deb6b5a)
    • If I understand correctly, this enables the can packer to preserve those bits when it recreates the ACC message. This fixes the unintended acceleration bug in the car.

Add logic so that ASL main on enables always on lateral

  • Added SPEED_LIMITER_MAIN to a new ACC_STATE definition in opendbc/mazda_2019.dbc (commit 6d35dd3).
    • This bit is non-zero whenever the ASL main is on (regardless of whether it is active with a set speed), similar to cruise control main.
    • ie: Press 'LIM' button on steering wheel → SPEED_LIMITER_MAIN is true → Press "Set" on steering wheel → SPEED_LIMITER_ACTIVE is true.
  • Whenever SPEED_LIMITER_MAIN is true, set cruiseState.available and cruiseState.nonAdaptive to true (commit 53d2fd1).
    • This enables always on lateral whilst preventing full engagement / longitudinal control regardless of whether a speed is set.

Verification

How I tested the bug fix:

  • Installed ckesoglou/openpilot mazda-frogpilot branch that contains only the opendbc/mazda_2019.dbc changes.
    • Confirmed that unintended acceleration bug was no longer present.
    • Confirmed regular cruise control always on lateral and full engagement features were still working.
  • Installed ckesoglou/openpilot mazda-frogpilot-asl-aol branch that contains all changes (opendbc/mazda_2019.dbc & car/mazda/carstate.py).
    • Confirmed that unintended acceleration bug was no longer present.
    • Confirmed that adjustable speed limiter main being on enabled always on lateral.
    • Confirmed that setting a speed with the ASL kept always on lateral enabled.
    • Confirmed regular cruise control always on lateral and full engagement features were still working.

Routes

Hosted on stable.konik.ai

Running MoreTore/openpilot mazda-frogpilot:

  • Openpilot on, ASL bug demo: 30d187bca2a78435_00000033--00210b309d
  • Openpilot off, ASL enable / disable log collection: 30d187bca2a78435_000001ef--75ef031da4 (parts 0, 1 & 2)

Running ckesoglou/openpilot mazda-frogpilot-asl-aol:

  • Openpilot on, testing ASL always on lateral and regular cruise control check: 30d187bca2a78435_00000003--8ed7edd049--0

@github-actions
Copy link
Copy Markdown

Please submit your pull request to the "MAKE-PRS-HERE" branch.

@github-actions github-actions Bot closed this May 31, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 31, 2026

Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • the change is something we merge
    • include a route or your device' dongle ID if relevant

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.

1 participant