MetaWear C++ API  0.20.0
C++ implementation of the MetaWear protocol
Classes | Typedefs | Enumerations | Functions | Variables
sensor_fusion.h File Reference

Performs sensor fusion using accelerometer, gyro, and magnetometer data. More...

#include "sensor_common.h"

Go to the source code of this file.

Classes

struct  MblMwCalibrationData
 Container class holding the IMU calibration data. More...
 

Typedefs

typedef void(* MblMwFnBoardPtrCalibDataPtr) (void *context, MblMwMetaWearBoard *board, const MblMwCalibrationData *data)
 Definition for callback functions that accept an MblMwMetaWearBoard and MblMwCalibrationData pointer. More...
 

Enumerations

enum  MblMwSensorFusionMode {
  MBL_MW_SENSOR_FUSION_MODE_SLEEP = 0 , MBL_MW_SENSOR_FUSION_MODE_NDOF , MBL_MW_SENSOR_FUSION_MODE_IMU_PLUS , MBL_MW_SENSOR_FUSION_MODE_COMPASS ,
  MBL_MW_SENSOR_FUSION_MODE_M4G
}
 Fusion modes supported by the algorithm.
 
enum  MblMwSensorFusionAccRange { MBL_MW_SENSOR_FUSION_ACC_RANGE_2G = 0 , MBL_MW_SENSOR_FUSION_ACC_RANGE_4G , MBL_MW_SENSOR_FUSION_ACC_RANGE_8G , MBL_MW_SENSOR_FUSION_ACC_RANGE_16G }
 Supported acceleration ranges.
 
enum  MblMwSensorFusionGyroRange { MBL_MW_SENSOR_FUSION_GYRO_RANGE_2000DPS = 0 , MBL_MW_SENSOR_FUSION_GYRO_RANGE_1000DPS , MBL_MW_SENSOR_FUSION_GYRO_RANGE_500DPS , MBL_MW_SENSOR_FUSION_GYRO_RANGE_250DPS }
 Supported rotation ranges.
 
enum  MblMwSensorFusionData {
  MBL_MW_SENSOR_FUSION_DATA_CORRECTED_ACC = 0 , MBL_MW_SENSOR_FUSION_DATA_CORRECTED_GYRO , MBL_MW_SENSOR_FUSION_DATA_CORRECTED_MAG , MBL_MW_SENSOR_FUSION_DATA_QUATERNION ,
  MBL_MW_SENSOR_FUSION_DATA_EULER_ANGLE , MBL_MW_SENSOR_FUSION_DATA_GRAVITY_VECTOR , MBL_MW_SENSOR_FUSION_DATA_LINEAR_ACC
}
 Data computed by the algorithm.
 

Functions

METAWEAR_API MblMwDataSignalmbl_mw_sensor_fusion_get_data_signal (const MblMwMetaWearBoard *board, MblMwSensorFusionData data)
 Get the data signal object representing data from the sensor fusion algorithm The sensor fusion algo is a kalman filter that combines acc, gyro, and mag data into outputs such as correct acceleration, euler angles or quaternions. More...
 
METAWEAR_API MblMwDataSignalmbl_mw_sensor_fusion_calibration_state_data_signal (const MblMwMetaWearBoard *board)
 Get the data signal object representing thecalibration state. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_set_mode (MblMwMetaWearBoard *board, MblMwSensorFusionMode mode)
 Set the operation mode See MblMwSensorFusionMode for allowed values. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_set_acc_range (MblMwMetaWearBoard *board, MblMwSensorFusionAccRange range)
 Set the accelerometer data range Sets the range of the acc in Gs, see MblMwSensorFusionAccRange for allowed values. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_set_gyro_range (MblMwMetaWearBoard *board, MblMwSensorFusionGyroRange range)
 Set the gyroscope data range Sets the range of the gyro in DPS, see MblMwSensorFusionGyroRange for allowed values. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_reset_orientation (MblMwMetaWearBoard *board)
 Reset the default orientation of the board. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_write_config (MblMwMetaWearBoard *board)
 Write the module configuration to the board Applies the MODE and RANGE values set in set_*(). More...
 
