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

calibrationd: convert existing calibration to numpy #23494

Merged
merged 2 commits into from
Jan 11, 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
9 changes: 5 additions & 4 deletions selfdrive/locationd/calibrationd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'''

import os
import copy
from typing import NoReturn
import numpy as np
import cereal.messaging as messaging
Expand Down Expand Up @@ -70,7 +69,7 @@ def __init__(self, param_put=False):
if param_put and calibration_params:
try:
msg = log.Event.from_bytes(calibration_params)
rpy_init = list(msg.liveCalibration.rpyCalib)
rpy_init = np.array(msg.liveCalibration.rpyCalib)
valid_blocks = msg.liveCalibration.validBlocks
except Exception:
cloudlog.exception("Error reading cached CalibrationParams")
Expand All @@ -80,13 +79,15 @@ def __init__(self, param_put=False):

def reset(self, rpy_init=RPY_INIT, valid_blocks=0, smooth_from=None):
if not np.isfinite(rpy_init).all():
self.rpy = copy.copy(RPY_INIT)
self.rpy = RPY_INIT.copy()
else:
self.rpy = rpy_init
self.rpy = rpy_init.copy()

if not np.isfinite(valid_blocks) or valid_blocks < 0:
self.valid_blocks = 0
else:
self.valid_blocks = valid_blocks

self.rpys = np.tile(self.rpy, (INPUTS_WANTED, 1))

self.idx = 0
Expand Down
4 changes: 3 additions & 1 deletion selfdrive/locationd/test/test_calibrationd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import random
import unittest

import numpy as np

import cereal.messaging as messaging
from common.params import Params
from selfdrive.locationd.calibrationd import Calibrator
Expand All @@ -16,7 +18,7 @@ def test_read_saved_params(self):
Params().put("CalibrationParams", msg.to_bytes())
c = Calibrator(param_put=True)

self.assertEqual(list(msg.liveCalibration.rpyCalib), c.rpy)
np.testing.assert_allclose(msg.liveCalibration.rpyCalib, c.rpy)
self.assertEqual(msg.liveCalibration.validBlocks, c.valid_blocks)


Expand Down