mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 09:03:43 +08:00
Merge pull request #261 from trung791997/bosch-a-parser-Dom
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@ class RadarInterface(RadarInterfaceBase):
|
||||
self.radar_wrong_config = False
|
||||
self.radar_off_can = CP.radarUnavailable
|
||||
self.bosch_a = None
|
||||
self.v_ego = None # set by card before each update; the Bosch-A decoder's reversing-coast bound reads it
|
||||
if not self.radar_off_can and CP.carFingerprint in (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G):
|
||||
from opendbc.car.honda.bosch_a_radar import BoschARadar
|
||||
self.bosch_a = BoschARadar(CP)
|
||||
@@ -33,8 +34,14 @@ class RadarInterface(RadarInterfaceBase):
|
||||
self.trigger_msg = 0x445
|
||||
self.updated_messages = set()
|
||||
|
||||
@property
|
||||
def point_statuses(self) -> dict[int, int] | None:
|
||||
"""Bosch-A F0 STATUS per point of the last RadarData returned; None for other radars."""
|
||||
return self.bosch_a.point_statuses if self.bosch_a is not None else None
|
||||
|
||||
def update(self, can_strings):
|
||||
if self.bosch_a is not None:
|
||||
self.bosch_a.v_ego = self.v_ego
|
||||
return self.bosch_a.update(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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import pytest
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.can_definitions import CanData
|
||||
from opendbc.car.honda.bosch_a_radar import bosch_a_range_offset_m
|
||||
from opendbc.car.honda.hondacan import CanBus
|
||||
from opendbc.car.honda.interface import CarInterface
|
||||
from opendbc.car.honda.radar_interface import RadarInterface
|
||||
@@ -52,12 +53,12 @@ def make_aux(frame_idx=0, rawc9=0, rawca=0, direct_vrel_raw=BOSCH_A_DIRECT_VREL_
|
||||
return bytes([B0, B1, B2, B3, B4, B5, B6, B7])
|
||||
|
||||
|
||||
def sweep(bus, index, timestamp, with_aux=True):
|
||||
def sweep(bus, index, timestamp, with_aux=True, status=7):
|
||||
frames = []
|
||||
for slot in range(16):
|
||||
base = 0x280 + 4 * slot if slot < 4 else 0x2D0 + 4 * (slot - 4)
|
||||
valid = slot == 0
|
||||
frames.extend((CanData(base, make_f0(index, 7 if valid else 15, 1000, 1024), bus),
|
||||
frames.extend((CanData(base, make_f0(index, status if valid else 15, 1000, 1024), bus),
|
||||
CanData(base + 1, make_f1(index), bus),
|
||||
CanData(base + 2, make_f2(index, 1 + index * 2), bus),
|
||||
CanData(base + 3, make_f3(index, track_id=1 if valid else 255), bus)))
|
||||
@@ -78,14 +79,35 @@ def test_actual_parser_points_silence_retires_and_new_track_recovers(identity):
|
||||
second = ri.update(sweep(bus, 1, 1_066_666_667))
|
||||
assert not second.errors.canError
|
||||
assert len(second.points) == 1
|
||||
assert second.points[0].dRel == pytest.approx(0.05712 * 1000 - 3.0)
|
||||
# firmware range: raw/16 minus the car's ROM offset n0/128 (Civic 346, CR-V 341)
|
||||
assert second.points[0].dRel == pytest.approx(1000 / 16 + bosch_a_range_offset_m(identity))
|
||||
assert second.points[0].yRel == pytest.approx(0.0)
|
||||
stale = ri.update([(1_400_000_000, [])])
|
||||
assert stale is not None and not stale.points and stale.errors.radarUnavailableTemporary
|
||||
assert ri.point_statuses == {}
|
||||
assert not ri.update(sweep(bus, 2, 1_466_666_667)).points
|
||||
assert len(ri.update(sweep(bus, 3, 1_533_333_334)).points) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("identity", (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G))
|
||||
def test_point_status_is_the_status_nibble_of_its_latest_observation(identity):
|
||||
# route 34 T479: the phantom lead's track was STATUS 9 for its first ~4 s, then 7
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
ri = RadarInterface(cp)
|
||||
bus = CanBus(cp).camera
|
||||
assert ri.point_statuses == {}
|
||||
ri.update(sweep(bus, 0, 1_000_000_000, status=9))
|
||||
unconfirmed = ri.update(sweep(bus, 1, 1_066_666_667, status=9))
|
||||
assert ri.point_statuses == {p.trackId: 9 for p in unconfirmed.points} and len(unconfirmed.points) == 1
|
||||
confirmed = ri.update(sweep(bus, 2, 1_133_333_334))
|
||||
assert ri.point_statuses == {p.trackId: 7 for p in confirmed.points} and len(confirmed.points) == 1
|
||||
|
||||
|
||||
def test_point_status_is_none_without_a_bosch_a_radar():
|
||||
cp = CarInterface.get_params(CAR.HONDA_CIVIC, gen_empty_fingerprint(), [], False, False, False)
|
||||
assert RadarInterface(cp).point_statuses is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("identity", (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G))
|
||||
def test_wrong_bus_cannot_create_radar_points(identity):
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
@@ -140,6 +162,15 @@ def test_actual_card_startup_publishes_radar_preference_before_construction(iden
|
||||
card = Car()
|
||||
assert card.CP.to_dict() == expected
|
||||
assert (RadarInterface(card.CP).rcp is not None) == available
|
||||
if saved_raw is None:
|
||||
car_state = card.CI.update([])
|
||||
car_state.vEgo = 9.6
|
||||
with monkeypatch.context() as input_batch:
|
||||
input_batch.setattr(card_module.messaging, "drain_sock_raw", lambda *args, **kwargs: [])
|
||||
input_batch.setattr(card.CI, "update", lambda frames: car_state)
|
||||
returned, radar_data = card.state_update(defer_radar=True)
|
||||
assert returned is car_state and radar_data is None
|
||||
assert card.RI.v_ego == pytest.approx(9.6)
|
||||
with structs.CarParams.from_bytes(saved.get("CarParams")) as published:
|
||||
assert published.to_dict() == expected
|
||||
for _ in range(10):
|
||||
|
||||
@@ -544,6 +544,7 @@ class Car:
|
||||
# Update carState from CAN
|
||||
observe_controller_can(self.CI, can_list)
|
||||
CS = self.CI.update(can_list)
|
||||
self.RI.v_ego = CS.vEgo # the Honda Bosch-A decoder bounds a reversing coast with it
|
||||
from openpilot.starpilot.car.gm.aol import f1_conventional_lateral_owner
|
||||
cancel_boot_ns = (time.clock_gettime_ns(time.CLOCK_BOOTTIME)
|
||||
if (getattr(self.CI.CS, 'ev6_aol_source_healthy', False) or
|
||||
|
||||
@@ -208,7 +208,8 @@ class RadarD:
|
||||
if honda_bosch_a_radar:
|
||||
from openpilot.starpilot.car.honda.radar import BoschALeadPolicy
|
||||
self.honda_bosch_a = BoschALeadPolicy()
|
||||
self.kalman_params = KalmanParams(1.0 / 15.0 if self.honda_bosch_a is not None else DT_MDL)
|
||||
from opendbc.car.honda.bosch_a_radar import BOSCH_A_FREQ_HZ
|
||||
self.kalman_params = KalmanParams(1.0 / BOSCH_A_FREQ_HZ if self.honda_bosch_a is not None else DT_MDL)
|
||||
self.lead_prob_filters = [FirstOrderFilter(0.0, 0.2, DT_MDL) for _ in range(2)]
|
||||
|
||||
self.v_ego = 0.0
|
||||
|
||||
@@ -341,6 +341,11 @@ class BoschALeadPolicy:
|
||||
self.tracks[identifier] = Track(identifier, v_lead, radar.kalman_params)
|
||||
measured = bool(point.deprecated.measured and fresh)
|
||||
self.tracks[identifier].update(point.dRel, point.yRel, point.vRel, v_lead, measured, measured)
|
||||
if not point.deprecated.measured:
|
||||
# A range-based coast can close faster than its frozen velocity filter.
|
||||
track = self.tracks[identifier]
|
||||
track.vLeadK = min(track.vLeadK, track.vLead)
|
||||
|
||||
|
||||
def leads(self, sm, radar, model_v_ego):
|
||||
leads = sm['modelV2'].leadsV3
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import copy
|
||||
import math
|
||||
import pytest
|
||||
from opendbc.car import gen_empty_fingerprint
|
||||
from opendbc.car.honda.bosch_a_radar import BOSCH_A_FREQ_HZ
|
||||
from opendbc.car.honda.hondacan import CanBus
|
||||
from opendbc.car.honda.interface import CarInterface
|
||||
from opendbc.car.honda.radar_interface import RadarInterface
|
||||
from opendbc.car.honda.tests.test_bosch_a_radar import sweep, make_f0, make_aux
|
||||
from opendbc.car.honda.values import CAR
|
||||
from openpilot.cereal import messaging
|
||||
from openpilot.selfdrive.controls.radard import RadarD
|
||||
from openpilot.starpilot.car.honda.tests.test_radar_pipeline import source_tick
|
||||
|
||||
|
||||
def frames(cp, index, distance, raw=864, uncertainty=0, range_sigma=1):
|
||||
data = sweep(CanBus(cp).camera, index, 1_000_000_000 + int(index * 1e9 / BOSCH_A_FREQ_HZ))
|
||||
offset = -346 / 128 if cp.carFingerprint == CAR.HONDA_CIVIC_BOSCH else -341 / 128
|
||||
data[0] = (
|
||||
data[0][0],
|
||||
[
|
||||
f._replace(dat=make_f0(index, 7, round((distance - offset) * 16), 1024, range_sigma_raw=range_sigma))
|
||||
if f.address == 0x280
|
||||
else f._replace(dat=make_aux(index, rawca=500, direct_vrel_raw=raw, direct_vrel_uncertainty_raw=uncertainty))
|
||||
if f.address == 0x2C8
|
||||
else f
|
||||
for f in data[0][1]
|
||||
],
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G))
|
||||
def test_decoder_coast_and_floor_keep_geometry_without_kalman_measurements(identity):
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
decoder = RadarInterface(cp)
|
||||
decoder.v_ego = 20.0
|
||||
radar = RadarD(honda_bosch_a_radar=True)
|
||||
sm = messaging.SubMaster(['modelV2', 'carState', 'radarTracks'])
|
||||
for i in range(5):
|
||||
rr = decoder.update(frames(cp, i, 50.0))
|
||||
source_tick(sm, i, rr, speed=20, probability=0.99, distance=50)
|
||||
radar.update(sm, sm['radarTracks'])
|
||||
track = radar.tracks[1]
|
||||
state = copy.deepcopy(track.kf.x)
|
||||
count = track.cnt
|
||||
for i in range(5, 20):
|
||||
rr = decoder.update(frames(cp, i, 50.0, raw=0 if i >= 10 else 864, uncertainty=0 if i >= 10 else 600))
|
||||
assert len(rr.points) == 1 and not rr.points[0].deprecated.measured
|
||||
source_tick(sm, i, rr, speed=20, probability=0.99, distance=50)
|
||||
radar.update(sm, sm['radarTracks'])
|
||||
assert track.cnt == count and track.kf.x == state and not track.measured
|
||||
assert radar.radar_state.leadOne.radar
|
||||
rr = decoder.update([(3_000_000_000, [])])
|
||||
source_tick(sm, 20, rr, speed=20)
|
||||
radar.update(sm, sm['radarTracks'])
|
||||
assert not radar.tracks and not radar.radar_state.leadOne.radar
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G))
|
||||
def test_floor_born_stopped_object_uses_closing_range_fit_in_planner_lead(identity):
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
decoder = RadarInterface(cp)
|
||||
decoder.v_ego = 20.0
|
||||
radar = RadarD(honda_bosch_a_radar=True)
|
||||
sm = messaging.SubMaster(['modelV2', 'carState', 'radarTracks'])
|
||||
for i in range(10):
|
||||
distance = 50.0 - 20 * i / BOSCH_A_FREQ_HZ
|
||||
rr = decoder.update(frames(cp, i, distance, raw=0))
|
||||
source_tick(sm, i, rr, speed=20, probability=0.99, distance=distance, lead_speed=0.0)
|
||||
radar.update(sm, sm['radarTracks'])
|
||||
point = rr.points[0]
|
||||
track = radar.tracks[1]
|
||||
assert point.vRel < -19.5 and not point.deprecated.measured
|
||||
assert track.cnt == 0 and not track.measured
|
||||
assert radar.radar_state.leadOne.radar
|
||||
assert radar.radar_state.leadOne.vLeadK < 0.5
|
||||
assert track.kf.x[0][0] == 8.0
|
||||
from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.long_mpc import LongitudinalMpc
|
||||
|
||||
mpc = LongitudinalMpc()
|
||||
mpc.set_weights()
|
||||
mpc.set_cur_state(20.0, 0.0)
|
||||
mpc.update(radar.radar_state)
|
||||
assert mpc.solution_status == 0 and min(mpc.a_solution) < -3.0
|
||||
|
||||
|
||||
def test_clarity_retains_nidec_track_decoding_and_no_bosch_metadata():
|
||||
from opendbc.can import CANPacker
|
||||
from opendbc.car.can_definitions import CanData
|
||||
|
||||
cp = CarInterface.get_non_essential_params(CAR.HONDA_CLARITY)
|
||||
decoder = RadarInterface(cp)
|
||||
assert decoder.bosch_a is None and decoder.point_statuses is None
|
||||
packer = CANPacker('acura_ilx_2016_nidec')
|
||||
messages = [
|
||||
packer.make_can_msg('TRACK_0', 1, {'LONG_DIST': 50, 'LAT_DIST': 1.5, 'REL_SPEED': -2, 'NEW_TRACK': 1}),
|
||||
packer.make_can_msg('TRACK_15', 1, {'LONG_DIST': 255}),
|
||||
]
|
||||
rr = decoder.update([(1_000_000_000, [CanData(*msg) for msg in messages])])
|
||||
assert len(rr.points) == 1
|
||||
assert rr.points[0].dRel == 50 and rr.points[0].yRel == -1.5 and rr.points[0].vRel == -2
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', tuple(CAR))
|
||||
def test_honda_configuration_decoder_routing_stays_restricted(identity):
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
decoder = RadarInterface(cp)
|
||||
if identity in (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G):
|
||||
assert decoder.bosch_a is not None
|
||||
else:
|
||||
assert decoder.bosch_a is None
|
||||
assert decoder.point_statuses is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('identity', (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G))
|
||||
@pytest.mark.parametrize('rejected_range', (False, True))
|
||||
def test_sustained_rejections_bound_history_without_changing_points(identity, rejected_range, monkeypatch):
|
||||
import opendbc.car.honda.bosch_a_radar as decoder_module
|
||||
|
||||
cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], False, False, False)
|
||||
batches = [
|
||||
frames(cp, i, 60.0 if rejected_range and i >= 5 else 50.0, raw=864 if rejected_range or i < 5 else 72, range_sigma=4 if rejected_range else 1)
|
||||
for i in range(300)
|
||||
]
|
||||
reference = RadarInterface(cp)
|
||||
with monkeypatch.context() as unbounded:
|
||||
unbounded.setattr(decoder_module, '_bosch_a_trim_run', lambda run: None)
|
||||
expected = [reference.update(batch).to_bytes() for batch in batches]
|
||||
decoder = RadarInterface(cp)
|
||||
for batch, original in zip(batches, expected, strict=True):
|
||||
assert decoder.update(batch).to_bytes() == original
|
||||
track = decoder.bosch_a._tracks[1]
|
||||
run = track.rejected_run if rejected_range else track.inconsistent_run
|
||||
original_run = reference.bosch_a._tracks[1].rejected_run if rejected_range else reference.bosch_a._tracks[1].inconsistent_run
|
||||
assert len(original_run) > 250
|
||||
assert len(run) <= 2 + max(decoder_module.BOSCH_A_REANCHOR_WINDOW, math.ceil(BOSCH_A_FREQ_HZ * decoder_module.BOSCH_A_COAST_FIT_WINDOW_S))
|
||||
assert run[0] == original_run[0]
|
||||
assert run[-decoder_module.BOSCH_A_REANCHOR_WINDOW :] == original_run[-decoder_module.BOSCH_A_REANCHOR_WINDOW :]
|
||||
@@ -3,6 +3,7 @@ import copy
|
||||
import pytest
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.honda.bosch_a_radar import BOSCH_A_FREQ_HZ
|
||||
from opendbc.car.honda.hondacan import CanBus
|
||||
from opendbc.car.honda.interface import CarInterface
|
||||
from opendbc.car.honda.radar_interface import RadarInterface
|
||||
@@ -12,7 +13,7 @@ from openpilot.cereal import messaging
|
||||
from openpilot.selfdrive.controls.radard import RadarD
|
||||
|
||||
|
||||
def source_tick(sm, tick, rr=None, speed=0.0, probability=0.0, distance=10.0, standstill=False):
|
||||
def source_tick(sm, tick, rr=None, speed=0.0, probability=0.0, distance=10.0, standstill=False, lead_speed=None):
|
||||
stamp = 1_000_000_000 + tick * 50_000_000
|
||||
model_event = messaging.new_message('modelV2', valid=True)
|
||||
model_event.logMonoTime = stamp
|
||||
@@ -22,7 +23,7 @@ def source_tick(sm, tick, rr=None, speed=0.0, probability=0.0, distance=10.0, st
|
||||
for lead in leads:
|
||||
lead.x = [distance + 1.52]
|
||||
lead.y = [0.0]
|
||||
lead.v = [speed]
|
||||
lead.v = [speed if lead_speed is None else lead_speed]
|
||||
lead.a = [0.0]
|
||||
lead.xStd = lead.yStd = lead.vStd = [1.0]
|
||||
lead.prob = probability
|
||||
@@ -67,7 +68,7 @@ def test_actual_radard_duplicate_and_predicted_point_hold_kalman_measurement():
|
||||
source_tick(sm, 3, radar_data(True, 2.0), speed=20.0)
|
||||
radar.update(sm, sm['radarTracks'])
|
||||
assert track.cnt == 2 and track.kf.x != original and track.measured
|
||||
assert radar.kalman_params.A[0][1] == pytest.approx(1.0 / 15.0)
|
||||
assert radar.kalman_params.A[0][1] == pytest.approx(1.0 / BOSCH_A_FREQ_HZ)
|
||||
|
||||
|
||||
def test_non_honda_radard_keeps_ordinary_duplicate_measurement_behavior():
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "20f6b8a98b3999009ef8c9e39253d3988d9a51b939dec3ac36c5a950b88160c5", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "383e0cdbc31d3c1df0c5adaa4f19606f78f44b1c1b6b498f20be507da050ac5c", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user