mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 10:13:44 +08:00
Smooth early Bolt pedal cruise and steering
This commit is contained in:
@@ -113,10 +113,11 @@ class GMPedalLongitudinalPolicy:
|
||||
|
||||
def prepare_pid(self, pid, target: float, error: float, speed: float,
|
||||
last_output: float, accel_limits: tuple[float, float], *,
|
||||
should_stop: bool = False, has_lead: bool | None = None) -> bool:
|
||||
should_stop: bool = False, has_lead: bool | None = None, gentle_cruise_settle: bool = False) -> bool:
|
||||
if pid.i > 0.0 and target < -0.05 and error < -0.25 and not (speed <= 0.35 and target > -0.40):
|
||||
bleed = _interp(abs(error), (0.25, 0.75, 1.5), (0.55, 0.25, 0.0))
|
||||
pid.i *= bleed
|
||||
# Retain the steady uphill demand through a minor no-lead cruise correction.
|
||||
pid.i *= .985 if gentle_cruise_settle and not should_stop and -.10 < target else bleed
|
||||
|
||||
handoff_threshold = _interp(speed, (0.0, 4.0, 12.0, 25.0), (0.35, 0.45, 0.55, 0.70))
|
||||
hold_frames = int(round(_interp(speed, (0.0, 4.0, 12.0, 25.0), (25.0, 20.0, 14.0, 10.0))))
|
||||
|
||||
@@ -114,7 +114,9 @@ class Controls:
|
||||
from openpilot.starpilot.car.volkswagen.model_smoothing import ControlSmoothing
|
||||
self.volkswagen_smoothing = ControlSmoothing(self.CP)
|
||||
from openpilot.starpilot.car.hyundai.model_smoothing import seconds as kona_smoothing
|
||||
from openpilot.starpilot.car.gm.model_smoothing import seconds as bolt_smoothing
|
||||
self.kona_smoothing = kona_smoothing(self.CP)
|
||||
self.bolt_smoothing = bolt_smoothing(self.CP)
|
||||
|
||||
self.CI = interfaces[self.CP.carFingerprint](self.CP)
|
||||
self.hyundai_lateral_fault = LateralFaultLatch(self.CP.carFingerprint)
|
||||
@@ -649,7 +651,8 @@ class Controls:
|
||||
kona_tau = getattr(self, "kona_smoothing", 0.)
|
||||
from openpilot.starpilot.car.subaru.smoothing import seconds as subaru_smooth_seconds, control_maximum
|
||||
|
||||
lat_delay = self.sm["lateralDelay"].lateralDelay + LAT_SMOOTH_SECONDS + subaru_smooth_seconds(CS.vEgo, control_maximum(self)) + kona_tau
|
||||
lat_delay = (self.sm["lateralDelay"].lateralDelay + LAT_SMOOTH_SECONDS + subaru_smooth_seconds(CS.vEgo, control_maximum(self)) +
|
||||
kona_tau + getattr(self, "bolt_smoothing", 0.))
|
||||
if getattr(self, "volkswagen_smoothing", None) is not None:
|
||||
lat_delay += self.volkswagen_smoothing.seconds(int(self.sm.logMonoTime["modelV2"]), time.monotonic_ns())
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ from openpilot.starpilot.lateral.lane_change_status_wire import (
|
||||
from openpilot.starpilot.models.receipt import ModelReceiptOwner
|
||||
from openpilot.starpilot.car.volkswagen.model_smoothing import seconds as volkswagen_smoothing
|
||||
from openpilot.starpilot.car.hyundai.model_smoothing import seconds as kona_smoothing
|
||||
from openpilot.starpilot.car.gm.model_smoothing import seconds as bolt_smoothing
|
||||
from openpilot.starpilot.models.status import ModelVariant
|
||||
from openpilot.starpilot.models.startup import report_load_timeout, wait_for_chestnut_power
|
||||
from openpilot.starpilot.models.recovery import STARTUP_FALLBACK_EXIT
|
||||
@@ -390,6 +391,7 @@ def main(demo=False):
|
||||
from openpilot.starpilot.car.subaru.smoothing import read_frozen, seconds as subaru_smooth_seconds, filter_action
|
||||
subaru_smoothing = read_frozen(CP, params)
|
||||
kona_tau = kona_smoothing(CP)
|
||||
bolt_tau = bolt_smoothing(CP)
|
||||
|
||||
st = time.monotonic()
|
||||
cloudlog.warning("loading model")
|
||||
@@ -581,7 +583,8 @@ def main(demo=False):
|
||||
v_ego = max(sm["carState"].vEgo, 0.)
|
||||
subaru_tau = subaru_smooth_seconds(v_ego, subaru_smoothing)
|
||||
volkswagen_tau = volkswagen_smoothing(CP, receipt_owner.load)
|
||||
lat_delay = sm["lateralDelay"].lateralDelay + LAT_SMOOTH_SECONDS + subaru_tau + volkswagen_tau + kona_tau
|
||||
steering_smoothing = subaru_tau + volkswagen_tau + kona_tau + bolt_tau
|
||||
lat_delay = sm["lateralDelay"].lateralDelay + LAT_SMOOTH_SECONDS + steering_smoothing
|
||||
if sm.updated["extrinsicsCalibration"] and sm.seen['narrowRoadCameraState'] and sm.seen['deviceState']:
|
||||
device_from_calib_euler = np.array(sm["extrinsicsCalibration"].rpyCalib, dtype=np.float32)
|
||||
dc = DEVICE_CAMERAS[(str(sm['deviceState'].deviceType), str(sm['narrowRoadCameraState'].sensor))]
|
||||
@@ -677,7 +680,7 @@ def main(demo=False):
|
||||
action = laboratory_action
|
||||
else:
|
||||
action = model.get_action_from_model(model_output, prev_action, lat_action_t, long_action_t, v_ego)
|
||||
filter_action(action, prev_action, v_ego, subaru_tau + volkswagen_tau + kona_tau)
|
||||
filter_action(action, prev_action, v_ego, steering_smoothing)
|
||||
prev_action = action
|
||||
fill_model_msg(modelv2_send, model_output, action,
|
||||
publish_state, meta_main.frame_id, meta_extra.frame_id, frame_id,
|
||||
|
||||
@@ -6,8 +6,12 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
from openpilot.cereal import log
|
||||
from opendbc.car.gm.values import CAR
|
||||
from openpilot.selfdrive.controls.lib.drive_helpers import smooth_value
|
||||
from openpilot.selfdrive.modeld.constants import LAT_SMOOTH_SECONDS
|
||||
from openpilot.starpilot.car.gm.model_smoothing import seconds as bolt_smoothing
|
||||
from openpilot.starpilot.car.subaru.smoothing import filter_action
|
||||
from openpilot.starpilot.longitudinal.tests.test_bolt_cc_integrator import params as bolt_params
|
||||
|
||||
|
||||
def action_function():
|
||||
@@ -46,3 +50,20 @@ def test_legacy_plan_action_is_unchanged():
|
||||
assert len(calls) == 1
|
||||
assert action.desiredCurvature == pytest.approx(smooth_value(0.02, 0.01, LAT_SMOOTH_SECONDS))
|
||||
assert action.desiredAcceleration == pytest.approx(smooth_value(0.4, 0.1, 0.3))
|
||||
|
||||
|
||||
def test_bolt_interceptor_restores_legacy_smoothing_without_touching_longitudinal_action():
|
||||
previous = log.ModelDataV2.Action(desiredCurvature=.001, desiredAcceleration=.1)
|
||||
for candidate, pedal, seconds in (
|
||||
(CAR.CHEVROLET_BOLT_CC_2017, True, 0.),
|
||||
(CAR.CHEVROLET_BOLT_CC_2018_2021, False, 0.),
|
||||
(CAR.CHEVROLET_BOLT_CC_2018_2021, True, .1),
|
||||
(CAR.CHEVROLET_BOLT_CC_2022_2023, True, 0.),
|
||||
):
|
||||
tau = bolt_smoothing(bolt_params(candidate, pedal=pedal))
|
||||
assert tau == seconds
|
||||
action = log.ModelDataV2.Action(desiredCurvature=.0016, desiredAcceleration=-.1, shouldStop=True)
|
||||
filter_action(action, previous, 34., tau)
|
||||
assert action.desiredCurvature == pytest.approx(smooth_value(.0016, .001, seconds))
|
||||
assert action.desiredAcceleration == pytest.approx(-.1)
|
||||
assert action.shouldStop
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from opendbc.car.gm.values import CAR, is_bolt_pedal_profile
|
||||
|
||||
|
||||
def seconds(cp):
|
||||
if cp.carFingerprint == CAR.CHEVROLET_BOLT_CC_2018_2021 and is_bolt_pedal_profile(cp):
|
||||
return .1
|
||||
return 0.
|
||||
@@ -9,7 +9,7 @@ from opendbc.car.toyota.pedal import supports_standstill_resume
|
||||
from openpilot.starpilot.longitudinal.toyota_output_policy import COROLLA, ToyotaOutputPolicy, development_enabled, production_enabled
|
||||
from openpilot.starpilot.longitudinal.ioniq6_start import Ioniq6StartPolicy, StartEvidence, eligible as ioniq6_start_eligible
|
||||
from openpilot.starpilot.longitudinal.vehicle_policy import policy_for as vehicle_policy_for, stopping_decel_rate, stopping_policy_for
|
||||
from opendbc.car.gm.longitudinal import GMPedalStartPolicy, volt_sng_resume_policy_for
|
||||
from opendbc.car.gm.longitudinal import GMPedalLongitudinalPolicy, GMPedalStartPolicy, volt_sng_resume_policy_for
|
||||
from opendbc.car.gm.bolt_mode import policy_for as bolt_mode_policy_for
|
||||
|
||||
LongCtrlState = car.CarControl.Actuators.LongControlState
|
||||
@@ -30,6 +30,7 @@ class LongitudinalContext:
|
||||
force_stop_braking: bool = False
|
||||
toyota_resume_fresh: bool = False
|
||||
toyota_brake_release: bool = False
|
||||
bolt_cruise_settle: bool = False
|
||||
|
||||
|
||||
class LongitudinalExtension:
|
||||
@@ -168,9 +169,13 @@ class LongitudinalExtension:
|
||||
self.bolt_mode.update(context.experimental_mode, DT_CTRL)
|
||||
feedforward = (self.vehicle_policy.feedforward(a_target, CS.vEgo, last_output)
|
||||
if self.vehicle_policy is not None else a_target)
|
||||
freeze_integrator = (self.vehicle_policy.prepare_pid(pid, a_target, error, CS.vEgo, last_output, accel_limits,
|
||||
should_stop=should_stop, has_lead=context.has_lead)
|
||||
if self.vehicle_policy is not None else False)
|
||||
freeze_integrator = False
|
||||
if context.bolt_cruise_settle and isinstance(self.vehicle_policy, GMPedalLongitudinalPolicy):
|
||||
freeze_integrator = self.vehicle_policy.prepare_pid(pid, a_target, error, CS.vEgo, last_output, accel_limits,
|
||||
should_stop=should_stop, gentle_cruise_settle=True)
|
||||
elif self.vehicle_policy is not None:
|
||||
freeze_integrator = self.vehicle_policy.prepare_pid(pid, a_target, error, CS.vEgo, last_output, accel_limits,
|
||||
should_stop=should_stop, has_lead=context.has_lead)
|
||||
if self.stopping_policy is not None:
|
||||
feedforward, stop_freeze = self.stopping_policy.prepare_pid(pid, a_target, error, CS, context)
|
||||
freeze_integrator |= stop_freeze
|
||||
|
||||
@@ -12,6 +12,7 @@ from opendbc.car.hyundai.blended_stopping import eligible as blended_longitudina
|
||||
|
||||
from openpilot.starpilot.feature_runtime import enabled as feature_enabled
|
||||
from openpilot.starpilot.conditional_mode.traffic_launch import TrafficLaunchState
|
||||
from openpilot.starpilot.conditional_mode.ui_action import fresh_service
|
||||
from openpilot.starpilot.longitudinal.toyota_output_policy import (CLOCK_PAIR_MAX_SKEW_NS, COROLLA, SIENNA_4G, clock_pair_ns,
|
||||
development_enabled as toyota_development_enabled,
|
||||
production_enabled as toyota_production_enabled, leads_from_radar)
|
||||
@@ -20,6 +21,7 @@ from openpilot.starpilot.longitudinal.force_stop_braking import eligible as dist
|
||||
from openpilot.starpilot.longitudinal.lead_takeoff_preferences import TakeoffPreferences
|
||||
from openpilot.starpilot.longitudinal.takeoffs import eligible as takeoff_eligible
|
||||
from opendbc.car.gm.conventional_pedal import policy_for as conventional_pedal_policy_for
|
||||
from opendbc.car.gm.values import CAR as GM
|
||||
from opendbc.car.gm.ordinary_cc import policy_for as ordinary_cc_policy_for
|
||||
from opendbc.car.gm.hybrid_cc import policy_for as hybrid_policy_for
|
||||
from opendbc.car.gm.suburban import SuburbanStopEvidence
|
||||
@@ -92,6 +94,7 @@ class LongitudinalInputs:
|
||||
self.force_stop_distance_braking = distance_braking_eligible(self.CP)
|
||||
gm_policy = gm_pedal_policy_for(self.CP)
|
||||
self.gm_start_enabled = gm_policy is not None and gm_policy.friction_variant
|
||||
self.bolt_cruise_settle = gm_policy is not None and cp.carFingerprint == GM.CHEVROLET_BOLT_CC_2018_2021
|
||||
installed_policy = installed_policy_for(self.CP)
|
||||
stop_policy = installed_policy.stop_policy() if hasattr(installed_policy, 'stop_policy') else None
|
||||
evidence_type = getattr(stop_policy, 'evidence_type', None)
|
||||
@@ -141,7 +144,7 @@ class LongitudinalInputs:
|
||||
return ['radarState', 'deviceState', 'starpilotLongitudinalPlan'] + (['slcState'] if self.ev9_long_enabled else [])
|
||||
if (self.toyota_sienna_replay or self.toyota_sienna_production or self.toyota_corolla_stop or
|
||||
self.ioniq6_start_enabled or self.gm_start_enabled or self.gm_volt_enabled or self.gm_euv_enabled or
|
||||
self.gm_cc_enabled or self.gm_cc_stop_enabled or self.gm_ascm_enabled or self.gm_suburban_enabled):
|
||||
self.gm_cc_enabled or self.gm_cc_stop_enabled or self.gm_ascm_enabled or self.gm_suburban_enabled or self.bolt_cruise_settle):
|
||||
return ['radarState', 'deviceState'] + (['slcState'] if self.gm_start_enabled or self.ev9_long_enabled else [])
|
||||
if self.ev9_long_enabled:
|
||||
return ['radarState', 'deviceState', 'slcState']
|
||||
@@ -193,6 +196,7 @@ class LongitudinalInputs:
|
||||
experimental_mode=bool(self.sm['selfdriveState'].experimentalMode) if self.sm.all_checks(['selfdriveState']) else None,
|
||||
start_evidence=self._ioniq6_start_evidence() if self.ioniq6_start_enabled else None,
|
||||
gm_start_evidence=self._gm_start_evidence() if self.gm_start_enabled and active else None,
|
||||
bolt_cruise_settle=active and self.bolt_cruise_settle and self._bolt_cruise_settle(),
|
||||
has_lead=(bool(self.sm['longitudinalPlan'].hasLead)
|
||||
if self.blended_longitudinal_enabled and self.sm.all_checks(['longitudinalPlan'])
|
||||
else cc_evidence.has_lead if cc_evidence is not None else volt_observation[0]
|
||||
@@ -204,6 +208,21 @@ class LongitudinalInputs:
|
||||
)
|
||||
|
||||
|
||||
def _bolt_cruise_settle(self):
|
||||
sm = self.sm
|
||||
cs, plan, state, device = (sm[name] for name in ('carState', 'longitudinalPlan', 'selfdriveState', 'deviceState'))
|
||||
if (not device.started or not state.enabled or state.experimentalMode or
|
||||
not cs.canValid or cs.canTimeout or cs.gasPressed or cs.brakePressed or cs.regenBraking or
|
||||
cs.vEgo < 20. or not 0. < cs.vEgo - cs.vCruise / 3.6 < .224 or
|
||||
not -.10 < plan.aTarget < -.05 or plan.longitudinalPlanSource != 'cruise' or
|
||||
plan.hasLead or plan.shouldStop or plan.fcw or not plan.allowThrottle):
|
||||
return False
|
||||
radar = sm['radarState']
|
||||
now, drive = time.monotonic_ns(), device.startedMonoTime
|
||||
return (not (radar.leadOne.present or radar.leadTwo.present) and 0 < drive < now and
|
||||
fresh_service(sm, 'deviceState', drive, now, 2_000_000_000) and
|
||||
all(fresh_service(sm, name, drive, now) for name in ('carState', 'longitudinalPlan', 'selfdriveState', 'radarState')))
|
||||
|
||||
def resume_sources_current(self):
|
||||
return self.resume_freshness.current(self.sm)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def attach_inputs(controls):
|
||||
inputs.faster_takeoffs = False
|
||||
inputs.force_stop_distance_braking = False
|
||||
for name in ('ev9_long_enabled', 'blended_longitudinal_enabled', 'toyota_sienna_replay', 'toyota_sienna_production', 'toyota_corolla_stop',
|
||||
'toyota_pedal_resume', 'ioniq6_start_enabled', 'gm_start_enabled', 'gm_volt_enabled', 'gm_euv_enabled',
|
||||
'toyota_pedal_resume', 'ioniq6_start_enabled', 'gm_start_enabled', 'gm_volt_enabled', 'gm_euv_enabled', 'bolt_cruise_settle',
|
||||
'gm_cc_enabled', 'gm_cc_stop_enabled', 'gm_ascm_enabled', 'gm_suburban_enabled'):
|
||||
setattr(inputs, name, False)
|
||||
inputs.gm_cc_evidence = None
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
from openpilot.starpilot.longitudinal.tests.extension_helpers import extension_state
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.gm.interface import CarInterface
|
||||
from opendbc.car.gm.values import CAR
|
||||
from opendbc.car.gm.bolt_cc import BoltCcLongitudinalPolicy
|
||||
from opendbc.car.gm.longitudinal import GMPedalLongitudinalPolicy
|
||||
from openpilot.cereal import log, messaging
|
||||
from openpilot.common.realtime import DT_CTRL
|
||||
from openpilot.selfdrive.controls.lib.longcontrol import LongControl
|
||||
from openpilot.starpilot.longitudinal.extension import LongitudinalContext
|
||||
from openpilot.starpilot.longitudinal.inputs import LongitudinalInputs
|
||||
from openpilot.starpilot.longitudinal.tests.test_cruise_ceiling import messages
|
||||
|
||||
|
||||
def params(identity, pedal=False):
|
||||
@@ -21,6 +26,42 @@ def params(identity, pedal=False):
|
||||
|
||||
|
||||
class TestBoltCcIntegrator(unittest.TestCase):
|
||||
def test_mild_cruise_correction_retains_pedal_integrator_only_with_current_evidence(self):
|
||||
cp = params(CAR.CHEVROLET_BOLT_CC_2018_2021, pedal=True)
|
||||
sm, _ = messages()
|
||||
plan = log.LongitudinalPlan.new_message(aTarget=-.06, allowThrottle=True, longitudinalPlanSource='cruise')
|
||||
device = messaging.new_message('deviceState').deviceState
|
||||
device.started, device.startedMonoTime = True, 1_000_000_000
|
||||
state = sm['carState']
|
||||
state.canValid, state.vCruise, state.vEgo, state.aEgo = True, 123.9, 34.483, .292
|
||||
sm.update(longitudinalPlan=plan, deviceState=device)
|
||||
inputs = LongitudinalInputs.__new__(LongitudinalInputs)
|
||||
inputs.messages = lambda: sm
|
||||
for checks, lead, target, source, stop, permitted in (
|
||||
(True, False, -.06, 'cruise', False, True),
|
||||
(False, False, -.06, 'cruise', False, False),
|
||||
(True, True, -.06, 'cruise', False, False),
|
||||
(True, False, -.20, 'cruise', False, False),
|
||||
(True, False, -.06, 'e2e', False, False),
|
||||
(True, False, -.06, 'cruise', True, False),
|
||||
):
|
||||
plan.hasLead, plan.aTarget, plan.longitudinalPlanSource, plan.shouldStop = lead, target, source, stop
|
||||
with patch('openpilot.starpilot.longitudinal.inputs.time.monotonic_ns', return_value=2_000_000_000), \
|
||||
patch('openpilot.starpilot.longitudinal.inputs.fresh_service', return_value=checks):
|
||||
settle = inputs._bolt_cruise_settle()
|
||||
self.assertEqual(settle, permitted)
|
||||
controller = LongControl(cp)
|
||||
controller.pid.i = .34
|
||||
controller.update(True, state, target, stop, (-3., 2.), context=LongitudinalContext(bolt_cruise_settle=settle))
|
||||
if permitted:
|
||||
self.assertGreater(controller.pid.i, .32)
|
||||
else:
|
||||
self.assertLess(controller.pid.i, .19)
|
||||
plan.shouldStop = False
|
||||
sm['radarState'].leadTwo.present = True
|
||||
with patch('openpilot.starpilot.longitudinal.inputs.fresh_service', return_value=True):
|
||||
self.assertFalse(inputs._bolt_cruise_settle())
|
||||
|
||||
def test_actual_longcontrol_reduces_stale_positive_integrator_during_deceleration(self):
|
||||
for identity in (CAR.CHEVROLET_BOLT_CC_2017, CAR.CHEVROLET_BOLT_CC_2018_2021, CAR.CHEVROLET_BOLT_CC_2022_2023):
|
||||
controller = LongControl(params(identity))
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "8be800fd6a55086f842a6d4de7e386d5383abe1a56399213f4e0d561f0001a54", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "6f98fdb6db8d60dba2c5cd017c83c7db7e37ae5b2c9431b8eb2884123ca224c1", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user