METAWEAR_API void mbl_mw_sensor_fusion_read_config (const MblMwMetaWearBoard *board, void *context, MblMwFnBoardPtrInt completed)
 Pulls the current sensor fusion configuration from the board. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_read_calibration_data (MblMwMetaWearBoard *board, void *context, MblMwFnBoardPtrCalibDataPtr completed)
 Retrieve IMU calibration data; free the memory allocated for the MblMwCalibrationData pointer with mbl_mw_memory_free. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_write_calibration_data (const MblMwMetaWearBoard *board, const MblMwCalibrationData *data)
 Write IMU calibration data. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_enable_data (MblMwMetaWearBoard *board, MblMwSensorFusionData data)
 Set a data enable bit Turns on the Kalman filter (sensor fusion) More...
 
METAWEAR_API void mbl_mw_sensor_fusion_clear_enabled_mask (MblMwMetaWearBoard *board)
 Clear all data enable bits Turns off the Kalman filter (sensor fusion) More...
 
METAWEAR_API void mbl_mw_sensor_fusion_start (const MblMwMetaWearBoard *board)
 Start sensor fusion The board will start gathering data from the gyroscope, accelerometer, and gyroscope and run the sensor fusion. More...
 
METAWEAR_API void mbl_mw_sensor_fusion_stop (const MblMwMetaWearBoard *board)
 Stop sensor fusion The board will stop gathering data from the gyroscope, accelerometer, and gyroscope and stop the sensor fusion. More...
 

Variables

const uint8_t MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_UNRELIABLE = 0
 
const uint8_t MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_LOW = 1
 
const uint8_t MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_MEDIUM = 2
 
const uint8_t MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_HIGH = 3
 

Detailed Description

Performs sensor fusion using accelerometer, gyro, and magnetometer data.

When using the sensor fusion module, do not use the accelerometer, gyro, and magnetometer functions.
The api will automatically configure the sensors based on the selected fusion mode.

Typedef Documentation

◆ MblMwFnBoardPtrCalibDataPtr

typedef void(* MblMwFnBoardPtrCalibDataPtr) (void *context, MblMwMetaWearBoard *board, const MblMwCalibrationData *data)

Definition for callback functions that accept an MblMwMetaWearBoard and MblMwCalibrationData pointer.

Parameters
contextAdditional parameters for the callback function
boardCalling object
dataPointer to calibration data

Function Documentation

◆ mbl_mw_sensor_fusion_calibration_state_data_signal()

METAWEAR_API MblMwDataSignal* mbl_mw_sensor_fusion_calibration_state_data_signal ( const MblMwMetaWearBoard board)

Get the data signal object representing thecalibration state.


This signal can only be used while the sensor fusion algorithm is running

Parameters
boardCalling object
Returns
Data signal object

◆ mbl_mw_sensor_fusion_clear_enabled_mask()

METAWEAR_API void mbl_mw_sensor_fusion_clear_enabled_mask ( MblMwMetaWearBoard board)

Clear all data enable bits Turns off the Kalman filter (sensor fusion)

Parameters
boardCalling object

◆ mbl_mw_sensor_fusion_enable_data()

METAWEAR_API void mbl_mw_sensor_fusion_enable_data ( MblMwMetaWearBoard board,
MblMwSensorFusionData  data 
)

Set a data enable bit Turns on the Kalman filter (sensor fusion)

Parameters
boardCalling object
dataSensor fuson data to enable

◆ mbl_mw_sensor_fusion_get_data_signal()

METAWEAR_API MblMwDataSignal* mbl_mw_sensor_fusion_get_data_signal ( const MblMwMetaWearBoard board,
MblMwSensorFusionData  data 
)

Get the data signal object representing data from the sensor fusion algorithm The sensor fusion algo is a kalman filter that combines acc, gyro, and mag data into outputs such as correct acceleration, euler angles or quaternions.

