9 Commits

Author SHA1 Message Date
brianhansonxyz 37e095eab7 controlsd: fix park short-circuit lac_log type mismatch crashing controlsd
The park short-circuit added in cea422b created lac_log as
LateralDebugState. publish_logs assigns lac_log to
controlsState.lateralControlState.<subtype> based on
CP.lateralTuning.which() — for torque-tuned cars (Hyundai Tucson here)
that's torqueState, expecting LateralTorqueState. The mismatch threw
a capnp KjException ("Value type mismatch") on the first state_control
cycle in park, killing controlsd. Manager respawned it, it crashed
again on the next park cycle, repeat — controlsState was never reliably
published, so the UI never saw the started/onroad transition and didn't
flip to the camera view.

Fix: call self.LaC.update(False, ...) which internally early-returns
when active is False (cheap) but produces the correct lac_log subtype
for whichever controller this car uses (LateralTorqueState for torque,
LateralPIDState for pid, LateralAngleState for angle). Pass through
the same sm reads the regular path uses; they're cached so the cost is
negligible.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 12:43:08 -05:00
brianhansonxyz 5d76576a15 sessions: document hyundai canfd steer torque bump
Reference for the 270->324 change in commit 4058269. Covers what each
constant means, the two-files-must-stay-in-lockstep rule, the path to
push higher (324 -> 384, the community-consensus safe ceiling), risks
and symptoms to watch for at higher values, verification steps, and
rollback procedure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 12:31:10 -05:00
brianhansonxyz 4058269762 hyundai canfd: bump steer max 270->324 (~+20%), rate_up 2->3, rate_down 3->5
Tucson (and other Hyundai CAN-FD HDA2 cars) get pinned to comma's
conservative steer ceiling of 270 in the CAN-FD branch of
selfdrive/car/hyundai/values.py and the matching panda safety limit
HYUNDAI_CANFD_STEERING_LIMITS. Comma's non-CAN-FD HKG default is 384;
PR commaai/openpilot#25723 merged 384 for HDA1 EV6/Ioniq 5 with
operator quote "max steer needed to be 384 to make basic turns."

Bumping to 324 (~+20%) keeps a safe margin under the proven 384
ceiling while giving enough headroom for moderate clover-style on-ramps
without the controller hitting the limit. Rate limits also nudged up
(2->3 up, 3->5 down) to match the slightly higher ceiling and reduce
ramp time / release lag; chose 5 instead of comma's 7 for delta_down to
keep release smoother. max_rt_delta scaled proportionally (112->134) so
the 250ms real-time check tracks the new ceiling.

Both files MUST stay in lockstep — panda safety enforces independently
and would reject larger commands if only one side was bumped. Panda
firmware re-flashes automatically on next pandad start because the
safety code hash changed.

References:
  https://github.com/commaai/openpilot/pull/25723   (HDA1 270->384)
  https://github.com/commaai/openpilot/issues/24122 (HKG torque blacklist)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 12:29:06 -05:00
brianhansonxyz 8b4b7e04b5 adopt modelrevert tree as the new clearpilot baseline
Replaces clearpilot's working state wholesale with the modelrevert branch's
tree (modelrevert tip cea422b). Discards the parked-controlsd manager-process
split and the two session READMEs that documented it; keeps the simpler
in-process park short-circuits (controlsd state_control, plannerd, frogpilot_process)
and the cached-output decimation (modeld, dmonitoringmodeld) that achieve
the same goal with less moving parts. Also brings in the locationd GPS
ignore, the calibrationd valid=calStatus gate, and the model-revert lineage's
controlsd / paramsd / torqued / events.py / carstate.py / interfaces.py.

This is a single new commit on clearpilot (no merge), so the branch advances
linearly while the file state matches modelrevert exactly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 12:17:35 -05:00
brianhansonxyz d639e28057 unblock startup chain + disable GPS in locationd; document session
Four logically-related changes that together get the manager booting
cleanly end-to-end after the prior session's baseline revert + parked-mode
split, plus a session doc.

boardd: trigger safety_setter_thread on ignition rising edge, not on
IsOnroad rising edge. The parked-mode split broke the stock assumption
that ignition rising implies IsOnroad rising — IsOnroad now requires
`started`, which requires thermald to see carState != park, which
requires controlsd_parked to publish carState, which can't happen until
boardd acks OBD multiplexing. Triggering on ignition edge restores the
"set safety as soon as the bus is alive" intent for both controlsd
variants.

