Device shut down timer
Added toggle to shut down the device after being offroad for a specified amount of time.
This commit is contained in:
@@ -243,6 +243,7 @@ std::unordered_map<std::string, uint32_t> keys = {
|
|||||||
{"CustomSignals", PERSISTENT},
|
{"CustomSignals", PERSISTENT},
|
||||||
{"CustomSounds", PERSISTENT},
|
{"CustomSounds", PERSISTENT},
|
||||||
{"CustomTheme", PERSISTENT},
|
{"CustomTheme", PERSISTENT},
|
||||||
|
{"DeviceShutdown", PERSISTENT},
|
||||||
{"FrogPilotTogglesUpdated", PERSISTENT},
|
{"FrogPilotTogglesUpdated", PERSISTENT},
|
||||||
{"GasRegenCmd", PERSISTENT},
|
{"GasRegenCmd", PERSISTENT},
|
||||||
{"GoatScream", PERSISTENT},
|
{"GoatScream", PERSISTENT},
|
||||||
|
|||||||
BIN
selfdrive/frogpilot/assets/toggle_icons/icon_time.png
Normal file
BIN
selfdrive/frogpilot/assets/toggle_icons/icon_time.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -13,6 +13,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
|
|||||||
{"CESignal", "Turn Signal When Below Highway Speeds", "Switch to 'Experimental Mode' when using turn signals below highway speeds to help assit with turns.", ""},
|
{"CESignal", "Turn Signal When Below Highway Speeds", "Switch to 'Experimental Mode' when using turn signals below highway speeds to help assit with turns.", ""},
|
||||||
|
|
||||||
{"CustomPersonalities", "Custom Driving Personalities", "Customize the driving personality profiles to your driving style.", "../frogpilot/assets/toggle_icons/icon_custom.png"},
|
{"CustomPersonalities", "Custom Driving Personalities", "Customize the driving personality profiles to your driving style.", "../frogpilot/assets/toggle_icons/icon_custom.png"},
|
||||||
|
{"DeviceShutdown", "Device Shutdown Timer", "Configure the timer for automatic device shutdown when offroad conserving energy and preventing battery drain.", "../frogpilot/assets/toggle_icons/icon_time.png"},
|
||||||
|
|
||||||
{"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"},
|
{"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"},
|
||||||
{"AverageCurvature", "Average Desired Curvature", "Use Pfeiferj's distance-based curvature adjustment for improved curve handling.", ""},
|
{"AverageCurvature", "Average Desired Curvature", "Use Pfeiferj's distance-based curvature adjustment for improved curve handling.", ""},
|
||||||
@@ -114,6 +115,13 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
|
|||||||
relaxedProfile = new FrogPilotDualParamControl(relaxedFollow, relaxedJerk, this, true);
|
relaxedProfile = new FrogPilotDualParamControl(relaxedFollow, relaxedJerk, this, true);
|
||||||
addItem(relaxedProfile);
|
addItem(relaxedProfile);
|
||||||
|
|
||||||
|
} else if (param == "DeviceShutdown") {
|
||||||
|
std::map<int, QString> shutdownLabels;
|
||||||
|
for (int i = 0; i <= 33; ++i) {
|
||||||
|
shutdownLabels[i] = i == 0 ? "Instant" : i <= 3 ? QString::number(i * 15) + " mins" : QString::number(i - 3) + (i == 4 ? " hour" : " hours");
|
||||||
|
}
|
||||||
|
toggle = new FrogPilotParamValueControl(param, title, desc, icon, 0, 33, shutdownLabels, this, false);
|
||||||
|
|
||||||
} else if (param == "LateralTune") {
|
} else if (param == "LateralTune") {
|
||||||
FrogPilotParamManageControl *lateralTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
|
FrogPilotParamManageControl *lateralTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
|
||||||
QObject::connect(lateralTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
|
QObject::connect(lateralTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from openpilot.common.params import Params
|
from openpilot.common.params import Params
|
||||||
@@ -39,6 +40,11 @@ class PowerMonitoring:
|
|||||||
self.car_battery_capacity_uWh = max((CAR_BATTERY_CAPACITY_uWh / 10), int(car_battery_capacity_uWh))
|
self.car_battery_capacity_uWh = max((CAR_BATTERY_CAPACITY_uWh / 10), int(car_battery_capacity_uWh))
|
||||||
|
|
||||||
# FrogPilot variables
|
# FrogPilot variables
|
||||||
|
device_shutdown_setting = self.params.get_int("DeviceShutdown")
|
||||||
|
# If the toggle is set for < 1 hour, configure by 15 minute increments
|
||||||
|
self.device_shutdown_time = (device_shutdown_setting - 3) * 3600 if device_shutdown_setting >= 4 else device_shutdown_setting * (60 * 15)
|
||||||
|
self.download_schedule = self.params.get_int("UpdateSchedule")
|
||||||
|
self.download_time = self.params.get_int("UpdateTime")
|
||||||
|
|
||||||
# Calculation tick
|
# Calculation tick
|
||||||
def calculate(self, voltage: Optional[int], ignition: bool):
|
def calculate(self, voltage: Optional[int], ignition: bool):
|
||||||
@@ -115,19 +121,45 @@ class PowerMonitoring:
|
|||||||
if offroad_timestamp is None:
|
if offroad_timestamp is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if self.download_schedule:
|
||||||
|
self.update_shutdown_time()
|
||||||
|
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
should_shutdown = False
|
should_shutdown = False
|
||||||
offroad_time = (now - offroad_timestamp)
|
offroad_time = (now - offroad_timestamp)
|
||||||
low_voltage_shutdown = (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3) and
|
low_voltage_shutdown = (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3) and
|
||||||
self.car_voltage_instant_mV > (VBATT_INSTANT_PAUSE_CHARGING * 1e3) and
|
self.car_voltage_instant_mV > (VBATT_INSTANT_PAUSE_CHARGING * 1e3) and
|
||||||
offroad_time > VOLTAGE_SHUTDOWN_MIN_OFFROAD_TIME_S)
|
offroad_time > VOLTAGE_SHUTDOWN_MIN_OFFROAD_TIME_S)
|
||||||
should_shutdown |= offroad_time > MAX_TIME_OFFROAD_S
|
should_shutdown |= offroad_time > self.device_shutdown_time
|
||||||
should_shutdown |= low_voltage_shutdown
|
should_shutdown |= low_voltage_shutdown
|
||||||
should_shutdown |= (self.car_battery_capacity_uWh <= 0)
|
should_shutdown |= (self.car_battery_capacity_uWh <= 0)
|
||||||
should_shutdown &= not ignition
|
should_shutdown &= not ignition
|
||||||
should_shutdown &= (not self.params.get_bool("DisablePowerDown"))
|
should_shutdown &= (not self.params.get_bool("DisablePowerDown"))
|
||||||
should_shutdown &= in_car
|
should_shutdown &= in_car
|
||||||
should_shutdown &= offroad_time > DELAY_SHUTDOWN_TIME_S
|
should_shutdown &= offroad_time > DELAY_SHUTDOWN_TIME_S if self.device_shutdown_time else True # If "Instant" is selected for the timer, shutdown immediately
|
||||||
should_shutdown |= self.params.get_bool("ForcePowerDown")
|
should_shutdown |= self.params.get_bool("ForcePowerDown")
|
||||||
should_shutdown &= started_seen or (now > MIN_ON_TIME_S)
|
should_shutdown &= started_seen or (now > MIN_ON_TIME_S)
|
||||||
return should_shutdown
|
return should_shutdown
|
||||||
|
|
||||||
|
def update_shutdown_time(self):
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# Adjust for daily or weekly schedule
|
||||||
|
hours = self.download_time // 2
|
||||||
|
minutes = (self.download_time % 2) * 30
|
||||||
|
|
||||||
|
next_update_time = datetime(now.year, now.month, now.day, hours, minutes)
|
||||||
|
|
||||||
|
if now >= next_update_time:
|
||||||
|
if self.download_schedule == 1: # Daily
|
||||||
|
next_update_time += timedelta(days=1)
|
||||||
|
elif self.download_schedule == 2: # Weekly
|
||||||
|
days_to_next_sunday = (6 - now.weekday()) % 7 or 7
|
||||||
|
next_update_time += timedelta(days=days_to_next_sunday)
|
||||||
|
|
||||||
|
# Add one hour buffer to give time for download
|
||||||
|
next_update_time += timedelta(hours=1)
|
||||||
|
|
||||||
|
# Update shutdown time if next update is within 24 hours
|
||||||
|
if next_update_time - now <= timedelta(hours=24):
|
||||||
|
self.device_shutdown_time = (next_update_time - now).total_seconds()
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ private:
|
|||||||
|
|
||||||
ButtonControl *updateTime;
|
ButtonControl *updateTime;
|
||||||
|
|
||||||
|
int deviceShutdown;
|
||||||
int schedule;
|
int schedule;
|
||||||
int time;
|
int time;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
time = params.getInt("UpdateTime");
|
time = params.getInt("UpdateTime");
|
||||||
|
deviceShutdown = params.getInt("DeviceShutdown") * 3600;
|
||||||
updateTime->setValue(hours[time]);
|
updateTime->setValue(hours[time]);
|
||||||
addItem(updateTime);
|
addItem(updateTime);
|
||||||
|
|
||||||
@@ -216,7 +217,7 @@ void SoftwarePanel::automaticUpdate() {
|
|||||||
|
|
||||||
static bool isDownloadCompleted = false;
|
static bool isDownloadCompleted = false;
|
||||||
if (isDownloadCompleted && params.getBool("UpdateAvailable")) {
|
if (isDownloadCompleted && params.getBool("UpdateAvailable")) {
|
||||||
params.putBool(true);
|
params.putBool(timer > deviceShutdown ? "DoShutdown" : "DoReboot", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user