mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 03:45:55 +08:00
Keep ACC Bolt dashboard status through physical paddle input
This commit is contained in:
@@ -254,8 +254,12 @@ def bolt_acc_pedal_dashboard_sensor_ready(CS, now_nanos):
|
||||
0 <= now_nanos - CS.stock_acc_status_ts_nanos <= STOCK_ACC_STATUS_TIMEOUT_NS)
|
||||
|
||||
|
||||
def bolt_acc_pedal_dashboard_drive_ready(CS, now_nanos):
|
||||
return (CS.out.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.low) and
|
||||
def bolt_acc_pedal_dashboard_drive_ready(CS, now_nanos, *, allow_paddle=False):
|
||||
paddle_ns, paddle_gear = getattr(CS, "bolt_acc_dashboard_paddle", (0, False))
|
||||
paddle_display = (allow_paddle and paddle_gear and CS.out.regenBraking and
|
||||
CS.out.gearShifter == structs.CarState.GearShifter.manumatic and
|
||||
0 < paddle_ns <= now_nanos <= paddle_ns + PEDAL_SENSOR_TIMEOUT_NS)
|
||||
return ((CS.out.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.low) or paddle_display) and
|
||||
CS.bolt_pedal_gear_ts_nanos > 0 and 0 <= now_nanos - CS.bolt_pedal_gear_ts_nanos <= 100_000_000 and
|
||||
CS.bolt_pedal_main_ts_nanos > 0 and 0 <= now_nanos - CS.bolt_pedal_main_ts_nanos <= 300_000_000)
|
||||
|
||||
@@ -930,7 +934,8 @@ class CarController(CarControllerBase):
|
||||
self.CP.carFingerprint == CAR.CHEVROLET_BOLT_ACC_2022_2023_PEDAL and
|
||||
is_bolt_pedal_profile(self.CP) and len(self.CP.safetyConfigs) == 1 and
|
||||
self.CP.safetyConfigs[0].safetyParam == 0x1CD and CS.out.canValid and not CS.out.canTimeout and
|
||||
bolt_acc_pedal_dashboard_sensor_ready(CS, now_nanos) and CS.out.cruiseState.available and bolt_acc_pedal_dashboard_drive_ready(CS, now_nanos)
|
||||
bolt_acc_pedal_dashboard_sensor_ready(CS, now_nanos) and CS.out.cruiseState.available and
|
||||
bolt_acc_pedal_dashboard_drive_ready(CS, now_nanos, allow_paddle=True)
|
||||
)
|
||||
if dashboard_ready:
|
||||
fcw = 3 if hud_alert == VisualAlert.fcw else int(getattr(CS, "stock_fcw_alert", 0)) & 3
|
||||
|
||||
@@ -76,6 +76,7 @@ class CarState(CarStateBase):
|
||||
self.pedal_sensor_healthy = False
|
||||
self.pedal_sensor_ts_nanos = 0
|
||||
self.bolt_pedal_gear_ts_nanos = 0
|
||||
self.bolt_acc_dashboard_paddle = (0, False)
|
||||
self.bolt_pedal_main_ts_nanos = 0
|
||||
self.pedal_sensor_counter = None
|
||||
self.pedal_packer = CANPacker(DBC[CP.carFingerprint][Bus.pt]) if CP.flags & GMFlags.PEDAL_LONG.value else None
|
||||
@@ -163,6 +164,12 @@ class CarState(CarStateBase):
|
||||
self.bolt_pedal_gear_ts_nanos = (self.conventional_cancel_credit.gear_ns if present_no_acc_pedal else
|
||||
pt_cp.ts_nanos["ECMPRDNL2"]["PRNDL2"])
|
||||
self.bolt_pedal_main_ts_nanos = pt_cp.ts_nanos["ECMEngineStatus"]["CruiseMainOn"]
|
||||
gear = pt_cp.vl["ECMPRDNL2"]
|
||||
self.bolt_acc_dashboard_paddle = (
|
||||
pt_cp.ts_nanos["EBCMRegenPaddle"]["RegenPaddle"],
|
||||
gear["PRNDL2"] == 5 and gear["ManualMode"] == 1 and
|
||||
pt_cp.vl["EBCMRegenPaddle"]["RegenPaddle"] == 2,
|
||||
)
|
||||
|
||||
if self.camera_pedal_profile is not None:
|
||||
analog = (("ECMAcceleratorPos", "BrakePedalPos") if self.camera_pedal_profile.brake_source == BrakeSource.BE else
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from opendbc.car import structs
|
||||
from opendbc.car.gm import gmcan
|
||||
from opendbc.car.gm.bolt_cc import button_bytes
|
||||
from opendbc.car.gm.carcontroller import bolt_acc_pedal_dashboard_drive_ready
|
||||
from opendbc.car.gm.tests import test_bolt_pedal as host_fixture
|
||||
from opendbc.car.gm.values import CAR, GMSafetyFlags
|
||||
from opendbc.safety.tests import test_gm_bolt_pedal as native_fixture
|
||||
from opendbc.safety.tests.libsafety import libsafety_py
|
||||
|
||||
|
||||
@pytest.mark.parametrize('gear,manual,paddle,expected', [
|
||||
(4, 0, 0, True), (6, 0, 0, True), (5, 1, 2, True),
|
||||
(5, 0, 2, False), (5, 1, 0, False), (5, 1, 1, False), (5, 1, 3, False),
|
||||
(0, 1, 2, False), (1, 1, 2, False), (2, 1, 2, False), (3, 1, 2, False),
|
||||
(4, 1, 2, False), (6, 1, 2, False), (7, 1, 2, False),
|
||||
])
|
||||
def test_native_dashboard_physical_paddle_scope(gear, manual, paddle, expected):
|
||||
case = native_fixture.TestGmBoltPedalSafety()
|
||||
case.setUp()
|
||||
case.init_mode(GMSafetyFlags.BOLT_ACC_PEDAL | GMSafetyFlags.BOLT_GEN2)
|
||||
safety = case.safety
|
||||
safety.set_timer(1)
|
||||
for name, values in (
|
||||
('ECMPRDNL2', {'PRNDL2': gear, 'ManualMode': manual}),
|
||||
('AcceleratorPedal2', {'CruiseState': 0}), ('ECMEngineStatus', {'CruiseMainOn': 1}),
|
||||
('PSCMStatus', {}), ('EBCMWheelSpdRear', {}),
|
||||
('EBCMRegenPaddle', {'RegenPaddle': paddle}), ('ASCMSteeringButton', {}),
|
||||
):
|
||||
assert safety.safety_rx_hook(case.stock(name, values))
|
||||
assert safety.safety_rx_hook(case.sensor(1))
|
||||
safety.safety_tick()
|
||||
assert safety.safety_config_valid()
|
||||
hud = structs.CarControl.HUDControl(leadDistanceBars=3)
|
||||
dashboard = gmcan.create_acc_dashboard_command(case.packer, 0, False, 72., hud, False, cruise_state=2)
|
||||
assert bool(safety.safety_tx_hook(case.packet(dashboard))) == expected
|
||||
assert safety.safety_fwd_hook(2, 0x370) == (-1 if expected else 0)
|
||||
active = gmcan.create_acc_dashboard_command(case.packer, 0, True, 72., hud, False, cruise_state=2)
|
||||
assert not safety.safety_tx_hook(case.packet(active))
|
||||
if manual or gear not in (4, 6):
|
||||
safety.set_controls_allowed(True)
|
||||
assert not safety.safety_tx_hook(case.packet(gmcan.create_pedal_command(case.packer, .2, 1)))
|
||||
assert case.recorded() == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize('invalid', ['paddle_stale', 'gear_stale', 'sensor_fault', 'main_off', 'relay', 'reset'])
|
||||
def test_native_dashboard_paddle_keeps_source_and_fault_guards(invalid):
|
||||
case = native_fixture.TestGmBoltPedalSafety()
|
||||
case.setUp()
|
||||
case.init_mode(GMSafetyFlags.BOLT_ACC_PEDAL | GMSafetyFlags.BOLT_GEN2)
|
||||
s = case.safety
|
||||
s.set_timer(1)
|
||||
assert s.safety_rx_hook(case.stock('ECMPRDNL2', {'PRNDL2': 5, 'ManualMode': 1}))
|
||||
assert s.safety_rx_hook(case.stock('EBCMRegenPaddle', {'RegenPaddle': 2}))
|
||||
s.set_timer(100002)
|
||||
for name, values in (
|
||||
('ECMPRDNL2', {'PRNDL2': 5, 'ManualMode': 1}),
|
||||
('EBCMRegenPaddle', {'RegenPaddle': 2}),
|
||||
('AcceleratorPedal2', {'CruiseState': 0}),
|
||||
('ECMEngineStatus', {'CruiseMainOn': int(invalid != 'main_off')}),
|
||||
('PSCMStatus', {}), ('EBCMWheelSpdRear', {}), ('ASCMSteeringButton', {}),
|
||||
):
|
||||
if (invalid == 'paddle_stale' and name == 'EBCMRegenPaddle' or
|
||||
invalid == 'gear_stale' and name == 'ECMPRDNL2'):
|
||||
continue
|
||||
assert s.safety_rx_hook(case.stock(name, values))
|
||||
assert s.safety_rx_hook(case.sensor(2, state=int(invalid == 'sensor_fault')))
|
||||
s.safety_tick()
|
||||
if invalid == 'relay':
|
||||
s.set_relay_malfunction(True)
|
||||
if invalid == 'reset':
|
||||
case.init_mode(GMSafetyFlags.BOLT_ACC_PEDAL | GMSafetyFlags.BOLT_GEN2)
|
||||
dashboard = gmcan.create_acc_dashboard_command(case.packer, 0, False, 72., structs.CarControl.HUDControl(), False, cruise_state=2)
|
||||
assert not s.safety_tx_hook(case.packet(dashboard))
|
||||
assert s.safety_fwd_hook(2, 0x370) == (-1 if invalid == 'relay' else 0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('bad', ['none', 'stale_paddle', 'future_paddle', 'stale_gear', 'stale_main', 'not_physical', 'not_regen'])
|
||||
def test_host_dashboard_paddle_does_not_expand_default_drive_gate(bad):
|
||||
now = 1_000_000_000
|
||||
cs = SimpleNamespace(
|
||||
out=SimpleNamespace(gearShifter=structs.CarState.GearShifter.manumatic, regenBraking=bad != 'not_regen'),
|
||||
bolt_acc_dashboard_paddle=(now, bad != 'not_physical'),
|
||||
bolt_pedal_gear_ts_nanos=now, bolt_pedal_main_ts_nanos=now,
|
||||
)
|
||||
if bad in ('stale_paddle', 'future_paddle'):
|
||||
cs.bolt_acc_dashboard_paddle = (now - 100_000_001 if bad == 'stale_paddle' else now + 1, True)
|
||||
if bad == 'stale_gear':
|
||||
cs.bolt_pedal_gear_ts_nanos -= 100_000_001
|
||||
if bad == 'stale_main':
|
||||
cs.bolt_pedal_main_ts_nanos -= 300_000_001
|
||||
assert not bolt_acc_pedal_dashboard_drive_ready(cs, now)
|
||||
assert bolt_acc_pedal_dashboard_drive_ready(cs, now, allow_paddle=True) == (bad == 'none')
|
||||
|
||||
|
||||
def test_actual_parser_controller_six_physical_paddle_cycles_keep_inactive_dashboard():
|
||||
fixture = host_fixture.TestBoltPedalStartupParser()
|
||||
cp = host_fixture.params(CAR.CHEVROLET_BOLT_ACC_2022_2023_PEDAL, pedal=True, camera=True)
|
||||
native = libsafety_py.libsafety
|
||||
assert native.set_safety_hooks(cp.safetyConfigs[0].safetyModel.raw, cp.safetyConfigs[0].safetyParam) == 0
|
||||
native.init_tests()
|
||||
native.reset_recorded_can()
|
||||
ci, _ = fixture.stream(cp, native=native)
|
||||
packer = ci.CS.pedal_packer
|
||||
control = structs.CarControl()
|
||||
for tick in range(144):
|
||||
pressed = tick % 24 in range(4, 20)
|
||||
now = 3_500_000_000 + tick * 10_000_000
|
||||
values = {
|
||||
'ECMPRDNL2': {'PRNDL2': 5 if pressed else 4, 'ManualMode': int(pressed)},
|
||||
'EBCMRegenPaddle': {'RegenPaddle': 2 if pressed else 0},
|
||||
'ECMEngineStatus': {'CruiseMainOn': 1, 'BrakePressed': 1},
|
||||
'AcceleratorPedal2': {'CruiseState': 0}, 'BCMDoorBeltStatus': {'LeftSeatBelt': 1},
|
||||
}
|
||||
frames = [packer.make_can_msg(name, 0, values.get(name, {})) for name in fixture.PT_MESSAGES
|
||||
if name not in ('GAS_SENSOR', 'ASCMSteeringButton')]
|
||||
frames += [host_fixture.TestBoltPedalMessages.sensor(packer, 0, (13 + tick) % 16),
|
||||
(0x1E1, button_bytes(1, tick % 4), 0),
|
||||
packer.make_can_msg('ASCMLKASteeringCmd', 2, {}),
|
||||
packer.make_can_msg('AEBCmd', 2, {}),
|
||||
packer.make_can_msg('ASCMActiveCruiseControlStatus', 2, {}),
|
||||
gmcan.create_friction_brake_command(ci.CC.packer_ch, 2, 0, (tick // 4) % 4, False, False, False, cp)]
|
||||
native.set_timer(now // 1000)
|
||||
for address, raw, bus in frames:
|
||||
assert native.safety_rx_hook(libsafety_py.make_CANPacket(address, bus, raw))
|
||||
native.safety_tick()
|
||||
state = ci.update([(now, frames)])
|
||||
assert state.canValid and not state.canTimeout
|
||||
assert state.regenBraking == pressed
|
||||
assert state.brakePressed
|
||||
ci.CC.frame = 104 + tick
|
||||
_, messages = ci.apply(control.as_reader(), now)
|
||||
dashboard = [m for m in messages if m[0] == 0x370]
|
||||
assert bool(dashboard) == (tick % 4 == 0)
|
||||
for address, raw, bus in dashboard:
|
||||
assert not (raw[2] & 0x80)
|
||||
assert native.safety_tx_hook(libsafety_py.make_CANPacket(address, bus, raw))
|
||||
assert native.safety_fwd_hook(2, 0x370) == -1
|
||||
assert not any(m[0] in (0xBD, 0x1F5) for m in messages)
|
||||
for address, raw, _ in messages:
|
||||
if address == 0x315:
|
||||
assert raw[:2] == bytes((0x10, 0))
|
||||
if address == 0x200:
|
||||
assert raw[:4] == bytes(4) and not (raw[4] & 0x80)
|
||||
if pressed:
|
||||
assert not ci.CC.bolt_pedal_admission(control, ci.CS, now)[0]
|
||||
@@ -133,6 +133,9 @@ static bool gm_bolt_pedal_drive_supported = false;
|
||||
static bool gm_pedal_forward_gear_ready = false;
|
||||
static bool gm_acc_pedal_forward_owner = false;
|
||||
static bool gm_acc_pedal_dashboard_seen = false;
|
||||
static bool gm_acc_dashboard_paddle_gear = false;
|
||||
static bool gm_acc_dashboard_paddle_pressed = false;
|
||||
static uint32_t gm_acc_dashboard_paddle_us = 0U;
|
||||
static uint32_t gm_acc_pedal_dashboard_us = 0U;
|
||||
static bool gm_bolt_pedal_removed = false;
|
||||
static bool gm_bolt_removed_acc_seen = false;
|
||||
@@ -184,8 +187,12 @@ static bool gm_pedal_main_ready(void) {
|
||||
}
|
||||
|
||||
static bool gm_acc_pedal_dashboard_current(void) {
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
const bool paddle_display = gm_acc_dashboard_paddle_gear && gm_acc_dashboard_paddle_pressed &&
|
||||
(safety_get_ts_elapsed(now, gm_acc_dashboard_paddle_us) <= 100000U) &&
|
||||
(safety_get_ts_elapsed(now, gm_regen_gear_last_us) <= 100000U);
|
||||
const bool physical = gm_acc_pedal_forward_owner && gm_pedal_sensor_current() &&
|
||||
gm_pedal_main_ready() && gm_pedal_drive_ready() && gm_acc_status_seen &&
|
||||
gm_pedal_main_ready() && (gm_pedal_drive_ready() || paddle_display) && gm_acc_status_seen &&
|
||||
(safety_get_ts_elapsed(microsecond_timer_get(), gm_acc_status_last_us) <= 300000U) &&
|
||||
!safety_rx_checks_invalid && !relay_malfunction;
|
||||
if (!physical) { gm_acc_pedal_dashboard_seen = false; }
|
||||
@@ -483,6 +490,8 @@ static void gm_rx_hook(const CANPacket_t *msg) {
|
||||
|
||||
if (msg_matches(msg, 0xBDU, 0U)) {
|
||||
regen_braking = (msg->data[0] >> 4) != 0U;
|
||||
gm_acc_dashboard_paddle_pressed = (msg->data[0] >> 4) == 2U;
|
||||
gm_acc_dashboard_paddle_us = microsecond_timer_get();
|
||||
gm_emit_paddle_after_stock(microsecond_timer_get(), 0xBDU, 7U, &gm_bd_feed);
|
||||
}
|
||||
if (msg_matches(msg, 0x1F5U, 0U)) {
|
||||
@@ -491,6 +500,7 @@ static void gm_rx_hook(const CANPacket_t *msg) {
|
||||
gm_pedal_forward_gear_ready = (((msg->data[3] & 0xFU) == 4U) || ((msg->data[3] & 0xFU) == 6U)) &&
|
||||
((msg->data[5] & 0x2U) == 0U);
|
||||
if (gm_bolt_pedal_removed || gm_bolt_present_cc_cancel) { gm_bolt_removed_gear_seen = true; }
|
||||
gm_acc_dashboard_paddle_gear = ((msg->data[3] & 0xFU) == 5U) && ((msg->data[5] & 0x2U) != 0U);
|
||||
gm_regen_gear_last_us = microsecond_timer_get();
|
||||
gm_emit_paddle_after_stock(microsecond_timer_get(), 0x1F5U, 8U, &gm_gear_feed);
|
||||
}
|
||||
@@ -1425,6 +1435,9 @@ static safety_config gm_init(uint16_t safety_param) {
|
||||
gm_pedal_forward_gear_ready = false;
|
||||
gm_acc_pedal_forward_owner = param == 0x1CDU;
|
||||
gm_acc_pedal_dashboard_seen = false;
|
||||
gm_acc_dashboard_paddle_gear = false;
|
||||
gm_acc_dashboard_paddle_pressed = false;
|
||||
gm_acc_dashboard_paddle_us = 0U;
|
||||
gm_acc_pedal_dashboard_us = 0U;
|
||||
gm_regen_gear_last_us = 0U;
|
||||
gm_paddle_internal_tx = false;
|
||||
|
||||
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
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "bb11ca763bdda9d694127873da2add6032c85a4937908445b5a42dd361fa176b", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "ce65850db4a6fd415b561b2493b6f061d820a002056d351eb13687a07204e86f", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user