Skip to content

Commit

Permalink
Loopback Resume Button
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettpall committed Jan 10, 2025
1 parent 0877994 commit b7c516d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
REPLAY = "REPLAY" in os.environ

EventName = log.OnroadEvent.EventName
ButtonType = car.CarState.ButtonEvent.Type

# forward
carlog.addHandler(ForwardingHandler(cloudlog))
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/cruise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit b7c516d

Please sign in to comment.