You probably don't want to use the gyro for this - it's power hungrey. But the accel works great. I DID add this capability to Version 7.00, and it appears to work better than I hoped. I'm using the accel to determine motion or not, and using that flag to power the gyro up and down as appropriate, and even turn off the fusion calculations when the part is not in motion. I see no visible artifacts when viewing the motion in the sensor fusion toolkit. Transitions are quick and it is nice and smooth. We've added low level hooks for power control, but the specific mechanism will be under your control within the fusion loop. Here's what it will look like:
static void fusion_task(void *pvParameters)
{
uint16_t i=0; // general counter variable
float motion_baseline[3] = {0.0, 0.0, 0.0};
bool stationary;
static bool lastStationary;
uint32_t stationaryCount = 0;
while (1)
{
xEventGroupWaitBits(event_group, /* The event group handle. */
B0, /* The bit pattern the event group is waiting for. */
pdTRUE, /* BIT_0 and BIT_4 will be cleared automatically. */
pdFALSE, /* Don't wait for both bits, either bit unblock task. */
portMAX_DELAY); /* Block indefinitely to wait for the condition to be met. */
// sfg.runFusion(&sfg); // Run the actual fusion algorithms
// Rather than call runFusion directly, this example invokes the lower level
// calls here. This allows us to check to see if the board is stationary,
// and if so, transition to a lower power state.
conditionSensorReadings(&sfg); // magCal is run as part of this
stationary = motionCheck(
sfg.Accel.fGc, // calibrated accelerometer reading
motion_baseline, // baseline to check new values against
0.01, // changes less than this are ignored
120, // three seconds at 40Hz rate
&stationaryCount);
if (stationary) {
if (!lastStationary) { // suspend some operations
FXAS21002_Idle(&(sensors[1]), &sfg);
}
clearFIFOs(&sfg);
} else {
if (lastStationary) { // restart operations
FXAS21002_Init(&(sensors[1]), &sfg);
}
// fuse the sensor data
sfg.runFusion(&sfg);
}
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
}
if (stationary) {
sfg.queueStatus(&sfg, LOWPOWER); // assume LOWPOWER status for next pass through the loop
} else {
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
lastStationary = stationary;
}
}
Regards,
Mike