mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 00:03:57 +08:00
Honda Accord: angle steering for the modified EPS firmware
This commit is contained in:
@@ -16,7 +16,8 @@ from opendbc.car.ford.discovery import (normal_bus0_selection as ford_normal_bus
|
||||
normal_bus0_queries as ford_normal_bus0_queries, normal_bus_query_brand)
|
||||
from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_topology, v60_bus_topology as volvo_v60_bus_topology
|
||||
from opendbc.car.hyundai.discovery import normal_bus_topology
|
||||
from opendbc.car.honda.discovery import nidec_bus0_topology, normal_bus_topology as honda_normal_bus_topology
|
||||
from opendbc.car.honda.discovery import (eps_needs_obd as honda_eps_needs_obd, nidec_bus0_topology,
|
||||
normal_bus_topology as honda_normal_bus_topology)
|
||||
from opendbc.car.honda.values import CAR as HONDA, HondaFlags
|
||||
from opendbc.car.mazda.discovery import normal_bus0_topology as mazda_normal_bus0_topology
|
||||
from opendbc.car.chrysler.discovery import normal_bus_topology as chrysler_normal_bus_topology
|
||||
@@ -215,6 +216,12 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu
|
||||
else:
|
||||
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing,
|
||||
query_brand=normal_brand, normal_bus_only=True)
|
||||
if normal_brand == 'honda' and honda_eps_needs_obd(match_fw_to_car(car_fw, vin)[1], car_fw):
|
||||
# Read this car's VIN and EPS through the OBD port, as the generic path below does. Without the VIN
|
||||
# the result is never cached, so every start would repeat the query.
|
||||
set_obd_multiplexing(True)
|
||||
vin_rx_addr, vin_rx_bus, vin = get_vin(can_recv, can_send, (0, 1))
|
||||
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing, query_brand='honda')
|
||||
ecu_rx_addrs = {(fw.responseAddress, fw.subAddress or None, fw.bus) for fw in car_fw if fw.responseAddress > 0}
|
||||
else:
|
||||
full_scan = True
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
from opendbc.car import ACCEL_MAX_TAKEOFF
|
||||
|
||||
@@ -10,9 +12,12 @@ from opendbc.car.honda.nidec_interceptor import NidecInterceptor, create_command
|
||||
from opendbc.car.honda.bosch_longitudinal import BoschLongitudinal, qualified as bosch_long_qualified
|
||||
from opendbc.car.honda.values import CAR, CruiseButtons, HondaFlags, CarControllerParams
|
||||
from opendbc.car.interfaces import CarControllerBase
|
||||
from opendbc.car.lateral import apply_steer_angle_limits_vm, get_max_angle_delta_vm
|
||||
from opendbc.car.vehicle_model import VehicleModel
|
||||
|
||||
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
||||
LongCtrlState = structs.CarControl.Actuators.LongControlState
|
||||
SteerControlType = structs.CarParams.SteerControlType
|
||||
|
||||
|
||||
def compute_gb_honda_bosch(accel, speed):
|
||||
@@ -120,6 +125,54 @@ class CarController(CarControllerBase):
|
||||
self.brake = 0.0
|
||||
self.last_torque = 0.0
|
||||
|
||||
# Accord angle-loop EPS (interface.py sets steerControlType = angle)
|
||||
self.angle_mode = CP.steerControlType == SteerControlType.angle
|
||||
self.VM = VehicleModel(CP) if self.angle_mode else None
|
||||
self.apply_angle_last = None # None until the first frame seeds the limiter from the wheel
|
||||
self.angle_steer_req = False # STEER_TORQUE_REQUEST of the last angle frame
|
||||
|
||||
def _angle_hold_allowed(self, CC, CS) -> bool:
|
||||
# The panda blocks a nonzero 0xE4 field unless lateral_controls_allowed(). Without an AOL policy that is
|
||||
# controls_allowed (needs ACC main on and engagement); with one it is a session-acknowledged axis permission the
|
||||
# carcontroller cannot see, so the hold is sent only in the subset every policy allows: enabled with main on.
|
||||
return bool(CS.out.cruiseState.available) and bool(CC.enabled)
|
||||
|
||||
def _update_angle(self, CC, CS) -> tuple[float, int]:
|
||||
"""Angle setpoint (deg) and the 0xE4 STEER_TORQUE field."""
|
||||
p = self.params
|
||||
steering_angle = float(CS.out.steeringAngleDeg)
|
||||
angle_last = steering_angle if self.apply_angle_last is None else self.apply_angle_last
|
||||
desired = float(CC.actuators.steeringAngleDeg)
|
||||
if CC.latActive:
|
||||
# error clip first: it shapes the request, bounding the P torque the setpoint asks of the EPS
|
||||
error_max = float(np.interp(CS.out.vEgoRaw, p.ANGLE_ERROR_MAX_BP, p.ANGLE_ERROR_MAX_V))
|
||||
desired = float(np.clip(desired, steering_angle - error_max, steering_angle + error_max))
|
||||
# The lateral accel and jerk limits (3.589) are the last adjustment: applied to exactly what is sent and seeded
|
||||
# from the last value sent. The panda runs the same check on the frame (honda.h) and blocks one that exceeds it,
|
||||
# so nothing may change the setpoint after this line.
|
||||
apply_angle = apply_steer_angle_limits_vm(desired, angle_last, CS.out.vEgoRaw, steering_angle, CC.latActive, p, self.VM)
|
||||
self.angle_steer_req = bool(CC.latActive)
|
||||
if CC.latActive:
|
||||
v = max(float(CS.out.vEgoRaw), 1.0)
|
||||
max_delta = min(get_max_angle_delta_vm(v, self.VM, p), p.ANGLE_LIMITS.MAX_ANGLE_RATE)
|
||||
if abs(apply_angle - angle_last) > max_delta + 1e-6:
|
||||
# The accel limit is further from the last value sent than the jerk limit lets one frame move: the wheel is
|
||||
# past the limit as the request starts. No setpoint satisfies both, and the panda would drop the frame, so
|
||||
# the request waits at the wheel until the wheel is back inside.
|
||||
apply_angle = steering_angle
|
||||
self.angle_steer_req = False
|
||||
self.apply_angle_last = apply_angle
|
||||
|
||||
# raw = round(-10 * deg), half-up; left-positive degrees are negative raw
|
||||
if CC.latActive:
|
||||
raw = math.floor(-10.0 * apply_angle + 0.5)
|
||||
elif self._angle_hold_allowed(CC, CS):
|
||||
# idle hold: keep the setpoint at the wheel so engagement starts without a step
|
||||
raw = math.floor(-10.0 * steering_angle + 0.5)
|
||||
else:
|
||||
raw = 0 # the panda blocks a nonzero field here
|
||||
return apply_angle, int(np.clip(raw, -p.ANGLE_RAW_MAX, p.ANGLE_RAW_MAX))
|
||||
|
||||
def update(self, CC, CS, now_nanos):
|
||||
_projection = self.learning_projection_observer
|
||||
if _projection is not None:
|
||||
@@ -176,7 +229,12 @@ class CarController(CarControllerBase):
|
||||
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))
|
||||
|
||||
# Send steering command.
|
||||
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.tja_control))
|
||||
if self.angle_mode:
|
||||
apply_angle, angle_raw = self._update_angle(CC, CS)
|
||||
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, angle_raw, self.angle_steer_req,
|
||||
self.tja_control, angle_arm=self.params.ANGLE_ARM))
|
||||
else:
|
||||
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.tja_control))
|
||||
if _projection is not None:
|
||||
_projection.emit('honda.STEERING_CONTROL', apply_torque, CC.latActive, can_sends[-1])
|
||||
|
||||
@@ -286,6 +344,9 @@ class CarController(CarControllerBase):
|
||||
new_actuators.brake = self.brake
|
||||
new_actuators.torque = self.last_torque
|
||||
new_actuators.torqueOutputCan = apply_torque
|
||||
if self.angle_mode:
|
||||
new_actuators.steeringAngleDeg = apply_angle
|
||||
new_actuators.torqueOutputCan = angle_raw # the 0xE4 STEER_TORQUE field as sent (-10 x deg)
|
||||
|
||||
self.frame += 1
|
||||
if _projection is not None:
|
||||
|
||||
@@ -13,6 +13,7 @@ from opendbc.car.dashboard_speed_limit import Tracker as LimitTracker, honda_sig
|
||||
from opendbc.can.dbc import DBC as CANDBC
|
||||
|
||||
TransmissionType = structs.CarParams.TransmissionType
|
||||
SteerControlType = structs.CarParams.SteerControlType
|
||||
ButtonType = structs.CarState.ButtonEvent.Type
|
||||
|
||||
BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise,
|
||||
@@ -120,6 +121,16 @@ class CarState(CarStateBase):
|
||||
ret.steerFaultPermanent = False
|
||||
ret.steerFaultTemporary = False
|
||||
|
||||
if self.CP.flags & HondaFlags.EPS_FW_UNREAD:
|
||||
ret.steerFaultPermanent = True
|
||||
|
||||
if self.CP.steerControlType == SteerControlType.angle and self.CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW:
|
||||
# the angle-loop EPS's angle is a valid absolute angle only while all three sensor status bits read 1; outside
|
||||
# that the EPS would servo from a false angle, so do not steer
|
||||
sensors = cp.vl["STEERING_SENSORS"]
|
||||
if not all(sensors[f"STEER_SENSOR_STATUS_{i}"] == 1 for i in (1, 2, 3)):
|
||||
ret.steerFaultTemporary = True
|
||||
|
||||
# All Honda EPS cut off slightly above standstill, some much higher
|
||||
# Don't alert in the near-standstill range, but alert for per-vehicle configured minimums above that
|
||||
if CarControllerParams.STEER_GLOBAL_MIN_SPEED < ret.vEgo < (self.CP.minSteerSpeed + 0.5):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from opendbc.car.honda.hondacan import honda_checksum
|
||||
from opendbc.car.honda.values import CAR
|
||||
|
||||
|
||||
# Classic Bosch: PT on bus 1 and the stock ACC camera on bus 2. This selects
|
||||
@@ -30,3 +31,9 @@ def normal_bus_topology(packets, *, layout=NORMAL_BUS_LAYOUT):
|
||||
|
||||
def nidec_bus0_topology(packets):
|
||||
return any(normal_bus_topology(packets, layout=layout) for layout in NIDEC_BUS0_LAYOUTS)
|
||||
|
||||
|
||||
def eps_needs_obd(candidates, car_fw) -> bool:
|
||||
"""The Accord's EPS answers only through the OBD port (never on the normal bus 1 wiring), and its firmware
|
||||
family decides between angle and torque steering. A normal-bus read that names the Accord is not complete."""
|
||||
return CAR.HONDA_ACCORD in candidates and not any(fw.ecu == "eps" and not fw.logging for fw in car_fw)
|
||||
|
||||
@@ -117,11 +117,15 @@ def create_acc_commands(packer, CAN, enabled, active, accel, gas, stopping_count
|
||||
return commands
|
||||
|
||||
|
||||
def create_steering_control(packer, CAN, apply_torque, lkas_active, tja_control):
|
||||
def create_steering_control(packer, CAN, apply_torque, lkas_active, tja_control, angle_arm=None):
|
||||
# angle_arm (Accord angle-loop EPS only): STEER_TORQUE is the angle setpoint, sent with the request off too, and
|
||||
# STEER_CONTROL_ARM carries the arm the EPS lane requires. None = the torque frame, unchanged.
|
||||
values = {
|
||||
"STEER_TORQUE": apply_torque if lkas_active else 0,
|
||||
"STEER_TORQUE": apply_torque if (lkas_active or angle_arm is not None) else 0,
|
||||
"STEER_TORQUE_REQUEST": lkas_active,
|
||||
}
|
||||
if angle_arm is not None:
|
||||
values["STEER_CONTROL_ARM"] = angle_arm
|
||||
|
||||
if tja_control:
|
||||
values["STEER_DOWN_TO_ZERO"] = lkas_active
|
||||
|
||||
@@ -7,7 +7,9 @@ from opendbc.car import Bus, 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, HondaSafetyFlags, MANUAL_TRANS_CARS, MODIFIED_EPS_FW, DBC
|
||||
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HondaSafetyFlags, MANUAL_TRANS_CARS, MODIFIED_EPS_FW, DBC, \
|
||||
is_accord_eps_angle_loop_fw
|
||||
from opendbc.car.lateral import MAX_LATERAL_ACCEL
|
||||
from opendbc.car.honda.carcontroller import CarController
|
||||
from opendbc.car.honda.carstate import CarState
|
||||
from opendbc.car.honda.radar_interface import RadarInterface
|
||||
@@ -100,7 +102,12 @@ class CarInterface(CarInterfaceBase):
|
||||
ret.longitudinalTuning.kiV = [1.2, 0.8, 0.5]
|
||||
|
||||
eps_observations = [fw for fw in car_fw if fw.ecu == "eps" and not fw.logging]
|
||||
modified_eps = any(b"," in fw.fwVersion for fw in eps_observations)
|
||||
# Accord angle-loop EPS firmware (39990-TVA,A16<letter>): the EPS closes the angle loop and openpilot sends the
|
||||
# setpoint. Not a torque-modified EPS, so it is kept out of the MODIFIED_EPS_FW allow-list check below (which would
|
||||
# otherwise make the car dashcam-only). Every EPS response must be the family; a mixed read falls through to it.
|
||||
eps_angle_loop_fw = (candidate == CAR.HONDA_ACCORD and len(eps_observations) > 0 and
|
||||
all(is_accord_eps_angle_loop_fw(fw.fwVersion) for fw in eps_observations))
|
||||
modified_eps = not eps_angle_loop_fw and any(b"," in fw.fwVersion for fw in eps_observations)
|
||||
eps_modified = bool(modified_eps) and all(
|
||||
fw.address == 0x18DA30F1 and fw.subAddress == 0 and
|
||||
fw.fwVersion in MODIFIED_EPS_FW.get(candidate, ()) for fw in eps_observations)
|
||||
@@ -121,6 +128,21 @@ class CarInterface(CarInterfaceBase):
|
||||
|
||||
elif candidate == CAR.HONDA_ACCORD:
|
||||
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = ([[0.3], [0.09]] if eps_modified else [[0.6], [0.18]])
|
||||
if eps_angle_loop_fw:
|
||||
# angle-loop EPS firmware: the EPS closes the angle loop, openpilot sends the setpoint
|
||||
ret.flags |= HondaFlags.EPS_ANGLE_LOOP_FW.value
|
||||
ret.safetyConfigs[-1].safetyParam |= HondaSafetyFlags.ACCORD_ANGLE.value
|
||||
ret.steerControlType = structs.CarParams.SteerControlType.angle
|
||||
ret.steerActuatorDelay = CarControllerParams.ANGLE_STEER_ACTUATOR_DELAY
|
||||
# The torque fit's MAX_LAT_ACCEL_MEASURED (0.32 m/s^2) means nothing to an angle setpoint; the onroad torque
|
||||
# bar divides by this, so normalise it by the angle limit instead (3.589 m/s^2, where the setpoint clamp binds).
|
||||
# Measured engaged hands-off over 35 routes: p99.9 3.46 m/s^2, per-route maxima 3.4-4.1. Only the bar and the
|
||||
# car docs read maxLateralAccel; no controller or torque tune does.
|
||||
ret.maxLateralAccel = MAX_LATERAL_ACCEL
|
||||
elif not docs and not eps_observations:
|
||||
# EPS fw unread: an angle-loop EPS would ignore torque frames (engaged, no steering, no alert), so fault instead.
|
||||
# Note: upstream lists this EPS as non-essential (lost without comma power); such an Accord faults here too.
|
||||
ret.flags |= HondaFlags.EPS_FW_UNREAD.value
|
||||
|
||||
elif candidate == CAR.HONDA_ACCORD_11G:
|
||||
ret.longitudinalActuatorDelay = 0.05
|
||||
|
||||
@@ -37,8 +37,11 @@ MANUAL_SELECTION_PORTS = CLASSIC_BOSCH | NIDEC | RADARLESS | CANFD_STOCK | ALT_R
|
||||
# qualified() runs several times per 100 Hz frame in card and selfdrived, so
|
||||
# everything that depends only on this module is computed once, and its flag
|
||||
# tests use plain ints: IntFlag operators cost microseconds each in Python.
|
||||
# EPS_ANGLE_LOOP_FW / EPS_FW_UNREAD: Accord-only EPS-firmware detections (interface.py); the angle car keeps AOL, and
|
||||
# an unread EPS is already a permanent steer fault in carstate, so neither may drop the car out of these owners.
|
||||
_DETECTED = int(HondaFlags.BOSCH_EXT_HUD | HondaFlags.BOSCH_ALT_BRAKE | HondaFlags.HAS_BSM |
|
||||
HondaFlags.EPS_MODIFIED | HondaFlags.HYBRID | HondaFlags.GAS_INTERCEPTOR)
|
||||
HondaFlags.EPS_MODIFIED | HondaFlags.HYBRID | HondaFlags.GAS_INTERCEPTOR |
|
||||
HondaFlags.EPS_ANGLE_LOOP_FW | HondaFlags.EPS_FW_UNREAD)
|
||||
_ALLOWED_FLAGS = {str(car): int(car.config.flags) | _DETECTED
|
||||
for car in CLASSIC_BOSCH | NIDEC | RADARLESS | CANFD_STOCK | ALT_RADAR_STOCK | {CAR.HONDA_ACCORD_11G}}
|
||||
_BOSCH, _BOSCH_RADARLESS, _BOSCH_ALT_BRAKE = int(HondaFlags.BOSCH), int(HondaFlags.BOSCH_RADARLESS), int(HondaFlags.BOSCH_ALT_BRAKE)
|
||||
@@ -102,6 +105,8 @@ def qualified(cp, *, marked_only=False):
|
||||
safety.safetyModel == _HONDA_NIDEC and safety.safetyParam == expected)
|
||||
if fingerprint in CLASSIC_BOSCH and flags & _BOSCH and not flags & _BOSCH_RADARLESS:
|
||||
expected = int(bool(flags & _BOSCH_ALT_BRAKE))
|
||||
if fingerprint == CAR.HONDA_ACCORD and flags & int(HondaFlags.EPS_ANGLE_LOOP_FW):
|
||||
expected |= int(HondaSafetyFlags.ACCORD_ANGLE)
|
||||
if cp.openpilotLongitudinalControl:
|
||||
expected |= int(HondaSafetyFlags.BOSCH_LONG)
|
||||
if fingerprint == CAR.ACURA_RDX_3G:
|
||||
|
||||
@@ -39,9 +39,11 @@ def test_mixed_nonlogging_eps_still_refuses_modified_profile(other):
|
||||
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
||||
|
||||
|
||||
def test_recorded_custom_angle_eps_remains_unsupported_in_mainline():
|
||||
def test_recorded_custom_angle_eps_steers_by_angle():
|
||||
cp = params(CAR.HONDA_ACCORD, [eps(ANGLE), eps(SERIAL, logging=True)])
|
||||
assert cp.dashcamOnly
|
||||
assert not cp.dashcamOnly
|
||||
assert cp.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert cp.steerControlType == structs.CarParams.SteerControlType.angle
|
||||
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
"""Accord on the angle-loop EPS firmware (39990-TVA,A16<letter>): detection, the 0xE4 frame, the setpoint limits."""
|
||||
import math
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from opendbc import get_generated_dbcs
|
||||
from opendbc.can import CANPacker
|
||||
from opendbc.car import Bus, gen_empty_fingerprint
|
||||
from opendbc.car.honda.carcontroller import CarController
|
||||
from opendbc.car.honda.carstate import CarState
|
||||
from opendbc.car.honda.hondacan import CanBus, create_steering_control
|
||||
from opendbc.car.honda.interface import CarInterface
|
||||
from opendbc.car.honda.values import CAR, DBC, CarControllerParams, HondaFlags, HondaSafetyFlags, is_accord_eps_angle_loop_fw, \
|
||||
accord_angle_steer_ratio, ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V
|
||||
from opendbc.car.interfaces import get_torque_params
|
||||
from opendbc.car.lateral import MAX_LATERAL_ACCEL, apply_steer_angle_limits_vm, get_max_angle_delta_vm, get_max_angle_vm
|
||||
from opendbc.car.toyota.interface import CarInterface as ToyotaInterface
|
||||
from opendbc.car.toyota.values import CAR as TOYOTA
|
||||
from opendbc.car.structs import CarParams
|
||||
|
||||
P = CarControllerParams
|
||||
STEERING_CONTROL = 0xE4
|
||||
|
||||
|
||||
def _eps_fw(fw: bytes):
|
||||
return [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=fw, address=0x18DA30F1, subAddress=0)]
|
||||
|
||||
|
||||
def accord_cp(eps_fw: bytes | None):
|
||||
car_fw = [] if eps_fw is None else _eps_fw(eps_fw)
|
||||
return CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), car_fw, False, False, False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fw, expected", [
|
||||
(b"39990-TVA,A16A\x00\x00", True), # V298, NUL-padded as the car reports it
|
||||
(b"39990-TVA,A16B\x00\x00", True), # V299
|
||||
(b"39990-TVA,A16C", True), # the release
|
||||
(b"39990-TVA,A160\x00\x00", False), # torque-map images
|
||||
(b"39990-TVA-A160\x00\x00", False), # stock
|
||||
(b"39990-TVA,A16", False),
|
||||
(b"39990-TVA,A16AB", False),
|
||||
(b"39990-TVA,A16a", False),
|
||||
(b"39990-TVB,A16A", False),
|
||||
])
|
||||
def test_fw_detection(fw, expected):
|
||||
assert is_accord_eps_angle_loop_fw(fw) is expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fw", [b"39990-TVA,A16A\x00\x00", b"39990-TVA,A16B\x00\x00", b"39990-TVA,A16C\x00\x00"])
|
||||
def test_angle_fw_selects_angle_control(fw):
|
||||
CP = accord_cp(fw)
|
||||
assert CP.steerControlType == CarParams.SteerControlType.angle
|
||||
assert CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||
assert CP.steerActuatorDelay == pytest.approx(P.ANGLE_STEER_ACTUATOR_DELAY)
|
||||
# the angle fw carries a ',' but is not a torque-modified EPS: it must not hit the MODIFIED_EPS_FW dashcam fallback
|
||||
assert not CP.dashcamOnly
|
||||
assert not CP.flags & HondaFlags.EPS_MODIFIED
|
||||
assert not CP.flags & HondaFlags.EPS_FW_UNREAD
|
||||
|
||||
|
||||
def test_angle_fw_on_another_honda_is_not_angle_control():
|
||||
# the family is Accord-only; on any other platform the ',' read is the upstream modified-EPS path
|
||||
CP = CarInterface.get_params(CAR.HONDA_CIVIC_BOSCH, gen_empty_fingerprint(), _eps_fw(b"39990-TVA,A16C\x00\x00"),
|
||||
False, False, False)
|
||||
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||
|
||||
|
||||
def test_mixed_eps_read_is_not_angle_control():
|
||||
car_fw = _eps_fw(b"39990-TVA,A16C\x00\x00") + _eps_fw(b"39990-TVA-A160\x00\x00")
|
||||
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), car_fw, False, False, False)
|
||||
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||
assert CP.dashcamOnly # upstream: a ',' EPS outside MODIFIED_EPS_FW
|
||||
|
||||
|
||||
def test_angle_control_needs_no_params():
|
||||
"""A fresh install selects angle control from the EPS fw alone and keeps the pid tuning block untouched.
|
||||
|
||||
Old tree (83fa2e68c8) also pinned this against stale torque-era toggles (ForceTorqueController, NNFF, NNFF Lite)
|
||||
passed into get_params; this tree's get_params takes no toggles and has no ForceTorqueController conversion at all,
|
||||
so only the fw-alone half of that test still has an API to exercise."""
|
||||
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), _eps_fw(b"39990-TVA,A16C"), False, False, False)
|
||||
assert CP.steerControlType == CarParams.SteerControlType.angle
|
||||
assert CP.lateralTuning.which() == "pid"
|
||||
assert CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP).angle_mode
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fw", [None, b"39990-TVA-A160\x00\x00", b"39990-TVA,A160\x00\x00"])
|
||||
def test_other_fw_keeps_torque_control(fw):
|
||||
CP = accord_cp(fw)
|
||||
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||
assert not CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP).angle_mode
|
||||
|
||||
|
||||
def test_max_lateral_accel_is_the_angle_limit_only_on_the_angle_fw():
|
||||
# the onroad torque bar divides by CP.maxLateralAccel; the torque fit's 0.32 m/s^2 pegged it on every turn
|
||||
torque_fit = get_torque_params()[CAR.HONDA_ACCORD]['MAX_LAT_ACCEL_MEASURED']
|
||||
assert torque_fit == pytest.approx(0.3247, abs=1e-4)
|
||||
assert accord_cp(b"39990-TVA,A16C").maxLateralAccel == pytest.approx(MAX_LATERAL_ACCEL)
|
||||
assert MAX_LATERAL_ACCEL == pytest.approx(3.589, abs=1e-3)
|
||||
for fw in (None, b"39990-TVA-A160\x00\x00", b"39990-TVA,A160\x00\x00"):
|
||||
assert accord_cp(fw).maxLateralAccel == pytest.approx(torque_fit)
|
||||
angle_fw = _eps_fw(b"39990-TVA,A16C")
|
||||
for car in (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G):
|
||||
CP = CarInterface.get_params(car, gen_empty_fingerprint(), angle_fw, False, False, False)
|
||||
assert CP.maxLateralAccel == pytest.approx(get_torque_params()[car]['MAX_LAT_ACCEL_MEASURED'])
|
||||
CP = ToyotaInterface.get_params(TOYOTA.TOYOTA_RAV4_TSS2, gen_empty_fingerprint(), [], False, False, False)
|
||||
assert CP.maxLateralAccel == pytest.approx(get_torque_params()[TOYOTA.TOYOTA_RAV4_TSS2]['MAX_LAT_ACCEL_MEASURED'])
|
||||
|
||||
|
||||
def _steer_faults(CP):
|
||||
# an unfed parser set: only the fault logic, not the bus contents, is under test
|
||||
CS = CarState(CP)
|
||||
ret = CS.update(CS.get_can_parsers(CP))
|
||||
return ret.steerFaultPermanent
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fw, angle, unread", [
|
||||
(b"39990-TVA,A16C\x00\x00", True, False), # angle EPS read -> angle mode
|
||||
(b"39990-TVA-A160\x00\x00", False, False), # stock EPS read -> torque mode, no fault
|
||||
(b"39990-TVA,A160\x00\x00", False, False), # torque-map EPS read -> torque mode, no fault
|
||||
(None, False, True), # no EPS fw at all -> permanent fault
|
||||
])
|
||||
def test_eps_fw_unread_faults(fw, angle, unread):
|
||||
CP = accord_cp(fw)
|
||||
assert (CP.steerControlType == CarParams.SteerControlType.angle) == angle
|
||||
assert bool(CP.flags & HondaFlags.EPS_FW_UNREAD) == unread
|
||||
if not angle:
|
||||
# same unfed bus for every case, so the fault is decided by the flag alone (the read cases are the control)
|
||||
assert _steer_faults(CP) == unread
|
||||
|
||||
|
||||
def test_docs_params_do_not_fault():
|
||||
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), [], False, False, True)
|
||||
assert not CP.flags & HondaFlags.EPS_FW_UNREAD
|
||||
|
||||
|
||||
def _upstream_dbc(tmp_path):
|
||||
# the Accord DBC without STEER_CONTROL_ARM, i.e. as it was before the signal was added. The *_generated DBCs are
|
||||
# built in memory in this tree (opendbc.get_generated_dbcs), so the stripped copy is written out from that content.
|
||||
name = DBC[CAR.HONDA_ACCORD][Bus.pt]
|
||||
content = get_generated_dbcs()[name]
|
||||
assert "STEER_CONTROL_ARM" in content
|
||||
lines = [ln for ln in content.splitlines(keepends=True) if "STEER_CONTROL_ARM" not in ln]
|
||||
path = tmp_path / f"{name}.dbc"
|
||||
path.write_text("".join(lines), encoding="utf-8")
|
||||
return str(path)
|
||||
|
||||
|
||||
def test_torque_frame_unchanged_by_the_dbc_signal(tmp_path):
|
||||
CP = accord_cp(None)
|
||||
new = CANPacker(DBC[CAR.HONDA_ACCORD][Bus.pt])
|
||||
old = CANPacker(_upstream_dbc(tmp_path))
|
||||
can = CanBus(CP)
|
||||
for torque in range(-4096, 4097, 37):
|
||||
for active in (False, True):
|
||||
for tja in (False, True):
|
||||
assert create_steering_control(new, can, torque, active, tja) == create_steering_control(old, can, torque, active, tja)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("active", [False, True])
|
||||
def test_angle_frame_carries_the_arm_and_a_valid_checksum(active):
|
||||
packer = CANPacker(DBC[CAR.HONDA_ACCORD][Bus.pt])
|
||||
can = CanBus(accord_cp(b"39990-TVA,A16C"))
|
||||
for raw in (-4000, -1234, -1, 0, 1, 987, 4000):
|
||||
addr, dat, _ = create_steering_control(packer, can, raw, active, False, angle_arm=P.ANGLE_ARM)
|
||||
assert addr == STEERING_CONTROL
|
||||
assert (dat[2] >> 2) & 0x3 == P.ANGLE_ARM # byte 2 bits 3:2
|
||||
assert int.from_bytes(dat[0:2], "big", signed=True) == raw # setpoint sent with the request off too
|
||||
assert bool(dat[2] & 0x80) == active # STEER_TORQUE_REQUEST
|
||||
sig = packer.dbc.addr_to_msg[addr].sigs["CHECKSUM"]
|
||||
zeroed = bytearray(dat)
|
||||
zeroed[4] &= 0xF0
|
||||
assert sig.calc_checksum(addr, sig, zeroed) == dat[4] & 0xF # CHECKSUM 35|4 = byte 4 low nibble
|
||||
|
||||
|
||||
def _controller(aol=False):
|
||||
CP = accord_cp(b"39990-TVA,A16C")
|
||||
if aol:
|
||||
CP.alternativeExperience |= 32 # always-on lateral: the hold must NOT depend on it (the 7.0 panda predicate is a session grant)
|
||||
return CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP)
|
||||
|
||||
|
||||
def _cc_cs(desired, measured, v, lat_active, enabled=True, main_on=True):
|
||||
CC = SimpleNamespace(actuators=SimpleNamespace(steeringAngleDeg=desired), latActive=lat_active, enabled=enabled)
|
||||
CS = SimpleNamespace(out=SimpleNamespace(steeringAngleDeg=measured, vEgoRaw=v, cruiseState=SimpleNamespace(available=main_on)))
|
||||
return CC, CS
|
||||
|
||||
|
||||
def test_error_clip_then_the_accel_and_jerk_limits():
|
||||
# the error clip shapes the request, the accel/jerk limiter runs last on it, and what is sent is the limiter's output
|
||||
cc = _controller()
|
||||
assert cc.angle_mode
|
||||
v, measured = 20.0, 0.0
|
||||
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||
state = measured
|
||||
for _ in range(400):
|
||||
state = apply_steer_angle_limits_vm(min(90.0, measured + err), state, v, measured, True, cc.params, cc.VM)
|
||||
apply_angle, raw = cc._update_angle(*_cc_cs(90.0, measured, v, True))
|
||||
assert apply_angle == cc.apply_angle_last == state
|
||||
assert raw == math.floor(-10.0 * apply_angle + 0.5)
|
||||
assert apply_angle == pytest.approx(measured + err) # the wheel never moved: the send settles on the clip
|
||||
|
||||
|
||||
@pytest.mark.parametrize("v", [1.0, 5.0, 10.0, 17.5, 26.9, 35.0])
|
||||
def test_what_is_sent_never_exceeds_the_accel_and_jerk_limits(v):
|
||||
# whatever the wheel does (a driver holding it far past the limit, or yanking it), every frame sent stays inside
|
||||
# the 3.589 lateral accel angle and steps no further than the 3.589 jerk limit from the previous frame sent
|
||||
rng = np.random.default_rng(int(v * 10))
|
||||
cc = _controller()
|
||||
max_angle = get_max_angle_vm(v, cc.VM, cc.params)
|
||||
max_delta = min(get_max_angle_delta_vm(v, cc.VM, cc.params), P.ANGLE_LIMITS.MAX_ANGLE_RATE)
|
||||
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||
wheel = min(max_angle + err + 10.0, 390.0) # held past the limit: the case the old order got wrong
|
||||
prev, _ = cc._update_angle(*_cc_cs(0.0, 0.0, v, True))
|
||||
for i in range(600):
|
||||
if i > 200:
|
||||
wheel = float(np.clip(wheel + rng.normal(0.0, 3.0), -390.0, 390.0)) # then moving up to several hundred deg/s
|
||||
sent, raw = cc._update_angle(*_cc_cs(float(rng.uniform(-400.0, 400.0)), wheel, v, True))
|
||||
assert abs(sent) <= min(max_angle, P.ANGLE_LIMITS.STEER_ANGLE_MAX) + 1e-9
|
||||
assert abs(sent - prev) <= max_delta + 1e-9
|
||||
assert raw == math.floor(-10.0 * sent + 0.5)
|
||||
prev = sent
|
||||
|
||||
|
||||
def test_wheel_motion_inside_the_error_clip_does_not_feed_the_setpoint():
|
||||
# same command, different wheel paths that stay inside the clip: the setpoint must not depend on the wheel
|
||||
rng = np.random.default_rng(0)
|
||||
a, b = _controller(), _controller()
|
||||
a.apply_angle_last = b.apply_angle_last = 0.0
|
||||
err = float(np.interp(12.0, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||
for i in range(300):
|
||||
desired = 20.0 * math.sin(i / 20.0)
|
||||
wheel = float(np.clip(rng.normal(0.0, 10.0), -(err - 21.0), err - 21.0))
|
||||
a._update_angle(*_cc_cs(desired, 0.0, 12.0, True))
|
||||
b._update_angle(*_cc_cs(desired, wheel, 12.0, True))
|
||||
assert a.apply_angle_last == b.apply_angle_last
|
||||
|
||||
|
||||
def test_setpoint_returns_to_the_request_at_the_jerk_limit_after_the_clip_releases():
|
||||
# wheel pushed away (clip binds), then let go: the setpoint walks back, it does not jump
|
||||
cc = _controller()
|
||||
v = 20.0
|
||||
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||
max_delta = get_max_angle_delta_vm(v, cc.VM, cc.params)
|
||||
cc.apply_angle_last = 0.0
|
||||
for _ in range(300):
|
||||
pushed, _ = cc._update_angle(*_cc_cs(0.0, err + 5.0, v, True))
|
||||
assert pushed == pytest.approx(5.0) # held at the clip edge, wheel - err
|
||||
back, _ = cc._update_angle(*_cc_cs(0.0, 0.0, v, True))
|
||||
assert back == pytest.approx(5.0 - max_delta)
|
||||
|
||||
|
||||
def test_request_waits_at_the_wheel_while_the_wheel_is_past_the_accel_limit():
|
||||
# lateral goes active with the wheel past the accel-limit angle: the limit is more than one jerk step away, so no
|
||||
# setpoint is legal. The frame holds the wheel with the request off, and the request starts once the wheel is inside.
|
||||
cc = _controller()
|
||||
v = 26.9
|
||||
max_angle = get_max_angle_vm(v, cc.VM, cc.params)
|
||||
max_delta = get_max_angle_delta_vm(v, cc.VM, cc.params)
|
||||
for wheel in (max_angle + 20.0, max_angle + 5.0, max_angle + max_delta + 0.1):
|
||||
sent, raw = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||
assert not cc.angle_steer_req
|
||||
assert sent == wheel and raw == math.floor(-10.0 * wheel + 0.5)
|
||||
wheel = max_angle + 0.5 * max_delta
|
||||
cc._update_angle(*_cc_cs(0.0, wheel, v, True)) # the last value sent was the wheel further out: one more frame waits
|
||||
assert not cc.angle_steer_req
|
||||
sent, raw = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||
assert cc.angle_steer_req
|
||||
assert sent == pytest.approx(wheel - max_delta) # one jerk step in from the wheel, inside the accel limit
|
||||
for _ in range(50): # and it stays on from there
|
||||
prev = sent
|
||||
sent, _ = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||
assert cc.angle_steer_req and abs(sent - prev) <= max_delta + 1e-9 and abs(sent) <= max_angle + 1e-9
|
||||
|
||||
|
||||
def test_request_bit_follows_lat_active_otherwise():
|
||||
cc = _controller()
|
||||
cc._update_angle(*_cc_cs(3.0, 1.0, 20.0, True))
|
||||
assert cc.angle_steer_req
|
||||
cc._update_angle(*_cc_cs(3.0, 1.0, 20.0, False))
|
||||
assert not cc.angle_steer_req
|
||||
|
||||
|
||||
def test_each_step_is_bounded_by_the_rate_limit():
|
||||
# MAX_ANGLE_RATE = 2.5 deg/frame (250 deg/s): no frame may step further than that
|
||||
cc = _controller()
|
||||
prev = 0.0
|
||||
for _ in range(5):
|
||||
a, _ = cc._update_angle(*_cc_cs(90.0, 0.0, 3.0, True))
|
||||
assert abs(a - prev) <= P.ANGLE_LIMITS.MAX_ANGLE_RATE + 1e-9
|
||||
prev = a
|
||||
|
||||
|
||||
def test_first_frame_seeds_from_the_wheel():
|
||||
cc = _controller()
|
||||
a, _ = cc._update_angle(*_cc_cs(30.0, 25.0, 10.0, True))
|
||||
assert abs(a - 25.0) <= P.ANGLE_LIMITS.MAX_ANGLE_RATE + 1e-9
|
||||
|
||||
|
||||
@pytest.mark.parametrize("enabled, main_on, aol, holds", [
|
||||
(True, True, False, True),
|
||||
(False, True, True, False), # always-on lateral with ACC main on: the panda's grant is not visible here, so no hold
|
||||
(True, True, True, True),
|
||||
(False, True, False, False),
|
||||
(True, False, False, False), # the panda drops controls_allowed with main off
|
||||
(False, False, True, False),
|
||||
])
|
||||
def test_idle_hold(enabled, main_on, aol, holds):
|
||||
cc = _controller(aol)
|
||||
measured = -12.34
|
||||
apply_angle, raw = cc._update_angle(*_cc_cs(50.0, measured, 15.0, False, enabled, main_on))
|
||||
assert apply_angle == measured # lateral off: the limiter follows the wheel
|
||||
assert raw == (math.floor(-10.0 * measured + 0.5) if holds else 0)
|
||||
|
||||
|
||||
def test_raw_is_clipped():
|
||||
cc = _controller()
|
||||
cc.apply_angle_last = 399.0
|
||||
_, raw = cc._update_angle(*_cc_cs(400.0, 399.0, 1.0, True))
|
||||
assert raw == -P.ANGLE_RAW_MAX
|
||||
|
||||
|
||||
def test_steer_ratio_map_level():
|
||||
assert accord_angle_steer_ratio(0.0) == pytest.approx(16.84)
|
||||
for deg in (0.0, 45.0, 120.0, -200.0, 500.0):
|
||||
expected = float(np.interp(abs(deg), ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V)) * 16.84 / 16.88
|
||||
assert accord_angle_steer_ratio(deg) == pytest.approx(expected)
|
||||
|
||||
|
||||
def test_error_clip_is_the_p_room_under_the_firmware_sum_clamp():
|
||||
# Operator rule (2026-10-21): the clip is the angle error where the V300 firmware's P term alone equals
|
||||
# Kmax - Imax (sum clamp 15360 after the 254/256 taper, so 15481 before it; I cap 4096 / 6144 / 8192 by
|
||||
# speed). Integer mirror of the image: E = 16 * 10 * deg, E' = (E * G(v)) >> 8, P = (E' * 112) >> 8.
|
||||
g_v = {3.1: 1178, 8.0: 1465, 10.0: 760, 11.75: 560, 17.5: 1068, 26.9: 2188}
|
||||
for v, clip in zip(P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V, strict=True):
|
||||
imax = 4096 if v <= 6.0 else (6144 if v <= 12.5 else 8192)
|
||||
p_of = lambda deg, v=v: (((16 * round(10 * deg) * g_v[v]) >> 8) * 112) >> 8 # noqa: E731
|
||||
assert p_of(clip) >= 15481 - imax > p_of(clip - 0.1)
|
||||
|
||||
|
||||
def test_angle_frame_is_sent_by_the_controller():
|
||||
# the full update(): angle mode packs the setpoint with the arm; the projection observer is never installed on angle
|
||||
CP = accord_cp(b"39990-TVA,A16C")
|
||||
ci = CarInterface(CP)
|
||||
from opendbc.car import structs
|
||||
CC = structs.CarControl(enabled=True, latActive=True)
|
||||
CC.actuators.steeringAngleDeg = 5.0
|
||||
ci.update([])
|
||||
out, sends = ci.apply(CC.as_reader(), 1_000_000_000)
|
||||
steer = [s for s in sends if s[0] == STEERING_CONTROL]
|
||||
assert len(steer) == 1
|
||||
dat = steer[0][1]
|
||||
assert (dat[2] >> 2) & 0x3 == P.ANGLE_ARM
|
||||
assert int.from_bytes(dat[0:2], "big", signed=True) == out.torqueOutputCan
|
||||
assert out.steeringAngleDeg == pytest.approx(-out.torqueOutputCan / 10.0, abs=0.05)
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -33,6 +34,32 @@ class TestHondaNormalDiscovery(unittest.TestCase):
|
||||
generic_query.assert_not_called()
|
||||
self.assertIsNone(actual[0])
|
||||
|
||||
def _accord_discovery(self, normal_read, obd_read):
|
||||
from opendbc.car.honda.values import CAR
|
||||
switches = []
|
||||
with patch('opendbc.car.car_helpers.get_vin', return_value=(-1, -1, VIN_UNKNOWN)) as vin, \
|
||||
patch('opendbc.car.car_helpers.get_fw_versions', side_effect=[normal_read, obd_read]) as query, \
|
||||
patch('opendbc.car.car_helpers.match_fw_to_car', return_value=(True, {CAR.HONDA_ACCORD})), \
|
||||
patch('opendbc.car.car_helpers.can_fingerprint', return_value=(None, {})):
|
||||
actual = fingerprint(lambda wait_for_one=False: [recorded_frames()], lambda frames: None, switches.append, None)
|
||||
return switches, vin, query, actual
|
||||
|
||||
def test_accord_without_an_eps_read_queries_the_obd_port(self):
|
||||
radar = SimpleNamespace(ecu="fwdRadar", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||
eps = SimpleNamespace(ecu="eps", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||
switches, vin, query, actual = self._accord_discovery([radar], [radar, eps])
|
||||
self.assertEqual(switches, [False, True, False])
|
||||
self.assertEqual(vin.call_count, 2)
|
||||
self.assertEqual([call.kwargs for call in query.call_args_list],
|
||||
[{'query_brand': 'honda', 'normal_bus_only': True}, {'query_brand': 'honda'}])
|
||||
self.assertEqual(actual[3], [radar, eps])
|
||||
|
||||
def test_accord_with_an_eps_read_stays_on_normal_wiring(self):
|
||||
eps = SimpleNamespace(ecu="eps", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||
switches, vin, query, _ = self._accord_discovery([eps], AssertionError("no second query"))
|
||||
self.assertFalse(any(switches))
|
||||
query.assert_called_once()
|
||||
|
||||
def test_incomplete_or_invalid_traffic_cannot_select_honda(self):
|
||||
from opendbc.car.honda.discovery import normal_bus_topology
|
||||
frames = recorded_frames()
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum, IntFlag
|
||||
|
||||
import numpy as np
|
||||
|
||||
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, structs, uds
|
||||
from opendbc.car.common.conversions import Conversions as CV
|
||||
from opendbc.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Column
|
||||
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
|
||||
from opendbc.car.honda.firmware_validation import validate_fw_match
|
||||
from opendbc.car.lateral import AngleSteeringLimitsVM, MAX_LATERAL_ACCEL, MAX_LATERAL_JERK
|
||||
|
||||
Ecu = structs.CarParams.Ecu
|
||||
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
||||
@@ -41,6 +44,27 @@ class CarControllerParams:
|
||||
STEER_DELTA_DOWN = 3
|
||||
STEER_GLOBAL_MIN_SPEED = 3 * CV.MPH_TO_MS
|
||||
|
||||
# ---- Accord on the angle-loop EPS firmware (HondaFlags.EPS_ANGLE_LOOP_FW). 0xE4 STEER_TORQUE carries an angle
|
||||
# setpoint, raw = round(-10 * deg) in carState.steeringAngleDeg's frame, and the EPS closes a 1 kHz angle loop on it.
|
||||
# The panda checks every such frame (STEER_CONTROL_ARM == 2) against the same lateral accel and jerk limits with
|
||||
# the same vehicle model (honda.h, HONDA_ACCORD_ANGLE_PARAMS), and blocks one that exceeds them.
|
||||
ANGLE_LIMITS: AngleSteeringLimitsVM = AngleSteeringLimitsVM(
|
||||
400, # deg; the EPS clamps its setpoint at raw +-4096
|
||||
MAX_LATERAL_ACCEL=MAX_LATERAL_ACCEL, # 3.589 m/s^2
|
||||
MAX_LATERAL_JERK=MAX_LATERAL_JERK, # 3.589 m/s^3
|
||||
MAX_ANGLE_RATE=2.5, # deg/frame = 250 deg/s (V299 drives ran 250; Tesla and Rivian run 250 deg/s too)
|
||||
)
|
||||
# Error clip |setpoint - measured angle| <= ANGLE_ERROR_MAX(v): bounds the P torque the setpoint can demand. Each
|
||||
# knot = the error at which the firmware's P term alone fills the room left under the PID sum clamp when the
|
||||
# integral sits at its cap (operator rule, 2026-10-21): P = Kmax - Imax, read from the V300 image:
|
||||
# P = ((16*10*deg * G(v)) >> 8) * 112 >> 8, Kmax = 15360 after the 254/256 taper (15481 before it),
|
||||
# Imax = 4096 (<= 6 m/s), 6144 (6-12.5 m/s), 8192 (above, the ICL), G(v) = 1178/1465/760/560/1068/2188 at the knots.
|
||||
ANGLE_ERROR_MAX_BP = [3.1, 8.0, 10.0, 11.75, 17.5, 26.9] # m/s, the firmware gain-table knots
|
||||
ANGLE_ERROR_MAX_V = [35.4, 23.4, 45.0, 61.0, 25.0, 12.2] # deg (was 17.0, 15.5, 19.5, 17.0, 8.5, 4.5, model-sized)
|
||||
ANGLE_RAW_MAX = 4000 # raw clip before packing
|
||||
ANGLE_ARM = 2 # 0xE4 STEER_CONTROL_ARM: the EPS lane runs only while it reads 2; sent on every frame
|
||||
ANGLE_STEER_ACTUATOR_DELAY = 0.15 # s, the inner angle loop's lag (model value; lagd learns the rest)
|
||||
|
||||
def __init__(self, CP):
|
||||
self.BOSCH_GAS_LOOKUP_BP = list(type(self).BOSCH_GAS_LOOKUP_BP)
|
||||
gas_max = {CAR.HONDA_CIVIC_BOSCH: 750, CAR.HONDA_ODYSSEY_5G_MMR: 2000,
|
||||
@@ -92,6 +116,7 @@ class HondaSafetyFlags(IntFlag):
|
||||
RADARLESS = 8
|
||||
BOSCH_CANFD = 16
|
||||
BOSCH_CANFD_MVL = 64
|
||||
ACCORD_ANGLE = 4096
|
||||
CLASSIC_LONG_AOL = 2048 # Exact marked DEBUG classic Bosch alpha owner.
|
||||
ALT_RADAR_AOL = 1024 # Exact marked DEBUG alpha owner; physical EPS/gear token.
|
||||
NIDEC_PEDAL_AOL = 512 # Model1 only; distinct from model20 STOCK_TJA.
|
||||
@@ -121,6 +146,55 @@ class HondaFlags(IntFlag):
|
||||
BOSCH_TJA_CONTROL = 4096
|
||||
EPS_MODIFIED = 8192
|
||||
GAS_INTERCEPTOR = 16384
|
||||
EPS_ANGLE_LOOP_FW = 32768 # the Accord EPS reports the angle-loop firmware (is_accord_eps_angle_loop_fw)
|
||||
EPS_FW_UNREAD = 65536 # Accord with no EPS fw response: the firmware family is unknown, so do not steer
|
||||
|
||||
|
||||
# Accord EPS angle-loop firmware family: 39990-TVA,A16 + exactly one capital letter (A16A, A16B, A16C ...). Torque
|
||||
# images read 39990-TVA,A160 (a digit) and stock 39990-TVA-A1x0, so neither matches.
|
||||
ACCORD_EPS_ANGLE_LOOP_FW_FAMILY = b"39990-TVA,A16"
|
||||
|
||||
|
||||
def is_accord_eps_angle_loop_fw(fw_version: bytes) -> bool:
|
||||
v = bytes(fw_version).rstrip(b"\x00") # the EPS pads fwVersion with NULs
|
||||
family = ACCORD_EPS_ANGLE_LOOP_FW_FAMILY
|
||||
return len(v) == len(family) + 1 and v.startswith(family) and ord("A") <= v[-1] <= ord("Z")
|
||||
|
||||
|
||||
# ---- Accord, angle mode only (steerControlType == angle): the variable-ratio rack map.
|
||||
# In angle mode sR turns the model's curvature 1:1 into the angle setpoint, so the ratio is a tune here and the learner
|
||||
# is ignored. SHAPE: absolute ratios measured over 82 routes, V[0] = the on-centre nominal. Not measurements:
|
||||
# 0-23 deg (pinned by convention, not identified), 31-61 deg (interpolated across two bins that failed the lag test),
|
||||
# 236+ deg (frozen; above 303 deg the data is parking speed). A compensation curve for calc_curvature's k = d/L,
|
||||
# not the rack's true geometry. Bands: shape +/-0.12, level +/-0.57.
|
||||
ACCORD_ANGLE_SR_BP = [0.0, 23.0, 31.0, 61.0, 76.0, 95.0, 116.0, 151.0, 178.0, 227.0, 236.0, 303.0, 380.0] # deg
|
||||
ACCORD_ANGLE_SR_V = [16.88, 16.88, 16.88, 16.25, 15.97, 15.45, 15.03, 14.68, 14.45, 14.09, 14.25, 12.98, 12.31] # :1
|
||||
# LEVEL: the served on-centre ratio; the whole shape is scaled by LEVEL / V[0]. 16.84 = the SteerRatio every angle
|
||||
# drive ran (V298/V299 configs).
|
||||
ACCORD_ANGLE_SR_LEVEL = 16.84
|
||||
|
||||
|
||||
def accord_angle_steer_ratio(steer_angle_deg: float) -> float:
|
||||
"""Local ratio of the Accord's rack at this wheel angle (deg, offset removed)."""
|
||||
ratio = float(np.interp(abs(steer_angle_deg), ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V))
|
||||
return ratio * ACCORD_ANGLE_SR_LEVEL / ACCORD_ANGLE_SR_V[0]
|
||||
|
||||
|
||||
def accord_angle_at_own_ratio(angle_vm_deg: float, sr_vm: float, max_passes: int = 10) -> float:
|
||||
"""The angle setpoint with the map evaluated at the DESIRED angle instead of the measured one.
|
||||
|
||||
controlsd sets VM.sR = map(measured angle) and get_steer_from_curvature is linear in sR, so the consistent setpoint
|
||||
is the fixed point theta = angle_vm_deg * map(theta) / sr_vm. Each pass shrinks the error by <= 0.44 (worst on the
|
||||
236-303 deg knot); stops within 0.01 deg, a tenth of the EPS setpoint quantum.
|
||||
"""
|
||||
theta = float(angle_vm_deg)
|
||||
for _ in range(max_passes):
|
||||
nxt = float(angle_vm_deg) * accord_angle_steer_ratio(theta) / sr_vm
|
||||
done = abs(nxt - theta) < 0.01
|
||||
theta = nxt
|
||||
if done:
|
||||
break
|
||||
return theta
|
||||
|
||||
|
||||
# Car button codes
|
||||
|
||||
@@ -2,6 +2,7 @@ BO_ 228 STEERING_CONTROL: 5 EON
|
||||
SG_ STEER_TORQUE : 7|16@0- (1,0) [-4096|4096] "" EPS
|
||||
SG_ DRIVER_OVERRIDE : 17|1@0+ (1,0) [0|1] "" XXX
|
||||
SG_ STEER_TORQUE_REQUEST : 23|1@0+ (1,0) [0|1] "" EPS
|
||||
SG_ STEER_CONTROL_ARM : 19|2@0+ (1,0) [0|3] "" EPS
|
||||
SG_ CONTROL_STATE : 26|3@0+ (1,0) [0|7] "" XXX
|
||||
SG_ CHECKSUM : 35|4@0+ (1,0) [0|15] "" EPS
|
||||
SG_ COUNTER : 37|2@0+ (1,0) [0|3] "" EPS
|
||||
@@ -206,6 +207,7 @@ BO_ 13275 LKAS_HUD_B: 8 ADAS
|
||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" BDY
|
||||
|
||||
CM_ SG_ 228 DRIVER_OVERRIDE "Appears to acknowledge STEER_STATUS.NO_TORQUE_ALERT_1";
|
||||
CM_ SG_ 228 STEER_CONTROL_ARM "Stock camera sends 0 or 1. The Accord angle-loop EPS firmware (39990-TVA,A16x) runs its lane only while this reads 2";
|
||||
CM_ SG_ 576 LINE_DISTANCE_VISIBLE "Length of line visible, undecoded";
|
||||
CM_ SG_ 577 LINE_FAR_EDGE_POSITION "Appears to be a measure of line thickness, indicates location of the portion of the line furthest from the car, undecoded";
|
||||
CM_ SG_ 577 LINE_PARAMETER "Unclear if this is low quality line curvature rate or if this is something else, but it is correlated with line curvature, undecoded";
|
||||
|
||||
@@ -34,6 +34,8 @@ static bool honda_fwd_brake = false;
|
||||
static bool honda_bosch_long = false;
|
||||
static bool honda_bosch_radarless = false;
|
||||
static bool honda_bosch_canfd = false;
|
||||
static bool honda_accord_angle = false;
|
||||
#define HONDA_PARAM_ACCORD_ANGLE 4096U
|
||||
static bool honda_mvl_stock = false;
|
||||
static uint8_t honda_mvl_buttons_fresh = 0U;
|
||||
static bool honda_rdx_high_gas = false;
|
||||
@@ -101,6 +103,23 @@ static uint8_t honda_get_counter(const CANPacket_t *msg) {
|
||||
return (msg->data[counter_byte] >> 4U) & 0x3U;
|
||||
}
|
||||
|
||||
// The Accord angle-loop EPS firmware (39990-TVA,A16x) exists only on classic Bosch. On it a 0xE4 frame with
|
||||
// STEER_CONTROL_ARM == 2 carries an angle setpoint in bytes 0-1 (-0.1 deg); the EPS runs its angle lane on no other
|
||||
// frame, and the stock camera only ever sends 0 or 1 there.
|
||||
static bool honda_angle_setpoint_capable(void) {
|
||||
return (honda_hw == HONDA_BOSCH) && honda_accord_angle;
|
||||
}
|
||||
|
||||
// Wheel angle for the angle setpoint check: where a request may start from, and what a request-off frame may hold.
|
||||
// STEERING_SENSORS is not a required RX check on Honda, so it arrives here, and its checksum is verified here.
|
||||
static void honda_optional_rx_hook(const CANPacket_t *msg) {
|
||||
if (honda_angle_setpoint_capable() && msg_matches(msg, 0x14AU, honda_get_pt_bus(), 8U) &&
|
||||
(honda_get_checksum(msg) == honda_compute_checksum(msg))) {
|
||||
// STEER_ANGLE, -0.1 deg: the same units and sign as the 0xE4 setpoint
|
||||
update_sample(&angle_meas, to_signed((msg->data[0] << 8) | msg->data[1], 16));
|
||||
}
|
||||
}
|
||||
|
||||
static void honda_rx_hook(const CANPacket_t *msg) {
|
||||
const bool pcm_cruise = ((honda_hw == HONDA_BOSCH) && !honda_bosch_long) || ((honda_hw == HONDA_NIDEC) && !honda_interceptor);
|
||||
unsigned int pt_bus = honda_get_pt_bus();
|
||||
@@ -111,6 +130,14 @@ static void honda_rx_hook(const CANPacket_t *msg) {
|
||||
vehicle_moving = msg->data[0] | msg->data[1];
|
||||
}
|
||||
|
||||
// speed for the angle setpoint check (Accord angle-loop EPS)
|
||||
if (honda_angle_setpoint_capable()) {
|
||||
if (msg_matches(msg, 0x158U, pt_bus)) {
|
||||
// ENGINE_DATA XMISSION_SPEED, 0.01 kph
|
||||
UPDATE_VEHICLE_SPEED(((msg->data[0] << 8) | msg->data[1]) * 0.01 * KPH_TO_MS);
|
||||
}
|
||||
}
|
||||
|
||||
// check ACC main state
|
||||
// 0x326 for all Bosch and some Nidec, 0x1A6 for some Nidec
|
||||
if ((!aol_honda_bosch_long && ((msg->addr == 0x326U) || (msg->addr == 0x1A6U))) ||
|
||||
@@ -317,6 +344,40 @@ static bool honda_tx_hook(const CANPacket_t *msg) {
|
||||
}
|
||||
}
|
||||
|
||||
// STEER: angle setpoint frames (STEER_CONTROL_ARM == 2, Accord angle-loop EPS) must stay inside the lateral
|
||||
// acceleration and jerk limits, checked with the vehicle model on the value as sent
|
||||
if ((msg->addr == 0xE4U) && (((msg->data[2] >> 2) & 0x3U) == 2U)) {
|
||||
const AngleSteeringLimits HONDA_ACCORD_ANGLE_LIMITS = {
|
||||
.max_angle = 4000, // 400 deg, the EPS clamps its setpoint just above this
|
||||
.angle_deg_to_can = 10,
|
||||
.frequency = 100U,
|
||||
};
|
||||
|
||||
// NOTE: HONDA_ACCORD, must match openpilot's VehicleModel
|
||||
const AngleSteeringParams HONDA_ACCORD_ANGLE_PARAMS = {
|
||||
.slip_factor = -0.0006999872680281922, // calc_slip_factor(VM)
|
||||
.steer_ratio = 16.33,
|
||||
.wheelbase = 2.83,
|
||||
};
|
||||
|
||||
const int desired_angle = to_signed((msg->data[0] << 8) | msg->data[1], 16);
|
||||
const bool steer_req = GET_BIT(msg, 23U); // STEER_TORQUE_REQUEST
|
||||
|
||||
bool violation = !honda_angle_setpoint_capable();
|
||||
if (!violation) {
|
||||
if (!steer_req && (desired_angle == 0)) {
|
||||
// request off with a zero field: nothing is commanded, the next request starts from the wheel
|
||||
desired_angle_last = SAFETY_CLAMP(angle_meas.values[0], -HONDA_ACCORD_ANGLE_LIMITS.max_angle, HONDA_ACCORD_ANGLE_LIMITS.max_angle);
|
||||
} else {
|
||||
violation |= steer_angle_cmd_checks_vm(desired_angle, steer_req, HONDA_ACCORD_ANGLE_LIMITS, HONDA_ACCORD_ANGLE_PARAMS);
|
||||
violation |= safety_max_limit_check(desired_angle, HONDA_ACCORD_ANGLE_LIMITS.max_angle, -HONDA_ACCORD_ANGLE_LIMITS.max_angle);
|
||||
}
|
||||
}
|
||||
if (violation) {
|
||||
tx = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Bosch supplemental control check
|
||||
if (msg->addr == 0xE5U) {
|
||||
if ((GET_BYTES_64_LE(msg, 0, 8) & 0x00FFFFFFFFFFFFFFULL) != 0x0000000010800004ULL) {
|
||||
@@ -381,6 +442,7 @@ static safety_config honda_nidec_init(uint16_t param) {
|
||||
const uint16_t HONDA_PARAM_NIDEC_ALT = 4;
|
||||
|
||||
honda_hw = HONDA_NIDEC;
|
||||
honda_accord_angle = false;
|
||||
honda_brake = 0;
|
||||
honda_brake_switch_prev = false;
|
||||
honda_fwd_brake = false;
|
||||
@@ -426,7 +488,14 @@ static safety_config honda_nidec_init(uint16_t param) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static safety_config honda_bosch_init(uint16_t param) {
|
||||
static safety_config honda_bosch_init(uint16_t requested_param) {
|
||||
// Apply the Accord flag only to the classic Bosch base configurations the host can select.
|
||||
const uint16_t param = (uint16_t)(requested_param & ~HONDA_PARAM_ACCORD_ANGLE);
|
||||
bool accord_base = (param == 0U) || (param == 1U);
|
||||
#ifdef ALLOW_DEBUG
|
||||
accord_base = accord_base || (param == 2U) || (param == 3U) || (param == 2082U) || (param == 2083U);
|
||||
#endif
|
||||
honda_accord_angle = GET_FLAG(requested_param, HONDA_PARAM_ACCORD_ANGLE) && accord_base;
|
||||
honda_mvl_stock = ((param == 80U) || (param == 81U)) && ((alternative_experience == 0) || (alternative_experience == 32));
|
||||
honda_mvl_buttons_fresh = 0U;
|
||||
honda_interceptor_reset(false);
|
||||
@@ -614,6 +683,7 @@ const safety_hooks honda_bosch_hooks = {
|
||||
.fwd = honda_mvl_stock_fwd_hook,
|
||||
.init = honda_bosch_init,
|
||||
.rx = honda_rx_hook,
|
||||
.optional_rx = honda_optional_rx_hook,
|
||||
.tx = honda_tx_hook,
|
||||
.get_counter = honda_get_counter,
|
||||
.get_checksum = honda_get_checksum,
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Accord angle-loop EPS: the panda bounds the 0xE4 angle setpoint by the lateral accel and jerk limits."""
|
||||
import math
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
|
||||
from opendbc.car import Bus, gen_empty_fingerprint
|
||||
from opendbc.car.honda.carcontroller import CarController
|
||||
from opendbc.car.honda.interface import CarInterface
|
||||
from opendbc.car.honda.values import CAR, DBC, CarControllerParams, HondaSafetyFlags
|
||||
from opendbc.car.lateral import MAX_LATERAL_ACCEL, get_max_angle_delta_vm, get_max_angle_vm
|
||||
from opendbc.car.structs import CarParams
|
||||
from opendbc.car.vehicle_model import VehicleModel, calc_slip_factor
|
||||
from opendbc.safety.tests.libsafety import libsafety_py
|
||||
from opendbc.safety.tests import test_honda # the module, so its test classes are not collected again here
|
||||
|
||||
P = CarControllerParams
|
||||
ARM = P.ANGLE_ARM
|
||||
DT_US = 10_000 # 0xE4 is sent at 100 Hz
|
||||
SPEEDS = (1.0, 3.0, 5.0, 8.0, 10.0, 12.0, 17.5, 22.0, 26.9, 31.0, 38.0)
|
||||
|
||||
|
||||
def accord_cp():
|
||||
fw = [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=b"39990-TVA,A16C", address=0x18DA30F1, subAddress=0)]
|
||||
return CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), fw, False, False, False)
|
||||
|
||||
|
||||
class TestHondaAccordAngleSetpoint(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.fixture = test_honda.TestHondaBoschAltBrakeSafety('test_spam_cancel_safety_check')
|
||||
self.fixture.setUp()
|
||||
self.safety = self.fixture.safety
|
||||
self.packer = self.fixture.packer
|
||||
self.CP = accord_cp()
|
||||
self.angle_flag = self.CP.safetyConfigs[0].safetyParam
|
||||
self.assertNotEqual(self.angle_flag, 0)
|
||||
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, self.angle_flag | 1), 0)
|
||||
self.safety.init_tests()
|
||||
self.VM = VehicleModel(self.CP)
|
||||
self.params = P(self.CP)
|
||||
self.t = 1_000_000
|
||||
self.safety.set_timer(self.t)
|
||||
|
||||
# ---- helpers
|
||||
def _angle_frame(self, raw, steer_req, arm=ARM, bus=None):
|
||||
values = {"STEER_TORQUE": raw, "STEER_TORQUE_REQUEST": steer_req, "STEER_CONTROL_ARM": arm}
|
||||
return self.packer.make_can_msg_safety("STEERING_CONTROL", self.fixture.STEER_BUS if bus is None else bus, values)
|
||||
|
||||
def _tx(self, raw, steer_req=True, arm=ARM, bus=None):
|
||||
self.t += DT_US
|
||||
self.safety.set_timer(self.t)
|
||||
return self.fixture._tx(self._angle_frame(raw, steer_req, arm, bus))
|
||||
|
||||
def _rx_speed(self, v_ms):
|
||||
self.fixture._rx(self.fixture._speed_msg(v_ms * 3.6))
|
||||
|
||||
def _rx_wheel(self, raw):
|
||||
# STEER_ANGLE is -0.1 deg per count: the raw count equals the 0xE4 raw for the same angle
|
||||
self.fixture._rx(self.packer.make_can_msg_safety("STEERING_SENSORS", self.fixture.PT_BUS, {"STEER_ANGLE": -raw / 10.0}))
|
||||
|
||||
def _settle(self, v_ms, wheel_raw=0):
|
||||
for _ in range(6):
|
||||
self._rx_speed(v_ms)
|
||||
self._rx_wheel(wheel_raw)
|
||||
|
||||
def _panda_max_angle_raw(self, v_ms):
|
||||
# the panda evaluates the model 1 m/s below its slowest speed sample and allows one count of rounding
|
||||
return int(get_max_angle_vm(max(v_ms - 1.0, 1.0), self.VM, self.params) * 10 + 1.0)
|
||||
|
||||
def _panda_max_delta_raw(self, v_ms):
|
||||
return int(get_max_angle_delta_vm(max(v_ms - 1.0, 1.0), self.VM, self.params) * 10 + 1.0)
|
||||
|
||||
def test_stock_profiles_and_incompatible_flag_combinations_reject_angle_frames(self):
|
||||
is_debug = self.safety.set_safety_hooks(CarParams.SafetyModel.allOutput, 0) == 0
|
||||
ordinary = (0, 1, 2, 3, 2082, 2083)
|
||||
invalid = (self.angle_flag | 8, self.angle_flag | 16, self.angle_flag | 128)
|
||||
if not is_debug:
|
||||
invalid += tuple(self.angle_flag | word for word in ordinary if word & 2)
|
||||
for word in ordinary + invalid:
|
||||
with self.subTest(word=word):
|
||||
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, word), 0)
|
||||
self.safety.init_tests()
|
||||
self._settle(10.0)
|
||||
self.safety.set_controls_allowed(True)
|
||||
bus = int(bool(is_debug and word & 2))
|
||||
self.assertFalse(self._tx(10, bus=bus), word)
|
||||
self.assertFalse(self._tx(0, steer_req=False, bus=bus), word)
|
||||
if word in ordinary:
|
||||
self.assertTrue(self._tx(10, arm=0, bus=bus), word)
|
||||
|
||||
def test_flag_preserves_lateral_on_supported_classic_bosch_configurations(self):
|
||||
is_debug = self.safety.set_safety_hooks(CarParams.SafetyModel.allOutput, 0) == 0
|
||||
base_words = (0, 1, 2, 3, 2082, 2083) if is_debug else (0, 1)
|
||||
for base in base_words:
|
||||
with self.subTest(base=base):
|
||||
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, self.angle_flag | base), 0)
|
||||
self.safety.init_tests()
|
||||
self._settle(10.0)
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.assertTrue(self._tx(10, bus=int(bool(base & 2))), base)
|
||||
|
||||
# ---- the model the panda uses is the one openpilot uses
|
||||
def test_vehicle_model_constants_match_openpilot(self):
|
||||
src = (Path(__file__).parents[1] / "modes" / "honda.h").read_text(encoding="utf-8")
|
||||
block = src[src.index("HONDA_ACCORD_ANGLE_PARAMS = {"):]
|
||||
block = block[:block.index("};")]
|
||||
read = {k: float(v) for k, v in re.findall(r"\.(\w+)\s*=\s*(-?[\d.]+)", block)}
|
||||
self.assertAlmostEqual(read["slip_factor"], calc_slip_factor(self.VM), places=12)
|
||||
self.assertAlmostEqual(read["steer_ratio"], self.CP.steerRatio, places=5)
|
||||
self.assertAlmostEqual(read["wheelbase"], self.CP.wheelbase, places=5)
|
||||
self.assertAlmostEqual(MAX_LATERAL_ACCEL, 3.589, places=3)
|
||||
self.assertEqual(self.params.ANGLE_LIMITS.MAX_LATERAL_ACCEL, MAX_LATERAL_ACCEL)
|
||||
|
||||
# ---- lateral acceleration limit
|
||||
def test_setpoint_beyond_the_lateral_accel_limit_is_blocked(self):
|
||||
for v in SPEEDS:
|
||||
limit = self._panda_max_angle_raw(v)
|
||||
if limit > 4000:
|
||||
continue # below ~5 m/s the 400 deg ceiling binds first (covered below)
|
||||
for sign in (-1, 1):
|
||||
self._settle(v)
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.set_desired_angle_last(sign * limit)
|
||||
self.assertTrue(self._tx(sign * limit), (v, sign))
|
||||
self.assertFalse(self._tx(sign * (limit + 1)), (v, sign))
|
||||
# the first blocked frame resets the panda to the wheel; a setpoint this far out stays blocked
|
||||
self.assertFalse(self._tx(sign * (limit + 1)), (v, sign))
|
||||
|
||||
def test_the_old_order_counterexample_is_blocked(self):
|
||||
# 26.9 m/s, wheel held at 42 deg: the old code sent 29.8 deg (5.4 m/s^2) against a 19.8 deg limit
|
||||
v = 26.9
|
||||
self._settle(v, wheel_raw=420)
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.set_desired_angle_last(298)
|
||||
self.assertFalse(self._tx(298))
|
||||
self.assertGreater(298, self._panda_max_angle_raw(v))
|
||||
|
||||
def test_setpoint_beyond_400_deg_is_blocked(self):
|
||||
self._settle(1.0, wheel_raw=4000)
|
||||
self.safety.set_controls_allowed(True)
|
||||
for raw, ok in ((4000, True), (4001, False), (-4000, True), (-4001, False), (4096, False)):
|
||||
self.safety.set_desired_angle_last(raw)
|
||||
self.assertEqual(ok, self._tx(raw), raw)
|
||||
|
||||
# ---- lateral jerk limit
|
||||
def test_step_beyond_the_lateral_jerk_limit_is_blocked(self):
|
||||
for v in SPEEDS:
|
||||
delta = self._panda_max_delta_raw(v)
|
||||
for sign in (-1, 1):
|
||||
for start in (0, 50):
|
||||
if start + delta + 1 > min(self._panda_max_angle_raw(v), 4000):
|
||||
continue
|
||||
self._settle(v, wheel_raw=sign * start)
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.set_desired_angle_last(sign * start)
|
||||
self.assertTrue(self._tx(sign * (start + delta)), (v, sign, start))
|
||||
self.safety.set_desired_angle_last(sign * start)
|
||||
self.assertFalse(self._tx(sign * (start + delta + 1)), (v, sign, start))
|
||||
|
||||
def test_a_blocked_frame_restarts_from_the_wheel(self):
|
||||
v = 20.0
|
||||
self._settle(v, wheel_raw=30)
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.set_desired_angle_last(30)
|
||||
self.assertFalse(self._tx(30 + self._panda_max_delta_raw(v) + 1))
|
||||
self.assertEqual(self.safety.get_desired_angle_last(), 30)
|
||||
self.assertTrue(self._tx(30 + self._panda_max_delta_raw(v)))
|
||||
|
||||
# ---- request off
|
||||
def test_request_off_frames(self):
|
||||
v = 15.0
|
||||
self._settle(v, wheel_raw=-234)
|
||||
for allowed in (True, False):
|
||||
self.safety.set_controls_allowed(allowed)
|
||||
self.assertTrue(self._tx(0, steer_req=False)) # nothing commanded
|
||||
self.assertEqual(self.safety.get_desired_angle_last(), -234)
|
||||
self.assertEqual(allowed, self._tx(-234, steer_req=False)) # hold at the wheel: only while lateral is allowed
|
||||
self.assertFalse(self._tx(-200, steer_req=False)) # anything else is not the wheel
|
||||
self.assertFalse(self._tx(100, steer_req=False))
|
||||
|
||||
def test_request_needs_controls_allowed(self):
|
||||
self._settle(15.0, wheel_raw=0)
|
||||
self.safety.set_controls_allowed(False)
|
||||
self.assertFalse(self._tx(0, steer_req=True))
|
||||
self.assertFalse(self._tx(5, steer_req=True))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.assertTrue(self._tx(0, steer_req=True))
|
||||
|
||||
def test_engage_from_a_zero_field_starts_at_the_wheel(self):
|
||||
# always-on lateral case: the carcontroller sends a zero field until the request, then starts from the wheel
|
||||
v = 25.0
|
||||
self._settle(v, wheel_raw=150)
|
||||
self.safety.set_controls_allowed(True)
|
||||
for _ in range(5):
|
||||
self.assertTrue(self._tx(0, steer_req=False))
|
||||
self.assertTrue(self._tx(150 + self._panda_max_delta_raw(v), steer_req=True))
|
||||
|
||||
# ---- torque frames (arm 0 or 1) are not angle setpoints
|
||||
def test_torque_frames_are_unaffected(self):
|
||||
self._settle(30.0)
|
||||
self.safety.set_controls_allowed(True)
|
||||
for arm in (0, 1):
|
||||
for raw in (-4096, -1000, 0, 1000, 4096):
|
||||
self.assertTrue(self._tx(raw, steer_req=True, arm=arm), (arm, raw))
|
||||
self.safety.set_controls_allowed(False)
|
||||
self.assertTrue(self._tx(0, steer_req=False, arm=0))
|
||||
self.assertFalse(self._tx(1000, steer_req=True, arm=0))
|
||||
|
||||
# ---- message rate
|
||||
def test_message_rate_limit(self):
|
||||
self._settle(20.0)
|
||||
self.safety.set_controls_allowed(True)
|
||||
blocked = False
|
||||
for _ in range(40): # 40 frames inside one 250 ms window: more than 100 Hz allows
|
||||
blocked |= not self.fixture._tx(self._angle_frame(0, True))
|
||||
self.assertTrue(blocked)
|
||||
|
||||
# ---- the carcontroller's own output is what the panda checks, and it always passes
|
||||
def _controller_frames(self, v_of, wheel_of, desired_of, frames):
|
||||
cc = CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, self.CP)
|
||||
blocked = withheld = 0
|
||||
for i in range(frames):
|
||||
v, wheel = v_of(i), wheel_of(i)
|
||||
wheel_raw = math.floor(-10.0 * wheel + 0.5)
|
||||
self._rx_speed(v)
|
||||
self._rx_wheel(wheel_raw)
|
||||
active = i >= 12 # as on the road, request-off frames come first: they fill the panda's samples
|
||||
CC = SimpleNamespace(actuators=SimpleNamespace(steeringAngleDeg=desired_of(i)), latActive=active, enabled=True)
|
||||
# carState reads the angle off the same STEER_ANGLE counts and the speed off the wheels
|
||||
CS = SimpleNamespace(out=SimpleNamespace(steeringAngleDeg=-wheel_raw / 10.0, vEgoRaw=v,
|
||||
cruiseState=SimpleNamespace(available=True)))
|
||||
_, raw = cc._update_angle(CC, CS)
|
||||
withheld += active and not cc.angle_steer_req
|
||||
blocked += not self._tx(raw, steer_req=cc.angle_steer_req)
|
||||
return blocked, withheld
|
||||
|
||||
def test_carcontroller_output_is_never_blocked(self):
|
||||
self.safety.set_controls_allowed(True)
|
||||
rng = np.random.default_rng(1)
|
||||
cases = {
|
||||
"lane keeping": (lambda i: 28.0, lambda i: 2.0 * math.sin(i / 60.0), lambda i: 3.0 * math.sin(i / 50.0)),
|
||||
"saturating request": (lambda i: 20.0, lambda i: 0.0, lambda i: 300.0 * math.sin(i / 100.0)),
|
||||
"random request": (lambda i: 12.0, lambda i: 10.0 * math.sin(i / 40.0), lambda i: float(rng.uniform(-400, 400))),
|
||||
"tight turn": (lambda i: 4.0, lambda i: min(i * 2.0, 380.0), lambda i: 400.0),
|
||||
"driver past the limit": (lambda i: 26.9, lambda i: min(i * 0.3, 45.0), lambda i: 0.0),
|
||||
"driver yank": (lambda i: 17.5, lambda i: 60.0 * math.sin(i / 8.0), lambda i: 5.0),
|
||||
"braking": (lambda i: max(30.0 - i * 0.03, 2.0), lambda i: 5.0, lambda i: 400.0),
|
||||
"accelerating": (lambda i: min(3.0 + i * 0.03, 35.0), lambda i: 0.0, lambda i: -400.0),
|
||||
}
|
||||
for name, (v_of, wheel_of, desired_of) in cases.items():
|
||||
self.safety.set_controls_allowed(True)
|
||||
blocked, withheld = self._controller_frames(v_of, wheel_of, desired_of, 900)
|
||||
self.assertEqual(0, blocked, name)
|
||||
# the request is withheld only where the wheel is past the limit when it would start: the yank reaches 60 deg
|
||||
# against a 38 deg limit. Everywhere else every frame carries the request.
|
||||
self.assertEqual(name == "driver yank", withheld > 0, (name, withheld))
|
||||
|
||||
|
||||
class TestHondaAngleSetpointOnOtherBosch(unittest.TestCase):
|
||||
"""A radarless or CAN FD Honda has no angle-loop EPS: an armed frame is never sent, and is blocked if it is."""
|
||||
|
||||
def test_armed_frame_is_blocked(self):
|
||||
fixture = test_honda.TestHondaBoschRadarlessSafety('test_spam_cancel_safety_check')
|
||||
fixture.setUp()
|
||||
fixture.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, HondaSafetyFlags.RADARLESS)
|
||||
fixture.safety.init_tests()
|
||||
fixture.safety.set_controls_allowed(True)
|
||||
for arm, ok in ((0, True), (1, True), (ARM, False)):
|
||||
# bytes 0-1 zero, STEER_TORQUE_REQUEST set, STEER_CONTROL_ARM in byte 2 bits 3:2
|
||||
packet = libsafety_py.make_CANPacket(0xE4, fixture.STEER_BUS, bytes([0, 0, 0x80 | (arm << 2), 0, 0]))
|
||||
self.assertEqual(ok, fixture._tx(packet), arm)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -16,6 +16,7 @@ from openpilot.selfdrive.controls.lib.cycle_timing import ControlCycleTiming, PU
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
|
||||
from opendbc.car.car_helpers import interfaces
|
||||
from opendbc.car.honda.values import CAR as HONDA_CAR, accord_angle_steer_ratio
|
||||
from opendbc.car.vehicle_model import VehicleModel
|
||||
from openpilot.selfdrive.controls.lib.drive_helpers import clip_curvature
|
||||
from openpilot.selfdrive.controls.lib.highway_correction_gain import HighwayCorrectionGain, predicted_lateral_accels, read_gain
|
||||
@@ -357,6 +358,9 @@ class Controls:
|
||||
torque_extension = getattr(self.LaC, 'starpilot_extension', None)
|
||||
if torque_extension is not None:
|
||||
sr = torque_extension.vehicle_model_ratio(sr, CS.vEgo)
|
||||
if self.CP.carFingerprint == HONDA_CAR.HONDA_ACCORD and self.CP.steerControlType == car.CarParams.SteerControlType.angle:
|
||||
# angle-loop EPS: the variable-ratio rack map at the measured angle replaces the learner
|
||||
sr = accord_angle_steer_ratio(CS.steeringAngleDeg - lp.angleOffsetDeg)
|
||||
self.VM.update_params(x, sr)
|
||||
|
||||
steer_angle_without_offset = math.radians(CS.steeringAngleDeg - lp.angleOffsetDeg)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import math
|
||||
|
||||
from openpilot.cereal import log
|
||||
from opendbc.car.honda.values import CAR as HONDA_CAR, HondaFlags, accord_angle_at_own_ratio
|
||||
from openpilot.selfdrive.controls.lib.latcontrol import LatControl
|
||||
from openpilot.starpilot.car.subaru.angle_tune import _ascent_angle_tracking_target, _ascent_low_speed_angle_target
|
||||
|
||||
@@ -14,7 +15,11 @@ class LatControlAngle(LatControl):
|
||||
self.is_ascent = CP.brand == 'subaru' and CP.carFingerprint == 'SUBARU_ASCENT_2023'
|
||||
self.ascent_angle_target = None
|
||||
self.sat_check_min_speed = 5.
|
||||
self.use_steer_limited_by_safety = CP.brand in ("tesla", "hyundai")
|
||||
# Accord on the angle-loop EPS: the EPS angle loop lags 0.3-0.6 s, so a raw angle-error rule flags ordinary turn
|
||||
# entries; its carcontroller limits the setpoint itself (lateral accel/jerk, error clip), so use carOutput instead
|
||||
self.is_accord_angle_loop = CP.brand == "honda" and bool(CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW)
|
||||
self.use_steer_limited_by_safety = CP.brand in ("tesla", "hyundai") or self.is_accord_angle_loop
|
||||
self.is_accord = CP.carFingerprint == HONDA_CAR.HONDA_ACCORD
|
||||
|
||||
def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, curvature_limited, lat_delay):
|
||||
angle_log = log.ControlsState.LateralAngleState.new_message()
|
||||
@@ -26,6 +31,9 @@ class LatControlAngle(LatControl):
|
||||
else:
|
||||
angle_log.active = True
|
||||
angle_steers_des = math.degrees(VM.get_steer_from_curvature(-desired_curvature, CS.vEgo, params.roll))
|
||||
if self.is_accord:
|
||||
# controlsd took sR from the rack map at the MEASURED angle; re-evaluate it at the desired angle
|
||||
angle_steers_des = accord_angle_at_own_ratio(angle_steers_des, VM.sR)
|
||||
angle_steers_des += params.angleOffsetDeg
|
||||
if self.is_ascent:
|
||||
if self.ascent_angle_target is None:
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
"""Accord on the angle-loop EPS: steerSaturated follows the carcontroller's limiter, not the raw angle error."""
|
||||
import pytest
|
||||
|
||||
from openpilot.cereal import log
|
||||
from opendbc.car import gen_empty_fingerprint
|
||||
from opendbc.car.structs import car
|
||||
from opendbc.car.honda import carcontroller as honda_carcontroller
|
||||
from opendbc.car.honda import interface as honda_interface
|
||||
from opendbc.car.honda.interface import CarInterface as HondaInterface
|
||||
from opendbc.car.honda.values import CAR as HONDA, HondaFlags
|
||||
from opendbc.car.nissan.interface import CarInterface as NissanInterface
|
||||
from opendbc.car.nissan.values import CAR as NISSAN
|
||||
from opendbc.car.structs import CarParams
|
||||
from opendbc.car.vehicle_model import VehicleModel
|
||||
from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle
|
||||
|
||||
DT = 0.01
|
||||
ERROR_DEG = 6.0 # an ordinary turn-entry error on the angle-loop EPS, above the 2.5 deg raw-error threshold
|
||||
|
||||
|
||||
class FakeParams:
|
||||
def get_bool(self, key, block=False, default=False):
|
||||
return default
|
||||
|
||||
def get_float(self, key, block=False, default=0.0):
|
||||
return default
|
||||
|
||||
def put_float(self, key, value):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fake_params(monkeypatch):
|
||||
# the Honda port may read Params in the interface/carcontroller; keep the test off the device store
|
||||
monkeypatch.setattr(honda_interface, "Params", FakeParams, raising=False)
|
||||
monkeypatch.setattr(honda_carcontroller, "Params", FakeParams, raising=False)
|
||||
|
||||
|
||||
def accord_cp(eps_fw: bytes):
|
||||
car_fw = [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=eps_fw, address=0x18DA30F1, subAddress=0)]
|
||||
return HondaInterface.get_params(HONDA.HONDA_ACCORD, gen_empty_fingerprint(), car_fw, False, False, False)
|
||||
|
||||
|
||||
def angle_cp():
|
||||
return accord_cp(b"39990-TVA,A16C")
|
||||
|
||||
|
||||
def torque_honda_cp():
|
||||
return accord_cp(b"39990-TVA-A160\x00\x00")
|
||||
|
||||
|
||||
def nissan_cp():
|
||||
return NissanInterface.get_non_essential_params(NISSAN.NISSAN_LEAF)
|
||||
|
||||
|
||||
def run(cp, steer_limited_by_safety, seconds=2.0, v_ego=20.0):
|
||||
cp_reader = cp.as_reader()
|
||||
controller = LatControlAngle(cp_reader, None, DT)
|
||||
VM = VehicleModel(cp_reader)
|
||||
params = log.VehicleParameters.new_message()
|
||||
CS = car.CarState.new_message()
|
||||
CS.vEgo = v_ego
|
||||
CS.steeringPressed = False
|
||||
CS.steeringAngleDeg = 0.0
|
||||
# find the desired angle for a small curvature, then hold the wheel ERROR_DEG short of it
|
||||
_, angle_des, _ = controller.update(True, CS, VM, params, False, 0.002, False, 0.2)
|
||||
controller.reset()
|
||||
CS.steeringAngleDeg = angle_des - ERROR_DEG
|
||||
saturated = []
|
||||
for _ in range(round(seconds / DT)):
|
||||
_, des, lac_log = controller.update(True, CS, VM, params, steer_limited_by_safety, 0.002, False, 0.2)
|
||||
assert abs((des - CS.steeringAngleDeg) - ERROR_DEG) < 1e-6
|
||||
saturated.append(lac_log.saturated)
|
||||
return controller, saturated
|
||||
|
||||
|
||||
def test_accord_angle_cp_takes_the_carcontroller_path():
|
||||
cp = angle_cp()
|
||||
assert cp.steerControlType == CarParams.SteerControlType.angle
|
||||
assert cp.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||
assert cp.steerLimitTimer == pytest.approx(0.8)
|
||||
|
||||
|
||||
def test_accord_angle_error_alone_does_not_saturate():
|
||||
controller, saturated = run(angle_cp(), steer_limited_by_safety=False)
|
||||
assert controller.use_steer_limited_by_safety
|
||||
assert not any(saturated)
|
||||
|
||||
|
||||
def test_accord_angle_limited_by_carcontroller_saturates():
|
||||
_, saturated = run(angle_cp(), steer_limited_by_safety=True)
|
||||
assert saturated[-1]
|
||||
# debounced by steerLimitTimer (0.8 s), not instantly
|
||||
assert not saturated[round(0.7 / DT)]
|
||||
|
||||
|
||||
def test_accord_angle_curvature_limited_still_saturates():
|
||||
cp = angle_cp().as_reader()
|
||||
controller = LatControlAngle(cp, None, DT)
|
||||
VM = VehicleModel(cp)
|
||||
CS = car.CarState.new_message()
|
||||
CS.vEgo = 20.0
|
||||
params = log.VehicleParameters.new_message()
|
||||
for _ in range(200):
|
||||
_, _, lac_log = controller.update(True, CS, VM, params, False, 0.0, True, 0.2)
|
||||
assert lac_log.saturated
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cp_fn", [torque_honda_cp, nissan_cp], ids=["honda_torque_fw", "nissan"])
|
||||
def test_other_cars_keep_the_angle_error_rule(cp_fn):
|
||||
controller, saturated = run(cp_fn(), steer_limited_by_safety=False)
|
||||
assert not controller.use_steer_limited_by_safety
|
||||
assert saturated[-1]
|
||||
|
||||
|
||||
def test_tesla_still_uses_carcontroller_path():
|
||||
from opendbc.car.tesla.interface import CarInterface as TeslaInterface
|
||||
from opendbc.car.tesla.values import CAR as TESLA
|
||||
controller, saturated = run(TeslaInterface.get_non_essential_params(TESLA.TESLA_MODEL_3), steer_limited_by_safety=False)
|
||||
assert controller.use_steer_limited_by_safety
|
||||
assert not any(saturated)
|
||||
Binary file not shown.
Binary file not shown.
@@ -607,12 +607,13 @@ int main() {
|
||||
unsupported.safety_param ^= 0x1U;
|
||||
assert(!aol_capable(unsupported, TEST_MODE, TEST_REGISTRY));
|
||||
|
||||
for (uint16_t word = 0U; word < 4096U; ++word) {
|
||||
for (uint16_t word = 0U; word < 8192U; ++word) {
|
||||
auto stock_honda = status();
|
||||
stock_honda.safety_mode = 20U;
|
||||
stock_honda.safety_param = word;
|
||||
const bool classic = word == 34U || word == 35U || word == 163U;
|
||||
const bool stock = word == 0U || word == 1U || word == 8U || word == 9U || word == 10U || word == 11U || word == 16U || word == 17U || word == 80U || word == 81U || word == 512U || word == 513U || word == 1058U || word == 1059U || word == 1570U || word == 1571U || word == 2082U || word == 2083U || word == 2211U;
|
||||
const bool stock = word == 0U || word == 1U || word == 8U || word == 9U || word == 10U || word == 11U || word == 16U || word == 17U || word == 80U || word == 81U || word == 512U || word == 513U || word == 1058U || word == 1059U || word == 1570U || word == 1571U || word == 2082U || word == 2083U || word == 2211U ||
|
||||
word == 4096U || word == 4097U || word == 6178U || word == 6179U;
|
||||
assert(aol_capable(stock_honda, 20U, VEHICLE_REGISTRY) == (classic || stock));
|
||||
assert(aol_runtime_enabled(false, stock_honda, VEHICLE_REGISTRY) == stock);
|
||||
stock_honda.safety_mode = 1U;
|
||||
|
||||
@@ -12,6 +12,7 @@ from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.common.filter_simple import FirstOrderFilter
|
||||
from openpilot.starpilot.ui.torque_feedback import accord_angle_error_bar, accord_angle_error_fraction
|
||||
|
||||
# TODO: arc_bar_pts doesn't consider rounded end caps part of the angle span
|
||||
TORQUE_ANGLE_SPAN = 12.7 # degrees on the default 476 px camera view; narrower views beside the navigation panel scale down
|
||||
@@ -162,6 +163,18 @@ class TorqueBar(Widget):
|
||||
if self._demo:
|
||||
return
|
||||
|
||||
# Accord on the angle-loop EPS firmware: the bar is the angle error the setpoint carries,
|
||||
# (setpoint sent - wheel angle) / the carcontroller's error clip at this speed, so full
|
||||
# scale means the clip is binding. Sign follows the torque branch: bar points the way the EPS pulls.
|
||||
if accord_angle_error_bar(ui_state.CP):
|
||||
car_state = ui_state.sm['carState']
|
||||
if not ui_state.sm['carControl'].latActive:
|
||||
self._torque_filter.update(0.0)
|
||||
else:
|
||||
setpoint = ui_state.sm['carOutput'].actuatorsOutput.steeringAngleDeg
|
||||
self._torque_filter.update(accord_angle_error_fraction(setpoint, car_state.steeringAngleDeg, car_state.vEgoRaw))
|
||||
return
|
||||
|
||||
# torque line
|
||||
if ui_state.sm['controlsState'].lateralControlState.which() in ('angleState', 'curvatureState'):
|
||||
controls_state = ui_state.sm['controlsState']
|
||||
|
||||
@@ -11,7 +11,8 @@ inline constexpr AolSafetyProfile HONDA_AOL_PROFILE{20U, honda_aol_param, false}
|
||||
|
||||
inline bool honda_stock_aol_param(uint16_t param) {
|
||||
return (param == 0U) || (param == 1U) || (param == 8U) || (param == 9U) || (param == 10U) || (param == 11U) || (param == 16U) || (param == 17U) || (param == 80U) || (param == 81U) || (param == 512U) || (param == 513U) ||
|
||||
(param == 1058U) || (param == 1059U) || (param == 1570U) || (param == 1571U) || (param == 2082U) || (param == 2083U) || (param == 2211U);
|
||||
(param == 1058U) || (param == 1059U) || (param == 1570U) || (param == 1571U) || (param == 2082U) || (param == 2083U) || (param == 2211U) ||
|
||||
(param == 4096U) || (param == 4097U) || (param == 6178U) || (param == 6179U);
|
||||
}
|
||||
|
||||
inline bool honda_nidec_aol_param(uint16_t param) {
|
||||
|
||||
@@ -4,6 +4,7 @@ from copy import deepcopy
|
||||
from types import SimpleNamespace as NS
|
||||
import unittest
|
||||
|
||||
from opendbc.car.honda.values import HondaFlags
|
||||
from openpilot.starpilot.ui.torque_feedback import observe_torque_feedback
|
||||
|
||||
|
||||
@@ -128,6 +129,27 @@ class TorqueFeedbackTests(unittest.TestCase):
|
||||
output.lateralControlMode = "newUnknownChannel"
|
||||
self.assertIsNone(observe(sm, cp).utilization)
|
||||
|
||||
def test_accord_angle_loop_shows_angle_error_not_roll(self):
|
||||
sm = Messages("angleState")
|
||||
cp = NS(brand="honda", flags=HondaFlags.EPS_ANGLE_LOOP_FW.value, maxLateralAccel=3.5886)
|
||||
sm["carState"].steeringAngleDeg = 1.0
|
||||
sm["carState"].vEgo = sm["carState"].vEgoRaw = 26.9
|
||||
sm["carOutput"].actuatorsOutput.steeringAngleDeg = 1.0
|
||||
sm["vehicleParameters"].roll = 0.0326 # the device's standing +1.87 deg roll bias
|
||||
sm["controlsState"].curvature = sm["controlsState"].desiredCurvature = 0.0
|
||||
self.assertEqual((observe(sm, cp).utilization, observe(sm, cp).source), (0.0, "angle_error"))
|
||||
self.assertEqual(observe(sm, NS(brand="honda", flags=0, maxLateralAccel=3.5886)).source, "lateral_acceleration_demand",
|
||||
"without the angle-loop flag the bar shows the lateral-acceleration demand")
|
||||
sm["carOutput"].actuatorsOutput.steeringAngleDeg = 1.0 + 6.1 # left of the wheel by half the 12.2 deg clip
|
||||
self.assertAlmostEqual(observe(sm, cp).utilization, -0.5)
|
||||
sm["carOutput"].actuatorsOutput.steeringAngleDeg = 1.0 - 50.0
|
||||
self.assertEqual(observe(sm, cp).utilization, 1.0)
|
||||
sm["carControl"].latActive = False
|
||||
self.assertEqual(observe(sm, cp).utilization, 0.0)
|
||||
sm["carControl"].latActive = True
|
||||
del sm["carOutput"]
|
||||
self.assertIsNone(observe(sm, cp).utilization)
|
||||
|
||||
def test_read_only(self):
|
||||
sm = Messages("angleState")
|
||||
before = deepcopy(vars(sm)), repr(sm)
|
||||
|
||||
@@ -4,6 +4,9 @@ from dataclasses import dataclass
|
||||
import math
|
||||
from typing import Any, Literal
|
||||
|
||||
import numpy as np
|
||||
from opendbc.car.honda.values import CarControllerParams as HondaParams, HondaFlags
|
||||
|
||||
|
||||
DEFAULT_MAX_LATERAL_ACCELERATION = 3.0
|
||||
LATERAL_STATES = frozenset(("pidState", "angleState", "debugState", "torqueState", "curvatureState",
|
||||
@@ -13,10 +16,26 @@ LATERAL_STATES = frozenset(("pidState", "angleState", "debugState", "torqueState
|
||||
@dataclass(frozen=True)
|
||||
class TorqueFeedback:
|
||||
utilization: float | None = None
|
||||
source: Literal["unavailable", "actuator_output", "lateral_acceleration_demand"] = "unavailable"
|
||||
source: Literal["unavailable", "actuator_output", "lateral_acceleration_demand", "angle_error"] = "unavailable"
|
||||
reason: str = "car_state_unavailable"
|
||||
|
||||
|
||||
def accord_angle_error_bar(car_params: Any) -> bool:
|
||||
try:
|
||||
return car_params.brand == "honda" and bool(car_params.flags & HondaFlags.EPS_ANGLE_LOOP_FW)
|
||||
except (AttributeError, TypeError):
|
||||
return False
|
||||
|
||||
|
||||
def accord_angle_error_fraction(setpoint_deg: float, angle_deg: float, v_ego: float) -> float:
|
||||
"""(setpoint - wheel) over the Accord error clip at this speed, clipped to +-1.
|
||||
|
||||
Negated like the torque branch: openpilot angles are left-positive and the bar draws +x to the
|
||||
right, so the bar must point the way the EPS is pulling the wheel (left pull = bar left)."""
|
||||
error_max = float(np.interp(v_ego, HondaParams.ANGLE_ERROR_MAX_BP, HondaParams.ANGLE_ERROR_MAX_V))
|
||||
return float(np.clip(-(setpoint_deg - angle_deg) / error_max, -1.0, 1.0))
|
||||
|
||||
|
||||
def _finite(value: Any) -> float | None:
|
||||
if type(value) not in (int, float):
|
||||
return None
|
||||
@@ -63,6 +82,15 @@ def observe_torque_feedback(car_state: Any, car_control: Any, controls_state: An
|
||||
return TorqueFeedback(reason="lateral_activity_unavailable")
|
||||
if not control.latActive:
|
||||
return TorqueFeedback(0.0, "lateral_acceleration_demand", "lateral_inactive")
|
||||
# Accord on the angle-loop EPS: show the angle error the setpoint carries, not the lateral-acceleration demand
|
||||
# (the estimate this replaced subtracted road roll, so the device's standing roll bias drew as a constant pull).
|
||||
if accord_angle_error_bar(car_params):
|
||||
setpoint = _finite(getattr(getattr(output, "actuatorsOutput", None), "steeringAngleDeg", None))
|
||||
angle = _finite(getattr(car, "steeringAngleDeg", None))
|
||||
speed = _finite(getattr(car, "vEgoRaw", None))
|
||||
if setpoint is None or angle is None or speed is None:
|
||||
return TorqueFeedback(reason="actuator_output_unavailable")
|
||||
return TorqueFeedback(accord_angle_error_fraction(setpoint, angle, speed), "angle_error", "observed")
|
||||
parameters = vehicle_parameters
|
||||
if parameters is None or getattr(parameters, "valid", None) is not True:
|
||||
return TorqueFeedback(reason="vehicle_parameters_unavailable")
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern const uint8_t gitversion[29];
|
||||
const uint8_t gitversion[29] = "DEV-82f431d8-Pf38f504f-DEBUG";
|
||||
const uint8_t gitversion[29] = "DEV-b666318e-Pf38f504f-DEBUG";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
DEV-ada7b6bd-Pf38f504f-DEBUG
|
||||
DEV-b666318e-Pf38f504f-DEBUG
|
||||
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "49e58307c2116cd8389e57cba937cb1b6e837e511d35a45157410dc0e1eda1ec", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "acef9537777327893a4cfa1443d045b496fe0e7ba60a475073800ccefa318a56", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user