@@ -239,14 +239,6 @@ void IMUMonitor::imu_offset()
239
239
if (!sfr::imu::gyro_z_value->get_value (&gyro_z)) {
240
240
gyro_z = 0 ;
241
241
}
242
- Serial.println (" Raw IMU Data:" );
243
- Serial.print (" Mag X: " ); Serial.println (mag_x);
244
- Serial.print (" Mag Y: " ); Serial.println (mag_y);
245
- Serial.print (" Mag Z: " ); Serial.println (mag_z);
246
- Serial.print (" Gyro X: " ); Serial.println (gyro_x);
247
- Serial.print (" Gyro Y: " ); Serial.println (gyro_y);
248
- Serial.print (" Gyro Z: " ); Serial.println (gyro_z);
249
- Serial.println (" ----------" );
250
242
251
243
/* Offset Contributions from PWM (ex: pwmX_oX is contribution of X mag to offset x)*/
252
244
float pwmX_ox, pwmX_oy, pwmX_oz;
@@ -273,51 +265,21 @@ void IMUMonitor::imu_offset()
273
265
float temp_z = (0.206 ) * temp_imu.temperature + (-6.835 );
274
266
/* ******************************************/
275
267
/* Total Offsets*/
276
-
277
268
float mag_xoffset = (pwmX_ox + pwmY_ox + pwmZ_ox) * Volt_c + temp_x + hardiron_x;// rewrite
278
269
float mag_yoffset = (pwmX_oy + pwmY_oy + pwmZ_oy) * Volt_c + temp_y + hardiron_y;
279
270
float mag_zoffset = (pwmX_oz + pwmY_oz + pwmZ_oz) * Volt_c + temp_z + hardiron_z;// rewrite this
280
271
281
- Serial.println (" Hard Iron Components: " );
282
- Serial.print (" Mag X: " ); Serial.println (hardiron_x);
283
- Serial.print (" Mag Y: " ); Serial.println (hardiron_y);
284
- Serial.print (" Mag Z: " ); Serial.println (hardiron_z);
285
- Serial.println (" ________" );
286
-
287
272
/* ******************************************/
288
273
/* Finally, adjust magnetometer/gyro readings*/
289
- // Serial.println("Unfiltered:");
290
- // Serial.print("Mag X: "); Serial.println(mag_x);
291
- // Serial.print("Mag Y: "); Serial.println(mag_y);
292
- // Serial.print("Mag Z: "); Serial.println(mag_z);
293
-
294
- // Serial.print("Gyro X: "); Serial.println(gyro_x);
295
- // Serial.print("Gyro Y: "); Serial.println(gyro_y);
296
- // Serial.print("Gyro Z: "); Serial.println(gyro_z);
297
- float mag_x_corrected = mag_x - mag_xoffset;
298
- float mag_y_corrected = mag_y - mag_yoffset;
299
- float mag_z_corrected = mag_z - mag_zoffset;
300
-
301
- float gyro_x_corrected = -(gyro_x - (-0.02297 ));
302
- float gyro_y_corrected = gyro_y - (0.03015 );
303
- float gyro_z_corrected = gyro_z - (-0.01396 );
304
-
305
- sfr::imu::mag_x_value->set_value (mag_x_corrected);
306
- sfr::imu::mag_y_value->set_value (mag_y_corrected);
307
- sfr::imu::mag_z_value->set_value (mag_z_corrected);
308
-
309
- sfr::imu::gyro_x_value->set_value (gyro_x_corrected);
310
- sfr::imu::gyro_y_value->set_value (gyro_y_corrected);
311
- sfr::imu::gyro_z_value->set_value (gyro_z_corrected);
312
- Serial.println (" Soft-Iron Filtered: " );
313
- Serial.print (" Mag X: " ); Serial.println (mag_x_corrected);
314
- Serial.print (" Mag Y: " ); Serial.println (mag_y_corrected);
315
- Serial.print (" Mag Z: " ); Serial.println (mag_z_corrected);
316
-
317
- Serial.print (" Gyro X: " ); Serial.println (gyro_x_corrected);
318
- Serial.print (" Gyro Y: " ); Serial.println (gyro_y_corrected);
319
- Serial.print (" Gyro Z: " ); Serial.println (gyro_z_corrected);
320
- Serial.print (" _________" );
274
+
275
+ sfr::imu::mag_x_value->set_value (mag_x - mag_xoffset);
276
+ sfr::imu::mag_y_value->set_value (mag_y - mag_yoffset);
277
+ sfr::imu::mag_z_value->set_value (mag_z - mag_zoffset);
278
+
279
+ // make gyro aligh with mag coor
280
+ sfr::imu::gyro_x_value->set_value (-(gyro_x - (-0.02297 )));
281
+ sfr::imu::gyro_y_value->set_value (gyro_y - (0.03015 ));
282
+ sfr::imu::gyro_z_value->set_value (gyro_z - (-0.01396 ));
321
283
}
322
284
323
285
// generate a normal random variable using Box-Muller transform
@@ -489,15 +451,6 @@ void IMUMonitor::capture_imu_values()
489
451
Serial.println (ekfObj.state (5 ));
490
452
#endif
491
453
// update the EKFed values
492
- Serial.println (" EKF Filtered:" );
493
- Serial.print (" Mag X: " ); Serial.println (ekfObj.state (0 ));
494
- Serial.print (" Mag Y: " );Serial.println (ekfObj.state (1 ));
495
- Serial.print (" Mag Z: " ); Serial.println (ekfObj.state (2 ));
496
- Serial.print (" Gyro X: " ); Serial.println (ekfObj.state (3 ));
497
- Serial.print (" Gyro Y: " ); Serial.println (ekfObj.state (4 ));
498
- Serial.print (" Gyro Z: " ); Serial.println (ekfObj.state (5 ));
499
- Serial.println (" _______" );
500
-
501
454
sfr::imu::mag_x_value->set_value (ekfObj.state (0 ));
502
455
sfr::imu::mag_y_value->set_value (ekfObj.state (1 ));
503
456
sfr::imu::mag_z_value->set_value (ekfObj.state (2 ));
0 commit comments