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..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", @@ -46,7 +62,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 +117,23 @@ 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() + 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(packets) + self.assertTrue(published.enableLongControl) + self.assertFalse(published.pedalLongActive) + + CI.CS.engagement.enableLongControl = False + published = CI.update(packets) + 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):