Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thermald: track engaged state in param and kmsg #23478

Merged
merged 4 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion selfdrive/common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ std::unordered_map<std::string, uint32_t> keys = {
{"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG},
{"AthenadPid", PERSISTENT},
{"AthenadUploadQueue", PERSISTENT},
{"BootedOnroad", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF},
{"CalibrationParams", PERSISTENT},
{"CarBatteryCapacity", PERSISTENT},
{"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION_ON},
Expand Down Expand Up @@ -121,6 +120,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"IMEI", PERSISTENT},
{"InstallDate", PERSISTENT},
{"IsDriverViewEnabled", CLEAR_ON_MANAGER_START},
{"IsEngaged", PERSISTENT},
{"IsLdwEnabled", PERSISTENT},
{"IsMetric", PERSISTENT},
{"IsOffroad", CLEAR_ON_MANAGER_START},
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/hardware/tici/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def get_gpu_usage_percent(self):
def initialize_hardware(self):
self.amplifier.initialize_configuration()

# Allow thermald to write engagement status to kmsg
os.system("sudo chmod a+w /dev/kmsg")

def get_networks(self):
r = {}

Expand Down
22 changes: 17 additions & 5 deletions selfdrive/thermald/thermald.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def thermald_thread() -> NoReturn:

pandaState_timeout = int(1000 * 2.5 * DT_TRML) # 2.5x the expected pandaState frequency
pandaState_sock = messaging.sub_sock('pandaStates', timeout=pandaState_timeout)
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState"])
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState", "controlsState"])

fan_speed = 0
count = 0
Expand Down Expand Up @@ -191,6 +191,7 @@ def thermald_thread() -> NoReturn:
handle_fan = None
is_uno = False
ui_running_prev = False
engaged_prev = False

params = Params()
power_monitor = PowerMonitoring()
Expand All @@ -202,10 +203,6 @@ def thermald_thread() -> NoReturn:
# TODO: use PI controller for UNO
controller = PIController(k_p=0, k_i=2e-3, neg_limit=-80, pos_limit=0, rate=(1 / DT_TRML))

# Leave flag for loggerd to indicate device was left onroad
if params.get_bool("IsOnroad"):
params.put_bool("BootedOnroad", True)

while True:
pandaStates = messaging.recv_sock(pandaState_sock, wait=True)

Expand Down Expand Up @@ -354,8 +351,23 @@ def thermald_thread() -> NoReturn:
if should_start != should_start_prev or (count == 0):
params.put_bool("IsOnroad", should_start)
params.put_bool("IsOffroad", not should_start)

params.put_bool("IsEngaged", False)
engaged_prev = False
HARDWARE.set_power_save(not should_start)

if sm.updated['controlsState']:
engaged = sm['controlsState'].enabled
if engaged != engaged_prev:
params.put_bool("IsEngaged", engaged)
engaged_prev = engaged

try:
with open('/dev/kmsg', 'w') as kmsg:
kmsg.write(f"[thermald] engaged: {engaged}")
except Exception:
pass

if should_start:
off_ts = None
if started_ts is None:
Expand Down