Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via a Chassis CAN passthrough gateway #5

Open
opened 2026-11-24 01:18:54 +00:00 by Steve · 0 comments
Owner

Summary

Scope out openpilot longitudinal (gas/brake) control for the 2018–2023 Nissan Leaf (ZE1, ProPILOT), using an inline CAN gateway, in a way that keeps stock emergency braking and could be acceptable upstream (comma / sunnypilot). Steering already works on the Leaf; speed is still the stock ProPILOT cruise.

Research/bench roadmap. Bench and a dedicated test car only — never a daily driver. This touches the brake path.

Code: https://github.com/siigna/leaf-gw (MIT; host-tested gateway core + the panda/Ocelot backend + the phase-0 validator).

Why it hasn't been done

The Leaf's accel/brake request messages sit on a CAN segment the stock comma "Nissan A" harness only listens to (its single intercept relay is used for the steering bus). Past attempts either silenced the forward-camera/ADAS ECU (drops stock AEB/FCW — not acceptable upstream; StarPilot ships this disabled) or needed extra interception hardware, which comma hasn't taken for a low-volume car. sunnypilot's ICBM (cruise-button spoofing) is the half-measure today; the stock ACC still does gas/brake.

Concretely, StarPilot mutes the ADAS ECU with a KWP2000 session to 0x707 (DisableNormalMessageTransmission, 28 02, held open by tester-present), then transmits its own 0x2B0/0x1C3 on the chassis bus with no competing transmitter. Muting the ADAS mutes its emergency braking too — that's the cost. This gateway keeps the ADAS live and arbitrates in-line instead; a plain comma harness + panda can't replace a running counter-stream, which is exactly why a separate in-line box is needed.

What's established

Measured from a public Leaf drive log and cross-checked against the factory service manual (ESM/eWD):

  • Decoded requests (panda bus 1, ~100 Hz each):
    • 0x2B0 — propulsion/regen request, ADAS unit → VCM (accel)
    • 0x1C3 — friction-brake request ("brake fluid pressure control signal"), ADAS unit → ABS actuator
  • ADAS control unit connector (M2) carries three CAN buses: V-CAN (pins 1/2), ITS-CAN (6/7, radar + lane camera), and the Chassis CAN segment (8/9) where 0x2B0/0x1C3 live. The gateway sits on Chassis CAN. Power at IGN (12) / GND (5).
  • Braking architecture: one hydraulic actuator (ABS actuator + electrically-driven intelligent brake) performs ABS/VDC/TCS/brake-assist and the ADAS brake request. ICC braking and Intelligent Emergency Braking share that single brake path — not separate actuation messages.
  • Companion bus-1 frames: 0x28E = ProPILOT brake-active, 0x28F = cruise state, 0x27A = speed/blinkers/driver-brake (status only). 0x288 is undecoded.
  • No stock AEB/emergency-brake flag is decoded anywhere. StarPilot's 0x1C3 "brake mode" bit is openpilot's own command decision, not a readback of the car's emergency state.

