82 switch (sensor_type) {
83 case SensorType::kAccelerometer:
86 FXOS8700_Accel_Init, FXOS8700_Accel_Read);
89 case SensorType::kMagnetometer:
92 FXOS8700_Mag_Init, FXOS8700_Mag_Read);
95 case SensorType::kMagnetometerAccelerometer:
98 FXOS8700_Init, FXOS8700_Read);
101 case SensorType::kGyroscope:
104 FXAS21002_Init, FXAS21002_Read);
107 case SensorType::kThermometer:
112 FXOS8700_Therm_Init, FXOS8700_Therm_Read);
115 case SensorType::kBarometer:
136 const void *tcp_client) {
145 sfg_, pin_i2c_sda, pin_i2c_scl);
223 sfg_->pControlSubsystem->stream(
sfg_);
224 sfg_->pControlSubsystem->write(
sfg_);
237 if (data_length > MAX_LEN_SERIAL_OUTPUT_BUF) {
240 char *out_buf = (
char *)(
sfg_->pControlSubsystem->serial_out_buf);
241 for (uint16_t i = 0; i < data_length; i++) {
242 out_buf[i] = buffer[i];
244 sfg_->pControlSubsystem->bytes_to_send = data_length;
245 sfg_->pControlSubsystem->write(
sfg_);
257 sfg_->pControlSubsystem->readCommands(
sfg_);
274 sfg_->pControlSubsystem->injectCommand(
sfg_, (uint8_t *)command, 4);
347 return (
sfg_->SV_9DOF_GBY_KALMAN.fRhoPl <= 90)
348 ? (
sfg_->SV_9DOF_GBY_KALMAN.fRhoPl + 270.0)
349 : (
sfg_->SV_9DOF_GBY_KALMAN.fRhoPl - 90.0);
363 return sfg_->SV_9DOF_GBY_KALMAN.fPhiPl;
377 return -(
sfg_->SV_9DOF_GBY_KALMAN.fThePl);
395 return sfg_->Temp.temperatureC;
413 return sfg_->SV_9DOF_GBY_KALMAN.fOmega[2];
427 return sfg_->SV_9DOF_GBY_KALMAN.fOmega[0];
441 return -(
sfg_->SV_9DOF_GBY_KALMAN.fOmega[1]);
455 return sfg_->Accel.fGc[1];
469 return sfg_->Accel.fGc[0];
483 return sfg_->Accel.fGc[2];
498 quat->
q0 =
sfg_->SV_9DOF_GBY_KALMAN.fqPl.q0;
499 quat->
q1 =
sfg_->SV_9DOF_GBY_KALMAN.fqPl.q1;
500 quat->
q2 =
sfg_->SV_9DOF_GBY_KALMAN.fqPl.q2;
501 quat->
q3 =
sfg_->SV_9DOF_GBY_KALMAN.fqPl.q3;
577 return sfg_->SV_9DOF_GBY_KALMAN.fDeltaPl;
608 return sfg_->SV_9DOF_GBY_KALMAN.fQv6x1[3];
ControlSubsystem * control_subsystem_
command and data streaming structure
float GetRollRadians(void)
float GetMagneticBMagTrial(void)
float GetPitchRadians(void)
float GetMagneticCalSolver(void)
uint8_t num_sensors_installed_
tracks how many sensors have been added to list
const uint8_t kLoopsPerAccelRead
how often an accelerometer read is performed
float GetRollDegrees(void)
void SaveMagneticCalibration(void)
Save current magnetic calibration to non-volatile memory.
bool InstallSensor(uint8_t sensor_i2c_addr, SensorType sensor_type)
Install Sensor in linked list The max length of the list is checked, and if there is room,...
uint8_t loops_per_fuse_counter_
counts how many times through loop have been done
float GetAccelXGees(void)
float GetTurnRateRadPerS(void)
const uint8_t kLoopsPerThermRead
how often a thermometer read is performed
float GetPitchDegrees(void)
float GetMagneticInclinationRad(void)
float GetRollRateRadPerS(void)
float GetMagneticInclinationDeg(void)
float GetHeadingRadians(void)
void UpdateWiFiStream(void *tcp_client)
Update the TCP client pointer. Call when a new TCP connection is made, as reported by WiFiServer::ava...
SensorFusionGlobals * sfg_
Primary sensor fusion data structure.
const uint8_t kLoopsPerMagRead
how often a magnetometer read is performed
float GetAccelYGees(void)
float GetPitchRateDegPerS(void)
void InjectCommand(const char *command)
Inject and process a single command in the control subsystem.
float GetPitchRateRadPerS(void)
float GetAccelYMPerSS(void)
void ProduceToolboxOutput(void)
Generate and send out data, formatted for NXP Orientation Sensor Toolbox. It is not mandatory to call...
PhysicalSensor * sensors_
linked list of up to 4 sensors
float GetTurnRateDegPerS(void)
float GetAccelXMPerSS(void)
float GetMagneticNoiseCovariance(void)
float GetMagneticFitErrorTrial(void)
void ReadSensors(void)
Reads all sensors. Applies HAL remapping, removes invalid values, and stores data for later processin...
void Begin(int pin_i2c_sda=-1, int pin_i2c_scl=-1)
const uint8_t kLoopsPerGyroRead
how often a gyroscope read is performed
float GetTemperatureC(void)
bool SendArbitraryData(const char *buffer, uint16_t data_length)
float GetMagneticFitError(void)
void InitializeStatusSubsystem(void)
Initialize the Status reporting system. Status is indicated by LEDs, but other means can be added.
bool InitializeInputOutputSubsystem(const Stream *serial_port=NULL, const void *tcp_client=NULL)
void RunFusion(void)
Apply fusion algorithm to sensor raw data. Sensor readings contained in global struct are calibrated ...
float GetMagneticBMag(void)
float GetTemperatureK(void)
float GetAccelZMPerSS(void)
void GetOrientationQuaternion(Quaternion *quat)
Return the orientation as a quaternion.
const uint8_t kLoopsPerFusionCalc
how often to fuse. Usually the max of previous 3 constants.
float GetRollRateDegPerS(void)
void InitializeSensorFusionGlobals(void)
Set the starting values of variables contained in sfg_.
float GetAccelZGees(void)
void ProcessCommands(void)
Process any incoming commands. Commands may arrive by serial or WiFi connection, depending on which o...
float GetHeadingDegrees(void)
int GetSystemStatus(void)
StatusSubsystem * status_subsystem_
visual status indicator structure
bool initializeIOSubsystem(ControlSubsystem *pComm, const void *serial_port, const void *tcp_client)
Initialize the control subsystem and all related hardware.
Defines control sub-system.
Provides function prototypes for driver level interfaces It does not have a corresponding ....
void initSensorFusionGlobals(SensorFusionGlobals *sfg, StatusSubsystem *pStatusSubsystem, ControlSubsystem *pControlSubsystem)
utility function to insert default values in the top level structure
The sensor_fusion.h file implements the top level programming interface.
#define PI
pi (it is also defined in Arduino.h)
@ NORMAL
Operation is Nominal.
const float kGeesToMPerSS
To convert acceleration in G to m/s^2, multiply by this constant.
const float kCelsiusToKelvin
To convert degrees C to K, add this constant.
const float kDegToRads
To convert Degrees to Radians, multiply by this constant.
void initializeStatusSubsystem(StatusSubsystem *pStatus)
Application-specific status subsystem.
The ControlSubsystem encapsulates command and data streaming functions.
float ftrFitErrorpc
trial value of fit error %
float fB
current geomagnetic field magnitude (uT)
float fFitErrorpc
current fit error %
float ftrB
trial value of geomagnetic field magnitude in uT
int32_t iValidMagCal
solver used: 0 (no calibration) or 4, 7, 10 element
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
quaternion structure definition
float q3
z vector component
float q1
x vector component
float q2
y vector component
The top level fusion structure.
struct MagCalibration MagCal
mag cal storage
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
installSensor_t * installSensor
function for installing a new sensor
setStatus_t * queueStatus
queue status change for next regular interval
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
runFusion_t * runFusion
run the fusion routines
readSensors_t * readSensors
read all physical sensors
setStatus_t * setStatus
change status indicator immediately
updateStatus_t * updateStatus
status=next status
StatusSubsystem() provides an object-like interface for communicating status to the user.
fusion_status_t status
Current status.