diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 92d9b7eb11ddfd..29abc878ea7353 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -25,6 +25,7 @@ REPLAY = "REPLAY" in os.environ EventName = log.OnroadEvent.EventName +ButtonType = car.CarState.ButtonEvent.Type # forward carlog.addHandler(ForwardingHandler(cloudlog)) @@ -73,6 +74,7 @@ def __init__(self, CI=None, RI=None) -> None: self.CC_prev = car.CarControl.new_message() self.initialized_prev = False + self.resume_prev = False self.last_actuators_output = structs.CarControl.Actuators() @@ -239,7 +241,7 @@ def step(self): CS, RD = self.state_update() if self.sm['carControl'].enabled and not self.CC_prev.enabled: - self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode) + self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode, self.resume_prev) self.state_publish(CS, RD) @@ -250,6 +252,11 @@ def step(self): self.initialized_prev = initialized + if any(b.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for b in CS.buttonEvents): + self.resume_prev = True + else: + self.resume_prev = False + def params_thread(self, evt): while not evt.is_set(): self.is_metric = self.params.get_bool("IsMetric") diff --git a/selfdrive/car/cruise.py b/selfdrive/car/cruise.py index b92d0c74659db3..652f58e0c77428 100644 --- a/selfdrive/car/cruise.py +++ b/selfdrive/car/cruise.py @@ -120,14 +120,14 @@ def update_button_timers(self, CS, enabled): 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) -> None: + def initialize_v_cruise(self, CS, experimental_mode: bool, resume_prev: bool) -> None: # initializing is handled by the PCM if self.CP.pcmCruise: return initial = V_CRUISE_INITIAL_EXPERIMENTAL_MODE if 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: + if resume_prev and self.v_cruise_initialized: self.v_cruise_kph = self.v_cruise_kph_last else: self.v_cruise_kph = int(round(clip(CS.vEgo * CV.MS_TO_KPH, initial, V_CRUISE_MAX)))