Compare commits

...

2 Commits

Author SHA1 Message Date
Jingsong Gao ee120a1488 MADS: pause when brake is already held (#2031)
Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
2026-11-20 16:58:46 -05:00
Jason Wen 61d3e421ec hardwared: avoid params lock in 2 Hz loop (#2109) 2026-11-20 16:07:18 -05:00
4 changed files with 23 additions and 16 deletions
-1
View File
@@ -172,7 +172,6 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"EnableCopyparty", {PERSISTENT | BACKUP, BOOL}},
{"EnableGithubRunner", {PERSISTENT | BACKUP, BOOL}},
{"GreenLightAlert", {PERSISTENT | BACKUP, BOOL, "0"}},
{"GithubRunnerSufficientVoltage", {CLEAR_ON_MANAGER_START , BOOL}},
{"HasAcceptedTermsSP", {PERSISTENT, STRING, "0"}},
{"HideVEgoUI", {PERSISTENT | BACKUP, BOOL, "0"}},
{"IntelligentCruiseButtonManagement", {PERSISTENT | BACKUP , BOOL}},
+1 -1
View File
@@ -139,7 +139,7 @@ class ModularAssistiveDrivingSystem:
self.transition_paused_state()
if self.steering_mode_on_brake == MadsSteeringModeOnBrake.PAUSE:
if self.pedal_pressed_non_gas_pressed(CS):
if CS.brakePressed or CS.regenBraking or self.pedal_pressed_non_gas_pressed(CS):
self.transition_paused_state()
self.events.remove(EventName.preEnableStandstill)
@@ -107,6 +107,22 @@ class TestShouldSilentLkasEnable(OpenpilotTestCase):
# pause
class TestPauseMode(OpenpilotTestCase):
def test_pauses_at_standstill_brake_already_held(self, mocker):
mads, sd = make_mads(mocker, MadsSteeringModeOnBrake.PAUSE)
mads.state_machine.state = State.enabled
mads.enabled = True
mads.active = True
sd.CS_prev = make_car_state(brake_pressed=True, standstill=True)
sd.sm['pandaStates'] = [make_panda_state(mocker, False)]
cs = make_car_state(brake_pressed=True, standstill=True)
run_frames(mads, sd, cs, n=199)
mads.update(cs)
assert not sd.events_sp.has(EventNameSP.controlsMismatchLateral)
assert mads.state_machine.state == State.paused
assert mads.lateral_mismatch_counter == 0
def test_stays_paused_at_standstill_brake_held(self, mocker):
mads, sd = make_mads(mocker, MadsSteeringModeOnBrake.PAUSE)
mads.state_machine.state = State.enabled
+6 -14
View File
@@ -253,6 +253,12 @@ def hardware_thread(end_event, hw_queue) -> None:
chestnut_status = ChestnutStatus()
branch = get_short_branch()
build_metadata = get_build_metadata()
is_unsupported_combo = COMMA_HARDWARE and HARDWARE.get_device_type() == "tici" and build_metadata.channel_type != "tici"
startup_conditions["not_tici"] = not is_unsupported_combo
onroad_conditions["not_tici"] = not is_unsupported_combo
set_offroad_alert_if_changed("Offroad_TiciSupport", is_unsupported_combo, extra_text=build_metadata.channel)
while not end_event.is_set():
sm.update(PANDA_STATES_TIMEOUT)
@@ -375,16 +381,6 @@ def hardware_thread(end_event, hw_queue) -> None:
startup_conditions["not_always_offroad"] = not offroad_mode
onroad_conditions["not_always_offroad"] = not offroad_mode
# if an unsupported device and branch is detected, going onroad is blocked
# only allow going onroad when:
# - TIZI, or
# - TICI and channel_type is "tici"
build_metadata = get_build_metadata()
is_unsupported_combo = COMMA_HARDWARE and HARDWARE.get_device_type() == "tici" and build_metadata.channel_type != "tici"
startup_conditions["not_tici"] = not is_unsupported_combo
onroad_conditions["not_tici"] = not is_unsupported_combo
set_offroad_alert("Offroad_TiciSupport", is_unsupported_combo, extra_text=build_metadata.channel)
# if the temperature enters the danger zone, go offroad to cool down
onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.critical
extra_text = f"{offroad_comp_temp:.1f}C"
@@ -443,10 +439,6 @@ def hardware_thread(end_event, hw_queue) -> None:
# Offroad power monitoring
voltage = None if peripheralState.pandaType == log.PandaState.PandaType.unknown else peripheralState.voltage
# GitHub runner auto off: 9V is used as the threshold because most desktop runners
# will rarely exceed 5V so 9V is set as our buffer between desk use and car use.
params.put_bool("GithubRunnerSufficientVoltage", ((voltage or 0) and voltage > 9000))
power_monitor.calculate(voltage, onroad_conditions["ignition"])
msg.deviceState.offroadPowerUsageUwh = power_monitor.get_power_used()
msg.deviceState.carBatteryCapacityUwh = max(0, power_monitor.get_car_battery_capacity())