mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-04 15:56:05 +08:00
0cb0bf8028
* Add Reverse ACC Change parameter and update cruise control logic * lint lint lint (and lint has been summoned!) * Add test for speed adjustment on reverse ACC button presses * Fix formatting in cruise speed test for reverse ACC button presses * Fix assertion in cruise speed test for reverse ACC button presses * Enhance speed adjustment test for reverse ACC functionality * Refactor speed adjustment test for clarity and consistency in reverse ACC behavior * Fix metric conversion in cruise speed update for reverse ACC functionality * custom-acc-speed-increments * simplify * remove unused params * move params & add test * lets see if this works * minor cosmetic stuff * clean up class names & old code * remove unused import * moved params to card * stupid strings * Add settings for developer reverse acceleration configuration * Refactor cruise control parameters to use a dictionary for custom acceleration increments * adjust for the default behavior * Remove unused param * Fuck pytest consistently failing on macos. Need to force a fail on the pipeline or I won't have confidence on the tests. * Revert "Fuck pytest consistently failing on macos. Need to force a fail on the pipeline or I won't have confidence on the tests." This reverts commit 05bac46a0c3964d8f7a3c4db652609eb25b8fd2a. * Refactor custom acceleration increment handling to improve clarity and initialization * Refactor AccIncrementOptionControl to accept range and per_value_change parameters for improved flexibility * Refactor custom acceleration increment handling to improve clarity and functionality * Adjusting tests * Static * no need for space changes * no need for space changes * no need for space changes * Refactor constructor formatting in AccIncrementOptionControl * Rename * Meaningless change to test CI * allow 1/5/10 increments for long press move developer panel src to /offroad/settings * update boundary condition for long press * clamp increments of 5/10 regardless of short or long press * update tests * update test for long_press non-standard values * move to cruise panel * init * use cereal * update tests * merge * bump * clean up * more clean up * no more layout warnings * trying to resolve dev ci merge conflicts * damn ui preview * stack layout enable only with oplong * bump opendbc * fix width * bump tinygrad * switch to params * remove cereal changes * sort params * cleanup * more cleanup * lint * rename * split vcruise_helper * move params to card thread hide widget for pcm cruise * simplify tests * further simplify tests * tests!! * Revert "tests!!" This reverts commit 85310a155e7a9f5a9b23685cb43b9c9b3c415818. * move tuple from init to update_v_cruise * lint * temp remove tests to check * Revert "temp remove tests to check" This reverts commit da1c96a5dbe5398e7cccfe9e2ad3bf0308b5fe3d. * handle exception * formatting * handle none condition * remove from tests * flip inheritance * read directly * set default * not needed * refactor inheritence * rename * already checks before invoking * unused * slight cleanup * lint * rename * diff * circular * just 1 parent for now * fix * fix increment check with remainder * red diff * type hint * update tests * clip them * formatting * always check toggle visibility * spaces are free * hide widgets when disabled * less * handle more states * private instead * red diff says wuuuut * fix panel click --------- Co-authored-by: DevTekVE <devtekve@gmail.com> Co-authored-by: Discountchubbs <159560811+Discountchubbs@users.noreply.github.com> Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
142 lines
5.4 KiB
Python
142 lines
5.4 KiB
Python
import math
|
|
import numpy as np
|
|
|
|
from cereal import car
|
|
from openpilot.common.conversions import Conversions as CV
|
|
from openpilot.sunnypilot.selfdrive.car.cruise_ext import VCruiseHelperSP
|
|
|
|
|
|
# WARNING: this value was determined based on the model's training distribution,
|
|
# model predictions above this speed can be unpredictable
|
|
# V_CRUISE's are in kph
|
|
V_CRUISE_MIN = 8
|
|
V_CRUISE_MAX = 145
|
|
V_CRUISE_UNSET = 255
|
|
V_CRUISE_INITIAL = 40
|
|
V_CRUISE_INITIAL_EXPERIMENTAL_MODE = 105
|
|
IMPERIAL_INCREMENT = round(CV.MPH_TO_KPH, 1) # round here to avoid rounding errors incrementing set speed
|
|
|
|
ButtonEvent = car.CarState.ButtonEvent
|
|
ButtonType = car.CarState.ButtonEvent.Type
|
|
CRUISE_LONG_PRESS = 50
|
|
CRUISE_NEAREST_FUNC = {
|
|
ButtonType.accelCruise: math.ceil,
|
|
ButtonType.decelCruise: math.floor,
|
|
}
|
|
CRUISE_INTERVAL_SIGN = {
|
|
ButtonType.accelCruise: +1,
|
|
ButtonType.decelCruise: -1,
|
|
}
|
|
|
|
|
|
class VCruiseHelper(VCruiseHelperSP):
|
|
def __init__(self, CP):
|
|
VCruiseHelperSP.__init__(self)
|
|
self.CP = CP
|
|
self.v_cruise_kph = V_CRUISE_UNSET
|
|
self.v_cruise_cluster_kph = V_CRUISE_UNSET
|
|
self.v_cruise_kph_last = 0
|
|
self.button_timers = {ButtonType.decelCruise: 0, ButtonType.accelCruise: 0}
|
|
self.button_change_states = {btn: {"standstill": False, "enabled": False} for btn in self.button_timers}
|
|
|
|
@property
|
|
def v_cruise_initialized(self):
|
|
return self.v_cruise_kph != V_CRUISE_UNSET
|
|
|
|
def update_v_cruise(self, CS, enabled, is_metric):
|
|
self.v_cruise_kph_last = self.v_cruise_kph
|
|
|
|
if CS.cruiseState.available:
|
|
if not self.CP.pcmCruise:
|
|
# if stock cruise is completely disabled, then we can use our own set speed logic
|
|
self._update_v_cruise_non_pcm(CS, enabled, is_metric)
|
|
self.v_cruise_cluster_kph = self.v_cruise_kph
|
|
self.update_button_timers(CS, enabled)
|
|
else:
|
|
self.v_cruise_kph = CS.cruiseState.speed * CV.MS_TO_KPH
|
|
self.v_cruise_cluster_kph = CS.cruiseState.speedCluster * CV.MS_TO_KPH
|
|
if CS.cruiseState.speed == 0:
|
|
self.v_cruise_kph = V_CRUISE_UNSET
|
|
self.v_cruise_cluster_kph = V_CRUISE_UNSET
|
|
elif CS.cruiseState.speed == -1:
|
|
self.v_cruise_kph = -1
|
|
self.v_cruise_cluster_kph = -1
|
|
else:
|
|
self.v_cruise_kph = V_CRUISE_UNSET
|
|
self.v_cruise_cluster_kph = V_CRUISE_UNSET
|
|
|
|
def _update_v_cruise_non_pcm(self, CS, enabled, is_metric):
|
|
# handle button presses. TODO: this should be in state_control, but a decelCruise press
|
|
# would have the effect of both enabling and changing speed is checked after the state transition
|
|
if not enabled:
|
|
return
|
|
|
|
long_press = False
|
|
button_type = None
|
|
|
|
v_cruise_delta = 1. if is_metric else IMPERIAL_INCREMENT
|
|
|
|
for b in CS.buttonEvents:
|
|
if b.type.raw in self.button_timers and not b.pressed:
|
|
if self.button_timers[b.type.raw] > CRUISE_LONG_PRESS:
|
|
return # end long press
|
|
button_type = b.type.raw
|
|
break
|
|
else:
|
|
for k, timer in self.button_timers.items():
|
|
if timer and timer % CRUISE_LONG_PRESS == 0:
|
|
button_type = k
|
|
long_press = True
|
|
break
|
|
|
|
if button_type is None:
|
|
return
|
|
|
|
# Don't adjust speed when pressing resume to exit standstill
|
|
cruise_standstill = self.button_change_states[button_type]["standstill"] or CS.cruiseState.standstill
|
|
if button_type == ButtonType.accelCruise and cruise_standstill:
|
|
return
|
|
|
|
# Don't adjust speed if we've enabled since the button was depressed (some ports enable on rising edge)
|
|
if not self.button_change_states[button_type]["enabled"]:
|
|
return
|
|
|
|
long_press, v_cruise_delta = VCruiseHelperSP.update_v_cruise_delta(self, long_press, v_cruise_delta)
|
|
if long_press and self.v_cruise_kph % v_cruise_delta != 0: # partial interval
|
|
self.v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](self.v_cruise_kph / v_cruise_delta) * v_cruise_delta
|
|
else:
|
|
self.v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type]
|
|
|
|
# If set is pressed while overriding, clip cruise speed to minimum of vEgo
|
|
if CS.gasPressed and button_type in (ButtonType.decelCruise, ButtonType.setCruise):
|
|
self.v_cruise_kph = max(self.v_cruise_kph, CS.vEgo * CV.MS_TO_KPH)
|
|
|
|
self.v_cruise_kph = np.clip(round(self.v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX)
|
|
|
|
def update_button_timers(self, CS, enabled):
|
|
# increment timer for buttons still pressed
|
|
for k in self.button_timers:
|
|
if self.button_timers[k] > 0:
|
|
self.button_timers[k] += 1
|
|
|
|
for b in CS.buttonEvents:
|
|
if b.type.raw in self.button_timers:
|
|
# Start/end timer and store current state on change of button pressed
|
|
self.button_timers[b.type.raw] = 1 if b.pressed else 0
|
|
self.button_change_states[b.type.raw] = {"standstill": CS.cruiseState.standstill, "enabled": enabled}
|
|
|
|
def initialize_v_cruise(self, CS, experimental_mode: bool, dynamic_experimental_control: bool) -> None:
|
|
# initializing is handled by the PCM
|
|
if self.CP.pcmCruise:
|
|
return
|
|
|
|
initial_experimental_mode = experimental_mode and not dynamic_experimental_control
|
|
initial = V_CRUISE_INITIAL_EXPERIMENTAL_MODE if initial_experimental_mode else V_CRUISE_INITIAL
|
|
|
|
if any(b.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for b in CS.buttonEvents) and self.v_cruise_initialized:
|
|
self.v_cruise_kph = self.v_cruise_kph_last
|
|
else:
|
|
self.v_cruise_kph = int(round(np.clip(CS.vEgo * CV.MS_TO_KPH, initial, V_CRUISE_MAX)))
|
|
|
|
self.v_cruise_cluster_kph = self.v_cruise_kph
|