Vehicles - Toyota - Automatically Lock/Unlock Doors

Automatically lock the doors when in drive and unlock when in park.

Credit goes to AlexandreSato!

https: //github.com/AlexandreSato/openpilot
Co-Authored-By: Alexandre Nobuharu Sato <66435071+alexandresato@users.noreply.github.com>
This commit is contained in:
FrogAi 2024-06-10 06:39:00 -07:00
parent 1fce763ad2
commit d8f8a9b754
1 changed files with 21 additions and 0 deletions

View File

@ -25,6 +25,11 @@ MAX_USER_TORQUE = 500
MAX_LTA_ANGLE = 94.9461 # deg
MAX_LTA_DRIVER_TORQUE_ALLOWANCE = 150 # slightly above steering pressed allows some resistance when changing lanes
# Lock / unlock door commands - Credit goes to AlexandreSato!
LOCK_CMD = b"\x40\x05\x30\x11\x00\x80\x00\x00"
UNLOCK_CMD = b"\x40\x05\x30\x11\x00\x40\x00\x00"
PARK = car.CarState.GearShifter.park
class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
@ -46,6 +51,9 @@ class CarController(CarControllerBase):
# FrogPilot variables
params = Params()
self.doors_locked = False
self.doors_unlocked = True
def update(self, CC, CS, now_nanos, frogpilot_toggles):
actuators = CC.actuators
hud_control = CC.hudControl
@ -205,5 +213,18 @@ class CarController(CarControllerBase):
new_actuators.accel = self.accel
new_actuators.gas = self.gas
# Lock doors when in drive / unlock doors when in park
if self.doors_unlocked and CS.out.gearShifter != PARK:
if frogpilot_toggles.lock_doors:
can_sends.append(make_can_msg(0x750, LOCK_CMD, 0))
self.doors_locked = True
self.doors_unlocked = False
elif self.doors_locked and CS.out.gearShifter == PARK:
if frogpilot_toggles.unlock_doors:
can_sends.append(make_can_msg(0x750, UNLOCK_CMD, 0))
self.doors_locked = False
self.doors_unlocked = True
self.frame += 1
return new_actuators, can_sends