torqued: cache bucket points every minute while onroad (#30515)

* torqued: cache bucket points every minute while onroad

* use put_nonblocking

* remove caching on exit

* unused

* more unused

* remove logging
pull/30721/head
Jason Wen 1 year ago committed by GitHub
parent ea94a6d89f
commit fcc671297e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      selfdrive/locationd/helpers.py
  2. 12
      selfdrive/locationd/torqued.py

@ -1,11 +1,8 @@
import numpy as np import numpy as np
import signal
import sys
from typing import List, Optional, Tuple, Any from typing import List, Optional, Tuple, Any
from cereal import log from cereal import log
from openpilot.common.params import Params from openpilot.common.params import put_nonblocking
from openpilot.common.swaglog import cloudlog
class NPQueue: class NPQueue:
@ -68,10 +65,6 @@ class ParameterEstimator:
raise NotImplementedError raise NotImplementedError
def cache_points_onexit(param_name, estimator, sig, frame): def cache_points(param_name, estimator, valid):
signal.signal(sig, signal.SIG_DFL) msg = estimator.get_msg(valid=valid, with_points=True)
cloudlog.warning(f"Caching {param_name} param") put_nonblocking(param_name, msg.to_bytes())
params = Params()
msg = estimator.get_msg(valid=True, with_points=True)
params.put(param_name, msg.to_bytes())
sys.exit(0)

@ -1,9 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import signal
import numpy as np import numpy as np
from collections import deque, defaultdict from collections import deque, defaultdict
from functools import partial
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import car, log from cereal import car, log
@ -12,7 +9,7 @@ from openpilot.common.realtime import config_realtime_process, DT_MDL
from openpilot.common.filter_simple import FirstOrderFilter from openpilot.common.filter_simple import FirstOrderFilter
from openpilot.common.swaglog import cloudlog from openpilot.common.swaglog import cloudlog
from openpilot.selfdrive.controls.lib.vehicle_model import ACCELERATION_DUE_TO_GRAVITY from openpilot.selfdrive.controls.lib.vehicle_model import ACCELERATION_DUE_TO_GRAVITY
from openpilot.selfdrive.locationd.helpers import PointBuckets, ParameterEstimator, cache_points_onexit from openpilot.selfdrive.locationd.helpers import PointBuckets, ParameterEstimator, cache_points
HISTORY = 5 # secs HISTORY = 5 # secs
POINTS_PER_BUCKET = 1500 POINTS_PER_BUCKET = 1500
@ -227,9 +224,6 @@ def main():
with car.CarParams.from_bytes(params.get("CarParams", block=True)) as CP: with car.CarParams.from_bytes(params.get("CarParams", block=True)) as CP:
estimator = TorqueEstimator(CP) estimator = TorqueEstimator(CP)
if "REPLAY" not in os.environ:
signal.signal(signal.SIGINT, partial(cache_points_onexit, "LiveTorqueParameters", estimator))
while True: while True:
sm.update() sm.update()
if sm.all_checks(): if sm.all_checks():
@ -242,6 +236,10 @@ def main():
if sm.frame % 5 == 0: if sm.frame % 5 == 0:
pm.send('liveTorqueParameters', estimator.get_msg(valid=sm.all_checks())) pm.send('liveTorqueParameters', estimator.get_msg(valid=sm.all_checks()))
# Cache points every 60 seconds while onroad
if sm.frame % 240 == 0:
cache_points("LiveTorqueParameters", estimator, sm.all_checks())
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save