@@ -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
0 commit comments