mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-09 09:43:41 +08:00
af53db3b07
* 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>
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
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
|
|
|
|
|
|
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():
|
|
return None
|
|
|
|
return self.dec.mode()
|
|
|
|
def update(self, sm: messaging.SubMaster) -> None:
|
|
self.dec.update(sm)
|
|
|
|
def publish_longitudinal_plan_sp(self, sm: messaging.SubMaster, pm: messaging.PubMaster) -> None:
|
|
plan_sp_send = messaging.new_message('longitudinalPlanSP')
|
|
|
|
plan_sp_send.valid = sm.all_checks(service_list=['carState', 'controlsState'])
|
|
|
|
longitudinalPlanSP = plan_sp_send.longitudinalPlanSP
|
|
|
|
# Dynamic Experimental Control
|
|
dec = longitudinalPlanSP.dec
|
|
dec.state = DecState.blended if self.dec.mode() == 'blended' else DecState.acc
|
|
dec.enabled = self.dec.enabled()
|
|
dec.active = self.dec.active()
|
|
|
|
pm.send('longitudinalPlanSP', plan_sp_send)
|