add speed-dependent torque config for per-speed LAF/friction seeds - #441
zephleggett wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
CarInterfaceto use a sunnypilot extension that provides speed-dependent torque callbacks, and movedMAZDA_CX5_2022from 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.
- 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.
56d0bcd to
234fcc2
Compare
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>
f2eb877 to
60b3f90
Compare
8322366 to
3c6d55c
Compare
3c6d55c to
e38980e
Compare
- speed_dependent.toml: per-car speed-binned LAF/friction config - SP interfaces: speed-dep config loader and interpolation in CarInterfaceBaseSP
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.
e38980e to
8e631bf
Compare
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.
|
This PR has had no activity for 60 days. It will be automatically closed in 7 days if there is no activity. |
|
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
|
@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. |
Companion PR: sunnypilot/sunnypilot#1776
Motivation
sunnypilot learns one
latAccelFactorand 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
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.get_speed_dep_config()— cached TOML loader inCarInterfaceBaseSP. Returns the parsed config dict, used by the torque estimator in the companion PR.Design
speed_dependent.tomlare completely unaffectedCarInterfaceBaseSPbehavior — the config loader is a standalone cached utility function