Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opendbc/car/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions opendbc/car/tesla/preap/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 35 additions & 1 deletion opendbc/car/tesla/preap/tests/test_preap_carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"):
Expand Down Expand Up @@ -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):
Expand Down
Loading