controlsd: drop the two `params_memory.put_bool("no_lat_lane_change",
...)` calls. The key was never registered in common/params.cc so
state_control crashed with UnknownKeyName on first cycle. The carcontroller
reads off `frogpilot_variables.no_lat_lane_change` (in-process), which
controlsd already sets; the UI reads `frogpilotCarControl.NoLatLaneChange`
from cereal, which nobody was setting in the restored controlsd. Add
`self.FPCC.noLatLaneChange = True/False` in the same lane-change branch
so the UI lane-edge indicator reflects state. No actuator change.

cereal/services.py: restore deviceState/managerState declarations to 2Hz
to match the restored DT_TRML=0.5 (thermald at 2Hz). Earlier fan-control
work bumped both to 5Hz; the realtime.py revert undid the thermald rate
bump but services.py wasn't reverted, so freq window [4.0, 6.0]Hz failed
on every cycle and controlsd fired commIssue continuously.

locationd: add a `clearpilot_disable_gps` const at the top of handle_gps
and OR it into the existing reject condition. With it true, every
gpsLocation message falls through to determine_gps_mode() — openpilot's
stock no-GPS path. last_gps_msg never updates, is_gps_ok() permanently
false. gpsd is untouched so UI / dashcamd / clock-set / night-mode auto-
switch keep working unchanged. The user's "drift right on straight roads"
symptom went away after this edit; the previous gpsd.py was hard-coding
vNED=[0,0,0] while the car was moving, feeding the Kalman contradictory
GPS-vs-IMU velocity observations that propagated into latcontrol_torque
through liveLocationKalman.angularVelocityCalibrated. Reversible by
flipping the const to false.

sessions/: a single README documenting this session. Includes the
calibrationd-still-stale investigation — liveCalibration.valid stuck at
False because of a Python SubMaster freq_ok issue with carState under
poll='cameraOdometry' (likely MSGQ NUM_READERS=12 eviction with too many
subscribers). 7ee923b already solved this exact failure mode by gating
calibrationd's publish on calStatus instead of sm.all_checks(); that
commit was reverted in 47321e3 as part of the variable-FPS rollback
but is unrelated to that family and is the natural next move.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 11:48:11 -05:00
brianhansonxyz 27cad05cd9 sessions: document baseline revert + parked-controlsd architecture
Briefing for the on-device agent covering commits 47321e3, f7e602c,
and 887b9c9: what was reverted vs kept, the UI re-wire, the parked
controlsd swap mechanism, build prerequisites, runtime verification
commands, and a troubleshooting playbook.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 09:18:34 -05:00
brianhansonxyz 887b9c9e12 parked-controlsd mode: shut down heavy stack while ignition+park
Adds a second controlsd variant that runs while ignition is on but the
car is in Park. It only listens to CAN and publishes carState — no
model, no planner, no lateral/long control, no actuator commands — so
modeld, locationd, calibrationd, plannerd, radard, paramsd, torqued,
dmonitoring*, soundd, loggerd all stay stopped while parked.

Manager swaps between the two via mutually-exclusive predicates:
  - controlsd_parked: ignition AND not started
  - controlsd (full): started (= ignition AND not_parked)

Thermald owns the swap. It already subscribes to carState; we add a
new onroad condition `not_parked` derived from gearShifter, with a
1.5s hysteresis on going into parked (R/P/D thrash protection) and
zero hysteresis on going out (instant wake on shift to D/R/N). At
boot we assume parked so the heavy stack waits for carState to
confirm gear has actually left Park.

Manager predicates can only see persistent Params, not pandaStates,
so thermald exposes ignition as a new IgnitionOn param (edge-written).
Reverse is treated as not-parked — driver is moving.

Files:
- selfdrive/controls/controlsd_parked.py (new, ~50 lines)
- selfdrive/thermald/thermald.py: not_parked condition + IgnitionOn
- selfdrive/manager/process_config.py: parked_only predicate + entry
- selfdrive/manager/manager.py: seed IgnitionOn=False
- common/params.cc: register IgnitionOn

The full controlsd is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 09:13:41 -05:00
brianhansonxyz f7e602c00b controlsd: re-wire UI hooks on top of restored baseline
Adds back the UI plumbing that the baseline controlsd doesn't have, so
the existing UI features keep working without changing driving logic:

- ScreenDisplayMode 5-state machine (auto-normal, auto-nightrider,
  manual normal, screen-off, manual nightrider) driven by the LFA
  debug button + gear edges. Replaces baseline's simple 0..2 cycle.
  Pure params write — no actuator effect.
