Skip to content

Commit d711f3c

Browse files
committed
fix(steami_config): Address PR review on magnetometer calibration.
1 parent 3918349 commit d711f3c

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

lib/steami_config/steami_config/device.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,25 @@ def get_magnetometer_calibration(self):
177177
if cm is None:
178178
return None
179179
return {
180-
"hard_iron_x": cm["hx"],
181-
"hard_iron_y": cm["hy"],
182-
"hard_iron_z": cm["hz"],
183-
"soft_iron_x": cm["sx"],
184-
"soft_iron_y": cm["sy"],
185-
"soft_iron_z": cm["sz"],
180+
"hard_iron_x": cm.get("hx", 0.0),
181+
"hard_iron_y": cm.get("hy", 0.0),
182+
"hard_iron_z": cm.get("hz", 0.0),
183+
"soft_iron_x": cm.get("sx", 1.0),
184+
"soft_iron_y": cm.get("sy", 1.0),
185+
"soft_iron_z": cm.get("sz", 1.0),
186186
}
187187

188188
def apply_magnetometer_calibration(self, lis2mdl_instance):
189189
"""Apply stored magnetometer calibration to a LIS2MDL instance.
190190
191191
The instance must have x_off/y_off/z_off and x_scale/y_scale/z_scale
192-
attributes.
192+
attributes. Only applies to LIS2MDL instances.
193193
194194
Args:
195195
lis2mdl_instance: a LIS2MDL driver instance.
196196
"""
197+
if type(lis2mdl_instance).__name__.lower() != "lis2mdl":
198+
return
197199
cal = self.get_magnetometer_calibration()
198200
if cal is None:
199201
return

tests/scenarios/steami_config.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ tests:
199199
200200
mag = LIS2MDL()
201201
dev.apply_magnetometer_calibration(mag)
202-
result = mag.x_off == 0 and mag.x_scale == 1
202+
result = (
203+
mag.x_off == 0 and mag.y_off == 0 and mag.z_off == 0
204+
and mag.x_scale == 1 and mag.y_scale == 1 and mag.z_scale == 1
205+
)
203206
expect_true: true
204207
mode: [mock]
205208

@@ -214,7 +217,14 @@ tests:
214217
dev2 = SteamiConfig(dev._flash)
215218
dev2.load()
216219
cal = dev2.get_magnetometer_calibration()
217-
result = cal["hard_iron_x"] == 5.5 and cal["soft_iron_x"] == 1.0
220+
result = (
221+
cal["hard_iron_x"] == 5.5
222+
and cal["hard_iron_y"] == -2.2
223+
and cal["hard_iron_z"] == 0.3
224+
and cal["soft_iron_x"] == 1.0
225+
and cal["soft_iron_y"] == 1.0
226+
and cal["soft_iron_z"] == 1.0
227+
)
218228
expect_true: true
219229
mode: [mock]
220230

0 commit comments

Comments
 (0)