Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via a Chassis CAN passthrough gateway #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 own0x2B0/0x1C3on 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):
0x2B0— propulsion/regen request, ADAS unit → VCM (accel)0x1C3— friction-brake request ("brake fluid pressure control signal"), ADAS unit → ABS actuator0x2B0/0x1C3live. The gateway sits on Chassis CAN. Power at IGN (12) / GND (5).0x28E= ProPILOT brake-active,0x28F= cruise state,0x27A= speed/blinkers/driver-brake (status only).0x288is undecoded.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)
0x2B0/0x1C3live), 12 = power.0x1C3stream is the right model.*1) is a CAN between the electrically-driven intelligent brake unit and the ABS control unit — downstream of the ADAS. Injecting0x1C3on Chassis CAN targets the ABS control unit, the correct place; no separate path to intercept.0x2B0/0x1C3byte scaling. StarPilot remains the only encoding source; see blocker #1.Stock-log validation (2026-11-24)
44211d9f2879657d/00000024--ddf4161f21(USNISSAN_LEAF_IC, sunnypilot, stock ICC engaged 61% of the time; 4 segments, 23,959 frames of each id on bus 1): every0x1C3checksum and every0x2B0inverse copy validates.0x2B0value field: T =(b2 << 4) | (b1 & 0xF), a 12-bit field with its inverted copy inb1_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.0x1C3pressure > 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,8cin Park,6c,4c, …); the gateway keeps stock's byte 3 when it substitutes. Bit0x20tracks "cruise available" (SHIOKAZE; 99.95% agreement on the fleet's 755k frames, the rest at on/off transitions), and byte 4 bit0x40is "engaged and moving".0x180follows 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.0x1C3field + checksum, worked out the0x2B0value field (T) and the brake-marker state, showedb4 & 0x40means engaged and moving, and found0x70728 02refused (7F 28 11) — StarPilot's silencing route doesn't work on that car.0x2B0/0x1C3appear 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).0x5FFnever appears on any bus in any of the 37 cars, so the heartbeat id is free (also a listed bench check).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.0x1C3is 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
0x2B0value 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":
0x2B0/0x1C3, inject openpilot's with correct counter/checksum at stock rate;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
0x2B0packer 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/0x1C3on bus 2. That doesn't replace the injection test below.) openpilot emits the real0x2B0/0x1C3on 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, inject0x2B0/0x1C3on 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.0x1C3continuously (≈0 when idle) so magnitude arbitration is viable; capture an ICC comfort stop vs an emergency stop and diff.0x288opportunistically (only undecoded bus-1 frame; possible out-of-band emergency signal).0x2B0actually became propulsion by watching0x1D4(VCM→inverter torque demand, signed 12-bit ×0.25 — well-decoded by the OpenInverter / Leaf-powertrain community); the chain is ADAS0x2B0→ VCM →0x1D4→ inverter. Additional downstream readouts to poll over UDS (per thecanairZE1 PID profile, tentative): ABS ECU0x740service0x22 12 09= brake master-cylinder pressure, inverter0x7840x22 12 25= motor torque (Nm), accel-pedal % — use these to confirm an injected brake/accel actually produced pressure/torque.No public ZE1 actuation decode exists. Survey (2026-11-24): the Leaf RE community works at adjacent layers — powertrain/battery (dalathegreat, OpenInverter/jsphuebner,
0x1D4torque), 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 the0x2B0/0x1C3injection 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/nissanpatch in the repo'sopenpilot/directory, when longitudinal is enabled, emits the car's real ADAS frames —0x2B0(propulsion/regen) and0x1C3(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 theaccel → (T, pressure)mapping (the 37-car fleet curve, provisional; brake gain still StarPilot's) + the real0x2B0/0x1C3packers; 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.nissan-safety-longitudinal.patchallows0x2B0/0x1C3TX on bus 2 under a LONG flag and bounds them with the sharedlongitudinal_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).pcmCruisestays True (as Toyota / Honda Nidec openpilot longitudinal). You engage stock ProPILOT as usual; panda keyscontrols_allowedoff its cruise state and openpilot supplies the acceleration. WithpcmCruiseFalse, openpilot would cancel the very cruise panda needs, so it could never engage.0x5FFon its V-CAN port at 50 Hz ('L' 'G' 'W', version, status, counter, checksum; added to the Leaf DBC asLEAF_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.341fb3d9), sunnypilot (sunnypilot/opendbc11c61f3e; 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 (c2b9a942ef; notec2hard-codes the retrofit fingerprint, so the Leaf isn't selected until that line is reverted) and FlowPilot (the maintainedjagheterfredrik/flowpilot,master9ea918ea; its Nissan support was broken by anapply()signature mismatch and a missing "System Unresponsive" liveness line, both fixed in the patch; plus phr00t'smaster84f25d06, 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 ownDisableRadarparam and spells the panda bounds out by hand.openpilot/check-forks.shapplies each to a fresh worktree at its pin and runs the nissan suites (--latestchecks fork heads for drift; RetroPilot and FlowPilot ship afork.shwith 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.ALLOW_DEBUGwhere our code sits behind it): 5 new findings, all fixed; no new suppressions beyond one the tree already uses for identical code.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 SocketCANcandump, 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:backends/panda/gw_panda.c) — a bare-metal, interrupt-driven interceptor modeled on the RetroPilot ocelotsmart_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 the0x5FFheartbeat there). Build-proven: compiles, links and signs an STM32F413 image under the realarm-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/0x1C3on 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.0x5FFis 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'sHARDWARE.md.Bench guide
Interactive ADAS connector map and the gateway plan: https://escargot.free/bench/leaf-adas-gateway.html
Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an IC-CAN passthrough gatewayto Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an Chassis CAN passthrough gatewayRoadmap: openpilot longitudinal for Nissan Leaf (ZE1) via an Chassis CAN passthrough gatewayto Roadmap: openpilot longitudinal for Nissan Leaf (ZE1) via a Chassis CAN passthrough gateway