ESM cross-check (2026-11-24, from the owner's 2018 ZE1 ESM/eWD)

  • Pinout confirmed. ADAS control unit connector: pins 1/2 = CAN ("V-CAN"), 5 = GND, 6/7 = ITS-CAN, 8/9 = "Chassis CAN" (the ESM/Nissan name for the ADAS↔brake bus, pins 8/9, where 0x2B0/0x1C3 live), 12 = power.
  • Single brake path confirmed. One ABS actuator/electric unit performs VDC/TCS/ABS/EBD/BLSD/brake-assist and the ADAS brake request — so magnitude arbitration on one 0x1C3 stream is the right model.
  • "Brake communication line" is internal. The ESM's separate brake line (*1) is a CAN between the electrically-driven intelligent brake unit and the ABS control unit — downstream of the ADAS. Injecting 0x1C3 on Chassis CAN targets the ABS control unit, the correct place; no separate path to intercept.
  • Scaling still unverified. The ESM CONSULT monitor exposes statuses, not raw CAN counts, and the descriptions are functional — so it does not independently confirm StarPilot's 0x2B0/0x1C3 byte scaling. StarPilot remains the only encoding source; see blocker #1.

Stock-log validation (2026-11-24)

  • Public route 44211d9f2879657d/00000024--ddf4161f21 (US NISSAN_LEAF_IC, sunnypilot, stock ICC engaged 61% of the time; 4 segments, 23,959 frames of each id on bus 1): every 0x1C3 checksum and every 0x2B0 inverse copy validates.
  • 0x2B0 value field: T = (b2 << 4) | (b1 & 0xF), a 12-bit field with its inverted copy in b1_hi:b0. Higher T = more deceleration. StarPilot's packer scrambled it (found in two steps: the US route showed the low nibbles out of order, then SHIOKAZE showed the top nibble was inverted). On ~755k frames from 38 cars the inverted copy holds on every frame and T moves smoothly. StarPilot's linear accel map is meaningless under T (its "0 m/s²" is T 2304, about +0.6 m/s²); this also affects StarPilot's own disabled alpha.
  • Stock values: idle T = 2595, friction-brake marker T = 3415 (only while 0x1C3 pressure > 0), active 2048–3071. "More braking" is simply the larger T, which is how the gateway arbitrates. Byte 3's top bits are a stock state field (ac, 8c in Park, 6c, 4c, …); the gateway keeps stock's byte 3 when it substitutes. Bit 0x20 tracks "cruise available" (SHIOKAZE; 99.95% agreement on the fleet's 755k frames, the rest at on/off transitions), and byte 4 bit 0x40 is "engaged and moving".
  • 0x180 follows T ~160 ms later (SHIOKAZE): signed 12-bit in byte 2 + byte 3's top nibble, D ≈ −0.796·T + 2067. In the fleet it's on panda bus 0 for Nissan A cars; the best segments fit D = −0.798·T + 2070 (corr −0.999, RMSE 1.1), median RMSE 8, departing when the pedal or friction brake takes over. Response or reflection is open, but the comma can read it directly, so the openpilot patches now use it as a follow check: if the car slows less than openpilot asked by > 60 counts for 1 s, openpilot disengages (accFaulted). Slowing more is allowed (stock winning). A perfect relay never trips it on the 37-car fleet (0 of 127 segments). Longitudinal is only offered when 0x180 is in the fingerprint. The lag and window are measured in time, not frames, so it holds at any controller rate, and a missing clock skips the check rather than crashing the controller.
  • Second car: SHIOKAZE (openpilot Discord; receive-only logs, June 2022 Japanese-spec ZE1 e+ G, IC harness) independently confirmed the 0x1C3 field + checksum, worked out the 0x2B0 value field (T) and the brake-marker state, showed b4 & 0x40 means engaged and moving, and found 0x707 28 02 refused (7F 28 11) — StarPilot's silencing route doesn't work on that car.
  • Fleet check (37 cars): comma's public commaCarSegments dataset has 1,172 Nissan A-harness and 166 IC-harness Leaf segments. Sampling 3 segments per car (106 segments, 31 + 6 cars, 635k frames of each id): zero checksum / inverse-copy failures, identical brake-marker bytes.
    • Stock 0x2B0/0x1C3 appear only on panda bus 1, on both harnesses, never on bus 0 or 2. So stock never competes with openpilot's frames on bus 2 (this was a listed bench check).
    • 0x5FF never appears on any bus in any of the 37 cars, so the heartbeat id is free (also a listed bench check).
  • Stock braking seen: the highest 0x1C3 (680–821) is always ICC's standstill hold (stop, brake marker, pressure ramps ~280 counts/s, release a few seconds later). The strongest braking while moving was a sudden 0.7 s ICC brake at 68 km/h (0 → 556, about −2 m/s²), ended by the driver pressing the accelerator. Magnitude arbitration handles both (stock is stronger, stock wins). No AEB event in the sample, so arbitration against a real emergency stop is still untested.
  • Accel scale (provisional): measured acceleration (from wheel speed) vs T during ICC across the 37-car sample correlates −0.76. Zero is near T ≈ 2530, about +0.8 m/s² at 2272 and −0.8 at 2784, flatter in between. openpilot now interpolates those medians; it still needs an active bench / test-car check.
  • Still open: brake pressure scaling (still StarPilot's), whether 0x1C3 is total or friction-only braking, and what byte 3's state bits and byte 7's 2-bit field mean.

The validator now also requires the 0x2B0 value to move smoothly, since a wrong bit order can still pass the inverse-copy check.

Proposed approach — inline passthrough gateway (keeps AEB)

An inline CAN gateway (three CAN buses: Chassis CAN ADAS side, Chassis CAN chassis side, and a third tapping V-CAN to read openpilot's command) on Chassis CAN — the battery-swap CAN-bridge pattern, the same idea as a Toyota "smart DSU":

  • default / disengaged / fault / power loss → straight passthrough, both directions, including the ADAS unit's braking;
  • engaged → forward everything except 0x2B0/0x1C3, inject openpilot's with correct counter/checksum at stock rate;
  • emergency-braking passthrough by magnitude: the gateway never silences the ADAS unit, so that unit keeps sending its own 0x1C3 (≈0 pressure idle, spiking for any braking incl. AEB). The gateway forwards whichever brake request is greater — openpilot's or the stock one — and always yields to a stronger stock request. AEB survives as a pass-through pressure spike; no decoded "emergency" flag required.

Upstream-fit: matches a pattern comma already ships; stock AEB preserved; frame-level panda-safety checks already exist in a fork. What's still needed from comma: whether they'd bless a bus-1 passthrough harness that preserves AEB, and what hardware path (comma-built harness / red panda).

Blockers / next steps

  1. [BLOCKER — layout done, scaling open] Verify the message layouts on an actual ZE1. The addresses, scaling and checksum started from StarPilot's disabled, firmware-pinned 2025-SV-Plus code. Stock logs from two ZE1s now settle the byte layout (see Stock-log validation below), and they showed StarPilot's 0x2B0 packer had two nibbles swapped (fixed everywhere). Still unverified: the scaling (counts per m/s², brake pressure units) and a capture off the owner's own 2018 car.
    1b. [SAFETY GATE] Confirm the openpilot TX bus is listen-only. (Fleet data: stock never puts 0x2B0/0x1C3 on bus 2. That doesn't replace the injection test below.) openpilot emits the real 0x2B0/0x1C3 on V-CAN; on the ZE1 those actuation signals natively live on Chassis CAN, a bus the comma only listens to — so they should be inert off the interceptor (stock car, or interceptor dead → frames reach no actuator; the gateway is what relays them to Chassis CAN). But "inert" is a property of the bus, not the frame (StarPilot actuates by transmitting them on a bus that reaches the ABS). So with the interceptor absent/passive, inject 0x2B0/0x1C3 on the chosen V-CAN segment and verify no actuation and that nothing crosses to Chassis CAN. This is also why there's no AEB-disabling shortcut here and why a gateway is required at all.
  2. Confirm the stock ADAS emits 0x1C3 continuously (≈0 when idle) so magnitude arbitration is viable; capture an ICC comfort stop vs an emergency stop and diff.
  3. Decode 0x288 opportunistically (only undecoded bus-1 frame; possible out-of-band emergency signal).
  4. Bench rig: used ADAS control unit (284E7-5SA*) + connector, a RetroPilot Ocelot Pro (3× CAN), dual USB-CAN analyzer. Prove passthrough adds no latency / drops no frames, and that the magnitude-arbitration + fail-open logic reverts to stock on any fault. Confirm an injected 0x2B0 actually became propulsion by watching 0x1D4 (VCM→inverter torque demand, signed 12-bit ×0.25 — well-decoded by the OpenInverter / Leaf-powertrain community); the chain is ADAS 0x2B0 → VCM → 0x1D4 → inverter. Additional downstream readouts to poll over UDS (per the canair ZE1 PID profile, tentative): ABS ECU 0x740 service 0x22 12 09 = brake master-cylinder pressure, inverter 0x784 0x22 12 25 = motor torque (Nm), accel-pedal % — use these to confirm an injected brake/accel actually produced pressure/torque.
  5. Only then a dedicated test car; validate AEB passthrough on a closed course.

No public ZE1 actuation decode exists. Survey (2026-11-24): the Leaf RE community works at adjacent layers — powertrain/battery (dalathegreat, OpenInverter/jsphuebner, 0x1D4 torque), diagnostic PIDs (canair/LeafSpy/CANZE — readouts incl. brake pressure, not the ADAS request), telematics/TCU (developerfromjokela, PCAutomotive/Black Hat), and ADAS cruise-button/status/lateral (opendbc, sunnypilot ICBM, seisyo58). None decode the 0x2B0/0x1C3 injection encoding; StarPilot's disabled/FW-pinned experiment is the only one. So the byte-level ZE1 encoding is unsolved in public — capturing it (blocker #1) is novel work, which is also why no one ships AEB-preserving Leaf longitudinal.

Prior work: StarPilot (firestar5683) Leaf longitudinal implementation (ECU-silencing method; disabled, 2025-only); sunnypilot ICBM; opendbc Nissan port; community decode by L7Weaver et al. Factory CAN/architecture facts verified against the Nissan ESM (owner's own subscription; not reproduced here). ADAS diagnostic ID 0x75D; forward camera 0x707.

openpilot integration (car side)

openpilot already does lateral on the Leaf; this adds longitudinal. The opendbc car/nissan patch in the repo's openpilot/ directory, when longitudinal is enabled, emits the car's real ADAS frames — 0x2B0 (propulsion/regen) and 0x1C3 (friction brake) — on the bus the comma can reach (V-CAN, panda bus 2). It does not silence the stock ADAS ECU (so AEB stays live) and does not spoof cruise buttons; the inline gateway reads the frames off V-CAN, re-emits them onto Chassis CAN with the stock counter, and yields to a stronger stock request (magnitude arbitration). This is the opendbc-idiomatic shape — a normal longitudinal port that happens to send on V-CAN — with no custom command frame.

  • leaf_gw_long.py — dependency-free spec of the accel → (T, pressure) mapping (the 37-car fleet curve, provisional; brake gain still StarPilot's) + the real 0x2B0/0x1C3 packers; its test round-trips pack→decode through the firmware core's own rules.
  • nissan-longitudinal.patch — three hooks into opendbc: carcontroller send, interface enable + accel limits + long safety flag, values constants.
  • panda safety: nissan-safety-longitudinal.patch allows 0x2B0/0x1C3 TX on bus 2 under a LONG flag and bounds them with the shared longitudinal_gas_checks/longitudinal_brake_checks (T 2272–3415, idle 2595 when not engaged, pressure ≤659) + get_longitudinal_allowed (also blocks when the driver presses the accelerator).
  • Engagement: pcmCruise stays True (as Toyota / Honda Nidec openpilot longitudinal). You engage stock ProPILOT as usual; panda keys controls_allowed off its cruise state and openpilot supplies the acceleration. With pcmCruise False, openpilot would cancel the very cruise panda needs, so it could never engage.
  • Gateway heartbeat: the gateway sends 0x5FF on its V-CAN port at 50 Hz ('L' 'G' 'W', version, status, counter, checksum; added to the Leaf DBC as LEAF_GW_HEARTBEAT). openpilot offers longitudinal only if the heartbeat is in the fingerprint at startup, and panda monitors it as an rx check, so control drops within ~1 s if it stops. Without a gateway, openpilot can't think it's driving while stock ProPILOT really is.
  • Six forks: patch sets for openpilot (opendbc 341fb3d9), sunnypilot (sunnypilot/opendbc 11c61f3e; ICBM button spoofing is off while openpilot long is on), StarPilot (0b2061d; a gateway mode beside StarPilot's silencing mode, which it leaves in place), RetroPilot (c2 b9a942ef; note c2 hard-codes the retrofit fingerprint, so the Leaf isn't selected until that line is reverted) and FlowPilot (the maintained jagheterfredrik/flowpilot, master 9ea918ea; its Nissan support was broken by an apply() signature mismatch and a missing "System Unresponsive" liveness line, both fixed in the patch; plus phr00t's master 84f25d06, its base and what the tarball install ships, as its own patch set with panda hunks for its older panda). RetroPilot's older tree opts in with its own DisableRadar param and spells the panda bounds out by hand. openpilot/check-forks.sh applies each to a fresh worktree at its pin and runs the nissan suites (--latest checks fork heads for drift; RetroPilot and FlowPilot ship a fork.sh with their own pinned nix env). Verified 2026-11-25 (after the T change): opendbc 114 passed / 15 skipped, sunnypilot 246 / 36, StarPilot 233 / 25, RetroPilot 72 + 12, FlowPilot 103 / 12 + 19, phr00t 76 / 9 + 19, plus the 5 nissan interface tests each.
  • MISRA: cppcheck on all six trees with each tree's pinned version, patched vs unpatched baseline (and with ALLOW_DEBUG where our code sits behind it): 5 new findings, all fixed; no new suppressions beyond one the tree already uses for identical code.
  • Heartbeat rate: 50 Hz, because RetroPilot fingerprints for only 0.1 s; about five heartbeats land in that window.

Phase-0 validator

Read-only decoder that checks the 0x1C3/0x2B0 layouts on a real ZE1 (blocker #1): tools/leaf_iccan_check.py. Capture Chassis CAN with a panda + Cabana, a USB-CAN adapter, or SocketCAN candump, and feed the log in. It checks the 0x1C3 checksum, the 0x2B0 inverse copy, and that the 0x2B0 value moves smoothly. Passes on the public route above. Pure decode, never touches a bus, safe on any car.

Implementation & hardware

The gateway is a small MIT core (leaf_gw + gw_engine: decode/encode, 0x1C3 checksum, magnitude arbitration, fail-open), host-tested (make test, nix flake check), with one firmware backend:

  • panda / Ocelot (backends/panda/gw_panda.c) — a bare-metal, interrupt-driven interceptor modeled on the RetroPilot ocelot smart_dsu: it calls the pure core straight from the CAN RX interrupts (CAN1=ADAS → decide → CAN2=chassis, CAN3=taps V-CAN to read openpilot's real 0x2B0/0x1C3, and sends the 0x5FF heartbeat there). Build-proven: compiles, links and signs an STM32F413 image under the real arm-none-eabi + scons build (nix build .#ocelot-firmware). Untested on a car.

Recommended board: a RetroPilot Ocelot Pro (STM32F413, 3× TJA1042, panda/Cabana-compatible). Three native CAN buses are required, not optional. There is no spare/free bus on the comma's Nissan A harness — the red panda's three buses are all used (EPS-side V-CAN = bus 0, ADAS-side V-CAN = bus 2, OBD-II = bus 1) — so openpilot sends the real 0x2B0/0x1C3 on V-CAN (the bus it already drives, bus 2) and the interceptor's third CAN taps V-CAN at M2 pins 1/2 to read them. CAN1/CAN2 do the Chassis CAN cut; the third is the V-CAN tap. A 2-CAN board (e.g. ESP32-C6) has no controller left to tap V-CAN, so the command would have to ride a Chassis CAN segment — putting the comma on the brake bus — which is why it isn't supported. Which V-CAN segment / bus number is a bench check. 0x5FF is unused on all 37 cars checked (fleet check above). No off-the-shelf interceptor ships a fail-open relay; an external normally-closed relay on the Chassis CAN cut is mandatory before any on-car use. Details in the repo's HARDWARE.md.

Bench guide

Interactive ADAS connector map and the gateway plan: https://escargot.free/bench/leaf-adas-gateway.html

## Summary Scope out openpilot **longitudinal** (gas/brake) control for the 2018–2023 Nissan Leaf (ZE1, ProPILOT), using an inline CAN gateway, in a way that **keeps stock emergency braking** and could be acceptable upstream (comma / sunnypilot). Steering already works on the Leaf; speed is still the stock ProPILOT cruise. Research/bench roadmap. **Bench and a dedicated test car only — never a daily driver.** This touches the brake path. **Code:** https://github.com/siigna/leaf-gw (MIT; host-tested gateway core + the panda/Ocelot backend + the phase-0 validator). ## Why it hasn't been done The Leaf's accel/brake request messages sit on a CAN segment the stock comma "Nissan A" harness only listens to (its single intercept relay is used for the steering bus). Past attempts either silenced the forward-camera/ADAS ECU (drops stock AEB/FCW — not acceptable upstream; StarPilot ships this disabled) or needed extra interception hardware, which comma hasn't taken for a low-volume car. sunnypilot's ICBM (cruise-button spoofing) is the half-measure today; the stock ACC still does gas/brake. Concretely, StarPilot mutes the ADAS ECU with a KWP2000 session to `0x707` (*DisableNormalMessageTransmission*, `28 02`, held open by tester-present), then transmits its own `0x2B0`/`0x1C3` on the chassis bus with no competing transmitter. Muting the ADAS mutes its emergency braking too — that's the cost. This gateway keeps the ADAS live and arbitrates in-line instead; a plain comma harness + panda can't replace a running counter-stream, which is exactly why a separate in-line box is needed. ## What's established Measured from a public Leaf drive log and cross-checked against the factory service manual (ESM/eWD): - **Decoded requests** (panda bus 1, ~100 Hz each): - `0x2B0` — propulsion/regen request, ADAS unit → VCM (accel) - `0x1C3` — friction-brake request ("brake fluid pressure control signal"), ADAS unit → ABS actuator - **ADAS control unit connector (M2)** carries three CAN buses: V-CAN (pins 1/2), ITS-CAN (6/7, radar + lane camera), and the Chassis CAN segment (8/9) where `0x2B0`/`0x1C3` live. The gateway sits on Chassis CAN. Power at IGN (12) / GND (5). - **Braking architecture:** one hydraulic actuator (ABS actuator + electrically-driven intelligent brake) performs ABS/VDC/TCS/brake-assist **and** the ADAS brake request. ICC braking and Intelligent Emergency Braking **share that single brake path** — not separate actuation messages. - Companion bus-1 frames: `0x28E` = ProPILOT brake-active, `0x28F` = cruise state, `0x27A` = speed/blinkers/driver-brake (status only). `0x288` is undecoded. - **No stock AEB/emergency-brake flag is decoded anywhere.** StarPilot's `0x1C3` "brake mode" bit is openpilot's *own* command decision, not a readback of the car's emergency state. ## ESM cross-check (2026-11-24, from the owner's 2018 ZE1 ESM/eWD) - **Pinout confirmed.** ADAS control unit connector: pins 1/2 = CAN ("V-CAN"), 5 = GND, 6/7 = ITS-CAN, **8/9 = "Chassis CAN"** (the ESM/Nissan name for the ADAS↔brake bus, pins 8/9, where `0x2B0`/`0x1C3` live), 12 = power. - **Single brake path confirmed.** One ABS actuator/electric unit performs VDC/TCS/ABS/EBD/BLSD/brake-assist *and* the ADAS brake request — so magnitude arbitration on one `0x1C3` stream is the right model. - **"Brake communication line" is internal.** The ESM's separate brake line (`*1`) is a CAN *between the electrically-driven intelligent brake unit and the ABS control unit* — downstream of the ADAS. Injecting `0x1C3` on Chassis CAN targets the ABS control unit, the correct place; no separate path to intercept. - **Scaling still unverified.** The ESM CONSULT monitor exposes statuses, not raw CAN counts, and the descriptions are functional — so it does **not** independently confirm StarPilot's `0x2B0`/`0x1C3` byte scaling. StarPilot remains the only encoding source; see blocker #1. ## Stock-log validation (2026-11-24) - **Public route** `44211d9f2879657d/00000024--ddf4161f21` (US `NISSAN_LEAF_IC`, sunnypilot, stock ICC engaged 61% of the time; 4 segments, 23,959 frames of each id on bus 1): every `0x1C3` checksum and every `0x2B0` inverse copy validates. - **`0x2B0` value field: T = `(b2 << 4) | (b1 & 0xF)`**, a 12-bit field with its inverted copy in `b1_hi:b0`. **Higher T = more deceleration.** StarPilot's packer scrambled it (found in two steps: the US route showed the low nibbles out of order, then SHIOKAZE showed the top nibble was inverted). On ~755k frames from 38 cars the inverted copy holds on every frame and T moves smoothly. StarPilot's linear accel map is meaningless under T (its "0 m/s²" is T 2304, about +0.6 m/s²); this also affects StarPilot's own disabled alpha. - **Stock values:** idle T = 2595, friction-brake marker T = 3415 (only while `0x1C3` pressure > 0), active 2048–3071. "More braking" is simply the larger T, which is how the gateway arbitrates. Byte 3's top bits are a stock state field (`ac`, `8c` in Park, `6c`, `4c`, …); the gateway keeps stock's byte 3 when it substitutes. Bit `0x20` tracks "cruise available" (SHIOKAZE; 99.95% agreement on the fleet's 755k frames, the rest at on/off transitions), and byte 4 bit `0x40` is "engaged and moving". - **`0x180` follows T ~160 ms later** (SHIOKAZE): signed 12-bit in byte 2 + byte 3's top nibble, D ≈ −0.796·T + 2067. In the fleet it's on panda **bus 0** for Nissan A cars; the best segments fit D = −0.798·T + 2070 (corr −0.999, RMSE 1.1), median RMSE 8, departing when the pedal or friction brake takes over. Response or reflection is open, but the comma can read it directly, so the openpilot patches now use it as a **follow check**: if the car slows less than openpilot asked by > 60 counts for 1 s, openpilot disengages (accFaulted). Slowing more is allowed (stock winning). A perfect relay never trips it on the 37-car fleet (0 of 127 segments). Longitudinal is only offered when 0x180 is in the fingerprint. The lag and window are measured in time, not frames, so it holds at any controller rate, and a missing clock skips the check rather than crashing the controller. - **Second car:** SHIOKAZE (openpilot Discord; receive-only logs, June 2022 Japanese-spec ZE1 e+ G, IC harness) independently confirmed the `0x1C3` field + checksum, worked out the `0x2B0` value field (T) and the brake-marker state, showed `b4 & 0x40` means engaged and moving, and found `0x707` `28 02` refused (`7F 28 11`) — StarPilot's silencing route doesn't work on that car. - **Fleet check (37 cars):** comma's public [commaCarSegments](https://huggingface.co/datasets/commaai/commaCarSegments) dataset has 1,172 Nissan A-harness and 166 IC-harness Leaf segments. Sampling 3 segments per car (106 segments, 31 + 6 cars, 635k frames of each id): zero checksum / inverse-copy failures, identical brake-marker bytes. - Stock `0x2B0`/`0x1C3` appear **only on panda bus 1**, on both harnesses, never on bus 0 or 2. So stock never competes with openpilot's frames on bus 2 (this was a listed bench check). - **`0x5FF` never appears** on any bus in any of the 37 cars, so the heartbeat id is free (also a listed bench check). - **Stock braking seen:** the highest `0x1C3` (680–821) is always ICC's standstill hold (stop, brake marker, pressure ramps ~280 counts/s, release a few seconds later). The strongest braking while moving was a sudden 0.7 s ICC brake at 68 km/h (0 → 556, about −2 m/s²), ended by the driver pressing the accelerator. Magnitude arbitration handles both (stock is stronger, stock wins). **No AEB event in the sample**, so arbitration against a real emergency stop is still untested. - **Accel scale (provisional):** measured acceleration (from wheel speed) vs T during ICC across the 37-car sample correlates −0.76. Zero is near T ≈ 2530, about +0.8 m/s² at 2272 and −0.8 at 2784, flatter in between. openpilot now interpolates those medians; it still needs an active bench / test-car check. - **Still open:** brake pressure scaling (still StarPilot's), whether `0x1C3` is total or friction-only braking, and what byte 3's state bits and byte 7's 2-bit field mean. The validator now also requires the `0x2B0` value to move smoothly, since a wrong bit order can still pass the inverse-copy check. ## Proposed approach — inline passthrough gateway (keeps AEB) An inline CAN gateway (three CAN buses: Chassis CAN ADAS side, Chassis CAN chassis side, and a third tapping V-CAN to read openpilot's command) on Chassis CAN — the battery-swap CAN-bridge pattern, the same idea as a Toyota "smart DSU": - default / disengaged / fault / power loss → **straight passthrough**, both directions, including the ADAS unit's braking; - engaged → forward everything except `0x2B0`/`0x1C3`, inject openpilot's with correct counter/checksum at stock rate; - **emergency-braking passthrough by magnitude:** the gateway never silences the ADAS unit, so that unit keeps sending its own `0x1C3` (≈0 pressure idle, spiking for any braking incl. AEB). The gateway forwards whichever brake request is greater — openpilot's or the stock one — and always yields to a stronger stock request. AEB survives as a pass-through pressure spike; no decoded "emergency" flag required. Upstream-fit: matches a pattern comma already ships; stock AEB preserved; frame-level panda-safety checks already exist in a fork. What's still needed from comma: whether they'd bless a bus-1 passthrough harness that preserves AEB, and what hardware path (comma-built harness / red panda). ## Blockers / next steps 1. **[BLOCKER — layout done, scaling open] Verify the message layouts on an actual ZE1.** The addresses, scaling and checksum started from StarPilot's **disabled, firmware-pinned** 2025-SV-Plus code. Stock logs from two ZE1s now settle the **byte layout** (see *Stock-log validation* below), and they showed StarPilot's `0x2B0` packer had two nibbles swapped (fixed everywhere). Still unverified: the **scaling** (counts per m/s², brake pressure units) and a capture off the owner's own 2018 car. 1b. **[SAFETY GATE] Confirm the openpilot TX bus is listen-only.** (Fleet data: stock never puts `0x2B0`/`0x1C3` on bus 2. That doesn't replace the injection test below.) openpilot emits the real `0x2B0`/`0x1C3` on V-CAN; on the ZE1 those actuation signals natively live on Chassis CAN, a bus the comma only *listens* to — so they should be inert off the interceptor (stock car, or interceptor dead → frames reach no actuator; the gateway is what relays them to Chassis CAN). But "inert" is a property of the *bus*, not the frame (StarPilot actuates by transmitting them on a bus that reaches the ABS). So with the interceptor absent/passive, inject `0x2B0`/`0x1C3` on the chosen V-CAN segment and verify **no actuation** and that **nothing crosses to Chassis CAN**. This is also why there's no AEB-disabling shortcut here and why a gateway is required at all. 2. Confirm the stock ADAS emits `0x1C3` continuously (≈0 when idle) so magnitude arbitration is viable; capture an ICC comfort stop vs an emergency stop and diff. 3. Decode `0x288` opportunistically (only undecoded bus-1 frame; possible out-of-band emergency signal). 4. Bench rig: used ADAS control unit (284E7-5SA*) + connector, a RetroPilot Ocelot Pro (3× CAN), dual USB-CAN analyzer. Prove passthrough adds no latency / drops no frames, and that the magnitude-arbitration + fail-open logic reverts to stock on any fault. Confirm an injected `0x2B0` actually became propulsion by watching `0x1D4` (VCM→inverter torque demand, signed 12-bit ×0.25 — well-decoded by the OpenInverter / Leaf-powertrain community); the chain is ADAS `0x2B0` → VCM → `0x1D4` → inverter. Additional downstream readouts to poll over UDS (per the `canair` ZE1 PID profile, tentative): ABS ECU `0x740` service `0x22 12 09` = brake master-cylinder pressure, inverter `0x784` `0x22 12 25` = motor torque (Nm), accel-pedal % — use these to confirm an injected brake/accel actually produced pressure/torque. 5. Only then a dedicated test car; validate AEB passthrough on a closed course. No public ZE1 **actuation** decode exists. Survey (2026-11-24): the Leaf RE community works at adjacent layers — powertrain/battery (dalathegreat, OpenInverter/jsphuebner, `0x1D4` torque), diagnostic PIDs (canair/LeafSpy/CANZE — readouts incl. brake pressure, not the ADAS request), telematics/TCU (developerfromjokela, PCAutomotive/Black Hat), and ADAS cruise-button/status/lateral (opendbc, sunnypilot ICBM, seisyo58). None decode the `0x2B0`/`0x1C3` injection encoding; StarPilot's disabled/FW-pinned experiment is the only one. So the byte-level ZE1 encoding is unsolved in public — capturing it (blocker #1) is novel work, which is also why no one ships AEB-preserving Leaf longitudinal. Prior work: StarPilot (firestar5683) Leaf longitudinal implementation (ECU-silencing method; disabled, 2025-only); sunnypilot ICBM; opendbc Nissan port; community decode by L7Weaver et al. Factory CAN/architecture facts verified against the Nissan ESM (owner's own subscription; not reproduced here). ADAS diagnostic ID 0x75D; forward camera 0x707. ## openpilot integration (car side) openpilot already does lateral on the Leaf; this adds longitudinal. The opendbc `car/nissan` patch in the repo's [`openpilot/`](https://github.com/siigna/leaf-gw/tree/main/openpilot) directory, when longitudinal is enabled, emits the car's **real** ADAS frames — `0x2B0` (propulsion/regen) and `0x1C3` (friction brake) — on the bus the comma can reach (**V-CAN**, panda bus 2). It does **not** silence the stock ADAS ECU (so AEB stays live) and does **not** spoof cruise buttons; the inline gateway reads the frames off V-CAN, re-emits them onto Chassis CAN with the stock counter, and yields to a stronger stock request (magnitude arbitration). This is the opendbc-idiomatic shape — a normal longitudinal port that happens to send on V-CAN — with no custom command frame. - `leaf_gw_long.py` — dependency-free spec of the `accel → (T, pressure)` mapping (the 37-car fleet curve, provisional; brake gain still StarPilot's) + the real `0x2B0`/`0x1C3` packers; its test round-trips pack→decode through the firmware core's own rules. - `nissan-longitudinal.patch` — three hooks into opendbc: carcontroller send, interface enable + accel limits + long safety flag, values constants. - panda safety: `nissan-safety-longitudinal.patch` allows `0x2B0`/`0x1C3` TX on bus 2 under a LONG flag and bounds them with the shared `longitudinal_gas_checks`/`longitudinal_brake_checks` (T 2272–3415, idle 2595 when not engaged, pressure ≤659) + `get_longitudinal_allowed` (also blocks when the driver presses the accelerator). - **Engagement:** `pcmCruise` stays True (as Toyota / Honda Nidec openpilot longitudinal). You engage stock ProPILOT as usual; panda keys `controls_allowed` off its cruise state and openpilot supplies the acceleration. With `pcmCruise` False, openpilot would cancel the very cruise panda needs, so it could never engage. - **Gateway heartbeat:** the gateway sends `0x5FF` on its V-CAN port at 50 Hz (`'L' 'G' 'W'`, version, status, counter, checksum; added to the Leaf DBC as `LEAF_GW_HEARTBEAT`). openpilot offers longitudinal only if the heartbeat is in the fingerprint at startup, and panda monitors it as an rx check, so control drops within ~1 s if it stops. Without a gateway, openpilot can't think it's driving while stock ProPILOT really is. - **Six forks:** patch sets for openpilot (opendbc `341fb3d9`), sunnypilot (`sunnypilot/opendbc` `11c61f3e`; ICBM button spoofing is off while openpilot long is on), StarPilot (`0b2061d`; a gateway mode beside StarPilot's silencing mode, which it leaves in place), RetroPilot (`c2` `b9a942ef`; note `c2` hard-codes the retrofit fingerprint, so the Leaf isn't selected until that line is reverted) and FlowPilot (the maintained `jagheterfredrik/flowpilot`, `master` `9ea918ea`; its Nissan support was broken by an `apply()` signature mismatch and a missing "System Unresponsive" liveness line, both fixed in the patch; plus phr00t's `master` `84f25d06`, its base and what the tarball install ships, as its own patch set with panda hunks for its older panda). RetroPilot's older tree opts in with its own `DisableRadar` param and spells the panda bounds out by hand. `openpilot/check-forks.sh` applies each to a fresh worktree at its pin and runs the nissan suites (`--latest` checks fork heads for drift; RetroPilot and FlowPilot ship a `fork.sh` with their own pinned nix env). Verified 2026-11-25 (after the T change): opendbc 114 passed / 15 skipped, sunnypilot 246 / 36, StarPilot 233 / 25, RetroPilot 72 + 12, FlowPilot 103 / 12 + 19, phr00t 76 / 9 + 19, plus the 5 nissan interface tests each. - **MISRA:** cppcheck on all six trees with each tree's pinned version, patched vs unpatched baseline (and with `ALLOW_DEBUG` where our code sits behind it): 5 new findings, all fixed; no new suppressions beyond one the tree already uses for identical code. - **Heartbeat rate:** 50 Hz, because RetroPilot fingerprints for only 0.1 s; about five heartbeats land in that window. ## Phase-0 validator Read-only decoder that checks the 0x1C3/0x2B0 layouts on a real ZE1 (blocker #1): [`tools/leaf_iccan_check.py`](https://github.com/siigna/leaf-gw/blob/main/tools/leaf_iccan_check.py). Capture Chassis CAN with a panda + Cabana, a USB-CAN adapter, or SocketCAN `candump`, and feed the log in. It checks the 0x1C3 checksum, the 0x2B0 inverse copy, and that the 0x2B0 value moves smoothly. Passes on the public route above. Pure decode, never touches a bus, safe on any car. ## Implementation & hardware The gateway is a small **MIT core** (`leaf_gw` + `gw_engine`: decode/encode, 0x1C3 checksum, magnitude arbitration, fail-open), host-tested (`make test`, `nix flake check`), with one firmware backend: - **panda / Ocelot** (`backends/panda/gw_panda.c`) — a bare-metal, interrupt-driven interceptor modeled on the RetroPilot ocelot `smart_dsu`: it calls the pure core straight from the CAN RX interrupts (CAN1=ADAS → decide → CAN2=chassis, CAN3=taps V-CAN to read openpilot's real 0x2B0/0x1C3, and sends the `0x5FF` heartbeat there). **Build-proven**: compiles, links and signs an STM32F413 image under the real `arm-none-eabi` + scons build (`nix build .#ocelot-firmware`). Untested on a car. Recommended board: a **RetroPilot Ocelot Pro** (STM32F413, 3× TJA1042, panda/Cabana-compatible). Three native CAN buses are required, not optional. There is **no spare/free bus** on the comma's Nissan A harness — the red panda's three buses are all used (EPS-side V-CAN = bus 0, ADAS-side V-CAN = bus 2, OBD-II = bus 1) — so openpilot sends the real `0x2B0`/`0x1C3` on **V-CAN** (the bus it already drives, bus 2) and the interceptor's third CAN taps V-CAN at M2 pins 1/2 to read them. CAN1/CAN2 do the Chassis CAN cut; the third is the V-CAN tap. A 2-CAN board (e.g. ESP32-C6) has no controller left to tap V-CAN, so the command would have to ride a Chassis CAN segment — putting the comma on the brake bus — which is why it isn't supported. Which V-CAN segment / bus number is a bench check. `0x5FF` is unused on all 37 cars checked (fleet check above). No off-the-shelf interceptor ships a fail-open relay; an **external normally-closed relay** on the Chassis CAN cut is mandatory before any on-car use. Details in the repo's `HARDWARE.md`. ## Bench guide Interactive ADAS connector map and the gateway plan: https://escargot.free/bench/leaf-adas-gateway.html
Steve changed title from Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an IC-CAN passthrough gateway to Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an Chassis CAN passthrough gateway 2026-11-25 07:57:28 +00:00
Steve changed title from Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an Chassis CAN passthrough gateway to Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via a Chassis CAN passthrough gateway 2026-11-25 07:57:35 +00:00
Sign in to join this conversation.
No description provided.