Sensor Fusion 7.00 Preview - Part 2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sensor Fusion 7.00 Preview - Part 2

1,424 Views
michaelestanley
NXP Employee
NXP Employee

Adding another teaser to the previous posting...

Here is a bare-metal implemention of the Version 7.00 sensor fusion:

 

// KSDK  and ISSDK Headers
#include "fsl_debug_console.h"  // KSDK header file for the debug interface
#include "board.h"              // KSDK header file to define board configuration
#include "pin_mux.h"            // KSDK header file for pin mux initialization functions
#include "clock_config.h"       // KSDK header file for clock configuration
#include "fsl_port.h"           // KSDK header file for Port I/O control
#include "fsl_i2c.h"            // KSDK header file for I2C interfaces
#include "fsl_pit.h"            // KSDK header feile for Periodic Interval Timer
#include "Driver_I2C_SDK2.h"    // ISSDK CMSIS I2C Driver
#include "fxas21002.h"          // Register and bit-field definitions
#include "mpl3115.h"            // Register and bit-field definitions
#include "fxos8700.h"           // Register and bit-field definitions
#include "fsl_smc.h"

// Sensor Fusion Headers
#include "sensor_fusion.h"      // top level magCal and sensor fusion interfaces
#include "control.h"           // Command/Streaming interface - application specific
#include "status.h"            // Status indicator interface - application specific
#include "drivers.h"           // NXP sensor drivers OR customer-supplied drivers
#include "driver_pit.h"         // Project-specific - PIT is used to control main() timing loop

// Global data structures
SensorFusionGlobals sfg;                ///< This is the primary sensor fusion data structure
ControlSubsystem controlSubsystem;      ///< used for serial communications
StatusSubsystem statusSubsystem;        ///< provides visual (usually LED) status indicator
PhysicalSensor sensors[3];              ///< This implementation uses up to 3 sensors

/// This is a bare-metal implementation of the NXP sensor fusion demo build.
int main(void)
{
    ARM_DRIVER_I2C* I2Cdrv = &I2C_S_DRIVER_BLOCKING;   // defined in the <shield>.h file
    uint16_t i=0;                       // general counter variable
    BOARD_InitPins();                   // defined in pin_mux.c, initializes pkg pins
    BOARD_BootClockRUN();               // defined in clock_config.c, initializes clocks
    BOARD_InitDebugConsole();           // defined in board.c, initializes the OpenSDA port
    I2Cdrv->Initialize(NULL);                                 // Initialize the KSDK driver for the I2C port

    I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);      // Configure the I2C bus speed

    initializeControlPort(&controlSubsystem);                           // configure pins and ports for the control sub-system
    initializeStatusSubsystem(&statusSubsystem);                        // configure pins and ports for the status sub-system
    initSensorFusionGlobals(&sfg, &statusSubsystem, &controlSubsystem); // Initialize sensor fusion structures
    // "install" the sensors we will be using
#if F_USING_ACCEL || F_USING_MAG
    sfg.installSensor(&sfg, &sensors[0], FXOS8700_I2C_ADDR,  1, (void*) I2Cdrv, FXOS8700_Init,  FXOS8700_Read);
#endif
#if F_USING_GYRO
    sfg.installSensor(&sfg, &sensors[1], FXAS21002_I2C_ADDR, 1, (void*) I2Cdrv, FXAS21002_Init, FXAS21002_Read);
#endif
#if F_USING_PRESSURE
    sfg.installSensor(&sfg, &sensors[2], MPL3115_I2C_ADDR,   1, (void*) I2Cdrv, MPL3115_Init,   MPL3115_Read);
#endif
    sfg.initializeFusionEngine(&sfg);         // This will initialize sensors and magnetic calibration

    pit_init(1000000/FUSION_HZ);                // pitIsrFlag will be set true at FUSION_HZ periodic intervals

    sfg.setStatus(&sfg, NORMAL);                // If we got this far, let's set status state to NORMAL
    while (true)
    {
        if (true == pitIsrFlag) {               // Check whether occur interupt and toggle LED
            sfg.readSensors(&sfg, 1);           // Reads sensors, applies HAL and does averaging (if applicable)
            sfg.conditionSensorReadings(&sfg);  // magCal is run as part of this
            sfg.runFusion(&sfg);                // Run the actual fusion algorithms
            sfg.applyPerturbation(&sfg);        // apply debug perturbation (testing only)
            sfg.loopcounter++;                  // The loop counter is used to "serialize" mag cal operations
            i=i+1;
            if (i>=4) {                         // Some status codes include a "blink" feature.  This loop
                    i=0;                        // should cycle at least four times for that to operate correctly.
                    sfg.updateStatus(&sfg);     // This is where pending status updates are made visible
            }

            sfg.queueStatus(&sfg, NORMAL);      // assume NORMAL status for next pass through the loop
            sfg.pControlSubsystem->stream(&sfg, sUARTOutputBuffer);      // Send stream data to the Sensor Fusion Toolbox
            pitIsrFlag = false;                 // Reset the flag for the next cycle
        }
    }
}
/// \endcode

