mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-01 08:43:41 +08:00
Exercise combined ModelD delay in the vehicle and Jetlink tests
This commit is contained in:
@@ -13,6 +13,7 @@ from openpilot.cereal import log
|
||||
from openpilot.selfdrive.controls.lib.drive_helpers import get_curvature_from_plan, smooth_value
|
||||
from openpilot.selfdrive.modeld.constants import ModelConstants
|
||||
from openpilot.starpilot.car.hyundai.model_smoothing import seconds
|
||||
from openpilot.starpilot.car.gm.model_smoothing import seconds as bolt_smoothing
|
||||
from openpilot.starpilot.car.subaru.smoothing import filter_action
|
||||
|
||||
|
||||
@@ -101,12 +102,12 @@ def test_common_model_join_keeps_filter_and_lookahead_matched(alpha):
|
||||
cp = setup(alpha)
|
||||
action = log.ModelDataV2.Action(desiredCurvature=.001, desiredAcceleration=-.25, shouldStop=True)
|
||||
previous = log.ModelDataV2.Action(desiredCurvature=0.)
|
||||
env = {'CP': cp, 'receipt_owner': SimpleNamespace(load=object()), 'v_ego': 18., 'subaru_smoothing': 0.,
|
||||
env = {'CP': cp, 'bolt_smoothing': bolt_smoothing, 'receipt_owner': SimpleNamespace(load=object()), 'v_ego': 18., 'subaru_smoothing': 0.,
|
||||
'subaru_smooth_seconds': lambda *args: 0., 'volkswagen_smoothing': lambda *args: 0.,
|
||||
'kona_smoothing': seconds, 'kona_tau': seconds(cp), 'LAT_SMOOTH_SECONDS': 0.,
|
||||
'sm': {'lateralDelay': SimpleNamespace(lateralDelay=.3)}, 'action': action, 'prev_action': previous,
|
||||
'filter_action': filter_action, 'frame_delay': .05, 'action_delay': .025, 'inputs': {}, 'np': np}
|
||||
wanted = {'kona_tau', 'subaru_tau', 'volkswagen_tau', 'lat_delay', 'lat_action_t'}
|
||||
wanted = {'kona_tau', 'subaru_tau', 'volkswagen_tau', 'bolt_tau', 'steering_smoothing', 'lat_delay', 'lat_action_t'}
|
||||
nodes = [n for n in ast.walk(tree) if isinstance(n, ast.Assign) and
|
||||
(any(isinstance(t, ast.Name) and t.id in wanted for t in n.targets) or
|
||||
any(isinstance(t, ast.Subscript) and ast.unparse(t) == "inputs['lateral_control_params']" for t in n.targets))]
|
||||
|
||||
@@ -10,6 +10,7 @@ from opendbc.car.volkswagen.values import CAR
|
||||
from openpilot.cereal import log
|
||||
from openpilot.selfdrive.controls.lib.drive_helpers import get_curvature_from_plan, smooth_value
|
||||
from openpilot.selfdrive.modeld.constants import ModelConstants
|
||||
from openpilot.starpilot.car.gm.model_smoothing import seconds as bolt_smoothing
|
||||
from openpilot.starpilot.car.subaru.smoothing import filter_action
|
||||
from openpilot.starpilot.car.volkswagen.model_smoothing import ControlSmoothing, POPV2_SHA256, seconds
|
||||
from openpilot.starpilot.models.status import ModelLoad, ModelVariant
|
||||
@@ -109,11 +110,11 @@ def test_model_join_applies_matching_input_delay_and_exactly_one_filter():
|
||||
cp, load = setup()
|
||||
previous = log.ModelDataV2.Action(desiredCurvature=0.)
|
||||
action = log.ModelDataV2.Action(desiredCurvature=.001, desiredAcceleration=-.25, shouldStop=True)
|
||||
env = {'CP': cp, 'receipt_owner': SimpleNamespace(load=load), 'v_ego': 18., 'subaru_smoothing': 0.,
|
||||
env = {'CP': cp, 'bolt_smoothing': bolt_smoothing, 'receipt_owner': SimpleNamespace(load=load), 'v_ego': 18., 'subaru_smoothing': 0.,
|
||||
'subaru_smooth_seconds': lambda speed, maximum: 0., 'volkswagen_smoothing': seconds,
|
||||
'kona_tau': 0., 'LAT_SMOOTH_SECONDS': 0., 'sm': {'lateralDelay': SimpleNamespace(lateralDelay=.2893982231616974)},
|
||||
'action': action, 'prev_action': previous, 'filter_action': filter_action}
|
||||
wanted = {'subaru_tau', 'volkswagen_tau', 'lat_delay'}
|
||||
wanted = {'subaru_tau', 'volkswagen_tau', 'bolt_tau', 'steering_smoothing', 'lat_delay'}
|
||||
nodes = [n for n in ast.walk(tree) if isinstance(n, ast.Assign) and
|
||||
any(isinstance(t, ast.Name) and t.id in wanted for t in n.targets)]
|
||||
filters = [n for n in ast.walk(tree) if isinstance(n, ast.Expr) and isinstance(n.value, ast.Call) and
|
||||
|
||||
@@ -40,18 +40,21 @@ def test_jetlink_gets_the_frames_delay_before_every_run():
|
||||
any(isinstance(child, ast.Call) and ast.unparse(child.func) == "model.run" for child in ast.walk(node)))
|
||||
assert (line("subaru_tau = subaru_smooth_seconds(v_ego, subaru_smoothing)") <
|
||||
line("volkswagen_tau = volkswagen_smoothing(CP, receipt_owner.load)") <
|
||||
line("lat_delay = sm['lateralDelay'].lateralDelay + LAT_SMOOTH_SECONDS + subaru_tau + volkswagen_tau + kona_tau") <
|
||||
line("steering_smoothing = subaru_tau + volkswagen_tau + kona_tau + bolt_tau") <
|
||||
line("lat_delay = sm['lateralDelay'].lateralDelay + LAT_SMOOTH_SECONDS + steering_smoothing") <
|
||||
line("model.lat_delay = lat_delay") < run)
|
||||
assignments = {ast.unparse(node.targets[0]): node for node in statements if isinstance(node, ast.Assign)}
|
||||
# Reuse the same joined runner across frames: each write must include the current delay and smoothing.
|
||||
model = SimpleNamespace(lat_delay=-1.)
|
||||
for delay, subaru_tau, volkswagen_tau, kona_tau in ((.1, 0., 0., 0.), (.25, .4, 0., 0.), (.05, 2., 0., 0.),
|
||||
(.2, 0., .3, 0.), (.15, .4, .3, 0.), (.3, 0., 0., .1), (.1, 0., 0., 0.)):
|
||||
for delay, subaru_tau, volkswagen_tau, kona_tau, bolt_tau in (
|
||||
(.1, 0., 0., 0., 0.), (.25, .4, 0., 0., 0.), (.05, 2., 0., 0., 0.),
|
||||
(.2, 0., .3, 0., 0.), (.15, .4, .3, 0., 0.), (.3, 0., 0., .1, 0.), (.2, 0., 0., 0., .1), (.1, 0., 0., 0., 0.),
|
||||
):
|
||||
env = {"sm": {"lateralDelay": SimpleNamespace(lateralDelay=delay)}, "LAT_SMOOTH_SECONDS": .03,
|
||||
"subaru_tau": subaru_tau, "volkswagen_tau": volkswagen_tau, "kona_tau": kona_tau, "model": model}
|
||||
code = ast.Module(body=[assignments["lat_delay"], assignments["model.lat_delay"]], type_ignores=[])
|
||||
"subaru_tau": subaru_tau, "volkswagen_tau": volkswagen_tau, "kona_tau": kona_tau, "bolt_tau": bolt_tau, "model": model}
|
||||
code = ast.Module(body=[assignments[name] for name in ("steering_smoothing", "lat_delay", "model.lat_delay")], type_ignores=[])
|
||||
exec(compile(ast.fix_missing_locations(code), str(MODEL_SOURCE), "exec"), env)
|
||||
assert model.lat_delay == pytest.approx(delay + .03 + subaru_tau + volkswagen_tau + kona_tau)
|
||||
assert model.lat_delay == pytest.approx(delay + .03 + subaru_tau + volkswagen_tau + kona_tau + bolt_tau)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("runner_chestnut,stored_active", [(True, False), (True, True), (False, True), (False, False)])
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "2614bb3f7b68edcd15463336ead8c005797a09e80d10a54bbd77ce3b36f5a995", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "88b579b3c1f7a0943811732338b3673a88619a6b7cefa6405d80c286f6e2420e", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user