Longitudinal Planner: Allow Non-MLSIM Models to Use MPC (#1012)

* gen 11 only api limit exceeded maybe not

* Try this for ModelDataV2.Action

* mpc mode

* Fix This

* Revert "Try this for ModelDataV2.Action"

This reverts commit e7db17980b3667de1399cac97ef92041f5d59eff.

* fix logic flaw

* Address comments for readability.

---------

Co-authored-by: Kumar <36933347+rav4kumar@users.noreply.github.com>
This commit is contained in:
James Vecellio-Grant
2025-07-05 21:23:32 -07:00
committed by GitHub
parent 394603727e
commit af53db3b07
2 changed files with 12 additions and 1 deletions

View File

@@ -94,9 +94,13 @@ class LongitudinalPlanner(LongitudinalPlannerSP):
def update(self, sm):
self.mode = 'blended' if sm['selfdriveState'].experimentalMode else 'acc'
if not self.mlsim:
self.mpc.mode = self.mode
LongitudinalPlannerSP.update(self, sm)
if dec_mpc_mode := self.get_mpc_mode():
self.mode = dec_mpc_mode
if not self.mlsim:
self.mpc.mode = dec_mpc_mode
if len(sm['carControl'].orientationNED) == 3:
accel_coast = get_coast_accel(sm['carControl'].orientationNED[1])
@@ -171,7 +175,7 @@ class LongitudinalPlanner(LongitudinalPlannerSP):
output_a_target_e2e = sm['modelV2'].action.desiredAcceleration
output_should_stop_e2e = sm['modelV2'].action.shouldStop
if self.mode == 'acc':
if self.mode == 'acc' or not self.mlsim:
output_a_target = output_a_target_mpc
self.output_should_stop = output_should_stop_mpc
else:

View File

@@ -8,6 +8,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.selfdrive.controls.lib.dec.dec import DynamicExperimentalController
from openpilot.sunnypilot.models.helpers import get_active_bundle
DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimentalControlState
@@ -15,6 +16,12 @@ DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimen
class LongitudinalPlannerSP:
def __init__(self, CP: structs.CarParams, mpc):
self.dec = DynamicExperimentalController(CP, mpc)
model_bundle = get_active_bundle()
self.generation = model_bundle.generation if model_bundle is not None else None
@property
def mlsim(self) -> bool:
return self.generation == 11
def get_mpc_mode(self) -> str | None:
if not self.dec.active():