18 #ifndef SENSOR_FUSION_TYPES_H 19 #define SENSOR_FUSION_TYPES_H 28 #include "issdk_hal.h" 38 typedef unsigned char byte;
81 #define PI 3.141592654F 82 #define PIOVER2 1.570796327F
83 #define FPIOVER180 0.01745329251994F
84 #define F180OVERPI 57.2957795130823F
85 #define F180OVERPISQ 3282.8063500117F
86 #define ONETHIRD 0.33333333F
87 #define ONESIXTH 0.166666667F
88 #define ONESIXTEENTH 0.0625F
89 #define ONEOVER12 0.083333333F
90 #define ONEOVER48 0.02083333333F
91 #define ONEOVER120 0.0083333333F
92 #define ONEOVER3840 0.0002604166667F
93 #define ONEOVERSQRT2 0.707106781F
94 #define SQRT15OVER4 0.968245837F
95 #define GTOMSEC2 9.80665
126 uint16_t read_loop_counter
138 #define SPI_ADDR 0x00 // Use SPI_ADDR as the address parameter to the installSensor function for SPI-based sensors. 374 float fQwCT6x3[6][3];
408 float fQwCT9x6[9][6];
511 #if F_6DOF_GB_BASIC // 6DOF accel and mag eCompass: (accel + mag) 517 #if F_9DOF_GBY_KALMAN 563 uint16_t numElements,
589 uint16_t maxFifoSize,
617 #endif // SENSOR_FUSION_TYPES_H
float fCountsPerg
counts per g
readSensors_t * readSensors
read all physical sensors
int32_t systick
systick timer;
Quaternion fLPq
low pass filtered orientation quaternion
void() ssUpdateStatus_t(struct StatusSubsystem *pStatus)
Quaternion fLPq
low pass filtered orientation quaternion
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
This structure defines the device specific info required by register I/O.
volatile uint8_t iPerturbation
test perturbation to be applied
bool isEnabled
true if the device is sampling
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
This is the 3DOF basic accelerometer state vector structure.
void conditionSensorReadings(SensorFusionGlobals *sfg)
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
readSensor_t * read
pointer to function to read sensor using the supplied drivers
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
int16_t iT
most recent unaveraged temperature (counts)
enum quaternion quaternion_type
the quaternion type to be transmitted
float fdeltat
sensor fusion interval (s)
int32_t systick_I2C
systick counter to benchmark I2C reads
float fgdeltat
g (m/s2) * fdeltat
int16_t iCountsPerg
counts per g
int32_t systick
systick timer
int32_t systick_Spare
systick counter for counts spare waiting for timing interrupt
Recoverable FAULT = something went wrong, but we can keep going.
void() runFusion_t(struct SensorFusionGlobals *sfg)
int32_t systick
systick timer
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
void zeroArray(struct StatusSubsystem *pStatus, void *data, uint16_t size, uint16_t numElements, uint8_t check)
float fLPChi
low pass tilt from vertical (deg)
SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector s...
Quaternion fq
unfiltered orientation quaternion
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
setStatus_t * queueStatus
queue status change for next regular interval
SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.
registerDeviceInfo_t * busInfo
information required for bus power management
This structure defines the spi slave command format.
void() clearFIFOs_t(struct SensorFusionGlobals *sfg)
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
uint8_t iFIFOCount
number of measurements read from FIFO
int8_t() readSensors_t(struct SensorFusionGlobals *sfg, uint16_t read_loop_counter)
Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
float fLPThe
low pass pitch (deg)
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
uint8_t iWhoAmI
sensor whoami
int8_t resetflag
flag to request re-initialization on next pass
void clearFIFOs(SensorFusionGlobals *sfg)
Function to clear FIFO at the end of each fusion computation.
float fdeltat
fusion time interval (s)
updateStatus_t * testStatus
increment to next enumerated status value (test only)
initializeSensor_t * initialize
pointer to function to initialize sensor using the supplied drivers
void addToFifo(union FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
uint16_t schedule
Parameter to control sensor sampling rate.
float flpf
low pass filter coefficient
The top level fusion structure.
float flpf
low pass filter coefficient
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
Receiving commands over wireless interface (momentary)
SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure...
float fT
most recent unaveraged temperature (C)
int8_t resetflag
flag to request re-initialization on next pass
float fCountsPeruT
counts per uT
int32_t systick
systick timer
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
This is the 3DOF basic magnetometer state vector structure/.
Quaternion derived from 3-axis accel (tilt)
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
float fmPerCount
meters per count
float fChiPl
tilt from vertical (deg)
Quaternion derived from 3-axis mag only (auto compass algorithm)
bool isEnabled
true if the device is sampling
quaternion structure definition
float fAlphaOver2
PI / 180 * fdeltat / 2.
Functions to convert between various orientation representations.
he ControlSubsystem encapsulates command and data streaming functions.
registerDeviceInfo_t deviceInfo
I2C device context.
int32_t systick
systick timer;
uint32_t iFlags
a bit-field of sensors and algorithms used
float fLPPsi
low pass yaw (deg)
float fLPPhi
low pass roll (deg)
float fRhoPl
compass (deg)
int8_t resetflag
flag to request re-initialization on next pass
float fDeltaPl
a posteriori inclination angle from Kalman filter (deg)
Quaternion fLPq
low pass filtered orientation quaternion
float fLPRho
low pass compass (deg)
Quaternion derived from full 9-axis sensor fusion.
void ApplyAccelHAL(struct AccelSensor *Accel)
Apply the accelerometer Hardware Abstraction Layer.
runFusion_t * runFusion
run the fusion routines
float fLPThe
low pass pitch (deg)
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
float fLPPsi
low pass yaw (deg)
Matrix manipulation functions.
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
Non-recoverable FAULT = something went very wrong.
readSensors_t readSensors
float flpf
low pass filter coefficient
float fLPDelta
low pass filtered inclination angle (deg)
int32_t iH
most recent unaveraged height (counts)
int32_t iP
most recent unaveraged pressure (counts)
int8_t() initializeSensor_t(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
precision accelerometer calibration structure
struct SensorFusionGlobals SensorFusionGlobals
The top level fusion structure.
uint8_t data[FXLS8962_DATA_SIZE]
int32_t systick
systick timer
Magnetic Calibration Structure.
float fLPT
low pass filtered temperature (C)
float fcosDeltaPl
cos(fDeltaPl)
float fLPChi
low pass tilt from vertical (deg)
Quaternion fq
unfiltered orientation quaternion
uint8_t iFIFOCount
number of measurements read from FIFO
struct PhysicalSensor * pSensors
a linked list of physical sensors
int8_t() readSensor_t(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
Quaternion fq
unfiltered orientation quaternion
Quaternion fq
unfiltered orientation quaternion
setStatus_t * setStatus
change status indicator immediately
float fDegPerSecPerCount
deg/s per count
int16_t iCountsPerDegPerSec
counts per deg/s
Quaternion fqPl
a posteriori orientation quaternion
uint8_t iWhoAmI
sensor whoami
Initializing sensors and algorithms.
The PressureSensor structure stores raw and processed measurements for an altimeter.
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
accelerometer measurement buffer
struct PhysicalSensor * next
pointer to next sensor in this linked list
Quaternion fq
orientation quaternion
float fdeltat
fusion filter sampling interval (s)
float fdeltat
fusion time interval (s)
installSensor_t installSensor
void() applyPerturbation_t(struct SensorFusionGlobals *sfg)
updateStatus_t * updateStatus
status=next status
float fLPThe
low pass pitch (deg)
float fuTPerCount
uT per count
float fH
most recent unaveraged height (m)
float fLPPsi
low pass yaw (deg)
void() initializeFusionEngine_t(struct SensorFusionGlobals *sfg)
installSensor_t * installSensor
function for installing a new sensor into t
void ApplyGyroHAL(struct GyroSensor *Gyro)
Apply the gyroscope Hardware Abstraction Layer.
struct ControlSubsystem * pControlSubsystem
struct StatusSubsystem * pStatusSubsystem
void() ssSetStatus_t(struct StatusSubsystem *pStatus, fusion_status_t status)
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
Receiving commands over wired interface (momentary)
bool isEnabled
true if the device is sampling
#define GYRO_FIFO_SIZE
FXAX21000, FXAS21002 have 32 element FIFO.
fusion_status_t
Application-specific serial communications system.
void() updateStatus_t(struct SensorFusionGlobals *sfg)
float fChi
tilt from vertical (deg)
void initSensorFusionGlobals(SensorFusionGlobals *sfg, struct StatusSubsystem *pStatusSubsystem, struct ControlSubsystem *pControlSubsystem)
utility function to insert default values in the top level structure
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
float fdeltat
sensor fusion interval (s)
Quaternion derived from 3-axis gyro only (rotation)
Lower level magnetic calibration interface.
int8_t() installSensor_t(struct SensorFusionGlobals *sfg, struct PhysicalSensor *sensor, uint16_t addr, uint16_t schedule, void *bus_driver, registerDeviceInfo_t *busInfo, initializeSensor_t *initialize, readSensor_t *read)
void() conditionSensorReadings_t(struct SensorFusionGlobals *sfg)
float fRhoPl
compass (deg)
int8_t iFirstAccelMagLock
denotes that 9DOF orientation has locked to 6DOF eCompass
int8_t resetflag
flag to request re-initialization on next pass
quaternion
the quaternion type to be transmitted
float fLPPhi
low pass roll (deg)
float fLPPhi
low pass roll (deg)
float fgPerCount
g per count
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
Implements accelerometer calibration routines.
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
Running in reduced power mode.
float fdeltat
fusion time interval (s)
void ApplyMagHAL(struct MagSensor *Mag)
Apply the magnetometer Hardware Abstraction Layer.
uint16_t addr
I2C address if applicable.
Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
float fLPRho
low pass compass (deg)
float fLPRho
low pass compass (deg)
int32_t systick
systick timer;
clearFIFOs_t * clearFIFOs
clear sensor FIFOs
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
struct SV_COMMON * SV_ptr
uint8_t iFIFOCount
number of measurements read from FIFO
float fCPerCount
degrees Celsius per count
float fLPChi
low pass tilt from vertical (deg)
SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.
uint8_t iWhoAmI
sensor whoami
int8_t resetflag
flag to request re-initialization on next pass
float flpf
low pass filter coefficient
void() setStatus_t(struct SensorFusionGlobals *sfg, fusion_status_t status)
Quaternion fqPl
a posteriori orientation quaternion
These are the state definitions for the status subsystem.
float fDelta
unfiltered inclination angle (deg)
uint8_t iWhoAmI
sensor whoami
float fsinDeltaPl
sin(fDeltaPl)
int8_t resetflag
flag to request re-initialization on next pass
int16_t iCountsPeruT
counts per uT
float fLPH
low pass filtered height (m)
int32_t systick
systick timer
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
float fChi
tilt from vertical (deg)
int8_t resetflag
flag to request re-initialization on next pass
applyPerturbation_t * applyPerturbation
apply step function for testing purposes
StatusSubsystem() provides an object-like interface for communicating status to the user...
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
float fChiPl
tilt from vertical (deg)
float fQv
measurement noise covariance matrix leading diagonal
applyPerturbation_t ApplyPerturbation
ApplyPerturbation is a reverse unit-step test function.
initializeFusionEngine_t initializeFusionEngine
bool isEnabled
true if the device is sampling
float fAlphaOver2
PI / 180 * fdeltat / 2.
float fdeltat
fusion time interval (s)