mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-07 08:43:40 +08:00
Update cruise.py
This commit is contained in:
@@ -36,6 +36,7 @@ class VCruiseHelper:
|
||||
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}
|
||||
self.v_speed_limit_kph = 0
|
||||
|
||||
@property
|
||||
def v_cruise_initialized(self):
|
||||
@@ -47,6 +48,7 @@ class VCruiseHelper:
|
||||
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_speed_limit(CS, enabled)
|
||||
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)
|
||||
@@ -63,6 +65,15 @@ class VCruiseHelper:
|
||||
self.v_cruise_kph = V_CRUISE_UNSET
|
||||
self.v_cruise_cluster_kph = V_CRUISE_UNSET
|
||||
|
||||
def _update_v_speed_limit(self, CS, enabled):
|
||||
if not enabled:
|
||||
return
|
||||
|
||||
speed_limit = CS.cruiseState.speedLimit * CV.MS_TO_KPH
|
||||
if speed_limit != self.v_speed_limit_kph and speed_limit != 0:
|
||||
self.v_cruise_kph = speed_limit
|
||||
self.v_cruise_kph = np.clip(round(self.v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX)
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user