Skip to content

Commit

Permalink
MADS? MADS!
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Aug 2, 2024
1 parent 1fe12db commit 81830c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion panda
Submodule panda updated from f8084f to 165da7
2 changes: 0 additions & 2 deletions selfdrive/car/tesla/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def __init__(self, CP):
def update(self, cp, cp_cam, cp_adas):
ret = car.CarState.new_message()

self.prev_mads_enabled = self.mads_enabled

# Vehicle speed
ret.vEgoRaw = cp.vl["ESP_B"]["ESP_vehicleSpeed"] * CV.KPH_TO_MS
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
Expand Down
11 changes: 5 additions & 6 deletions selfdrive/car/tesla/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam, self.cp_adas)

# TODO: Implement detection of half vs full press of stalk for MADS control
# Until then, we're disabling main state control to prevent it from trying to self-engage without user input
self.CS.mads_enabled = False # Tesla has no "cruise main state", as cruise is automatically available

if ret.cruiseState.available:
if self.enable_mads:
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
self.CS.madsEnabled = True
for b in self.CS.button_events:
if b.type == ButtonType.altButton1 and b.pressed:
self.CS.madsEnabled = True
elif b.type == ButtonType.altButton2 and b.pressed:
self.CS.madsEnabled = False
self.CS.madsEnabled = self.get_acc_mads(ret.cruiseState.enabled, self.CS.accEnabled, self.CS.madsEnabled)
else:
self.CS.madsEnabled = False
Expand Down
6 changes: 4 additions & 2 deletions selfdrive/car/tesla/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class CANBUS:
Button(car.CarState.ButtonEvent.Type.rightBlinker, "SCCM_leftStalk", "SCCM_turnIndicatorStalkStatus", [1, 2]),
Button(car.CarState.ButtonEvent.Type.accelCruise, "VCLEFT_switchStatus", "VCLEFT_swcRightScrollTicks", list(range(1, 10))),
Button(car.CarState.ButtonEvent.Type.decelCruise, "VCLEFT_switchStatus", "VCLEFT_swcRightScrollTicks", list(range(-9, 0))),
Button(car.CarState.ButtonEvent.Type.cancel, "SCCM_rightStalk", "SCCM_rightStalkStatus", [1, 2]),
Button(car.CarState.ButtonEvent.Type.resumeCruise, "SCCM_rightStalk", "SCCM_rightStalkStatus", [3, 4]),
Button(car.CarState.ButtonEvent.Type.cancel, "SCCM_rightStalk", "SCCM_rightStalkStatus", [1]),
Button(car.CarState.ButtonEvent.Type.resumeCruise, "SCCM_rightStalk", "SCCM_rightStalkStatus", [4]),
Button(car.CarState.ButtonEvent.Type.altButton1, "SCCM_rightStalk", "SCCM_rightStalkStatus", [3]), # MADS engaged
Button(car.CarState.ButtonEvent.Type.altButton2, "SCCM_rightStalk", "SCCM_rightStalkStatus", [2]), # MADS disengaged
]


Expand Down

0 comments on commit 81830c8

Please sign in to comment.