- Speed/cruise-warning overlay tick at ~2Hz feeding SpeedState, which
  writes ClearpilotSpeedDisplay / ClearpilotSpeedLimitDisplay /
  ClearpilotCruiseWarning for the onroad UI. Reads gpsLocation,
  CarSpeedLimit, and CS.cruiseState — no actuator effect.
- frogpilot_variables.no_lat_lane_change is now populated alongside
  the existing Params write, so the perf-optimized carcontroller (which
  takes the bit as an argument instead of re-reading Params on the
  100Hz hot path) still sees the lane-change suppression signal.
- ScreenDisplayMode init switched from put_bool to put_int (UI reads
  it as int).
- gpsLocation added to SubMaster (ignore_alive/avg_freq/valid set,
  since gpsd is a ClearPilot addition not present everywhere).

No changes to controlsd's lateral or longitudinal control paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 08:44:52 -05:00
brianhansonxyz 47321e3867 restore driving logic to pre-variable-fps baseline
Wholesale revert of driving-relevant files to the snapshot in
/projects/openpilot/archive/clearpilot (HEAD 980f0aa). Goal: get
known-good driving behavior back, then re-introduce optimizations
slowly to track down a "feels like the wheel pulls right" regression.

Files restored from baseline:
- selfdrive/controls/controlsd.py
- selfdrive/controls/lib/events.py
- selfdrive/controls/lib/longitudinal_planner.py
- selfdrive/modeld/modeld.py
- selfdrive/modeld/dmonitoringmodeld.py
- selfdrive/locationd/calibrationd.py
- selfdrive/locationd/paramsd.py
- selfdrive/locationd/torqued.py
- selfdrive/car/interfaces.py
- selfdrive/car/hyundai/carstate.py (CAN-FD telemetry preserved as a
  commented block for future re-enable)
- selfdrive/monitoring/dmonitoringd.py
- selfdrive/frogpilot/controls/frogpilot_planner.py
- common/realtime.py

