Skip to content

add speed-dependent torque config for per-speed LAF/friction seeds - #441

Open
zephleggett wants to merge 1 commit into
sunnypilot:masterfrom
zephleggett:speed-dep-torque
Open

zephleggett wants to merge 1 commit into
sunnypilot:masterfrom
zephleggett:speed-dep-torque

Conversation

@zephleggett

@zephleggett zephleggett commented Mar 21, 2026 •

Copy link
Copy Markdown

Companion PR: sunnypilot/sunnypilot#1776

Motivation

sunnypilot learns one latAccelFactor and uses it everywhere. On cars with non-linear EPS output, this is a compromise — it either over-steers at low speed or under-steers at highway speed.

Speed-dependent torque learning runs independent SVD fits across speed bins so each bin converges to the correct LAF and friction for that speed range. This PR adds the opendbc-side config infrastructure.

What this does

  1. speed_dependent.toml — per-car config with speed breakpoints, LAF seed values, and friction seed values. Cars not in this file use default bins seeded with global offline values.

  2. get_speed_dep_config() — cached TOML loader in CarInterfaceBaseSP. Returns the parsed config dict, used by the torque estimator in the companion PR.

Design

  • Config-driven: cars not in speed_dependent.toml are completely unaffected
  • Generalizes to any car — just add learned breakpoints to the TOML
  • All learning and per-frame interpolation logic lives in the sunnypilot repo (companion PR)
  • No changes to existing CarInterfaceBaseSP behavior — the config loader is a standalone cached utility function

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

This PR adds infrastructure for speed-dependent lateral torque tuning, allowing configured cars (starting with Mazda CX-5 2022) to use interpolated latAccelFactor (LAF) values across speed bins rather than a single global scalar.

Changes:

  • Added a cached loader for speed_dependent.toml (get_speed_dependent_torque_params()).
  • Introduced per-car speed-binned torque config (speed_dependent.toml) and seeded Mazda CX-5 2022 breakpoints/values.
  • Wired Mazda’s CarInterface to use a sunnypilot extension that provides speed-dependent torque callbacks, and moved MAZDA_CX5_2022 from substitute to override torque params.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
opendbc/sunnypilot/car/mazda/interface_ext.py Adds speed-dependent torque callback closures and live-update hook for LAF bins.
opendbc/car/torque_data/substitute.toml Removes MAZDA_CX5_2022 substitute mapping so it can be overridden directly.
opendbc/car/torque_data/speed_dependent.toml New speed-binned torque parameter config (first entry: MAZDA_CX5_2022).
opendbc/car/torque_data/override.toml Adds scalar override params for MAZDA_CX5_2022 based on speed-bin interpolation.
opendbc/car/mazda/interface.py Wires Mazda interface to use the extension when speed-dependent config exists.
opendbc/car/interfaces.py Adds SPEED_DEPENDENT_TORQUE_PATH and cached loader for the new TOML.

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

Comment thread opendbc/car/mazda/interface.py Outdated
Comment thread opendbc/sunnypilot/car/mazda/interface_ext.py Outdated
Comment thread opendbc/sunnypilot/car/mazda/interface_ext.py Outdated
Comment thread opendbc/sunnypilot/car/mazda/interface_ext.py Outdated
Comment thread opendbc/car/interfaces.py Outdated
@zephleggett
zephleggett marked this pull request as draft March 21, 2026 17:27
zephleggett added a commit to zephleggett/opendbc that referenced this pull request Mar 21, 2026
- Early-return when speed_dep is False (prevents AttributeError on
  unconfigured cars)
- Reject updates when laf_bp or valid_bp length doesn't match the
  configured table (prevents IndexError)

Resolves Copilot review comments on sunnypilot#441.
@zephleggett
zephleggett force-pushed the speed-dep-torque branch 2 times, most recently from 56d0bcd to 234fcc2 Compare March 21, 2026 23:02
ACTS-HORIZON added a commit to ACTS-HORIZON/opendbc that referenced this pull request Mar 23, 2026
Implements PR sunnypilot#441 from sunnypilot/opendbc: adds speed_dependent.toml
with per-car speed-binned LAF/friction values (Mazda CX-5 2022 starter
values), and extends CarInterfaceBaseSP with lazy-init speed-dep
callbacks and update_speed_dep_laf() with ±30% sanity bounds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zephleggett
zephleggett force-pushed the speed-dep-torque branch 3 times, most recently from f2eb877 to 60b3f90 Compare March 24, 2026 21:45
@zephleggett zephleggett changed the title add speed-dependent torque config and interface for Mazda CX-5 2022 add speed-dependent torque config for per-speed LAF/friction seeds Mar 25, 2026
@zephleggett
zephleggett marked this pull request as ready for review March 25, 2026 19:22
- speed_dependent.toml: per-car speed-binned LAF/friction config
- SP interfaces: speed-dep config loader and interpolation in CarInterfaceBaseSP
zephleggett added a commit to zephleggett/openpilot that referenced this pull request Apr 5, 2026
Adds opt-in per-speed-bin latAccelFactor and friction learning, gated by
SpeedDependentTorqueToggle (offroad-only, default off).

Learning: torqued_ext runs independent SVD fit per speed bin, publishes
per-bin values via cereal. Per-bin validity uses upstream's is_valid()
with bucket minimums scaled by bin count. All thresholds derive from
upstream constants — sanity bounds respect the Less Restrict toggle.

Controller: latcontrol_torque_ext interpolates latAccelFactor and friction
by speed each frame. Invalid bins fall back to TOML seeds (configured
cars) or global filtered values.

All feature logic lives in the SP overlay layer. Upstream torqued.py has
only two hook calls (_on_torque_point, _extend_msg). controlsd.py and
latcontrol_torque.py are untouched.

Depends on: sunnypilot/opendbc#441

59 tests across two test files cover learning, interpolation, cache
restore, NaN handling, fallback logic, and toggle gating.
CHaucke89 pushed a commit to CHaucke89/cloudypilot that referenced this pull request Apr 8, 2026
Adds opt-in per-speed-bin latAccelFactor and friction learning, gated by
SpeedDependentTorqueToggle (offroad-only, default off).

Learning: torqued_ext runs independent SVD fit per speed bin, publishes
per-bin values via cereal. Per-bin validity uses upstream's is_valid()
with bucket minimums scaled by bin count. All thresholds derive from
upstream constants — sanity bounds respect the Less Restrict toggle.

Controller: latcontrol_torque_ext interpolates latAccelFactor and friction
by speed each frame. Invalid bins fall back to TOML seeds (configured
cars) or global filtered values.

All feature logic lives in the SP overlay layer. Upstream torqued.py has
only two hook calls (_on_torque_point, _extend_msg). controlsd.py and
latcontrol_torque.py are untouched.

Depends on: sunnypilot/opendbc#441

59 tests across two test files cover learning, interpolation, cache
restore, NaN handling, fallback logic, and toggle gating.
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

This PR has had no activity for 60 days. It will be automatically closed in 7 days if there is no activity.

@github-actions

Copy link
Copy Markdown

This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes.

@github-actions github-actions Bot closed this Jun 12, 2026
@sunnyhaibin sunnyhaibin reopened this Aug 7, 2026
@sunnyhaibin sunnyhaibin removed the stale label Aug 7, 2026
@zephleggett

Copy link
Copy Markdown
Author

@sunnyhaibin if you are interested in this I can ensure the PRs are up-to-date with my 'zoompilot' fork. I have about 100 users driving with this feature on my fork.

I'm happy to port any zoompilot feature to SunnyPilot. This was my original intention.

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.

3 participants