Skip to content

Commit

Permalink
MADS: Map cruise main and lateral buttons to button events (commaai#361)
Browse files Browse the repository at this point in the history
* MADS: Map cruise main and lateral buttons to button events

* different style

* nah
  • Loading branch information
sunnyhaibin authored Jul 30, 2024
1 parent 4e237e5 commit 4d7afe3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def _update(self, c):
self.sp_update_params()

self.CS.button_events.extend(create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}))
self.CS.button_events.extend(create_button_events(self.CS.lkas_enabled, self.CS.prev_lkas_enabled, {1: ButtonType.altButton1}))

self.CS.mads_enabled = self.get_sp_cruise_main_state(ret, self.CS)

Expand All @@ -108,7 +109,7 @@ def _update(self, c):
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if self.CS.prev_lkas_enabled != 1 and self.CS.lkas_enabled == 1:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.lkas_disabled = not self.CS.lkas_disabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
Expand Down
3 changes: 2 additions & 1 deletion selfdrive/car/ford/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _update(self, c):
self.sp_update_params()

self.CS.button_events.extend(create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}))
self.CS.button_events.extend(create_button_events(self.CS.lkas_enabled, self.CS.prev_lkas_enabled, {1: ButtonType.altButton1}))

self.CS.mads_enabled = self.get_sp_cruise_main_state(ret, self.CS)

Expand All @@ -85,7 +86,7 @@ def _update(self, c):
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if not self.CS.prev_lkas_enabled and self.CS.lkas_enabled:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
Expand Down
4 changes: 3 additions & 1 deletion selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def _update(self, c):
]
distance_button = self.CS.distance_button

self.CS.button_events.extend(create_button_events(self.CS.lkas_enabled, self.CS.prev_lkas_enabled, {1: ButtonType.altButton1}))

self.CS.mads_enabled = self.get_sp_cruise_main_state(ret, self.CS)

if not self.CP.pcmCruise:
Expand All @@ -231,7 +233,7 @@ def _update(self, c):
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if self.CS.prev_lkas_enabled != 1 and self.CS.lkas_enabled == 1:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _update(self, c):
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if self.CS.prev_cruise_setting != 1 and self.CS.cruise_setting == 1:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
Expand Down
14 changes: 6 additions & 8 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)
self.sp_update_params()

self.CS.button_events = create_button_events(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT)
self.CS.button_events.extend(create_button_events(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT))
self.CS.button_events.extend(create_button_events(self.CS.lfa_enabled, self.CS.prev_lfa_enabled, {1: ButtonType.altButton1}))
self.CS.button_events.extend(create_button_events(self.CS.main_buttons[-1], self.CS.prev_main_buttons, {1: ButtonType.altButton3}))

self.CS.accEnabled = self.get_sp_v_cruise_non_pcm_state(ret, self.CS.accEnabled,
self.CS.button_events, c.vCruise)
Expand All @@ -214,16 +216,12 @@ def _update(self, c):

if ret.cruiseState.available:
if not self.CP.pcmCruiseSpeed:
if self.CS.prev_main_buttons == 1:
if self.CS.main_buttons[-1] != 1:
self.CS.accEnabled = True
elif self.CS.prev_cruise_buttons == 4:
if self.CS.cruise_buttons[-1] != 4:
self.accEnabled = True
if any(b.type in (ButtonType.altButton3, ButtonType.cancel) and not b.pressed for b in self.CS.button_events):
self.CS.accEnabled = True
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if self.CS.prev_lfa_enabled != 1 and self.CS.lfa_enabled == 1:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
Expand Down
8 changes: 3 additions & 5 deletions selfdrive/car/mazda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def _update(self, c):
self.sp_update_params()

# TODO: add button types for inc and dec
self.CS.button_events = [
*self.CS.button_events,
*create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})
]
self.CS.button_events.extend(create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}))
self.CS.button_events.extend(create_button_events(self.CS.lkas_enabled, self.CS.prev_lkas_enabled, {1: ButtonType.altButton1}))

self.CS.mads_enabled = self.get_sp_cruise_main_state(ret, self.CS)

Expand All @@ -54,7 +52,7 @@ def _update(self, c):
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
if self.CS.prev_lkas_enabled != self.CS.lkas_enabled:
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
self.CS.madsEnabled = not self.CS.madsEnabled
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
Expand Down

0 comments on commit 4d7afe3

Please sign in to comment.