mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 01:53:40 +08:00
Recover rejected Bolt pedal counters without retrying actuation
This commit is contained in:
@@ -313,6 +313,9 @@ class CarController(CarControllerBase):
|
||||
|
||||
self.lka_steering_cmd_counter = 0
|
||||
self.bolt_steering_pending: tuple[int, int] | None = None
|
||||
self.bolt_pedal_recovery = is_bolt_pedal_profile(CP)
|
||||
self.bolt_pedal_last_command = None
|
||||
self.bolt_pedal_rejection_ns = None
|
||||
self.bolt_steering_receipt_seeded = False
|
||||
self.lka_icon_status_last = (False, False)
|
||||
|
||||
@@ -463,6 +466,17 @@ class CarController(CarControllerBase):
|
||||
self.regen_paddle_pressed = commanded_accel < -.02
|
||||
return self.regen_paddle_pressed
|
||||
|
||||
def observe_pedal_rejections(self, can_packets):
|
||||
pending = self.bolt_pedal_last_command
|
||||
if pending is None:
|
||||
return
|
||||
raw, sent_ns = pending
|
||||
for stamp, packets in can_packets:
|
||||
for address, data, bus in packets:
|
||||
if (address == 0x200 and bus == 192 and bytes(data) == raw and
|
||||
sent_ns <= stamp <= sent_ns + 40_000_000):
|
||||
self.bolt_pedal_rejection_ns = stamp
|
||||
|
||||
def observe_steering_receipts(self, can_packets):
|
||||
for stamp, packets in can_packets:
|
||||
for address, raw, bus in packets:
|
||||
@@ -545,6 +559,15 @@ class CarController(CarControllerBase):
|
||||
|
||||
# Send CAN commands.
|
||||
can_sends = []
|
||||
if self.bolt_pedal_rejection_ns is not None:
|
||||
pending = self.bolt_pedal_last_command
|
||||
rejected_ns = self.bolt_pedal_rejection_ns
|
||||
self.bolt_pedal_rejection_ns = None
|
||||
if pending is not None and pending[1] <= rejected_ns <= now_nanos <= pending[1] + 40_000_000:
|
||||
# A rejected active counter never reached the interceptor; fill it with zero output.
|
||||
can_sends.append(gmcan.create_pedal_command(self.packer_pt, 0., pending[0][4] & 0xF))
|
||||
self.bolt_pedal_last_command = None
|
||||
|
||||
cc_gateway = self.CP.carFingerprint in CC_GATEWAY_STOCK_CAR or self.volt_cc_profile
|
||||
stock_cruise_fresh = (not cc_gateway or
|
||||
(CS.cc_gateway_cruise_ts_nanos > 0 and
|
||||
@@ -898,7 +921,10 @@ class CarController(CarControllerBase):
|
||||
if self.bolt_acc_pedal_stop_hold:
|
||||
pedal = 0.0
|
||||
self.pedal_steady = 0.0
|
||||
can_sends.append(gmcan.create_pedal_command(self.packer_pt, pedal, (self.frame // 4) % 16))
|
||||
pedal_command = gmcan.create_pedal_command(self.packer_pt, pedal, (self.frame // 4) % 16)
|
||||
can_sends.append(pedal_command)
|
||||
if self.bolt_pedal_recovery:
|
||||
self.bolt_pedal_last_command = (bytes(pedal_command.dat), now_nanos) if pedal_command.dat[4] & 0x80 else None
|
||||
if CC.enabled:
|
||||
self.paddle_handoff_frames = 2
|
||||
feed_release = bool(self.paddle_handoff_frames)
|
||||
|
||||
@@ -53,6 +53,8 @@ class CarInterface(CarInterfaceBase):
|
||||
return super().apply(c, now_nanos)
|
||||
|
||||
def update(self, can_packets):
|
||||
if self.CC.bolt_pedal_recovery:
|
||||
self.CC.observe_pedal_rejections(can_packets)
|
||||
if self.CC.bolt_steering_ack_counter:
|
||||
self.CC.observe_steering_receipts(can_packets)
|
||||
self.CS.bolt_steering_pending = self.CC.bolt_steering_pending
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from opendbc.car import structs
|
||||
from opendbc.car.gm import gmcan
|
||||
from opendbc.car.gm.carcontroller import CarController
|
||||
from opendbc.car.gm.interface import CarInterface
|
||||
from opendbc.car.gm.tests.test_bolt_pedal import params
|
||||
from opendbc.car.gm.values import CAR, DBC, PEDAL_BOLT_CAR
|
||||
|
||||
|
||||
class TestBoltPedalRejections(unittest.TestCase):
|
||||
def setup_controller(self, candidate=CAR.CHEVROLET_BOLT_ACC_2022_2023_PEDAL):
|
||||
cp = params(candidate, pedal=True)
|
||||
ci = CarInterface(cp)
|
||||
controller = ci.CC
|
||||
controller.frame = controller.last_steer_frame = 4
|
||||
out = structs.CarState(vEgo=1.5, aEgo=0.)
|
||||
out.gearShifter = structs.CarState.GearShifter.low
|
||||
out.cruiseState.available = True
|
||||
cs = SimpleNamespace(stock_acc_status_ts_nanos=1_000_000_000, out=out, pedal_sensor_healthy=True, pedal_sensor_ts_nanos=1_000_000_000,
|
||||
bolt_pedal_standstill_ts_nanos=1_000_000_000,
|
||||
bolt_pedal_main_ts_nanos=1_000_000_000, bolt_pedal_gear_ts_nanos=1_000_000_000,
|
||||
cam_lka_steering_cmd_counter=0, loopback_lka_steering_cmd_updated=False,
|
||||
loopback_lka_steering_cmd_ts_nanos=1_000_000_000,
|
||||
pt_lka_steering_cmd_counter=0, buttons_counter=0)
|
||||
cc = structs.CarControl(enabled=True, longActive=True)
|
||||
cc.actuators.accel = .3
|
||||
cc.actuators.longControlState = structs.CarControl.Actuators.LongControlState.pid
|
||||
return ci, controller, cs, cc
|
||||
|
||||
def test_actual_caller_retries_rejected_active_counter_as_zero(self):
|
||||
for candidate in PEDAL_BOLT_CAR:
|
||||
with self.subTest(candidate=candidate):
|
||||
ci, controller, cs, cc = self.setup_controller(candidate)
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_000_000_000)
|
||||
command = next(m for m in commands if m[0] == 0x200)
|
||||
self.assertTrue(command.dat[4] & 0x80)
|
||||
ci.update([(1_004_000_000, [(command.address, command.dat, 192)])])
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_010_000_000)
|
||||
pedal = [m for m in commands if m[0] == 0x200]
|
||||
self.assertEqual(len(pedal), 1)
|
||||
self.assertEqual(pedal[0].dat, gmcan.create_pedal_command(controller.packer_pt, 0., command.dat[4] & 15).dat)
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_020_000_000)
|
||||
self.assertFalse(any(m[0] == 0x200 for m in commands))
|
||||
|
||||
def test_receipts_require_exact_current_rejected_command(self):
|
||||
for kind in ('accepted', 'bus2', 'different', 'older', 'expired', 'future', 'superseded'):
|
||||
with self.subTest(kind=kind):
|
||||
ci, controller, cs, cc = self.setup_controller()
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_000_000_000)
|
||||
command = next(m for m in commands if m[0] == 0x200)
|
||||
raw = bytearray(command.dat)
|
||||
bus, stamp = 192, 1_004_000_000
|
||||
if kind == 'accepted':
|
||||
bus = 128
|
||||
elif kind == 'bus2':
|
||||
bus = 194
|
||||
elif kind == 'different':
|
||||
raw[0] ^= 1
|
||||
elif kind == 'older':
|
||||
stamp = 999_999_999
|
||||
elif kind == 'expired':
|
||||
stamp = 1_040_000_001
|
||||
elif kind == 'future':
|
||||
stamp = 1_030_000_000
|
||||
ci.update([(stamp, [(0x200, bytes(raw), bus)])])
|
||||
if kind == 'superseded':
|
||||
controller.bolt_pedal_last_command = None
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_010_000_000)
|
||||
self.assertFalse(any(m[0] == 0x200 for m in commands))
|
||||
|
||||
def test_recovery_expiry_and_disabled_commands_do_not_retry(self):
|
||||
for disabled, now in ((False, 1_040_000_001), (True, 1_010_000_000)):
|
||||
ci, controller, cs, cc = self.setup_controller()
|
||||
cc.longActive = not disabled
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_000_000_000)
|
||||
command = next(m for m in commands if m[0] == 0x200)
|
||||
ci.update([(1_004_000_000, [(0x200, command.dat, 192)])])
|
||||
_, commands = controller.update(cc.as_reader(), cs, now)
|
||||
self.assertFalse(any(m[0] == 0x200 for m in commands))
|
||||
|
||||
def test_recovery_precedes_next_scheduled_counter(self):
|
||||
ci, controller, cs, cc = self.setup_controller()
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_000_000_000)
|
||||
command = next(m for m in commands if m[0] == 0x200)
|
||||
ci.update([(1_004_000_000, [(0x200, command.dat, 192)])])
|
||||
controller.frame = controller.last_steer_frame = 8
|
||||
_, commands = controller.update(cc.as_reader(), cs, 1_040_000_000)
|
||||
pedal = [m for m in commands if m[0] == 0x200]
|
||||
self.assertEqual(len(pedal), 2)
|
||||
self.assertFalse(pedal[0].dat[4] & 128)
|
||||
self.assertEqual(pedal[0].dat[4] & 15, command.dat[4] & 15)
|
||||
self.assertTrue(pedal[1].dat[4] & 128)
|
||||
self.assertEqual(pedal[1].dat[4] & 15, (command.dat[4] + 1) & 15)
|
||||
|
||||
def test_stock_and_volt_owners_do_not_admit_recovery(self):
|
||||
for candidate in (CAR.CHEVROLET_VOLT, CAR.CHEVROLET_VOLT_2019, CAR.CHEVROLET_BOLT_EUV):
|
||||
cp = params(candidate, pedal=False)
|
||||
self.assertFalse(getattr(CarController(DBC[candidate], cp), 'bolt_pedal_recovery', False))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "1a982781346731e1bcc732fdd82f03b2ba5ff3fecff0d68ba00434d2fd9865a3", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "ea6ab5d0b6adee40c257b279855e7ba2d56ae7e1eb2466afffc4341da38bd7f7", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user