mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-18 05:23:57 +08:00
small calibration refactor + tests (#2641)
* calibration tests * read from capnp * save using cereal struct * reset calibration if new car * car params old-commit-hash: ee43eb552b9a5d5d1cfea65f00150325c9808a2d
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import random
|
||||
import unittest
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from common.params import Params
|
||||
from selfdrive.locationd.calibrationd import Calibrator
|
||||
|
||||
|
||||
class TestCalibrationd(unittest.TestCase):
|
||||
|
||||
def test_read_saved_params_json(self):
|
||||
r = [random.random() for _ in range(3)]
|
||||
b = random.randint(1, 10)
|
||||
cal_params = {"calib_radians": r,
|
||||
"valid_blocks": b}
|
||||
Params().put("CalibrationParams", json.dumps(cal_params).encode('utf8'))
|
||||
c = Calibrator(param_put=True)
|
||||
|
||||
self.assertEqual(r, c.rpy)
|
||||
self.assertEqual(b, c.valid_blocks)
|
||||
|
||||
def test_read_saved_params(self):
|
||||
msg = messaging.new_message('liveCalibration')
|
||||
msg.liveCalibration.validBlocks = random.randint(1, 10)
|
||||
msg.liveCalibration.rpyCalib = [random.random() for _ in range(3)]
|
||||
Params().put("CalibrationParams", msg.to_bytes())
|
||||
c = Calibrator(param_put=True)
|
||||
|
||||
self.assertEqual(list(msg.liveCalibration.rpyCalib), c.rpy)
|
||||
self.assertEqual(msg.liveCalibration.validBlocks, c.valid_blocks)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user