Skip to content

Commit

Permalink
use ParameterUpdater in selfdrived
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 8, 2024
1 parent 1fd0382 commit aa77831
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
16 changes: 12 additions & 4 deletions selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 18 additions & 19 deletions selfdrive/selfdrived/selfdrived.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
import os
import time
import threading

import cereal.messaging as messaging

Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit aa77831

Please sign in to comment.