Correct Malibu Hybrid driver pedal and OEM buttons

This commit is contained in:
firestar5683
2026-11-16 20:24:09 -06:00
parent e5dde0e0ea
commit ee122139f4
25 changed files with 117 additions and 20 deletions
+4 -1
View File
@@ -504,7 +504,10 @@ class CarState(CarStateBase):
elif self.camera_pedal_profile is not None and self.camera_pedal_profile.longitudinal:
ret.gasPressed = ret.gasPressed or first + second > 1190
else:
ret.gasPressed = (125677 * first + 251976 * second > 198510000 if self.volt_cc_pedal_profile is not None else sum(tracks) / 2. > 23.0)
if self.volt_cc_pedal_profile is not None or self.hybrid_profile is not None:
ret.gasPressed = 125677 * first + 251976 * second > 198510000
else:
ret.gasPressed = sum(tracks) / 2. > 23.0
ret.steeringAngleDeg = pt_cp.vl["PSCMSteeringAngle"]["SteeringWheelAngle"]
ret.steeringRateDeg = pt_cp.vl["PSCMSteeringAngle"]["SteeringWheelRate"]
+6 -3
View File
@@ -103,8 +103,11 @@ def physical_semantic(raw: bytes, *, bus: int) -> str | None:
if bus != 0 or len(raw) != 7 or raw[:3] != bytes(3) or raw[3] not in (1, 0x41) or raw[4] > 3:
return None
word = int.from_bytes(raw[5:7], 'big')
unique = {0x15EE: 'neutral', 0x1FCC: 'neutral', 0x55AE: 'resume', 0x5F8C: 'resume',
0x2ACD: 'main', 0x20EF: 'main', 0x60AF: 'cancel', 0x6A8D: 'cancel'}
# OEM receive codes differ from the custom transmit phase table.
unique = {0x10FF: 'neutral', 0x15EE: 'neutral', 0x1ADD: 'neutral', 0x1FCC: 'neutral',
0x20EF: 'resume', 0x25DE: 'resume', 0x2ACD: 'resume', 0x2FBC: 'resume',
0x50BF: 'main', 0x55AE: 'main', 0x5A9D: 'main', 0x5F8C: 'main',
0x60AF: 'cancel', 0x659E: 'cancel', 0x6A8D: 'cancel', 0x6F7C: 'cancel'}
if word in unique:
return unique[word]
if raw == standard_set_bytes(raw[4]) or (raw[4] == 0 and word in (0x30DF, 0x35CE, 0x3ABD, 0x3FAC)):
@@ -215,7 +218,7 @@ def status_ready(cs, now_ns):
physical is not None and rearm_ready(cs, now_ns) and
0 < physical.main_ns <= now_ns <= physical.main_ns + 300_000_000 and
physical.main_on and not physical.brake_pressed and
not physical.accelerator_pressed and not physical.sensor_gas and
not physical.sensor_gas and
len(physical.camera_ns) == (0 if profile.removed else 2) and
all(0 < stamp <= now_ns <= stamp + 1_000_000_000 for stamp in physical.camera_ns))
@@ -86,7 +86,7 @@ def test_pedal_set_during_accelerator_override_retains_intent_without_actuation(
try:
case.reset(0xE802, alternative)
case.warm()
kwargs = {'tracks': (1000, 500)} if sensor_override else {'gas': True}
kwargs = {'tracks': (1000, 500), 'gas': sensor_override}
case.feed(**kwargs)
case.rx(0x1E1, standard_set_bytes(0))
assert not case.safety.get_controls_allowed()
@@ -0,0 +1,86 @@
"""OEM receive semantics and driver pedal identity from the Malibu route."""
import pytest
from opendbc.car.gm.hybrid_cc import HybridButtons, physical_semantic
from opendbc.safety.tests import test_gm_hybrid_cc as native_fixture
WORDS = {
1: (0x10FF, 0x15EE, 0x1ADD, 0x1FCC),
2: (0x20EF, 0x25DE, 0x2ACD, 0x2FBC),
3: (0x30DF, 0x35CE, 0x3ABD, 0x3FAC),
5: (0x50BF, 0x55AE, 0x5A9D, 0x5F8C),
6: (0x60AF, 0x659E, 0x6A8D, 0x6F7C),
}
NAMES = {1: 'neutral', 2: 'resume', 3: 'set', 5: 'main', 6: 'cancel'}
def raw(word, prefix=0x41):
return bytes((0, 0, 0, prefix, 0, word >> 8, word & 255))
@pytest.mark.parametrize('button', WORDS)
@pytest.mark.parametrize('prefix', (1, 0x41))
def test_all_recorded_oem_phases(button, prefix):
for word in WORDS[button]:
assert physical_semantic(raw(word, prefix), bus=0) == NAMES[button]
for bus in (2, 128, 130):
assert physical_semantic(raw(word, prefix), bus=bus) is None
def test_held_resume_is_one_press_not_main():
h = HybridButtons()
edges = []
for tick, word in enumerate((0x15EE,) + WORDS[2] * 20 + (0x1FCC,)):
h.observe_packets([(1_000_000_000 + tick * 30_000_000, [(0x1E1, raw(word), 0)])])
edges += h.update(True)[2]
assert edges == [(1, 2), (2, 1)]
@pytest.mark.parametrize('profile', (0xE802, 0xE803))
@pytest.mark.parametrize('alternative', (0, 32))
def test_native_output_is_not_driver_gas(profile, alternative):
f = native_fixture.TestGmHybridCc(methodName='runTest')
f.setUp()
try:
f.reset(profile, alternative)
f.warm()
f.slot(0x30DF)
f.slot(0x1FCC)
assert f.safety.get_controls_allowed()
f.advance(20_000)
f.feed(gas=True, tracks=(604, 304))
assert f.pedal(counter=0)
f.advance(20_000)
f.feed(gas=False, tracks=(1000, 500))
assert not f.pedal(counter=1)
f.advance(20_000)
f.feed(gas=True, tracks=(604, 304))
assert f.pedal(counter=2)
f.advance(110_000)
f.feed(gas=True, missing=0x201)
assert not f.pedal(counter=3)
finally:
f.tearDown()
@pytest.mark.parametrize('profile', (0xE800, 0xE801, 0xE802, 0xE803))
def test_native_resume_hold_and_cancel_each_phase(profile):
f = native_fixture.TestGmHybridCc(methodName='runTest')
f.setUp()
try:
for cancel in WORDS[6]:
f.reset(profile)
f.warm()
for word in WORDS[2] * 3:
f.slot(word)
assert f.safety.get_controls_allowed()
f.slot(cancel)
assert not f.safety.get_controls_allowed()
f.slot(0x15EE)
assert not f.safety.get_controls_allowed()
f.slot(0x20EF)
assert f.safety.get_controls_allowed()
f.slot(0x55AE)
assert not f.safety.get_controls_allowed()
finally:
f.tearDown()
@@ -573,15 +573,15 @@ class TestMalibuHybridCc(unittest.TestCase):
self.assertEqual(cp.safetyConfigs[0].safetyParam, 0xE804 + int(removed))
def test_semantic_unknown_packets_do_not_release_a_physical_press(self):
from opendbc.car.gm.hybrid_cc import HybridButtons, custom_bytes, standard_set_bytes
from opendbc.car.gm.hybrid_cc import HybridButtons, standard_set_bytes
buttons = HybridButtons()
def receive(stamp, raw):
buttons.observe_packets([(stamp, [(0x1E1, raw, 0)])])
return buttons.update(True)[2]
self.assertEqual(receive(1, bytes.fromhex('000000410015ee')), [])
self.assertEqual(receive(2, custom_bytes('resume', 0, 0x41)), [(1, 2)])
for stamp, word in enumerate(('10ff', '1add', '659e', '6f7c'), 3):
self.assertEqual(receive(2, bytes.fromhex('000000410020ef')), [(1, 2)])
for stamp, word in enumerate(('20ee', '25df', '2acc', '2fbd'), 3):
self.assertEqual(receive(stamp, bytes.fromhex('0000004100' + word)), [])
self.assertEqual(receive(8, bytes.fromhex('00000041001fcc')), [(2, 1)])
self.assertEqual(receive(9, standard_set_bytes(2)), [(1, 3)])
@@ -790,7 +790,8 @@ class TestMalibuHybridCc(unittest.TestCase):
packer.make_can_msg('ECMPRDNL2', 0, {'PRNDL2': 7, 'ManualMode': 1}),
packer.make_can_msg('EBCMRegenPaddle', 0, {}),
(0x1E1, bytes.fromhex('000000010015ee' if tick % 2 else '00000001001fcc'), 0)]
sensor = bytearray((612).to_bytes(2, 'big') + (285).to_bytes(2, 'big') + bytes((tick % 16, 0)))
sensor = bytearray((1000 if blocked and fault == 'accelerator' else 612).to_bytes(2, 'big') +
(500 if blocked and fault == 'accelerator' else 285).to_bytes(2, 'big') + bytes((tick % 16, 0)))
sensor[-1] = pedal_crc(sensor)
frames.append((0x201, bytes(sensor), 0))
if not removed:
@@ -820,7 +821,7 @@ class TestMalibuHybridCc(unittest.TestCase):
recovered |= tick >= 210 and bool(statuses)
if removed and blocked and (fault != 'main_expiry' or tick >= 110):
if fault == 'accelerator':
self.assertFalse(state.gasPressed) # Healthy pedal data replaces the host gas state.
self.assertTrue(state.gasPressed) # The physical sensor, not ECU output, is driver input.
self.assertTrue(ci.CS.hybrid_status.accelerator_pressed)
if fault == 'main_expiry':
self.assertGreater(now - ci.CS.hybrid_status.main_ns, 300_000_000)
@@ -121,10 +121,10 @@ static uint8_t gm_hybrid_semantic(const CANPacket_t *msg) {
const uint16_t word = ((uint16_t)msg->data[5] << 8U) | msg->data[6];
uint8_t button = 0U;
if (gm_hybrid_tuple(msg)) {
if ((word == 0x15EEU) || (word == 0x1FCCU)) { button = 1U; }
else if ((word == 0x55AEU) || (word == 0x5F8CU)) { button = 2U; }
else if ((word == 0x2ACDU) || (word == 0x20EFU)) { button = 5U; }
else if ((word == 0x60AFU) || (word == 0x6A8DU)) { button = 6U; }
if ((word == 0x10FFU) || (word == 0x15EEU) || (word == 0x1ADDU) || (word == 0x1FCCU)) { button = 1U; }
else if ((word == 0x20EFU) || (word == 0x25DEU) || (word == 0x2ACDU) || (word == 0x2FBCU)) { button = 2U; }
else if ((word == 0x50BFU) || (word == 0x55AEU) || (word == 0x5A9DU) || (word == 0x5F8CU)) { button = 5U; }
else if ((word == 0x60AFU) || (word == 0x659EU) || (word == 0x6A8DU) || (word == 0x6F7CU)) { button = 6U; }
else if ((msg->data[4] == 0U) && ((word == 0x30DFU) || (word == 0x35CEU) ||
(word == 0x3ABDU) || (word == 0x3FACU))) { button = 3U; }
else {
@@ -163,7 +163,10 @@ static void gm_hybrid_rx(const CANPacket_t *msg) {
(((msg->data[4] >> 3U) & 7U) == 1U) && ((msg->data[4] & 7U) == 1U);
vehicle_moving = ((((unsigned int)msg->data[0] << 8U) | msg->data[1]) > 10U) ||
((((unsigned int)msg->data[2] << 8U) | msg->data[3]) > 10U);
} else if (i == 3U) { gas_pressed = msg->data[5] != 0U; }
} else if (i == 3U) {
// On pedal profiles this is the interceptor output, not driver input.
if (!gm_hybrid_pedal) { gas_pressed = msg->data[5] != 0U; }
}
else if (i == 4U) { gm_hybrid_main = GET_BIT(msg, 29U); brake_pressed = GET_BIT(msg, 40U); }
else if (i == 5U) {
gm_hybrid_stock_active = GET_BIT(msg, 39U);
@@ -181,6 +184,7 @@ static void gm_hybrid_rx(const CANPacket_t *msg) {
(gm_pedal_crc(msg) == msg->data[5]) && (!gm_hybrid_sensor_seen || (counter != gm_hybrid_sensor_counter));
gm_hybrid_sensor_seen = true; gm_hybrid_sensor_counter = counter;
gm_hybrid_sensor_gas = ((125677U * track1) + (251976U * track2)) > (uint32_t)198510000U;
gas_pressed = gm_hybrid_sensor_gas;
} else {
}
if (i == 2U) {
@@ -85,7 +85,7 @@ class TestGmHybridCc(unittest.TestCase):
self.safety.aol_set_host_request(3)
def arm(self):
self.slot(0x55AE)
self.slot(0x20EF)
self.assertTrue(self.safety.get_controls_allowed())
self.slot(0x15EE)
@@ -93,7 +93,7 @@ class TestGmHybridCc(unittest.TestCase):
return self.safety.safety_tx_hook(self.packet(gmcan.create_pedal_command(self.packer, fraction, counter)))
def test_physical_cancel_main_and_standard_set_have_distinct_rearm_effects(self):
for physical_word in (0x2ACD, 0x20EF, 0x60AF, 0x6A8D):
for physical_word in (0x55AE, 0x5F8C, 0x60AF, 0x6A8D):
with self.subTest(physical_word=hex(physical_word)):
self.reset(0xE801)
self.warm()
@@ -328,7 +328,7 @@ class TestGmHybridCc(unittest.TestCase):
self.assertTrue(self.steering())
self.reset(word, alternative)
self.warm(stock=False)
self.slot(0x55AE)
self.slot(0x20EF)
if alternative == 0:
self.assertFalse(self.steering())
self.assertFalse(self.safety.get_controls_allowed())
@@ -420,7 +420,7 @@ class TestGmHybridCc(unittest.TestCase):
if word >= 0xE804:
self.stock_frame(True)
else:
self.slot(0x55AE)
self.slot(0x20EF)
self.assertFalse(self.safety.get_controls_allowed())
self.advance(10_000)
self.feed(stock=word >= 0xE804)
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
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "0cbe99b149104a517282e2a630e1170ebac4ae03963149a46e69ee6348cb92e6", "schema_version": 1}
{"protected_inventory_sha256": "60bef42e07e5f5ed97bb4220d25cd99d044e618e8b2dab1bcc32f96d4068a289", "schema_version": 1}