bug: fix braking issue while experimental and using old model (#881)

* Fixes an issue on the long planner since Tomb Raider models, where the models are now meant to output the acceleration target and the "should stop" instead of it being calculated. However, older models (particularly those running on modeld_v2 from SP) do not output this. Leading to a "coasting" situation instead of braking when only e2e is used which is totally wrong.
This commit is contained in:
Nayan
2025-05-09 05:37:59 -04:00
committed by GitHub
parent f09a3b32d1
commit 6de9526d4d
3 changed files with 7 additions and 1 deletions
@@ -178,6 +178,10 @@ class LongitudinalPlanner(LongitudinalPlannerSP):
output_a_target = min(output_a_target_mpc, output_a_target_e2e)
self.output_should_stop = output_should_stop_e2e or output_should_stop_mpc
if not self.is_stock:
# To support non Tomb Raider models
output_a_target, self.output_should_stop = output_a_target_mpc, output_should_stop_mpc
for idx in range(2):
accel_clip[idx] = np.clip(accel_clip[idx], self.prev_accel_clip[idx] - 0.05, self.prev_accel_clip[idx] + 0.05)
self.output_a_target = np.clip(output_a_target, accel_clip[0], accel_clip[1])
+1 -1
View File
@@ -19,7 +19,7 @@ from openpilot.system.hardware import PC
from openpilot.system.hardware.hw import Paths
from pathlib import Path
CURRENT_SELECTOR_VERSION = 2
CURRENT_SELECTOR_VERSION = 3
REQUIRED_MIN_SELECTOR_VERSION = 2
USE_ONNX = os.getenv('USE_ONNX', PC)
@@ -7,6 +7,7 @@ See the LICENSE.md file in the root directory for more details.
from cereal import messaging, custom
from opendbc.car import structs
from openpilot.sunnypilot.models.helpers import get_active_model_runner
from openpilot.sunnypilot.selfdrive.controls.lib.dec.dec import DynamicExperimentalController
DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimentalControlState
@@ -15,6 +16,7 @@ DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimen
class LongitudinalPlannerSP:
def __init__(self, CP: structs.CarParams, mpc):
self.dec = DynamicExperimentalController(CP, mpc)
self.is_stock = get_active_model_runner() == custom.ModelManagerSP.Runner.stock
def get_mpc_mode(self) -> str | None:
if not self.dec.active():