Intentionally NOT restored (kept as current):
- selfdrive/thermald/* (fan/power tuning kept)
- selfdrive/car/hyundai/carcontroller.py + hyundaicanfd.py (perf-only
  hoist of no_lat_lane_change Params read; behavior-equivalent)
- cereal/services.py, cereal/custom.capnp (additive only)
- selfdrive/manager/*, common/params.cc (heavy ClearPilot
  infrastructure: bench mode, log dir, dashcamd, gpsd, params)
- All selfdrive/ui/, selfdrive/clearpilot/, system/clearpilot/

UI features will be re-wired in a follow-up commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 08:40:02 -05:00
4 changed files with 197 additions and 8 deletions
+9 -4
View File
@@ -1,11 +1,16 @@
#include "safety_hyundai_common.h"
const SteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = {
.max_steer = 270,
.max_rt_delta = 112,
// CLEARPILOT: bumped from comma defaults (270/2/3/112) by ~20% so this Tucson HDA2
// can hold modest curvature in place. Mirrors the rate-limit shape comma uses for
// its non-CAN-FD high-torque HKG default (384/3/7). Must stay in lockstep with
// STEER_MAX in selfdrive/car/hyundai/values.py — panda enforces independently and
// will reject larger commands if openpilot's value exceeds this.
.max_steer = 324,
.max_rt_delta = 134,
.max_rt_interval = 250000,
.max_rate_up = 2,
.max_rate_down = 3,
.max_rate_up = 3,
.max_rate_down = 5,
.driver_torque_allowance = 250,
.driver_torque_factor = 2,
.type = TorqueDriverLimited,
+5 -3
View File
@@ -27,12 +27,14 @@ class CarControllerParams:
self.STEER_STEP = 1 # 100 Hz
if CP.carFingerprint in CANFD_CAR:
self.STEER_MAX = 270
# CLEARPILOT: bumped from comma defaults (270/2/3) by ~20% — must stay in
# lockstep with HYUNDAI_CANFD_STEERING_LIMITS in panda/board/safety/safety_hyundai_canfd.h.
self.STEER_MAX = 324
self.STEER_DRIVER_ALLOWANCE = 250
self.STEER_DRIVER_MULTIPLIER = 2
self.STEER_THRESHOLD = 250
self.STEER_DELTA_UP = 2
self.STEER_DELTA_DOWN = 3
self.STEER_DELTA_UP = 3
self.STEER_DELTA_DOWN = 5
# To determine the limit for your car, find the maximum value that the stock LKAS will request.
# If the max stock LKAS request is <384, add your car to this list.
+6 -1
View File
@@ -681,7 +681,12 @@ class Controls:
self.LoC.reset(v_pid=CS.vEgo)
self.frogpilot_variables.no_lat_lane_change = False
self.FPCC.noLatLaneChange = False
lac_log = log.ControlsState.LateralDebugState.new_message()
# Call LaC.update with active=False so we get the right lac_log subtype
# for this car's lateralTuning (torque vs pid vs angle). Internally it
# early-returns when active is False — cheap.
lp = self.sm['liveParameters']
_, _, lac_log = self.LaC.update(False, CS, self.VM, lp, self.steer_limited, 0.0,
self.sm['liveLocationKalman'], model_data=self.sm['modelV2'])
return CC, lac_log
# Update VehicleModel
@@ -0,0 +1,177 @@
# Session: 2026-04-26 — Hyundai CAN-FD steering torque bump
Documentation for commit `4058269` on `clearpilot`. Reference for any
future re-tuning.
## What changed
Bumped this Tucson HDA2 (CAN-FD platform) from comma's conservative
steer ceiling to a value that gives more headroom on tighter on-ramp
clovers, plus a small rate-limit nudge so the controller can actually
reach the new ceiling within reasonable transient time.
| Constant | Before (comma default for CAN-FD) | After (this commit) | Comma's non-CAN-FD HKG default |
|---|---:|---:|---:|
| `max_steer` / `STEER_MAX` | 270 | **324** | 384 |
| `max_rate_up` / `STEER_DELTA_UP` | 2 | **3** | 3 |
| `max_rate_down` / `STEER_DELTA_DOWN` | 3 | **5** | 7 |
| `max_rt_delta` | 112 | **134** | ~150 |
## Where the change lives — TWO files in lockstep
The panda safety firmware enforces these limits **independently** of
openpilot. If only one side is bumped, panda rejects the larger
commands and you get cut-out / `commIssue` behavior. **Always change
both, always to the same numbers, in the same commit.**
1. **`panda/board/safety/safety_hyundai_canfd.h`** (lines 3-19)
- `HYUNDAI_CANFD_STEERING_LIMITS` struct: `max_steer`, `max_rate_up`,
`max_rate_down`, `max_rt_delta`.
- This is C; modifying it changes the panda firmware hash, which
forces an automatic re-flash on next `pandad` start. No manual
panda flash command needed.
2. **`selfdrive/car/hyundai/values.py`** (CAN-FD branch of
`CarControllerParams.__init__`, lines 29-36)
- `STEER_MAX`, `STEER_DELTA_UP`, `STEER_DELTA_DOWN`.
- Pure Python; picked up on next `controlsd` start.
## What each constant does
- **`max_steer` / `STEER_MAX`** — peak torque magnitude the controller
can request. Hard ceiling. Going past this is the headline "more
torque" knob.
- **`max_rate_up` / `STEER_DELTA_UP`** — per-100Hz-cycle upward slew
cap. Higher = faster ramp into a turn. With `max_rate_up = 3` and
`max_steer = 324`, time from 0 to ceiling is 324 / 3 = 108 cycles =
1.08 s.
- **`max_rate_down` / `STEER_DELTA_DOWN`** — per-cycle downward slew
cap. Higher = faster release back toward straight. We chose 5 (vs
comma's 7) for a smoother release feel.
- **`max_rt_delta`** — cumulative torque change allowed across a
rolling 250 ms window (`max_rt_interval`). It's a long-window
envelope check, separate from the per-cycle rate. Should scale with
`max_steer` — we used `max_steer × ~0.41` to mirror comma's ratio.
- **`driver_torque_allowance` / `STEER_DRIVER_ALLOWANCE`** — driver
wheel torque (Nm read off the wheel) that's tolerated before the
system starts derating its own command. Left at 250.
- **`driver_torque_factor` / `STEER_DRIVER_MULTIPLIER`** — how
aggressively the system fights driver input above the allowance.
Left at 2.
## How to go higher (path to 384)
`384` is the community-consensus safe ceiling for HKG. Comma uses it
as the default for every non-CAN-FD HKG that isn't on the explicit
255-blacklist, and they merged it for HDA1 CAN-FD (EV6 / Ioniq 5) in
[openpilot PR #25723](https://github.com/commaai/openpilot/pull/25723).
The PR author noted "max steer needed to be 384 to make basic turns."
Tucson NX4 HDA2 is **not** on the 255-blacklist (see
[issue #24122](https://github.com/commaai/openpilot/issues/24122) for
the verified blacklist).
To go from 324 → 384:
```c
// panda/board/safety/safety_hyundai_canfd.h
.max_steer = 384,
.max_rt_delta = 158, // ~max_steer × 0.41
.max_rate_up = 3,
.max_rate_down = 5, // or 7 for comma-matched aggressive release
```
```python
# selfdrive/car/hyundai/values.py CAN-FD branch
self.STEER_MAX = 384
self.STEER_DELTA_UP = 3
self.STEER_DELTA_DOWN = 5 # or 7
```
Beyond 384 is uncharted for HKG — comma has not tested past it. Some
forks (sunnypilot has discussions) try higher for very heavy vehicles
but with mixed results. Don't go past 384 without an explicit reason.
## Things to watch for / community-flagged risks at higher values
1. **EPS time-out cut every ~90 frames.** The CAN-FD safety already
forces a brief torque cut to stop the EPS from faulting (the
`min_valid_request_frames = 89`, `max_invalid_request_frames = 2`,
`min_valid_request_rt_interval = 810000` block of
`HYUNDAI_CANFD_STEERING_LIMITS`). This is independent of
`max_steer`. Bumping the ceiling does not lengthen the cut-free
window — you just hold the higher torque for the same ~890 ms before
the brief cut. If you're getting `Steering Temporarily Unavailable`
*during sustained turns*, the issue is this cut, not the ceiling,
and it can't be tuned without risking a real EPS fault.
2. **`steerTempUnavailable` / "Cruise Fault: Restart the Car".** Has
been reported on cars in the 255-blacklist when pushed to 384.
Tucson NX4 is not blacklisted, so 324384 is normally safe — but if
you see this alert during slow sweeping turns, that's the symptom.
Roll back to 270 and confirm.
3. **Lateral accel retune.** Higher torque headroom can cause the
torque controller to overshoot if `latAccelFactor` was tuned for
the old ceiling. EV6/Ioniq 5 testing in PR #25723 had to drop
lateral accel to 2.5 m/s² when bumping from 270 to 384. Watch for
over-correction (zig-zag in lane center) after a bump and retune
`latAccelFactor` in `selfdrive/locationd/torqued.py` or via the
torque-tune Params if needed.
4. **Driver-fight feel.** `driver_torque_allowance = 250` /
`driver_torque_factor = 2` is the blending knob. Most "openpilot
fights my hands" complaints come from people who lowered allowance
or raised factor. Don't touch these without a specific reason.
5. **Panda safety hash mismatch.** Changing
`safety_hyundai_canfd.h` regenerates the panda firmware binary with
a different signed hash. On the next `pandad` start, pandad detects
the mismatch and re-flashes the panda automatically (see
`pandad.log`: "Panda firmware out of date" → "flash: flashing" →
"Done flashing"). Takes ~10 s. No manual action needed; just expect
a brief delay before controls come up.
## Verifying the change took effect
```bash
# 1. Confirm the rebuild happened and panda firmware was re-signed.
grep "panda/board/obj/panda_h7" /tmp/build_only.log 2>/dev/null # or run build_only.sh and watch for "signing N bytes"
# 2. Watch for re-flash on launch.
tail -f /data/log2/current/pandad.log
# Should see: "Panda firmware out of date, update required"
# "flash: flashing"
# "Done flashing"
# 3. Confirm the openpilot side is using the new value.
su - comma -c 'PYTHONPATH=/data/openpilot python3 -c "
from cereal import car
from openpilot.common.params import Params
cp_bytes = Params().get(\"CarParams\")
with car.CarParams.from_bytes(cp_bytes) as cp:
print(\"safetyConfig safetyParam:\", [c.safetyParam for c in cp.safetyConfigs])
"'
# 4. Live-check the actual commanded torque ceiling (drive a moderate turn).
# carControl.actuators.steer should now be able to peak above 0.79 (270/255 normalized)
# but stay under 1.0 (full saturation at the new ceiling).
```
## Rollback
If anything misbehaves, revert just the two-file commit:
```bash
git revert 4058269
chown -R comma:comma /data/openpilot
su - comma -c "bash /data/openpilot/build_only.sh"
# Next pandad launch will re-flash back to 270.
```
## Sources
- [openpilot PR #25723 — HDA1 EV6/Ioniq 5 270 → 384](https://github.com/commaai/openpilot/pull/25723)
- [openpilot issue #24122 — HKG torque blacklist verification](https://github.com/commaai/openpilot/issues/24122)
- [openpilot PR #26427 — Hyundai Tucson 2023 support](https://github.com/commaai/openpilot/pull/26427)
- [sunnypilot — increasing torque help](https://community.sunnypilot.ai/t/increasing-torque-help-needed/2082)
- [sunnypilot — raising torque for heavier vehicles](https://community.sunnypilot.ai/t/raising-the-torque-for-heavier-vehicles/862)