Files
StarPilot/openpilot/starpilot/lateral/tests/test_bolt_vehicle_model.py
T
firestar5683 80fbb4f6db Feature registration
Register vehicle controls, planner modes, UI actions and Galaxy services after their providers exist. Wire the shared runtime entrypoints and cover their combined behavior.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Kacper Rączy <gfw.kra@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: haraschax <6804392+haraschax@users.noreply.github.com>
Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

64 lines
3.1 KiB
Python

from unittest.mock import patch
import math
import os
from types import SimpleNamespace
import unittest
from opendbc.car.gm.values import CAR
from openpilot.common.params import Params
from openpilot.common.prefix import OpenpilotPrefix
from openpilot.selfdrive.controls.controlsd import Controls
from openpilot.starpilot.longitudinal.tests.test_bolt_mode_transition import params
class VehicleModelUpdated(Exception):
pass
class TestBoltVehicleModel(unittest.TestCase):
def test_actual_controls_ratio_is_scoped_and_recomputed_from_live_input(self):
identities = (CAR.CHEVROLET_BOLT_CC_2017, CAR.CHEVROLET_BOLT_CC_2018_2021,
CAR.CHEVROLET_BOLT_CC_2022_2023, CAR.CHEVROLET_BOLT_ACC_2022_2023,
CAR.CHEVROLET_BOLT_ACC_2022_2023_PEDAL, CAR.CHEVROLET_BOLT_EUV)
for identity in identities:
for mode in ('starpilot', 'standard'):
if identity == CAR.CHEVROLET_BOLT_EUV and mode == 'starpilot':
continue
with self.subTest(identity=identity, mode=mode), OpenpilotPrefix(), patch.dict(os.environ, {'SIMULATION': '1'}):
cp = params(identity, alpha=True)
settings = Params()
settings.put('CarParams', cp.to_bytes(), block=True)
if mode == 'standard' and identity != CAR.CHEVROLET_BOLT_EUV:
document = {'version': 1, 'vehicles': {str(identity): {'brand': 'gm', 'mode': 'standard'}}}
settings.put('LateralControllerSelection', document, block=True)
controls = Controls()
self.assertEqual(controls.LaC.controller_mode.value, mode)
real_update = controls.VM.update_params
for index, (speed, live_ratio) in enumerate(((0., 16.8), (8., 16.8), (25., 16.8),
(25., 16.8), (5., 17.2), (35., 17.2), (0., 16.8))):
if index == 4:
controls.LaC.reset()
self.enterContext(patch.object(controls, 'sm', {'carState': SimpleNamespace(vEgo=speed),
'vehicleParameters': SimpleNamespace(stiffnessFactor=1.1, steerRatio=live_ratio)}, create=True))
observed = []
def capture(stiffness, ratio, real_update=real_update, observed=observed):
real_update(stiffness, ratio)
observed.append((stiffness, ratio))
raise VehicleModelUpdated
with patch.object(controls.VM, 'update_params', side_effect=capture):
with self.assertRaises(VehicleModelUpdated):
controls.state_control()
scale = 1.0
if mode == 'starpilot' and identity == CAR.CHEVROLET_BOLT_CC_2017:
# Literal original controlsd caller and vehicle_tunes speed law.
onset, width = 20 * .44704, 4 * .44704
scale += .045 / (1 + math.exp(-(max(speed, 0.) - onset) / width))
elif mode == 'starpilot' and identity == CAR.CHEVROLET_BOLT_CC_2018_2021:
scale = 1.01
self.assertEqual(observed[0][0], 1.1)
self.assertAlmostEqual(observed[0][1], live_ratio * scale, places=10)
self.assertEqual(len(observed), 1)