Parameters
boardCalling object
dataDesired sensor fusion data
Returns
Data signal object
Return type can be MblMwCorrectedCartesianFloat, MblMwQuaternion, MblMwEulerAngl, MblMwCartesianFloat

◆ mbl_mw_sensor_fusion_read_calibration_data()

METAWEAR_API void mbl_mw_sensor_fusion_read_calibration_data ( MblMwMetaWearBoard board,
void *  context,
MblMwFnBoardPtrCalibDataPtr  completed 
)

Retrieve IMU calibration data; free the memory allocated for the MblMwCalibrationData pointer with mbl_mw_memory_free.

Only call this function when the calibration state of the IMUs is at high accuracy.
This function can only be used with firmware v1.4.3+.

Parameters
boardCalling object
contextPointer to additional data for the callback function
completedCallback function that is executed when the task is finished

◆ mbl_mw_sensor_fusion_read_config()

METAWEAR_API void mbl_mw_sensor_fusion_read_config ( const MblMwMetaWearBoard board,
void *  context,
MblMwFnBoardPtrInt  completed 
)

Pulls the current sensor fusion configuration from the board.

Parameters
boardCalling object
contextPointer to additional data for the callback function
completedCallback function that is executed when the task is finished

◆ mbl_mw_sensor_fusion_reset_orientation()

METAWEAR_API void mbl_mw_sensor_fusion_reset_orientation ( MblMwMetaWearBoard board)

Reset the default orientation of the board.

Works while sensor fusion is running or off. Works for NDOF and IMUPLUS only.

Parameters
boardCalling object

◆ mbl_mw_sensor_fusion_set_acc_range()

METAWEAR_API void mbl_mw_sensor_fusion_set_acc_range ( MblMwMetaWearBoard board,
MblMwSensorFusionAccRange  range 
)

Set the accelerometer data range Sets the range of the acc in Gs, see MblMwSensorFusionAccRange for allowed values.

Parameters
boardCalling object
rangeNew data range of the accelerometer

◆ mbl_mw_sensor_fusion_set_gyro_range()

METAWEAR_API void mbl_mw_sensor_fusion_set_gyro_range ( MblMwMetaWearBoard board,
MblMwSensorFusionGyroRange  range 
)

Set the gyroscope data range Sets the range of the gyro in DPS, see MblMwSensorFusionGyroRange for allowed values.

Parameters
boardCalling object
rangeNew data range of the gyroscope

◆ mbl_mw_sensor_fusion_set_mode()

METAWEAR_API void mbl_mw_sensor_fusion_set_mode ( MblMwMetaWearBoard board,
MblMwSensorFusionMode  mode 
)

Set the operation mode See MblMwSensorFusionMode for allowed values.

Parameters
boardCalling object
modeNew operation mode

◆ mbl_mw_sensor_fusion_start()

METAWEAR_API void mbl_mw_sensor_fusion_start ( const MblMwMetaWearBoard board)

Start sensor fusion The board will start gathering data from the gyroscope, accelerometer, and gyroscope and run the sensor fusion.

Parameters
boardCalling object

◆ mbl_mw_sensor_fusion_stop()

METAWEAR_API void mbl_mw_sensor_fusion_stop ( const MblMwMetaWearBoard board)

Stop sensor fusion The board will stop gathering data from the gyroscope, accelerometer, and gyroscope and stop the sensor fusion.

Parameters
boardCalling object

◆ mbl_mw_sensor_fusion_write_calibration_data()

METAWEAR_API void mbl_mw_sensor_fusion_write_calibration_data ( const MblMwMetaWearBoard board,
const MblMwCalibrationData data 
)

Write IMU calibration data.

The data will be reloaded everytime the mode changes. This function can only be used with firmware v1.4.3+

Parameters
boardCalling object
dataCalibration data to load

◆ mbl_mw_sensor_fusion_write_config()

METAWEAR_API void mbl_mw_sensor_fusion_write_config ( MblMwMetaWearBoard board)

Write the module configuration to the board Applies the MODE and RANGE values set in set_*().

Parameters
boardCalling object