honda: port Bosch-A 16-slot radar decoder, enable for full HONDA_BOSCH_A harness

Ports the 16-slot Bosch-A object-bank radar decoder (16 slots x 4 main frames
+ 1 aux frame each) and enables it behind a HondaBoschARadar toggle (default
on) for the full HONDA_BOSCH_A harness category: N-Box, Accord, Civic (incl.
Diesel), CR-V, CR-V Hybrid, Acura RDX, Insight, and Honda e -- 10 platforms
total, derived as HONDA_BOSCH - HONDA_BOSCH_RADARLESS - HONDA_BOSCH_CANFD -
HONDA_BOSCH_ALT_RADAR.

RX-only: never transmits on the radar bus, so it takes no CAN authority.
Factory AEB/CMBS/FCW stay live as long as stock longitudinal remains in
control; enabling openpilot longitudinal (alpha) disables them regardless
of this toggle, via the existing UDS CommunicationControl call in
CarInterface.init() -- documented consistently now via a new HondaCarDocs
Footnote.EXP_LONG and matching comments on all 10 platform configs.

86 new tests for the decoder (gate-open/closed coverage for every affected
platform) plus the existing 19 in test_honda.py all pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
JamesL787
2026-08-25 18:09:20 -04:00
parent 28ec3ccb80
commit b13dd7d75e
7 changed files with 2827 additions and 21 deletions
+1
View File
@@ -62,6 +62,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"GsmRoaming", {PERSISTENT, BOOL}},
{"HardwareSerial", {PERSISTENT, STRING}},
{"HasAcceptedTerms", {PERSISTENT, STRING, "0"}},
{"HondaBoschARadar", {PERSISTENT, BOOL, "1"}},
{"HondaGasFactorParams", {PERSISTENT, FLOAT}},
{"HondaLateralPidKiScale", {PERSISTENT, FLOAT, "1.0", "1.0", 3}},
{"HondaLateralPidKpScale", {PERSISTENT, FLOAT, "1.0", "1.0", 3}},
+11 -2
View File
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
import numpy as np
from openpilot.common.params import Params, UnknownKeyName
from opendbc.car import get_safety_config, structs, uds
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.disable_ecu import disable_ecu
from opendbc.car.honda.hondacan import CanBus
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HONDA_BOSCH, HONDA_BOSCH_CANFD, \
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HONDA_BOSCH, HONDA_BOSCH_A, HONDA_BOSCH_CANFD, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS, HondaSafetyFlags
from opendbc.car.honda.carcontroller import CarController
from opendbc.car.honda.carstate import CarState
@@ -44,7 +45,15 @@ class CarInterface(CarInterfaceBase):
cfgs.insert(0, get_safety_config(structs.CarParams.SafetyModel.noOutput))
ret.safetyConfigs = cfgs
ret.radarUnavailable = True
# HONDA_BOSCH_A platforms (plain bosch_a harness: not CANFD, not radarless, not alt-radar) have
# a firmware-correct RadarInterface (16-slot Bosch-A object bank, RX-only) and use it by
# default via HondaBoschARadar: every other Bosch platform still has no parsed radar DBC and
# keeps radarUnavailable=True regardless.
try:
bosch_a_radar_tryout = not docs and Params().get_bool("HondaBoschARadar")
except UnknownKeyName:
bosch_a_radar_tryout = False
ret.radarUnavailable = not (candidate in HONDA_BOSCH_A and bosch_a_radar_tryout)
# Disable the radar and let openpilot control longitudinal
# WARNING: THIS DISABLES AEB!
# If Bosch radarless, this blocks ACC messages from the camera
@@ -1,8 +1,13 @@
#!/usr/bin/env python3
import math
from collections import deque
from dataclasses import dataclass, field
from opendbc.can import CANParser
from opendbc.car import Bus, structs
from opendbc.car.interfaces import RadarInterfaceBase
from opendbc.car.honda.hondacan import CanBus
from opendbc.car.honda.values import DBC
from opendbc.car.interfaces import RadarInterfaceBase
def _create_nidec_can_parser(car_fingerprint):
@@ -11,39 +16,615 @@ def _create_nidec_can_parser(car_fingerprint):
return CANParser(DBC[car_fingerprint][Bus.radar], messages, 1)
# ============================================================================
# Honda Bosch-A 16-slot object bank
# ============================================================================
# 16 CAN-visible object slots. Each slot has 4 main frames (f0..f3, one CAN ID each -- NOT sub-frames
# muxed onto a shared ID) plus one synchronized auxiliary 5th frame. This supersedes any prior model of
# 0x280/0x284/0x288/0x28C as pieces of one object, or of 0x2C8/0x2C9 as a separate "coarse" list: it is
# ONE 16-slot bank with one auxiliary frame per slot. See honda_bosch_a_radar.dbc for the bit geometry.
BOSCH_A_DBC_NAME = 'honda_bosch_a_radar'
BOSCH_A_NUM_SLOTS = 16
def _bosch_a_main_base(slot: int) -> int:
return 0x280 + 4 * slot if slot < 4 else 0x2D0 + 4 * (slot - 4)
def _bosch_a_aux_id(slot: int) -> int:
return 0x2C8 + slot if slot < 8 else 0x290 + (slot - 8)
BOSCH_A_MAIN_IDS = [[_bosch_a_main_base(s) + i for i in range(4)] for s in range(BOSCH_A_NUM_SLOTS)]
BOSCH_A_AUX_IDS = [_bosch_a_aux_id(s) for s in range(BOSCH_A_NUM_SLOTS)]
BOSCH_A_ALL_IDS = [addr for ids in BOSCH_A_MAIN_IDS for addr in ids] + BOSCH_A_AUX_IDS
# Publish RadarPoints when the last MAIN object frame arrives. Passive captures prove that slot 15's
# companion frame, 0x297, follows 0x2FF and is the final observed object-family frame in a full sweep:
#
# ... 0x2FC, 0x2FD, 0x2FE, 0x2FF, 0x297
#
# Keep 0x2FF as the RadarPoint trigger while the companion data remains optional/debug-only. Making
# 0x297 the sole trigger would allow one dropped auxiliary frame to suppress an otherwise-valid point
# update, contrary to the parser's "aux never gates validity" contract.
BOSCH_A_TRIGGER_MSG = BOSCH_A_MAIN_IDS[BOSCH_A_NUM_SLOTS - 1][3]
BOSCH_A_SWEEP_END_MSG = BOSCH_A_AUX_IDS[BOSCH_A_NUM_SLOTS - 1] # 0x297
# Observed coherent Bosch-A sweep cadence is ~14.5-16 Hz in the available captures.
BOSCH_A_FREQ_HZ = 15
# Range: f0 raw_range (12-bit, B2:B3 high nibble) -> meters. Firmware q16 = 8*raw_range; physical
# calibration keeps slope/offset as named, replay-refinable constants (do not add a second radar/camera
# longitudinal offset on top of this).
BOSCH_A_RANGE_SCALE_M = 0.05712
BOSCH_A_RANGE_OFFSET_M = -3.0
# Azimuth: f0 raw_angle (11-bit, B4:B5 high 3 bits), offset-binary about 1024.
#
# The f3 angular-edge pair independently closes the exact center-angle scale:
# azimuth_rad = (raw_angle - 1024) / 2048
#
# This supersedes the older empirical 0.032 deg/count fit.
BOSCH_A_AZIMUTH_SCALE_RAD = 1.0 / 2048.0
BOSCH_A_AZIMUTH_CENTER = 1024
# Invalid sentinels (section 3/4/5/6 of the spec).
BOSCH_A_STATUS_INVALID = 0xF
BOSCH_A_RANGE_RAW_INVALID = 0xFFF
BOSCH_A_ANGLE_RAW_INVALID = 0x7FF
BOSCH_A_LIFE_INVALID = 0xFFF
BOSCH_A_TRACK_ID_MIN = 1
BOSCH_A_TRACK_ID_MAX = 0x3F
# AUX logical 0x00CA has an explicit 0x3FF invalid sentinel. Firmware proves the normalization below;
# captures strongly support interpreting the active value as previous/current range ratio.
BOSCH_A_RANGE_RATIO_INVALID = 0x3FF
BOSCH_A_LOGICAL_00CA_INVALID = BOSCH_A_RANGE_RATIO_INVALID # compatibility/debug alias
BOSCH_A_RANGE_RATIO_SCALE = 0.001
BOSCH_A_RANGE_RATIO_OFFSET = 0.5
# The synchronized AUX frame contains an 11-bit offset-binary velocity-like field and a 10-bit
# companion quality/uncertainty field. The byte locations are now decoded in the DBC. The exact
# Bosch descriptor name is still being verified, so keep the conversion constants isolated here.
# Capture validation shows active values in [0, 1728], with 0x7FE used as the inactive sentinel.
BOSCH_A_DIRECT_VREL_INVALID = 0x7FE
BOSCH_A_DIRECT_VREL_MIN_RAW = 0
BOSCH_A_DIRECT_VREL_MAX_RAW = 1728
BOSCH_A_DIRECT_VREL_CENTER_RAW = 864
BOSCH_A_DIRECT_VREL_SCALE_MPS = 1.0 / 64.0
# Empirical raw-quality policy. U11 error against an independent range-derivative reference rises
# with u10 in a graded way, not a cliff: replay evidence bins it roughly as 0-255 clean, 256-511 only
# mildly degraded, 512-767 clearly degraded, 768+ worst. 511 is set at that mild/clear boundary so
# U11 is still trusted directly through the mildly-degraded band; only u10 above this triggers the
# high-u10 coast path below. This is deliberately not presented as a Bosch physical unit or
# descriptor constant; it keeps saturated/high-uncertainty AUX values from becoming authoritative
# velocity measurements.
BOSCH_A_DIRECT_VREL_MAX_UNCERTAINTY_RAW = 511
# Measurement-authority policy. These are replay-derived safety/tuning gates, not recovered Bosch
# constants. Range innovation is measured from the previous accepted observation so a reset cannot
# become the baseline for following sweeps.
BOSCH_A_RANGE_SIGMA_DEGRADED_RAW = 4
BOSCH_A_RANGE_INNOVATION_MAX_M = 2.0
BOSCH_A_RANGE_INNOVATION_HARD_MAX_M = 5.0
BOSCH_A_FALLBACK_RANGE_RATE_MAX_MPS = 50.0
BOSCH_A_USE_TAN_LATERAL_PROJECTION = True
# Accepted-range history is retained for continuity and the adjacent two-point fallback. Rejected
# range resets never enter it, and it is not used for a multi-sample OLS velocity fit.
BOSCH_A_VREL_MAX_SAMPLES = 8
# Staleness gate -- TUNING constant, reused plumbing pattern (not a firmware fact). At the observed
# ~15 Hz cadence, 0.20 s is approximately three missed sweeps.
BOSCH_A_STALE_S = 0.20
@dataclass
class _BoschASlotState:
last_seen_nanos: int | None = None
# Firmware logical-ID companion data -- telemetry/debug only for now, never a RadarPoint validity
# gate. 0x00C9 has a firmware transform but no proven physical meaning; 0x00CA has an explicit
# invalid sentinel and its physical meaning remains unresolved.
logical_00c9_raw: float = float('nan')
logical_00ca_raw: float = float('nan')
direct_vrel_raw: int | None = None
direct_vrel_uncertainty_raw: int | None = None
def reset(self):
self.last_seen_nanos = None
self.logical_00c9_raw = float('nan')
self.logical_00ca_raw = float('nan')
self.direct_vrel_raw = None
self.direct_vrel_uncertainty_raw = None
@dataclass
class _BoschATrackState:
"""Persistent state for one Bosch CAN object identity, independent of wire slot."""
track_id: int
prev_frame_idx: int | None = None
prev_life: int | None = None
last_seen_nanos: int | None = None
wire_slot: int | None = None
samples: deque = field(default_factory=lambda: deque(maxlen=BOSCH_A_VREL_MAX_SAMPLES))
last_trusted_vrel: float | None = None
last_trusted_vrel_nanos: int | None = None
def _bosch_a_direct_vrel(raw_value: int | float | None,
uncertainty_raw: int | float | None = None) -> float | None:
"""Decode the capture-validated AUX relative-velocity candidate.
None means that AUX was absent/invalid and the caller should use the existing fallback policy. The [0, 1728]
active domain is deliberately enforced here because values above the observed +13.5 m/s rail have
not appeared on active objects; 0x7FE is the observed inactive sentinel.
"""
if raw_value is None:
return None
raw = int(raw_value)
if raw == BOSCH_A_DIRECT_VREL_INVALID:
return None
if not BOSCH_A_DIRECT_VREL_MIN_RAW <= raw <= BOSCH_A_DIRECT_VREL_MAX_RAW:
return None
# u10 is retained as a raw quality indicator because its physical units remain unresolved. The
# conservative threshold is evidence-backed tuning, not a recovered firmware validity rule.
if uncertainty_raw is not None and int(uncertainty_raw) > BOSCH_A_DIRECT_VREL_MAX_UNCERTAINTY_RAW:
return None
return (raw - BOSCH_A_DIRECT_VREL_CENTER_RAW) * BOSCH_A_DIRECT_VREL_SCALE_MPS
def _bosch_a_range_ratio(raw_value: int | float | None) -> float | None:
if raw_value is None:
return None
raw = int(raw_value)
if raw == BOSCH_A_RANGE_RATIO_INVALID or not 0 <= raw < BOSCH_A_RANGE_RATIO_INVALID:
return None
return BOSCH_A_RANGE_RATIO_OFFSET + BOSCH_A_RANGE_RATIO_SCALE * raw
def _bosch_a_range_ratio_vrel(raw_value: int | float | None, d_rel: float, dt: float) -> float | None:
"""Return the range rate implied by the empirical previous/current range ratio."""
ratio = _bosch_a_range_ratio(raw_value)
if ratio is None or dt <= 0.0 or not math.isfinite(d_rel):
return None
return d_rel * (1.0 - ratio) / dt
def _bosch_a_measurement_degraded(range_sigma_raw: int, existence_raw: int,
direct_vrel_uncertainty_raw: int | None) -> bool:
range_quality_bad = range_sigma_raw >= BOSCH_A_RANGE_SIGMA_DEGRADED_RAW or existence_raw in (0, 0x7F)
velocity_quality_bad = (direct_vrel_uncertainty_raw is not None and
direct_vrel_uncertainty_raw > BOSCH_A_DIRECT_VREL_MAX_UNCERTAINTY_RAW)
return range_quality_bad or velocity_quality_bad
def _create_bosch_a_can_parser(CP):
messages = [(addr, BOSCH_A_FREQ_HZ) for addr in BOSCH_A_ALL_IDS]
# Bus.radar selects the Bosch-A DBC; the object/fusion feed itself is
# physically on the camera-side ACC-CAN.
return CANParser(DBC[CP.carFingerprint][Bus.radar], messages, CanBus(CP).camera)
class RadarInterface(RadarInterfaceBase):
def __init__(self, CP):
super().__init__(CP)
self.track_id = 0
self.radar_fault = False
self.radar_wrong_config = False
self.radar_off_can = CP.radarUnavailable
self.bosch_a_radar = (not self.radar_off_can and Bus.radar in DBC[CP.carFingerprint] and
DBC[CP.carFingerprint][Bus.radar] == BOSCH_A_DBC_NAME)
# Nidec
if self.radar_off_can:
self.rcp = None
self.trigger_msg = 0x445
elif self.bosch_a_radar:
self.rcp = _create_bosch_a_can_parser(CP)
self.trigger_msg = BOSCH_A_TRIGGER_MSG
self._slots = [_BoschASlotState() for _ in range(BOSCH_A_NUM_SLOTS)]
self._tracks: dict[int, _BoschATrackState] = {}
self._slot_track_ids: list[int | None] = [None] * BOSCH_A_NUM_SLOTS
self._last_trigger_nanos = -1
else:
# Nidec
self.rcp = _create_nidec_can_parser(CP.carFingerprint)
self.trigger_msg = 0x445
self.trigger_msg = 0x445
self.track_id = 0
self.radar_fault = False
self.radar_wrong_config = False
self.updated_messages = set()
def update(self, can_strings):
# in Bosch radar and we are only steering for now, so sleep 0.05s to keep
# radard at 20Hz and return no points
if self.radar_off_can:
if self.radar_off_can or self.rcp is None:
return super().update(None)
vls = self.rcp.update(can_strings)
self.updated_messages.update(vls)
if self.trigger_msg not in self.updated_messages:
if self.bosch_a_radar and self._last_trigger_nanos >= 0:
now = self.rcp._last_update_nanos
if (now - self._last_trigger_nanos) * 1e-9 > BOSCH_A_STALE_S:
return self._bosch_a_stale_radardata()
return None
rr = self._update(self.updated_messages)
self.updated_messages.clear()
return rr
def _bosch_a_stale_radardata(self):
# Whole-bus silence: clear every live point/history and emit an EMPTY RadarData (not None) so
# radard drops any lead within a cycle instead of freezing a phantom. The next observation starts
# a fresh incarnation for its CAN identity.
self.pts.clear()
self._tracks.clear()
self._slot_track_ids = [None] * BOSCH_A_NUM_SLOTS
for slot_state in self._slots:
slot_state.reset()
self._last_trigger_nanos = -1
stale = structs.RadarData()
if not self.rcp.can_valid:
stale.errors.canError = True
stale.errors.radarUnavailableTemporary = True
return stale
def _bosch_a_retire_track(self, track_id: int):
self._tracks.pop(track_id, None)
self.pts.pop(track_id, None)
for slot, slot_track_id in enumerate(self._slot_track_ids):
if slot_track_id == track_id:
self._slot_track_ids[slot] = None
def _bosch_a_retire_stale_tracks(self, now: int):
for track_id, track in list(self._tracks.items()):
if track.last_seen_nanos is not None and (now - track.last_seen_nanos) * 1e-9 > BOSCH_A_STALE_S:
self._bosch_a_retire_track(track_id)
def _update(self, updated_messages):
if self.bosch_a_radar:
return self._update_bosch_a(updated_messages)
return self._update_nidec(updated_messages)
def _update_bosch_a(self, updated_messages):
ret = structs.RadarData()
if not self.rcp.can_valid:
ret.errors.canError = True
now = self.rcp._last_update_nanos
self._last_trigger_nanos = now
self._bosch_a_retire_stale_tracks(now)
observations = []
for slot in range(BOSCH_A_NUM_SLOTS):
f0, f1, f2, f3 = BOSCH_A_MAIN_IDS[slot]
aux = BOSCH_A_AUX_IDS[slot]
st = self._slots[slot]
if not (f0 in updated_messages and f1 in updated_messages and
f2 in updated_messages and f3 in updated_messages):
# Incomplete main-frame set: a missing CAN frame must not be treated as a lifecycle mismatch or
# death/replacement. Logical tracks are retired independently by their global staleness gate.
continue
v0 = self.rcp.vl[f0]
v1 = self.rcp.vl[f1]
v2 = self.rcp.vl[f2]
v3 = self.rcp.vl[f3]
idx0 = int(v0['FRAME_IDX'])
if not (idx0 == int(v1['FRAME_IDX']) == int(v2['FRAME_IDX']) == int(v3['FRAME_IDX'])):
# The four main frames don't share a common cycle index -- not a coherent observation this
# window. Only combine main-frame data from a coherent common frame index (section 2).
continue
status = int(v0['STATUS'])
range_raw = int(v0['RANGE_RAW'])
angle_raw = int(v0['AZIMUTH_RAW'])
range_sigma_raw = int(v0['RANGE_SIGMA_RAW'])
existence_raw = int(v1['OBJECT_EXISTENCE_PROBABILITY_RAW'])
life = int(v2['LIFECYCLE_RAW'])
track_id = int(v3['TRACK_ID'])
track_id_valid = BOSCH_A_TRACK_ID_MIN <= track_id <= BOSCH_A_TRACK_ID_MAX
st.last_seen_nanos = now
direct_vrel_raw = None
direct_vrel_uncertainty_raw = None
range_ratio_raw = None
# Attach synchronized companion data only when its cycle matches. Missing AUX never invalidates
# an otherwise coherent F0-F3 object; it only removes independent motion/quality evidence.
if aux in updated_messages:
av = self.rcp.vl[aux]
if int(av['FRAME_IDX']) == idx0:
direct_vrel_raw = int(av['REL_VELOCITY_RAW'])
direct_vrel_uncertainty_raw = int(av['REL_VELOCITY_UNCERTAINTY_RAW'])
range_ratio_raw = int(av['RANGE_RATIO_RAW'])
logical_00c9_raw = av['FW_LID_00C9_RAW']
logical_00ca_raw = av['FW_LID_00CA_RAW']
st.logical_00c9_raw = logical_00c9_raw
st.logical_00ca_raw = (
logical_00ca_raw if logical_00ca_raw != BOSCH_A_LOGICAL_00CA_INVALID else float('nan')
)
st.direct_vrel_raw = direct_vrel_raw
st.direct_vrel_uncertainty_raw = direct_vrel_uncertainty_raw
object_valid = (status != BOSCH_A_STATUS_INVALID and range_raw != BOSCH_A_RANGE_RAW_INVALID and
angle_raw != BOSCH_A_ANGLE_RAW_INVALID and life != BOSCH_A_LIFE_INVALID)
observations.append({
'slot': slot,
'frame_idx': idx0,
'life': life,
'track_id': track_id,
'track_id_valid': track_id_valid,
'object_valid': object_valid,
'range_sigma_raw': range_sigma_raw,
'existence_raw': existence_raw,
'direct_vrel_raw': direct_vrel_raw,
'direct_vrel_uncertainty_raw': direct_vrel_uncertainty_raw,
'range_ratio_raw': range_ratio_raw,
})
# First collapse duplicate wire observations of one CAN identity. The dictionary is also the
# output uniqueness boundary: one valid Bosch identity can never create two RadarPoints.
valid_by_id = {}
for observation in observations:
if not (observation['object_valid'] and observation['track_id_valid']):
# An invalid observation ends publication for the object currently occupying this wire slot,
# but it does not immediately destroy the persistent state. The object may be multiplexed to
# another slot or may return before the per-identity stale deadline; a later lifecycle break
# or staleness expiry will clear its derivative history.
ids_to_hide = {self._slot_track_ids[observation['slot']]}
if observation['track_id_valid']:
ids_to_hide.add(observation['track_id'])
for invalid_id in ids_to_hide - {None}:
self.pts.pop(invalid_id, None)
continue
track_id = observation['track_id']
current = valid_by_id.get(track_id)
if current is None:
valid_by_id[track_id] = observation
continue
# Prefer the wire slot currently associated with the persistent state. If neither candidate is
# preferred, retain the lower slot for deterministic handling of a malformed duplicate frame.
track = self._tracks.get(track_id)
current_score = (0 if track is not None and track.wire_slot == current['slot'] else 1, current['slot'])
candidate_score = (0 if track is not None and track.wire_slot == observation['slot'] else 1,
observation['slot'])
if candidate_score < current_score:
valid_by_id[track_id] = observation
valid_ids = set(valid_by_id)
for track_id, observation in sorted(valid_by_id.items(), key=lambda item: item[1]['slot']):
slot = observation['slot']
idx0 = observation['frame_idx']
life = observation['life']
# A wire-slot replacement ends publication for the old occupant, but not its persistent
# identity/history. If the old ID is still valid in another slot this sweep, keep its point;
# otherwise hide it until that ID returns or reaches its own stale deadline.
old_id = self._slot_track_ids[slot]
if old_id is not None and old_id != track_id and old_id not in valid_ids:
self.pts.pop(old_id, None)
track = self._tracks.get(track_id)
if track is None:
track = _BoschATrackState(track_id=track_id)
self._tracks[track_id] = track
same_incarnation = False
if track.prev_frame_idx is not None and track.prev_life is not None:
frame_delta = (idx0 - track.prev_frame_idx) & 0xF
life_delta = (life - track.prev_life) & 0xFFF
same_incarnation = life_delta == 2 * frame_delta
if not same_incarnation:
# The CAN identity remains the externally-visible key, but a lifecycle discontinuity starts a
# new incarnation and must not inherit the previous object's range-rate history.
track.samples.clear()
track.last_trusted_vrel = None
track.last_trusted_vrel_nanos = None
self.pts.pop(track_id, None)
v0 = self.rcp.vl[BOSCH_A_MAIN_IDS[slot][0]]
range_raw = int(v0['RANGE_RAW'])
angle_raw = int(v0['AZIMUTH_RAW'])
dRel = BOSCH_A_RANGE_SCALE_M * range_raw + BOSCH_A_RANGE_OFFSET_M
azimuth_rad = BOSCH_A_AZIMUTH_SCALE_RAD * (angle_raw - BOSCH_A_AZIMUTH_CENTER)
# The firmware's internal geometry path uses tan(angle) for a forward-axis distance. The
# Bosch object range is consumed as that forward-axis quantity here, so use the same projection
# rather than treating it as radial/slant range. Keep the switch explicit while the final
# output bridge remains under static review.
#
# Sign: AZIMUTH_RAW > center (positive azimuth_rad) is a LEFT-of-center detection in car frame's
# y axis (left is positive), matching the Nidec RadarPoint.yRel contract. Confirmed against real
# captures 2026-08-22: a stationary cluster of queued vehicles visible on the left in the road
# camera was rendering on the right in both the Qt and raylib radar-track overlays with the
# previously-flipped sign.
lateral_projection = math.tan if BOSCH_A_USE_TAN_LATERAL_PROJECTION else math.sin
yRel = dRel * lateral_projection(azimuth_rad)
now_s = now * 1e-9
direct_vrel_raw = observation['direct_vrel_raw']
direct_vrel_uncertainty_raw = observation['direct_vrel_uncertainty_raw']
direct_vrel = _bosch_a_direct_vrel(direct_vrel_raw, direct_vrel_uncertainty_raw)
live_direct_vrel = _bosch_a_direct_vrel(direct_vrel_raw)
range_ratio_raw = observation['range_ratio_raw']
# A live U11 rejected solely by the conservative U10 qualification threshold is neither an
# unavailable velocity nor permission to synthesize a one-sweep range derivative. It is also
# NOT permission to skip range-innovation checking below: u10 correlates with range_sigma in
# replay data, so a high-u10 sweep is exactly the condition where a bad/discontinuous range
# (slot migration, reset) is most likely, not less likely. Range acceptance is therefore
# decided on the same terms as every other sweep first; only once the range clears that gate
# does a high-u10 U11 fall back to coasting instead of publishing a synthesized derivative.
high_u10_live_vrel = (direct_vrel is None and live_direct_vrel is not None and
direct_vrel_uncertainty_raw is not None and
direct_vrel_uncertainty_raw > BOSCH_A_DIRECT_VREL_MAX_UNCERTAINTY_RAW)
# Validate against the previous accepted range. Qualified U11 and the range-ratio field are
# independent corroboration paths; high-U10 U11 is deliberately excluded from this decision.
previous_sample = track.samples[-1] if track.samples else None
fallback_vrel = 0.0
ratio_vrel = None
range_rejected = False
degraded = _bosch_a_measurement_degraded(
observation['range_sigma_raw'], observation['existence_raw'], direct_vrel_uncertainty_raw,
)
if previous_sample is not None:
previous_time, previous_range = previous_sample
dt = now_s - previous_time
if dt <= 0.0:
range_rejected = True
else:
fallback_vrel = (dRel - previous_range) / dt
ratio = _bosch_a_range_ratio(range_ratio_raw)
ratio_vrel = _bosch_a_range_ratio_vrel(range_ratio_raw, dRel, dt)
residuals_m = []
if direct_vrel is not None:
residuals_m.append(abs(dRel - (previous_range + direct_vrel * dt)))
if ratio is not None:
residuals_m.append(abs(previous_range - dRel * ratio))
if residuals_m:
innovation_m = min(residuals_m)
range_rejected = (
innovation_m > BOSCH_A_RANGE_INNOVATION_HARD_MAX_M or
(degraded and innovation_m > BOSCH_A_RANGE_INNOVATION_MAX_M)
)
else:
range_rejected = abs(fallback_vrel) > BOSCH_A_FALLBACK_RANGE_RATE_MAX_MPS
if range_rejected:
# Keep the last accepted point briefly as an unmeasured coast. The rejected geometry is not
# published and never becomes the baseline for a later derivative.
accepted_fresh = previous_sample is not None and now_s - previous_sample[0] <= BOSCH_A_STALE_S
point = self.pts.get(track_id)
if accepted_fresh and point is not None:
point.measured = False
else:
self.pts.pop(track_id, None)
track.prev_frame_idx = idx0
track.prev_life = life
track.last_seen_nanos = now
track.wire_slot = slot
for old_slot, old_id in enumerate(self._slot_track_ids):
if old_slot != slot and old_id == track_id:
self._slot_track_ids[old_slot] = None
self._slot_track_ids[slot] = track_id
continue
if high_u10_live_vrel:
# The range cleared innovation checking above, so geometry here is trustworthy; only vRel is
# in question. Preserve current geometry but coast only a recent authoritative motion
# estimate without a KF update, rather than publishing a one-sweep-derivative synthesis.
trusted_fresh = (track.last_trusted_vrel is not None and track.last_trusted_vrel_nanos is not None and
(now - track.last_trusted_vrel_nanos) * 1e-9 <= BOSCH_A_STALE_S)
if trusted_fresh:
point = self.pts.get(track_id)
if point is not None:
point.dRel = dRel
point.yRel = yRel
point.vRel = track.last_trusted_vrel
point.measured = False
else:
track.last_trusted_vrel = None
track.last_trusted_vrel_nanos = None
self.pts.pop(track_id, None)
# Do not let a coast-only range observation become a future derivative baseline.
track.prev_frame_idx = idx0
track.prev_life = life
track.last_seen_nanos = now
track.wire_slot = slot
for old_slot, old_id in enumerate(self._slot_track_ids):
if old_slot != slot and old_id == track_id:
self._slot_track_ids[old_slot] = None
self._slot_track_ids[slot] = track_id
continue
# Native U11 is unavailable here (sentinel/out-of-range -- the high-u10-but-live case above
# already returned before this point) and the range-ratio field is unusable or degraded too.
# The remaining option is the raw one-sweep (dRel-previous_range)/dt derivative, which is
# structurally the same hazard the high-u10 case guards against: a synthesized rate becoming an
# authoritative measurement. Coast a recent trusted velocity instead, on the same terms as above,
# rather than publish it.
# A true birth observation (no previous accepted range yet) can never mature into a published
# point this cycle regardless of vRel source -- `matured` below requires a second sample -- so
# only intercept once a fallback derivative would actually have something to poison.
u11_and_ratio_unavailable = (direct_vrel is None and (ratio_vrel is None or degraded) and
previous_sample is not None)
if u11_and_ratio_unavailable:
trusted_fresh = (track.last_trusted_vrel is not None and track.last_trusted_vrel_nanos is not None and
(now - track.last_trusted_vrel_nanos) * 1e-9 <= BOSCH_A_STALE_S)
if trusted_fresh:
point = self.pts.get(track_id)
if point is not None:
point.dRel = dRel
point.yRel = yRel
point.vRel = track.last_trusted_vrel
point.measured = False
else:
track.last_trusted_vrel = None
track.last_trusted_vrel_nanos = None
self.pts.pop(track_id, None)
# Do not let a coast-only range observation become a future derivative baseline.
track.prev_frame_idx = idx0
track.prev_life = life
track.last_seen_nanos = now
track.wire_slot = slot
for old_slot, old_id in enumerate(self._slot_track_ids):
if old_slot != slot and old_id == track_id:
self._slot_track_ids[old_slot] = None
self._slot_track_ids[slot] = track_id
continue
track.samples.append((now_s, dRel))
sample_count = len(track.samples)
# Prefer qualified native U11; otherwise the range-ratio field. The raw one-sweep derivative is
# never published as a measurement -- see the coast/drop branch above, which intercepts before
# this point whenever neither native U11 nor the ratio field is usable.
if direct_vrel is not None:
vRel = direct_vrel
else:
vRel = ratio_vrel
trustworthy_vrel = True
# A birth observation has no range-rate yet. Keep it as history, but do not publish a RadarPoint
# until a second coherent observation of the same CAN identity supplies a finite derivative.
matured = sample_count >= 2 and math.isfinite(vRel)
if trustworthy_vrel:
track.last_trusted_vrel = vRel
track.last_trusted_vrel_nanos = now
if matured and track_id not in self.pts:
self.pts[track_id] = structs.RadarData.RadarPoint()
self.pts[track_id].trackId = track_id
self.pts[track_id].aRel = float('nan')
self.pts[track_id].yvRel = float('nan')
if matured:
self.pts[track_id].dRel = dRel
self.pts[track_id].yRel = yRel
self.pts[track_id].vRel = vRel
self.pts[track_id].measured = True
else:
self.pts.pop(track_id, None)
track.prev_frame_idx = idx0
track.prev_life = life
track.last_seen_nanos = now
track.wire_slot = slot
for old_slot, old_id in enumerate(self._slot_track_ids):
if old_slot != slot and old_id == track_id:
self._slot_track_ids[old_slot] = None
self._slot_track_ids[slot] = track_id
ret.points = [self.pts[track_id] for track_id in sorted(self.pts)]
return ret
def _update_nidec(self, updated_messages):
ret = structs.RadarData()
for ii in sorted(updated_messages):
File diff suppressed because it is too large Load Diff
+70 -10
View File
@@ -117,11 +117,17 @@ class HondaCarDocs(CarDocs):
self.car_parts = CarParts.common([harness])
if CP.alphaLongitudinalAvailable:
self.footnotes.append(Footnote.EXP_LONG)
class Footnote(Enum):
CIVIC_DIESEL = CarFootnote(
"2019 Honda Civic 1.6L Diesel Sedan does not have ALC below 12mph.",
Column.FSR_STEERING)
EXP_LONG = CarFootnote(
"Enabling longitudinal control (alpha) will disable all CMBS functionality, including AEB and FCW.",
Column.LONGITUDINAL)
@dataclass
@@ -162,7 +168,12 @@ class CAR(Platforms):
HondaCarDocs("Honda N-Box 2018", "All", min_steer_speed=5.),
],
CarSpecs(mass=890., wheelbase=2.520, steerRatio=18.64),
{Bus.pt: 'acura_rdx_2020_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'acura_rdx_2020_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_ACCORD = HondaBoschPlatformConfig(
[
@@ -172,7 +183,12 @@ class CAR(Platforms):
],
# steerRatio: 11.82 is spec end-to-end
CarSpecs(mass=3279 * CV.LB_TO_KG, wheelbase=2.83, steerRatio=16.33, centerToFrontRatio=0.39, tireStiffnessFactor=0.8467),
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.radar: 'honda_bosch_a_radar'},
flags=HondaFlags.ALLOW_MANUAL_TRANS,
)
HONDA_ACCORD_11G = HondaBoschCANFDPlatformConfig(
@@ -190,12 +206,22 @@ class CAR(Platforms):
HondaCarDocs("Honda Civic Hatchback 2019-21", "All", min_steer_speed=12. * CV.MPH_TO_MS),
],
CarSpecs(mass=1326, wheelbase=2.7, steerRatio=15.38, centerToFrontRatio=0.4), # steerRatio: 10.93 is end-to-end spec
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_CIVIC_BOSCH_DIESEL = HondaBoschPlatformConfig(
[], # don't show in docs
HONDA_CIVIC_BOSCH.specs,
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_CIVIC_2022 = HondaBoschPlatformConfig(
[
@@ -214,7 +240,12 @@ class CAR(Platforms):
[HondaCarDocs("Honda CR-V 2017-22", min_steer_speed=15. * CV.MPH_TO_MS)],
# steerRatio: 12.3 is spec end-to-end
CarSpecs(mass=3410 * CV.LB_TO_KG, wheelbase=2.66, steerRatio=16.0, centerToFrontRatio=0.41, tireStiffnessFactor=0.677),
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.body: 'honda_crv_ex_2017_body_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.body: 'honda_crv_ex_2017_body_generated', Bus.radar: 'honda_bosch_a_radar'},
flags=HondaFlags.BOSCH_ALT_BRAKE,
)
HONDA_CRV_6G = HondaBoschCANFDPlatformConfig(
@@ -228,7 +259,12 @@ class CAR(Platforms):
[HondaCarDocs("Honda CR-V Hybrid 2017-22", min_steer_speed=12. * CV.MPH_TO_MS)],
# mass: mean of 4 models in kg, steerRatio: 12.3 is spec end-to-end
CarSpecs(mass=1667, wheelbase=2.66, steerRatio=16, centerToFrontRatio=0.41, tireStiffnessFactor=0.677),
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_civic_hatchback_ex_2017_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_HRV_3G = HondaBoschPlatformConfig(
[HondaCarDocs("Honda HR-V 2023-25", "All")],
@@ -245,7 +281,12 @@ class CAR(Platforms):
ACURA_RDX_3G = HondaBoschPlatformConfig(
[HondaCarDocs("Acura RDX 2019-21", "All", min_steer_speed=3. * CV.MPH_TO_MS)],
CarSpecs(mass=4068 * CV.LB_TO_KG, wheelbase=2.75, steerRatio=11.95, centerToFrontRatio=0.41, tireStiffnessFactor=0.677), # as spec
{Bus.pt: 'acura_rdx_2020_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'acura_rdx_2020_can_generated', Bus.radar: 'honda_bosch_a_radar'},
flags=HondaFlags.BOSCH_ALT_BRAKE,
)
ACURA_RDX_3G_MMR = HondaBoschPlatformConfig(
@@ -257,17 +298,32 @@ class CAR(Platforms):
HONDA_INSIGHT = HondaBoschPlatformConfig(
[HondaCarDocs("Honda Insight 2019-22", "All", min_steer_speed=3. * CV.MPH_TO_MS)],
CarSpecs(mass=2987 * CV.LB_TO_KG, wheelbase=2.7, steerRatio=15.0, centerToFrontRatio=0.39, tireStiffnessFactor=0.82), # as spec
{Bus.pt: 'honda_insight_ex_2019_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_insight_ex_2019_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_E = HondaBoschPlatformConfig(
[HondaCarDocs("Honda e 2020", "All", min_steer_speed=3. * CV.MPH_TO_MS)],
CarSpecs(mass=3338.8 * CV.LB_TO_KG, wheelbase=2.5, centerToFrontRatio=0.5, steerRatio=16.71, tireStiffnessFactor=0.82),
{Bus.pt: 'acura_rdx_2020_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'acura_rdx_2020_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_E_ADVANCE = HondaBoschPlatformConfig(
[], # don't show in docs, base trim already in docs
CarSpecs(mass=1527, wheelbase=2.5, centerToFrontRatio=0.5, steerRatio=16.71, tireStiffnessFactor=0.82),
{Bus.pt: 'honda_e_advance_2020_can_generated'},
# Bus.radar = the hand-written 16-slot Bosch-A object bank DBC (see radar_interface.py for the decode).
# RX-parse only; the decode itself takes no CAN authority, so factory AEB/CMBS/FCW stay live as long as
# stock longitudinal remains in control. Enabling openpilot longitudinal (alpha) disables all CMBS
# functionality, including AEB and FCW -- see Footnote.EXP_LONG and CarInterface.init()'s UDS
# CommunicationControl call, which suppresses the stock radar's longitudinal TX for the same reason.
{Bus.pt: 'honda_e_advance_2020_can_generated', Bus.radar: 'honda_bosch_a_radar'},
)
HONDA_PILOT_4G = HondaBoschCANFDPlatformConfig(
[HondaCarDocs("Honda Pilot 2023-25", "All")],
@@ -468,6 +524,10 @@ HONDA_BOSCH = CAR.with_flags(HondaFlags.BOSCH)
HONDA_BOSCH_RADARLESS = CAR.with_flags(HondaFlags.BOSCH_RADARLESS)
HONDA_BOSCH_CANFD = CAR.with_flags(HondaFlags.BOSCH_CANFD)
HONDA_BOSCH_ALT_RADAR = CAR.with_flags(HondaFlags.BOSCH_ALT_RADAR)
# Plain bosch_a harness: not CANFD, not radarless, not alt-radar. These platforms have a firmware-correct
# RadarInterface (16-slot Bosch-A object bank, RX-only, see radar_interface.py) available behind
# HondaBoschARadar; every other Bosch platform still has no parsed radar DBC and stays radarUnavailable.
HONDA_BOSCH_A = HONDA_BOSCH - HONDA_BOSCH_RADARLESS - HONDA_BOSCH_CANFD - HONDA_BOSCH_ALT_RADAR
HONDA_BOSCH_TJA_CONTROL = CAR.with_flags(HondaFlags.BOSCH_TJA_CONTROL)
HONDA_CAMERA_MESSAGE_CARS = {
CAR.HONDA_ACCORD,
File diff suppressed because it is too large Load Diff
@@ -428,6 +428,15 @@
"parent_key": "AdvancedLongitudinalTune",
"settings_tier": "advanced"
},
{
"key": "HondaBoschARadar",
"label": "Honda Bosch-A Radar",
"description": "Honda Bosch-A harness only (N-Box, Accord, Civic, CR-V, CR-V Hybrid, Acura RDX, Insight, Honda e). Parses the car's own 16-slot Bosch-A radar CAN traffic into real leadOne/leadTwo tracks instead of treating the car as radarless. RX-only -- never transmits on the radar bus. Factory AEB/CMBS/FCW remain available as long as stock longitudinal stays in control; enabling openpilot longitudinal (alpha) disables them regardless of this toggle. Restart required to take effect.",
"data_type": "bool",
"ui_type": "toggle",
"parent_key": "AdvancedLongitudinalTune",
"settings_tier": "advanced"
},
{
"key": "CustomAccelProfile",
"label": "Custom Accel Profile",