Skip to content

Commit edc9a23

Browse files
committed
test(steami_config): add accelerometer calibration tests
1 parent 74c5b0e commit edc9a23

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

tests/scenarios/steami_config.yaml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tests:
4848
expect_true: true
4949
mode: [mock]
5050

51+
# -- Mock Temperature Calibration --
5152
- name: "Set and get temperature calibration"
5253
action: script
5354
script: |
@@ -126,6 +127,7 @@ tests:
126127
expect_true: true
127128
mode: [mock]
128129

130+
# -- Mock Magnetometer Calibration --
129131
- name: "Set and get magnetometer calibration"
130132
action: script
131133
script: |
@@ -243,6 +245,98 @@ tests:
243245
result = dev.board_name == "Test-Board"
244246
expect_true: true
245247
mode: [mock]
248+
249+
# -- Mock Accelerometer Calibration --
250+
- name: "Set and get accelerometer calibration"
251+
action: script
252+
script: |
253+
dev._data = {}
254+
dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03)
255+
cal = dev.get_accelerometer_calibration()
256+
result = (
257+
cal["ox"] == 0.01
258+
and cal["oy"] == -0.02
259+
and cal["oz"] == 0.03
260+
)
261+
expect_true: true
262+
mode: [mock]
263+
264+
- name: "Get accelerometer calibration returns None when not set"
265+
action: script
266+
script: |
267+
dev._data = {}
268+
result = dev.get_accelerometer_calibration() is None
269+
expect_true: true
270+
mode: [mock]
271+
272+
- name: "Apply accelerometer calibration to ISM330DL"
273+
action: script
274+
script: |
275+
dev._data = {"cal_accel": {"ox": 0.01, "oy": -0.02, "oz": 0.03}}
276+
277+
class ISM330DL(object):
278+
def __init__(self):
279+
self._accel_offset_x = 0.0
280+
self._accel_offset_y = 0.0
281+
self._accel_offset_z = 0.0
282+
283+
def set_accel_offset(self, ox=0.0, oy=0.0, oz=0.0):
284+
self._accel_offset_x = ox
285+
self._accel_offset_y = oy
286+
self._accel_offset_z = oz
287+
288+
imu = ISM330DL()
289+
dev.apply_accelerometer_calibration(imu)
290+
result = (
291+
imu._accel_offset_x == 0.01
292+
and imu._accel_offset_y == -0.02
293+
and imu._accel_offset_z == 0.03
294+
)
295+
expect_true: true
296+
mode: [mock]
297+
298+
- name: "Apply accelerometer calibration does nothing when not set"
299+
action: script
300+
script: |
301+
dev._data = {}
302+
303+
class ISM330DL(object):
304+
def __init__(self):
305+
self._accel_offset_x = 0.0
306+
self._accel_offset_y = 0.0
307+
self._accel_offset_z = 0.0
308+
309+
def set_accel_offset(self, ox=0.0, oy=0.0, oz=0.0):
310+
self._accel_offset_x = ox
311+
self._accel_offset_y = oy
312+
self._accel_offset_z = oz
313+
314+
imu = ISM330DL()
315+
dev.apply_accelerometer_calibration(imu)
316+
result = (
317+
imu._accel_offset_x == 0.0
318+
and imu._accel_offset_y == 0.0
319+
and imu._accel_offset_z == 0.0
320+
)
321+
expect_true: true
322+
mode: [mock]
323+
324+
- name: "Accelerometer calibration survives save/load"
325+
action: script
326+
script: |
327+
dev._data = {}
328+
dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03)
329+
dev.save()
330+
dev2 = SteamiConfig(dev._bridge)
331+
dev2.load()
332+
cal = dev2.get_accelerometer_calibration()
333+
result = (
334+
cal["ox"] == 0.01
335+
and cal["oy"] == -0.02
336+
and cal["oz"] == 0.03
337+
)
338+
expect_true: true
339+
mode: [mock]
246340

247341
# ----- Hardware -----
248342

@@ -286,6 +380,7 @@ tests:
286380
expect_true: true
287381
mode: [hardware]
288382

383+
# -- Hardware Temperature Calibration --
289384
- name: "Apply calibration to real sensor"
290385
action: script
291386
script: |
@@ -310,6 +405,7 @@ tests:
310405
expect_true: true
311406
mode: [hardware]
312407

408+
# -- Hardware Magnetometer Calibration --
313409
- name: "Save and load magnetometer calibration on hardware"
314410
action: script
315411
script: |
@@ -381,3 +477,67 @@ tests:
381477
)
382478
expect_true: true
383479
mode: [hardware]
480+
481+
# -- Hardware Accelerometer Calibration --
482+
- name: "Save and load accelerometer calibration on hardware"
483+
action: script
484+
script: |
485+
from time import sleep_ms
486+
dev._bridge.clear_config()
487+
dev._data = {}
488+
dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03)
489+
dev.save()
490+
sleep_ms(200)
491+
dev2 = SteamiConfig(dev._bridge)
492+
dev2.load()
493+
cal = dev2.get_accelerometer_calibration()
494+
result = (
495+
cal["ox"] == 0.01
496+
and cal["oy"] == -0.02
497+
and cal["oz"] == 0.03
498+
)
499+
expect_true: true
500+
mode: [hardware]
501+
502+
- name: "Apply accelerometer calibration to real ISM330DL"
503+
action: script
504+
script: |
505+
from time import sleep_ms
506+
from ism330dl import ISM330DL
507+
imu = ISM330DL(i2c)
508+
dev._bridge.clear_config()
509+
dev._data = {}
510+
dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03)
511+
dev.save()
512+
sleep_ms(200)
513+
dev2 = SteamiConfig(dev._bridge)
514+
dev2.load()
515+
dev2.apply_accelerometer_calibration(imu)
516+
ox, oy, oz = imu.get_accel_offset()
517+
result = ox == 0.01 and oy == -0.02 and oz == 0.03
518+
expect_true: true
519+
mode: [hardware]
520+
521+
- name: "Accelerometer calibration coexists with temperature calibration"
522+
action: script
523+
script: |
524+
from time import sleep_ms
525+
dev._bridge.clear_config()
526+
dev._data = {}
527+
dev.set_temperature_calibration("hts221", gain=1.05, offset=-0.3)
528+
dev.set_accelerometer_calibration(ox=0.01, oy=-0.02, oz=0.03)
529+
dev.save()
530+
sleep_ms(200)
531+
dev2 = SteamiConfig(dev._bridge)
532+
dev2.load()
533+
tc = dev2.get_temperature_calibration("hts221")
534+
ac = dev2.get_accelerometer_calibration()
535+
result = (
536+
tc["gain"] == 1.05
537+
and tc["offset"] == -0.3
538+
and ac["ox"] == 0.01
539+
and ac["oy"] == -0.02
540+
and ac["oz"] == 0.03
541+
)
542+
expect_true: true
543+
mode: [hardware]

0 commit comments

Comments
 (0)