From c982b4b156eef3f316f863bc4190aab046842191 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 29 Aug 2026 02:07:36 +0000 Subject: [PATCH 1/2] tesla_preap: publish enableLongControl on CarState Interceptor authority (pedalLongActive) drops on gas override while the FSM long flag stays true. Brake and first-pull drop the FSM flag while cruise stays. Publish enableLongControl so selfdrived can chime on those edges instead of the long-lived cruise session. --- opendbc/car/car.capnp | 1 + opendbc/car/tesla/preap/carstate.py | 1 + .../tesla/preap/tests/test_preap_carstate.py | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/opendbc/car/car.capnp b/opendbc/car/car.capnp index a5326184f6c..4b617ef8084 100644 --- a/opendbc/car/car.capnp +++ b/opendbc/car/car.capnp @@ -221,6 +221,7 @@ struct CarState { vdasLimitedAccel @74 :Float32; # NAP: jerk-limited VDAS acceleration command pedalCommandDi @75 :Float32; # NAP: controller DI-domain command/seed; RESET wire frames carry zero pedalAuthorityFailed @76 :Bool; # NAP: bounded pedal authority acquisition failed + enableLongControl @77 :Bool; # NAP: Pre-AP FSM is modulating longitudinal (stays true during gas override) # cruise state cruiseState @10 :CruiseState; diff --git a/opendbc/car/tesla/preap/carstate.py b/opendbc/car/tesla/preap/carstate.py index c44b1bab294..dbe84f9f139 100644 --- a/opendbc/car/tesla/preap/carstate.py +++ b/opendbc/car/tesla/preap/carstate.py @@ -183,6 +183,7 @@ def update_preap(cs, can_parsers): and cs.enableLongControl and cs.di_cruise_state not in ("STANDBY", "ENABLED") ) + ret.enableLongControl = bool(cs.engagement.enableLongControl) ret.pedalLongActive = bool(getattr(cs, 'pedal_authority_active', False)) and nap_conf.use_pedal ret.pedalAuthorityRequested = bool(getattr(cs, 'pedal_authority_requested', False)) ret.pedalAuthorityState = int(getattr(cs, 'pedal_authority_state', 0)) & 0xFF diff --git a/opendbc/car/tesla/preap/tests/test_preap_carstate.py b/opendbc/car/tesla/preap/tests/test_preap_carstate.py index 7bc1cd69c44..d7a9eb4bf8d 100644 --- a/opendbc/car/tesla/preap/tests/test_preap_carstate.py +++ b/opendbc/car/tesla/preap/tests/test_preap_carstate.py @@ -46,7 +46,8 @@ def test_nap_specific_fields_on_carstate(self): CI = self._make_interface() CS = CI.update([]) for field in ("teslaCCEngaged", "teslaCCDisengaged", "teslaCCNotArmed", - "pedalMaxRegen", "pedalLongActive", "pedalAuthorityRequested", + "pedalMaxRegen", "pedalLongActive", "enableLongControl", + "pedalAuthorityRequested", "pedalAuthorityState", "pedalAuthorityAction", "pedalCommandCounter", "pedalFeedbackState", "pedalFeedbackCounter", "pedalFirstEnabledMonoTime", "vdasLimitedAccel", "pedalCommandDi", "pedalAuthorityFailed"): @@ -100,6 +101,22 @@ def test_pedal_long_active_reports_accepted_authority_not_request_intent(self): CI.CS.pedal_authority_active = True self.assertTrue(CI.update([]).pedalLongActive) + def test_enable_long_control_publishes_fsm_flag_not_interceptor_authority(self): + CI = self._make_interface() + CI.CS.engagement.cruiseEnabled = True + CI.CS.engagement.enableLongControl = True + CI.CS.pedal_authority_active = False + + with patch.object(type(nap_conf), "use_pedal", new_callable=PropertyMock, return_value=True): + published = CI.update([]) + self.assertTrue(published.enableLongControl) + self.assertFalse(published.pedalLongActive) + + CI.CS.engagement.enableLongControl = False + published = CI.update([]) + self.assertFalse(published.enableLongControl) + self.assertFalse(published.pedalLongActive) + def test_hands_on_level_two_disengages(self): for hands_on_level, should_disengage in ((1, False), (2, True), (3, True)): with self.subTest(hands_on_level=hands_on_level): From f6a9e82002d5f4bb8d385507da5b7d62c91b421d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 29 Aug 2026 02:10:06 +0000 Subject: [PATCH 2/2] tesla_preap: keep enableLongControl publish test engageable Empty CAN defaults doors to OPEN and gear to invalid, so check_can_engage cleared the FSM flag before CarState published it. Drive + closed doors keep the flag so the test can distinguish it from interceptor authority. --- .../tesla/preap/tests/test_preap_carstate.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/opendbc/car/tesla/preap/tests/test_preap_carstate.py b/opendbc/car/tesla/preap/tests/test_preap_carstate.py index d7a9eb4bf8d..03291b59bba 100644 --- a/opendbc/car/tesla/preap/tests/test_preap_carstate.py +++ b/opendbc/car/tesla/preap/tests/test_preap_carstate.py @@ -25,6 +25,22 @@ def _can_packet(message, values): address, dat, bus = CANPacker("tesla_preap").make_can_msg(message, 0, values) return [(1, [CanData(address, dat, bus)])] + def _engageable_packets(self): + # Empty CAN defaults doors to OPEN and gear to invalid, which check_can_engage + # treats as blocked and clears enableLongControl. Drive + closed doors keep the FSM. + packer = CANPacker("tesla_preap") + messages = [] + for name, values in ( + ("DI_torque2", {"DI_gear": 4}), + ("GTW_carState", { + "DOOR_STATE_FL": 0, "DOOR_STATE_FR": 0, "DOOR_STATE_RL": 0, + "DOOR_STATE_RR": 0, "DOOR_STATE_FrontTrunk": 0, "BOOT_STATE": 0, + }), + ): + address, dat, bus = packer.make_can_msg(name, 0, values) + messages.append(CanData(address, dat, bus)) + return [(1, messages)] + def _make_interface(self): CarInterface = interfaces["TESLA_MODEL_S_PREAP"] CP = CarInterface.get_params("TESLA_MODEL_S_PREAP", @@ -103,17 +119,18 @@ def test_pedal_long_active_reports_accepted_authority_not_request_intent(self): def test_enable_long_control_publishes_fsm_flag_not_interceptor_authority(self): CI = self._make_interface() + packets = self._engageable_packets() CI.CS.engagement.cruiseEnabled = True CI.CS.engagement.enableLongControl = True CI.CS.pedal_authority_active = False with patch.object(type(nap_conf), "use_pedal", new_callable=PropertyMock, return_value=True): - published = CI.update([]) + published = CI.update(packets) self.assertTrue(published.enableLongControl) self.assertFalse(published.pedalLongActive) CI.CS.engagement.enableLongControl = False - published = CI.update([]) + published = CI.update(packets) self.assertFalse(published.enableLongControl) self.assertFalse(published.pedalLongActive)