Sensor Fusion¶
Sensor fusion combines data from different sensors to compute something that cannot be calculated from one sensor alone. MetaMotion boards run a Bosch sensor fusion algorithm that performs computations using BMI160 and BMM150 data in the firmware. When using the sensor fusion algorithm, it is important that you do not simultaneously use the Accelerometer, Gyro, and Magnetometer modules. Use the ISensorFusionBosch interface to configure the algorithm which in turn will appropriately configure the required sensors.
using MbientLab.MetaWear.Core;
ISensorFusionBosch sensorFusion = metawear.GetModule<ISensorFusionBosch>();
Configuration¶
There are 4 operation modes that use different combinations of the accelerometer, gyro, and magnetometer, enumerated by the Mode enum. This, along with the data ranges for the accelerometer and gyroscope are set with the Configure method.
Mode | Description |
---|---|
NDoF | Calculates absolute orientation from accelerometer, gyro, and magnetometer |
IMUPlus | Calculates relative orientation in space from accelerometer and gyro data |
Compass | Determines geographic direction from th Earth’s magnetic field |
M4G | Similar to IMUPlus except rotation is detected with the magnetometer |
The data rate and sensors used by the algorithm differ on based on the selected mode.
Mode | Acc | Gyro | Mag |
---|---|---|---|
NDoF | 100Hz | 100Hz | 25Hz |
IMUPlus | 100Hz | 100Hz | N/A |
Compass | 25Hz | N/A | 25Hz |
M4G | 50Hz | N/A | 50Hz |
using MbientLab.MetaWear.Core.SensorFusionBosch;
// default settings is NDoF mode with +/-16g acc range and 2000dps gyro range
sensorFusion.Configure();
Calibration¶
The IMU sensors will need some calibration in order to improve their accuracy. After starting the sensor fusion algorithm, follow the calibration motions outlined in this Bosch tutorial video (YouTube).
When the sensor fusion algorithm is calibrated, it will return the IMU calibration data. The data can be written to the board after each power cycle to automatically calibrate the algorithm. You can combine this with the Macro module to store the calibration in the flash memory.
// Use this token to cancel the calibration process
var cts = new CancellationTokenSource();
var data = await sensorFusion.Calibrate(cts.Token);
// After a powr cycle, write the calibration data before configuring
// the sensor fusion algorithm
sensorFusion.WriteCalibrationData(data);
Data¶
The algorithm can compute quaternion values and Euler angles as well as separating acceleration sources into linear motion and gravity. Furthermore, it can use data from the other IMUs to correct the errors from the raw sensors. Note that the units and type casting of the sensor fusion data is different for each type of data.
Data | Units | Type |
---|---|---|
Acceleration | g | CorrectedAcceleration |
Angular Velocity | deg/s | CorrectedAngularVelocity |
Magnetic Field | T | CorrectedMagneticField |
Quaternion | None | Quaternion |
Euler Angles | degrees | EulerAngles |
Linear Acc | g | Acceleration |
Gravity | g | Acceleration |
using MbientLab.MetaWear.Data;
// stream quaternion values from the board
await sensorFusion.Quaternion.AddRouteAsync(source =>
source.Stream(data => Console.WriteLine("Quaternion = " + data.Value<Quaternion>()))
);