diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 030b8650b14875..6d6ea4e878a56f 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -250,13 +250,21 @@ def step(self): self.initialized_prev = initialized + def read_parameters(self, parameter_updater: ParameterUpdater) -> None: + self.is_metric = parameter_updater.get_param_value('is_metric') + self.experimental_mode = parameter_updater.get_param_value('experimental_mode') + def card_thread(self): - parameter_updater = ParameterUpdater() + params_to_update = { + 'IsMetric': 'bool', + 'ExperimentalMode': 'bool', + } + parameter_updater = ParameterUpdater(params_to_update) + parameter_updater.start() + try: while True: - self.is_metric = parameter_updater.get_param_value('is_metric') - self.experimental_mode = parameter_updater.get_param_value('experimental_mode') - + self.read_parameters(parameter_updater) self.step() self.rk.monitor_time() finally: diff --git a/selfdrive/selfdrived/selfdrived.py b/selfdrive/selfdrived/selfdrived.py index d24939884d5798..633cd53ab73e21 100755 --- a/selfdrive/selfdrived/selfdrived.py +++ b/selfdrive/selfdrived/selfdrived.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 import os -import time -import threading import cereal.messaging as messaging @@ -10,6 +8,7 @@ from panda import ALTERNATIVE_EXPERIENCE +from openpilot.common.parameter_updater import ParameterUpdater from openpilot.common.params import Params from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper, DT_CTRL from openpilot.common.swaglog import cloudlog @@ -84,7 +83,7 @@ def __init__(self, CP=None): ignore_valid=ignore, frequency=int(1/DT_CTRL)) # read params - self.is_metric = self.params.get_bool("IsMetric") + self.is_metric = False self.is_ldw_enabled = self.params.get_bool("IsLdwEnabled") car_recognized = self.CP.carName != 'mock' @@ -111,7 +110,7 @@ def __init__(self, CP=None): self.logged_comm_issue = None self.not_running_prev = None self.experimental_mode = False - self.personality = self.read_personality_param() + self.personality = log.LongitudinalPersonality.standard self.recalibrating_seen = False self.state_machine = StateMachine() self.rk = Ratekeeper(100, print_delay_threshold=None) @@ -462,30 +461,30 @@ def step(self): self.CS_prev = CS - def read_personality_param(self): + def read_parameters(self, parameter_updater: ParameterUpdater) -> None: + self.is_metric = parameter_updater.get_param_value("IsMetric") + self.experimental_mode = parameter_updater.get_param_value("ExperimentalMode") and self.CP.openpilotLongitudinalControl try: - return int(self.params.get('LongitudinalPersonality')) + self.personality = int(parameter_updater.get_param_value('LongitudinalPersonality')) except (ValueError, TypeError): - return log.LongitudinalPersonality.standard - - def params_thread(self, evt): - while not evt.is_set(): - self.is_metric = self.params.get_bool("IsMetric") - self.experimental_mode = self.params.get_bool("ExperimentalMode") and self.CP.openpilotLongitudinalControl - self.personality = self.read_personality_param() - time.sleep(0.1) + self.personality = log.LongitudinalPersonality.standard def run(self): - e = threading.Event() - t = threading.Thread(target=self.params_thread, args=(e, )) + params_to_update = { + 'IsMetric': 'bool', + 'ExperimentalMode': 'bool', + 'LongitudinalPersonality': 'str' + } + parameter_updater = ParameterUpdater(params_to_update) + parameter_updater.start() + try: - t.start() while True: + self.read_parameters(parameter_updater) self.step() self.rk.monitor_time() finally: - e.set() - t.join() + parameter_updater.stop() def main():