mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-30 11:23:49 +08:00
1b570ef418
* Introduce zero inputs for Lead, and plan to conform with new SP model introduced Monday, July 7, 2025 * Clean this up * We can revert this after dev-c3-new testing and ready to merge. * This needs to be apart of the conditional else fail * Add full conditional * Update longitudinal_planner.py * Mypy from myphone! * red diff * Make generation a property for clarity * Even clearer! * Affix to generation, while allowing older models to use this IF param is set. * seems a bit repetitive yea? * dynamic * Make most outputs dynamic * Rm toggle from refactor * refactor(modeld): simplify MHP output parsing logic - Introduced `_parse_mhp_output` helper to remove redundancy and streamline `parse_dynamic_outputs`. - Ensures improved code maintainability and clarity. * refactor(longitudinal_planner): streamline generation handling logic - Simplified `generation` assignment with inline conditional for better readability. - Adjusted `mlsim` logic to default to model simulation when `generation` is unset. * for ease of syncs from now on * fix --------- Co-authored-by: DevTekVE <devtekve@gmail.com>
49 lines
1.7 KiB
Python
49 lines
1.7 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)
|
|
self.generation = int(model_bundle.generation) if (model_bundle := get_active_bundle()) else None
|
|
|
|
@property
|
|
def mlsim(self) -> bool:
|
|
# If we don't have a generation set, we assume it's default model. Which as of today are mlsim.
|
|
return bool(self.generation is None or 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)
|