Labels (1)
Tags (1)
0 Replies
%3CLINGO-SUB%20id%3D%22lingo-sub-586178%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ESensor%20Fusion%207.00%20Preview%20-%20Part%202%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-586178%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAdding%20another%20teaser%20to%20the%20previous%20posting...%3C%2FP%3E%3CP%3EHere%20is%20a%20bare-metal%20implemention%20of%20the%20Version%207.00%20sensor%20fusion%3A%3C%2FP%3E%3CP%20style%3D%22min-height%3A%208pt%3B%20padding%3A%200px%3B%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%2F%2F%20KSDK%26nbsp%3B%20and%20ISSDK%20Headers%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fsl_debug_console.h%22%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20for%20the%20debug%20interface%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22board.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20to%20define%20board%20configuration%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22pin_mux.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20for%20pin%20mux%20initialization%20functions%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22clock_config.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20for%20clock%20configuration%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fsl_port.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20for%20Port%20I%2FO%20control%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fsl_i2c.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20file%20for%20I2C%20interfaces%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fsl_pit.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20KSDK%20header%20feile%20for%20Periodic%20Interval%20Timer%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22Driver_I2C_SDK2.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20ISSDK%20CMSIS%20I2C%20Driver%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fxas21002.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Register%20and%20bit-field%20definitions%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22mpl3115.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Register%20and%20bit-field%20definitions%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fxos8700.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Register%20and%20bit-field%20definitions%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22fsl_smc.h%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%2F%2F%20Sensor%20Fusion%20Headers%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22sensor_fusion.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20top%20level%20magCal%20and%20sensor%20fusion%20interfaces%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22control.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Command%2FStreaming%20interface%20-%20application%20specific%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22status.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Status%20indicator%20interface%20-%20application%20specific%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22drivers.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20NXP%20sensor%20drivers%20OR%20customer-supplied%20drivers%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23include%20%22driver_pit.h%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Project-specific%20-%20PIT%20is%20used%20to%20control%20main()%20timing%20loop%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%2F%2F%20Global%20data%20structures%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3ESensorFusionGlobals%20sfg%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%2F%26lt%3B%20This%20is%20the%20primary%20sensor%20fusion%20data%20structure%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3EControlSubsystem%20controlSubsystem%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%2F%26lt%3B%20used%20for%20serial%20communications%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3EStatusSubsystem%20statusSubsystem%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%2F%26lt%3B%20provides%20visual%20(usually%20LED)%20status%20indicator%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3EPhysicalSensor%20sensors%5B3%5D%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%2F%26lt%3B%20This%20implementation%20uses%20up%20to%203%20sensors%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%2F%2F%2F%20This%20is%20a%20bare-metal%20implementation%20of%20the%20NXP%20sensor%20fusion%20demo%20build.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3Eint%20main(void)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ARM_DRIVER_I2C*%20I2Cdrv%20%3D%20%26amp%3BI2C_S_DRIVER_BLOCKING%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20defined%20in%20the%20%3CSHIELD%3E.h%20file%3C%2FSHIELD%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20uint16_t%20i%3D0%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20general%20counter%20variable%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20BOARD_InitPins()%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20defined%20in%20pin_mux.c%2C%20initializes%20pkg%20pins%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20BOARD_BootClockRUN()%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20defined%20in%20clock_config.c%2C%20initializes%20clocks%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20BOARD_InitDebugConsole()%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20defined%20in%20board.c%2C%20initializes%20the%20OpenSDA%20port%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I2Cdrv-%26gt%3BInitialize(NULL)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Initialize%20the%20KSDK%20driver%20for%20the%20I2C%20port%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20I2Cdrv-%26gt%3BControl(ARM_I2C_BUS_SPEED%2C%20ARM_I2C_BUS_SPEED_FAST)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Configure%20the%20I2C%20bus%20speed%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20initializeControlPort(%26amp%3BcontrolSubsystem)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20configure%20pins%20and%20ports%20for%20the%20control%20sub-system%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20initializeStatusSubsystem(%26amp%3BstatusSubsystem)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20configure%20pins%20and%20ports%20for%20the%20status%20sub-system%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20initSensorFusionGlobals(%26amp%3Bsfg%2C%20%26amp%3BstatusSubsystem%2C%20%26amp%3BcontrolSubsystem)%3B%20%2F%2F%20Initialize%20sensor%20fusion%20structures%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20%22install%22%20the%20sensors%20we%20will%20be%20using%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23if%20F_USING_ACCEL%20%7C%7C%20F_USING_MAG%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.installSensor(%26amp%3Bsfg%2C%20%26amp%3Bsensors%5B0%5D%2C%20FXOS8700_I2C_ADDR%2C%26nbsp%3B%201%2C%20(void*)%20I2Cdrv%2C%20FXOS8700_Init%2C%26nbsp%3B%20FXOS8700_Read)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23endif%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23if%20F_USING_GYRO%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.installSensor(%26amp%3Bsfg%2C%20%26amp%3Bsensors%5B1%5D%2C%20FXAS21002_I2C_ADDR%2C%201%2C%20(void*)%20I2Cdrv%2C%20FXAS21002_Init%2C%20FXAS21002_Read)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23endif%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23if%20F_USING_PRESSURE%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.installSensor(%26amp%3Bsfg%2C%20%26amp%3Bsensors%5B2%5D%2C%20MPL3115_I2C_ADDR%2C%26nbsp%3B%26nbsp%3B%201%2C%20(void*)%20I2Cdrv%2C%20MPL3115_Init%2C%26nbsp%3B%26nbsp%3B%20MPL3115_Read)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%23endif%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.initializeFusionEngine(%26amp%3Bsfg)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20This%20will%20initialize%20sensors%20and%20magnetic%20calibration%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20pit_init(1000000%2FFUSION_HZ)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20pitIsrFlag%20will%20be%20set%20true%20at%20FUSION_HZ%20periodic%20intervals%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.setStatus(%26amp%3Bsfg%2C%20NORMAL)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20If%20we%20got%20this%20far%2C%20let's%20set%20status%20state%20to%20NORMAL%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20while%20(true)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(true%20%3D%3D%20pitIsrFlag)%20%7B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Check%20whether%20occur%20interupt%20and%20toggle%20LED%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.readSensors(%26amp%3Bsfg%2C%201)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Reads%20sensors%2C%20applies%20HAL%20and%20does%20averaging%20(if%20applicable)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.conditionSensorReadings(%26amp%3Bsfg)%3B%26nbsp%3B%20%2F%2F%20magCal%20is%20run%20as%20part%20of%20this%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.runFusion(%26amp%3Bsfg)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Run%20the%20actual%20fusion%20algorithms%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.applyPerturbation(%26amp%3Bsfg)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20apply%20debug%20perturbation%20(testing%20only)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.loopcounter%2B%2B%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20The%20loop%20counter%20is%20used%20to%20%22serialize%22%20mag%20cal%20operations%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20i%3Di%2B1%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(i%26gt%3B%3D4)%20%7B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Some%20status%20codes%20include%20a%20%22blink%22%20feature.%26nbsp%3B%20This%20loop%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20i%3D0%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20should%20cycle%20at%20least%20four%20times%20for%20that%20to%20operate%20correctly.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.updateStatus(%26amp%3Bsfg)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20This%20is%20where%20pending%20status%20updates%20are%20made%20visible%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.queueStatus(%26amp%3Bsfg%2C%20NORMAL)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20assume%20NORMAL%20status%20for%20next%20pass%20through%20the%20loop%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sfg.pControlSubsystem-%26gt%3Bstream(%26amp%3Bsfg%2C%20sUARTOutputBuffer)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Send%20stream%20data%20to%20the%20Sensor%20Fusion%20Toolbox%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20pitIsrFlag%20%3D%20false%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Reset%20the%20flag%20for%20the%20next%20cycle%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20courier%20new%2Ccourier%3B%20font-size%3A%208pt%3B%22%3E%2F%2F%2F%20%5Cendcode%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-586178%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3ESensorFusion%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E