* Controls: Vision Turn Speed Control * fix * Data type temp fix * format * more * even more * self contain targets * state cleanup * fix * param updates * no need * use similar state machine * raise exception if not found * new state * entirely internal * use long active * more * rename and expose aTarget * rename to SCC-V * init tests * slight tests * expose toggle * lint * todo * remove lat planner sub and mock sm data * introduce aTarget * rename * rename * update fill_model_msg.py to calculate PLAN_T_IDXS for lanelines and road edges * sync upstream * no SCC-V yet * Revert "no SCC-V yet" This reverts commit b67281bcac0dce0c6c3237afc2584cf29144c83c. * wrap it with SCC main * leave enabled out of here * wat * enabled and active on cereal * OP long for now, enable for ICBM once merged * need this * unused * let's go hybrid * fix * add override state * update tests * huh * don't math here if not enabled * ui: Smart Cruise Control - Vision (SCC-V) (#1253) * vtsc-ui * slight cleanup * more cleanup * unused * a bit more * pulse like it's hot * draw only enabled and active * let's try this for now * settle * finalize UI * brighter color so we blind devtekve * add long override --------- Co-authored-by: Jason Wen <haibin.wen3@gmail.com> * slight cleanup * more * type hints --------- Co-authored-by: discountchubbs <alexgrant990@gmail.com> Co-authored-by: Kumar <36933347+rav4kumar@users.noreply.github.com>
79 lines
3.1 KiB
Python
79 lines
3.1 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.selfdrive.controls.lib.smart_cruise_control.smart_cruise_control import SmartCruiseControl
|
|
from openpilot.sunnypilot.models.helpers import get_active_bundle
|
|
|
|
DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimentalControlState
|
|
Source = custom.LongitudinalPlanSP.LongitudinalPlanSource
|
|
|
|
|
|
class LongitudinalPlannerSP:
|
|
def __init__(self, CP: structs.CarParams, mpc):
|
|
self.dec = DynamicExperimentalController(CP, mpc)
|
|
self.scc = SmartCruiseControl()
|
|
self.generation = int(model_bundle.generation) if (model_bundle := get_active_bundle()) else None
|
|
self.source = Source.cruise
|
|
|
|
@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_targets(self, sm: messaging.SubMaster, v_ego: float, a_ego: float, v_cruise: float) -> tuple[float, float]:
|
|
self.scc.update(sm, v_ego, a_ego, v_cruise)
|
|
|
|
targets = {
|
|
Source.cruise: (v_cruise, a_ego),
|
|
Source.sccVision: (self.scc.vision.output_v_target, self.scc.vision.output_a_target)
|
|
}
|
|
|
|
self.source = min(targets, key=lambda k: targets[k][0])
|
|
v_target, a_target = targets[self.source]
|
|
|
|
return v_target, a_target
|
|
|
|
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
|
|
longitudinalPlanSP.longitudinalPlanSource = self.source
|
|
|
|
# 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()
|
|
|
|
# Smart Cruise Control
|
|
smartCruiseControl = longitudinalPlanSP.smartCruiseControl
|
|
# Vision Turn Speed Control
|
|
sccVision = smartCruiseControl.vision
|
|
sccVision.state = self.scc.vision.state
|
|
sccVision.vTarget = float(self.scc.vision.output_v_target)
|
|
sccVision.aTarget = float(self.scc.vision.output_a_target)
|
|
sccVision.currentLateralAccel = float(self.scc.vision.current_lat_acc)
|
|
sccVision.maxPredictedLateralAccel = float(self.scc.vision.max_pred_lat_acc)
|
|
sccVision.enabled = self.scc.vision.is_enabled
|
|
sccVision.active = self.scc.vision.is_active
|
|
|
|
pm.send('longitudinalPlanSP', plan_sp_send)
|