Skip to content

Commit

Permalink
read params in a thread
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Dec 14, 2023
1 parent ae85ee0 commit fe24bdc
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import math
import time
import threading
from typing import SupportsFloat

from cereal import car, log
Expand Down Expand Up @@ -852,11 +853,6 @@ def step(self):
start_time = time.monotonic()
self.prof.checkpoint("Ratekeeper", ignore=True)

self.is_metric = self.params.get_bool("IsMetric")
self.experimental_mode = self.params.get_bool("ExperimentalMode") and self.CP.openpilotLongitudinalControl
if self.CP.notCar:
self.joystick_mode = self.params.get_bool("JoystickDebugMode")

# Sample data from sockets and get a carState
CS = self.data_sample()
cloudlog.timestamp("Data sampled")
Expand All @@ -881,11 +877,26 @@ def step(self):

self.CS_prev = CS

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
if self.CP.notCar:
self.joystick_mode = self.params.get_bool("JoystickDebugMode")
time.sleep(0.1)

def controlsd_thread(self):
while True:
self.step()
self.rk.monitor_time()
self.prof.display()
e = threading.Event()
t = threading.Thread(target=self.params_thread, args=(e, ))
try:
t.start()
while True:
self.step()
self.rk.monitor_time()
self.prof.display()
except SystemExit:
e.set()
t.join()


def main():
Expand Down

0 comments on commit fe24bdc

Please sign in to comment.