mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 00:03:57 +08:00
Match fresh speed limits on Redneck Cruise SET
This commit is contained in:
@@ -869,6 +869,10 @@ class Car:
|
||||
self.v_cruise_helper.update_v_cruise(CS, self.sm['carControl'].enabled, self.is_metric, pending,
|
||||
slc_enabled=getattr(self, 'slc_control_enabled', getattr(self, 'slc_replay', False)),
|
||||
wheel_context=wheel_context)
|
||||
redneck_cruise = getattr(self, 'redneck_cruise', None)
|
||||
if redneck_cruise is not None and (self.slc_match_on_engage or redneck_cruise.set_match_ns):
|
||||
now_ns = int(self.can_log_mono_time) if REPLAY and hasattr(self, 'can_log_mono_time') else time.monotonic_ns()
|
||||
redneck_cruise.match_limit_on_set(self, CS, now_ns)
|
||||
if self.sm['carControl'].enabled and not self.CC_prev.enabled:
|
||||
target, initial = None, None
|
||||
now_ns = int(self.can_log_mono_time) if REPLAY and hasattr(self, 'can_log_mono_time') else time.monotonic_ns()
|
||||
|
||||
@@ -4,7 +4,7 @@ from opendbc.car.structs import car
|
||||
from opendbc.car import apply_hysteresis
|
||||
from openpilot.common.constants import CV
|
||||
from openpilot.common.realtime import DT_CTRL
|
||||
from openpilot.selfdrive.car.cruise import V_CRUISE_UNSET
|
||||
from openpilot.selfdrive.car.cruise import V_CRUISE_MIN, V_CRUISE_UNSET, slc_target_kph
|
||||
|
||||
def ready(cs, cc):
|
||||
return (cc.enabled and cs.canValid and not cs.canTimeout and cs.gearShifter == car.CarState.GearShifter.drive and
|
||||
@@ -184,6 +184,7 @@ class RedneckCruise:
|
||||
self.is_ready = False
|
||||
self.is_ready_prev = False
|
||||
self.cruise_button_timers = dict(CRUISE_BUTTON_TIMERS)
|
||||
self.set_match_ns = 0
|
||||
|
||||
@staticmethod
|
||||
def _send_button_for_state(state: str) -> int:
|
||||
@@ -284,6 +285,41 @@ class RedneckCruise:
|
||||
return send_button, self.v_target
|
||||
|
||||
|
||||
def match_limit_on_set(self, card, cs, now_ns: int) -> None:
|
||||
cc = card.sm['carControl']
|
||||
if (not card.slc_match_on_engage or not card.slc_control_enabled or not cs.canValid or cs.canTimeout or
|
||||
not cs.cruiseState.available or cs.gearShifter != car.CarState.GearShifter.drive or
|
||||
cs.standstill or cs.brakePressed or cs.gasPressed or cs.accFaulted):
|
||||
self.set_match_ns = 0
|
||||
return
|
||||
if not self.set_match_ns and not cs.buttonEvents:
|
||||
return
|
||||
pressed = {button.type.raw for button in cs.buttonEvents if button.pressed}
|
||||
if pressed.intersection((ButtonType.accelCruise, ButtonType.resumeCruise, ButtonType.cancel, ButtonType.mainCruise)):
|
||||
self.set_match_ns = 0
|
||||
return
|
||||
if (not cc.enabled and not card.CS_prev.cruiseState.enabled and
|
||||
pressed.intersection((ButtonType.decelCruise, ButtonType.setCruise))):
|
||||
self.set_match_ns = now_ns
|
||||
if not 0 < self.set_match_ns <= now_ns <= self.set_match_ns + 500_000_000:
|
||||
self.set_match_ns = 0
|
||||
return
|
||||
|
||||
helper = card.v_cruise_helper
|
||||
if (not cc.enabled or not cs.cruiseState.enabled or not current(card.sm, 'carControl', now_ns) or
|
||||
not V_CRUISE_MIN <= helper.v_cruise_kph < V_CRUISE_UNSET):
|
||||
return
|
||||
self.set_match_ns = 0
|
||||
from openpilot.starpilot.speed_limits.physical_actions import engagement_state
|
||||
evidence = getattr(card.CI.CS, 'dashboard_limit', None)
|
||||
state = engagement_state(card.sm, evidence.observation if evidence is not None else None, card.slc_producer_session,
|
||||
now_ns, after_ns=card.slc_source_floor_ns)
|
||||
if state is not None:
|
||||
target = slc_target_kph(state.presentationAdjustedLimit, card.is_metric)
|
||||
minimum = get_minimum_set_speed(card.is_metric) * (1. if card.is_metric else CV.MPH_TO_KPH)
|
||||
if minimum <= target < helper.v_cruise_kph:
|
||||
helper.apply_slc_target(state.presentationAdjustedLimit, card.is_metric)
|
||||
|
||||
def update(self, card, cs, cc, now_ns):
|
||||
update(card, cs, cc, now_ns)
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ DESCRIPTIONS = {
|
||||
'SpeedLimitController': 'Follows accepted limits plus offsets up to SET speed. Missing data uses the previous accepted limit.',
|
||||
'SLCOnEngage': ('Starts software cruise SET at the SLC limit plus offset. ' +
|
||||
'A limit accepted this session remains available during data gaps. Previous-drive history does not initialize SET. ' +
|
||||
'RES restores the previous SET.'),
|
||||
'RES restores the previous SET. Redneck Cruise lowers the new SET only when a current limit is available.'),
|
||||
'SLCOverrideMode': ('Cruise uses this target when you lift off the accelerator. ' +
|
||||
'Holding your speed uses the highest speed you reached, up to SET.'),
|
||||
'SLCWheelOverride': 'Press + to raise SET past the adjusted limit and use your new SET speed.',
|
||||
|
||||
@@ -185,6 +185,12 @@ class SettingsGatewayTest(unittest.TestCase):
|
||||
intent = self.gateway.preview(page['view'], slc_row(page), 0, self.session, self.generation, value='On')
|
||||
self.assertTrue(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
self.assertTrue(self.params.get_bool('SpeedLimitController'))
|
||||
page = self.page('slc')
|
||||
index = next(i for i, row in enumerate(page['rows']) if row['label'] == 'Match Speed Limit on Engage')
|
||||
self.assertTrue(page['rows'][index]['available'])
|
||||
intent = self.gateway.preview(page['view'], index, 0, self.session, self.generation, value='On')
|
||||
self.assertTrue(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
self.assertTrue(self.params.get_bool('SLCOnEngage'))
|
||||
self.assertFalse(selected(cp))
|
||||
self.assertFalse(cp.openpilotLongitudinalControl)
|
||||
self.assertEqual(cp.as_reader().as_builder().to_bytes(), raw)
|
||||
|
||||
@@ -83,6 +83,45 @@ def engage(instance, *, now=START + 10_000_000):
|
||||
return cs
|
||||
|
||||
|
||||
@pytest.mark.parametrize('gesture,match,limit,delay,expected', [
|
||||
('decelCruise', True, 50., 80_000_000, 50.),
|
||||
('decelCruise', False, 50., 80_000_000, 60.),
|
||||
('accelCruise', True, 50., 80_000_000, 60.),
|
||||
('decelCruise', True, 70., 80_000_000, 60.),
|
||||
('decelCruise', True, 20., 80_000_000, 60.),
|
||||
('decelCruise', True, 50., 550_000_000, 60.),
|
||||
])
|
||||
def test_redneck_set_matching_preserves_the_stock_ceiling_and_resume(gesture, match, limit, delay, expected):
|
||||
from opendbc.car.hyundai.interface import CarInterface
|
||||
from opendbc.car.hyundai.software_cruise import prepare
|
||||
from opendbc.car.hyundai.values import CAR
|
||||
from openpilot.starpilot.car.hyundai.redneck_cruise import RedneckCruise
|
||||
|
||||
_, sm, _ = drive(metric=True, limit=limit, offset=0.)
|
||||
cp = prepare(CarInterface.get_non_essential_params(CAR.HYUNDAI_KONA_NON_SCC), True)
|
||||
instance = owner(sm, cp, metric=True, match=match)
|
||||
instance.redneck_cruise = RedneckCruise(cp, SimpleNamespace(redneckCruiseAvailable=True, pcmCruiseSpeed=False))
|
||||
sm.seen, sm.recv_time = dict(sm.valid), {}
|
||||
|
||||
def step(now, *, enabled, stock_speed, buttons=()):
|
||||
sm.advance(now)
|
||||
sm.recv_time['carControl'] = now / 1e9
|
||||
sm['carControl'].enabled = enabled
|
||||
cs = car.CarState(canValid=True, vEgo=15., gearShifter='drive', buttonEvents=list(buttons),
|
||||
cruiseState={'available': True, 'enabled': enabled, 'speed': stock_speed / 3.6, 'speedCluster': stock_speed / 3.6})
|
||||
with patch.object(card.time, 'monotonic_ns', return_value=now), patch.object(cruise, 'monotonic_ns', return_value=now):
|
||||
instance.update_cruise_speed(cs)
|
||||
instance.CS_prev = cs
|
||||
instance.CC_prev = car.CarControl(enabled=enabled)
|
||||
return instance.v_cruise_helper.v_cruise_kph
|
||||
|
||||
step(START, enabled=False, stock_speed=0., buttons=({'type': gesture, 'pressed': True},))
|
||||
assert step(START + 20_000_000, enabled=True, stock_speed=0.) == cruise.V_CRUISE_UNSET
|
||||
assert step(START + delay, enabled=True, stock_speed=60.) == pytest.approx(expected)
|
||||
assert step(START + delay + 20_000_000, enabled=True, stock_speed=60.) == pytest.approx(expected)
|
||||
assert not sm['carControl'].longActive and not cp.openpilotLongitudinalControl
|
||||
|
||||
|
||||
def receipt(instance, *, now=START + 10_000_000, event_id=1):
|
||||
kind, state, previous, selected, observed = instance.slc_receipts[-1]
|
||||
return CruiseEvent(event_id, observed, previous, selected, 'decel', instance.slc_producer_session, now,
|
||||
|
||||
@@ -1187,7 +1187,8 @@ class FeatureSettingsOwner:
|
||||
rows.extend(self.wheel.rows())
|
||||
elif page == FeaturePage.SLC:
|
||||
cp = self.vehicle_params()
|
||||
slc_available = system_long if cp is None else self.longitudinal_available() or hyundai_software_cruise.slc_configurable(cp, self.params)
|
||||
button_cruise = hyundai_software_cruise.slc_configurable(cp, self.params)
|
||||
slc_available = system_long if cp is None else self.longitudinal_available() or button_cruise
|
||||
system_long = slc_available and self.authority("slc")
|
||||
allowed = configurable and system_long
|
||||
offsets_ready, offset_rows = self.slc_offsets.rows(allowed, repair_allowed=parked and allowed)
|
||||
@@ -1207,10 +1208,10 @@ class FeatureSettingsOwner:
|
||||
control_row = self._bool_row("SpeedLimitController", "Speed Limit Controller",
|
||||
allowed and (offsets_ready or control == "1"), reason=control_reason)
|
||||
rows.append(replace(control_row, reason=control_reason) if control_row.choices else control_row)
|
||||
cp = self.vehicle_params()
|
||||
if cp is not None and not cp.pcmCruise:
|
||||
if cp is not None and (not cp.pcmCruise or button_cruise):
|
||||
rows.append(self._bool_row("SLCOnEngage", "Match Speed Limit on Engage", allowed and control == "1",
|
||||
reason="Start SET at the SLC limit plus offset. RES restores your previous SET"))
|
||||
reason="Lower your new SET to the speed limit plus offset when using Redneck Cruise"
|
||||
if button_cruise else "Start SET at the SLC limit plus offset. RES restores your previous SET"))
|
||||
rows.append(self._bool_row("ShowSpeedLimits", "Show speed limit signs", self.authority("preferences"),
|
||||
reason="Display signs independently of Speed Limit Controller; does not change cruise speed"))
|
||||
rows.extend(policy_rows(self._value, self._readable, allowed=allowed))
|
||||
@@ -1755,7 +1756,8 @@ class FeatureSettingsOwner:
|
||||
return False
|
||||
if key in ("SLCOnEngage", WHEEL_OVERRIDE_KEY):
|
||||
cp = self.vehicle_params()
|
||||
if cp is None or cp.pcmCruise or not self.longitudinal_available() or (
|
||||
button_match = key == "SLCOnEngage" and hyundai_software_cruise.slc_configurable(cp, self.params)
|
||||
if (not (button_match or cp is not None and not cp.pcmCruise and self.longitudinal_available()) or
|
||||
request.value == "On" and self._raw("SpeedLimitController") != b"1"):
|
||||
return False
|
||||
encoded = "1" if request.value == "On" else "0"
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "10f065f423abef911e5618c0a80693a823a5fa2e1a70d477e067cff1a48d3983", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "c454452ab3886acf6be36a19dee5d8fa00c870d7ba56568c0f1db8fbb77a3bb9", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user