Skip to content

Commit

Permalink
MADS: add toggle for Cruise Main button engage (commaai#82)
Browse files Browse the repository at this point in the history
* MADS: add toggle for Cruise Main button engage

* add toggle
  • Loading branch information
sunnyhaibin authored May 31, 2023
1 parent 99de690 commit 356a601
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _update(self, c):

buttonEvents = []

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if ret.cruiseState.available:
if self.enable_mads:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _update(self, c):
if self.CS.cruise_buttons != CruiseButtons.UNPRESS and self.CS.prev_cruise_buttons != CruiseButtons.UNPRESS:
buttonEvents.append(create_button_event(CruiseButtons.UNPRESS, self.CS.prev_cruise_buttons, BUTTONS_DICT, CruiseButtons.UNPRESS))

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if not self.CP.pcmCruise:
if any(b.type == ButtonType.accelCruise and b.pressed for b in buttonEvents):
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 @@ -344,7 +344,7 @@ def _update(self, c):
if self.CS.cruise_setting != self.CS.prev_cruise_setting:
buttonEvents.append(create_button_event(self.CS.cruise_setting, self.CS.prev_cruise_setting, {1: ButtonType.altButton1}))

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

self.CS.accEnabled, buttonEvents = self.get_sp_v_cruise_non_pcm_state(ret.cruiseState.available, self.CS.accEnabled,
buttonEvents, c.vCruise)
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/hyundai/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def update(self, cp, cp_cam):
if self.CP.flags & HyundaiFlags.SP_CAN_LFA_BTN:
self.lfa_enabled = cp.vl["BCM_PO_11"]["LFA_Pressed"]

self.mads_enabled = False if not self.control_initialized else ret.cruiseState.available
self.mads_enabled = False if not (self.control_initialized or self.mads_main_toggle) else ret.cruiseState.available

if self.CP.flags & HyundaiFlags.SP_NAV_MSG:
self._update_traffic_signals(self.CP, cp, cp_cam)
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ def sp_update_params(self, CS):
self.gac = self.param_s.get_bool("GapAdjustCruise")
self.gac_mode = round(float(self.param_s.get("GapAdjustCruiseMode", encoding="utf8")))
self.reverse_dm_cam = self.param_s.get_bool("ReverseDmCam")
CS.mads_main_toggle = self.param_s.get_bool("MadsCruiseMain")

class RadarInterfaceBase(ABC):
def __init__(self, CP):
Expand Down Expand Up @@ -587,6 +588,7 @@ def __init__(self, CP):
self.control_initialized = False
self.gap_dist_button = 0
self.gac_tr = round(float(self.param_s.get("GapAdjustCruiseTr", encoding="utf8")))
self.mads_main_toggle = self.param_s.get_bool("MadsCruiseMain")

# Q = np.matrix([[0.0, 0.0], [0.0, 100.0]])
# R = 0.3
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/mazda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _update(self, c):
be.type = ButtonType.cancel
buttonEvents.append(be)

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if ret.cruiseState.available:
if self.enable_mads:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/nissan/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _update(self, c):
#be.type = car.CarState.ButtonEvent.Type.accelCruise
#buttonEvents.append(be)

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if ret.cruiseState.available:
if self.enable_mads:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/subaru/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _update(self, c):

buttonEvents = []

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if ret.cruiseState.available:
if self.enable_mads:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _update(self, c):
if self.CS.gap_dist_button != self.CS.prev_gap_dist_button:
buttonEvents.append(create_button_event(self.CS.gap_dist_button, self.CS.prev_gap_dist_button, {1: ButtonType.gapAdjustCruise}))

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

if ret.cruiseState.available:
if self.enable_mads:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/volkswagen/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _update(self, c):
be.pressed = self.CS.buttonStates[button]
buttonEvents.append(be)

self.CS.mads_enabled = False if not self.CS.control_initialized else ret.cruiseState.available
self.CS.mads_enabled = False if not (self.CS.control_initialized or self.CS.mads_main_toggle) else ret.cruiseState.available

self.CS.accEnabled, buttonEvents = self.get_sp_v_cruise_non_pcm_state(ret.cruiseState.available, self.CS.accEnabled,
buttonEvents, c.vCruise,
Expand Down
13 changes: 13 additions & 0 deletions selfdrive/ui/qt/offroad/sunnypilot_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ SPControlsPanel::SPControlsPanel(QWidget *parent) : QWidget(parent) {
accMadsCombo->setEnabled(offroad);
});
madsSubControl->addWidget(accMadsCombo);
madsSubControl->addWidget(horizontal_line());

// Controls: Enable M.A.D.S. with Cruise Main
madsCruiseMain = new ParamControl(
"MadsCruiseMain",
tr("Toggle M.A.D.S. with Cruise Main"),
tr("Allows M.A.D.S. engagement/disengagement with \"Cruise Main\" cruise control button from the steering wheel."),
"../assets/offroad/icon_openpilot.png"
);
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
madsCruiseMain->setEnabled(offroad);
});
madsSubControl->addWidget(madsCruiseMain);
connect(madsControl, &ToggleControl::toggleFlipped, [=](bool state) {
updateToggles();
});
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/offroad/sunnypilot_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public slots:
ParamControl *madsControl;
ParamControl *disengageLateralOnBrake;
ParamControl *accMadsCombo;
ParamControl *madsCruiseMain;
ParamControl *belowSpeed;
ParamControl *dlpControl;
ParamControl *dlpCurve;
Expand Down

0 comments on commit 356a601

Please sign in to comment.