Skip to content

Commit

Permalink
Toyota: Automatically Lock/Unlock Doors
Browse files Browse the repository at this point in the history
reword

params: fix not defined values

fix
  • Loading branch information
Edison-CBS committed Aug 4, 2024
1 parent 7215a17 commit ffe93f1
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ std::unordered_map<std::string, uint32_t> keys = {
{"UpdaterTargetBranch", CLEAR_ON_MANAGER_START},
{"UpdaterLastFetchTime", PERSISTENT},
{"Version", PERSISTENT},

// extra parameters
{"ToyotaDoors", PERSISTENT},
};

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion panda
18 changes: 18 additions & 0 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
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

# Time values for hysteresis
RESUME_HYSTERESIS_TIME = 1.5 # seconds

Expand All @@ -52,6 +58,8 @@ def __init__(self, dbc_name, CP, VM):
self.gas = 0
self.accel = 0

self.doors_locked = False

def update(self, CC, CS, now_nanos):
actuators = CC.actuators
hud_control = CC.hudControl
Expand Down Expand Up @@ -209,5 +217,15 @@ def update(self, CC, CS, now_nanos):
new_actuators.accel = self.accel
new_actuators.gas = self.gas

# Lock doors when in drive / unlock doors when in park
if not self.doors_locked and CS.out.gearShifter != PARK:
if self.params.get_bool("ToyotaDoors") and self.CP.carName == "toyota":
can_sends.append(make_can_msg(0x750, LOCK_CMD, 0))
self.doors_locked = True
elif self.doors_locked and CS.out.gearShifter == PARK:
if self.params.get_bool("ToyotaDoors") and self.CP.carName == "toyota":
can_sends.append(make_can_msg(0x750, UNLOCK_CMD, 0))
self.doors_locked = False

self.frame += 1
return new_actuators, can_sends
6 changes: 6 additions & 0 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
tr("Display speed in km/h instead of mph."),
"../assets/offroad/icon_metric.png",
},
{
"ToyotaDoors",
tr("Automatically Lock/Unlock Doors"),
tr("Automatically lock the doors when in drive and unlock when in park."),
"",
},
};


Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ Esto puede tardar un minuto.</translation>
<source>Enable the openpilot longitudinal control (alpha) toggle to allow Experimental mode.</source>
<translation>Activar el control longitudinal (fase experimental) para permitir el modo Experimental.</translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ Cela peut prendre jusqu&apos;à une minute.</translation>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,14 @@ Isso pode levar até um minuto.</translation>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation>Habilite o monitoramento do motorista mesmo quando o openpilot não estiver acionado.</translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_th.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation>即使在openpilot未激活时也启用驾驶员监控。</translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ This may take up to a minute.</source>
<source>Enable driver monitoring even when openpilot is not engaged.</source>
<translation>即使在openpilot未激活時也啟用駕駛監控。</translation>
</message>
<message>
<source>Automatically Lock/Unlock Doors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatically lock the doors when in drive and unlock when in park.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Updater</name>
Expand Down
3 changes: 3 additions & 0 deletions system/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def manager_init() -> None:
("LanguageSetting", "main_en"),
("OpenpilotEnabledToggle", "1"),
("LongitudinalPersonality", str(log.LongitudinalPersonality.standard)),

# Default extra parameters
("ToyotaDoors", "1"),
]
if not PC:
default_params.append(("LastUpdateTime", datetime.datetime.now(datetime.UTC).replace(tzinfo=None).isoformat().encode('utf8')))
Expand Down

0 comments on commit ffe93f1

Please sign in to comment.