XRobots / openDog

CAD and code for each episode of my open source dog series
GNU General Public License v3.0
825 stars 189 forks source link

IMU data reads #21

Open alanbithell opened 5 years ago

alanbithell commented 5 years ago

In your function dmpDataReady, instead of setting IMUdataReady = 1, try incrementing the value, then in your main loop, read the data IMUdataReady times to clear the FIFO and decrement that counter with each loop. This will prevent fifo overflow and give you the most recent value from the IMU. I would have added this to code and created a PR but part 19 isn't up.

void dmpDataReady() {
    IMUdataReady++;
}

...main loop...

// IMU test
while (IMUdataReady > 0) {
    readAngles();
    IMUdataRead--;
}
XRobots commented 5 years ago

According to the example code it'll read multiple values out of the FIFO when the function is called anyway, so it should never leave anything behind.

alanbithell commented 5 years ago

Ah, fair enough. Perhaps then for your use case, you don’t really need a FIFO buffer, you just want the latest value. Could you disable the FIFO? Set the rate to max and just manually read the values in your main loop? That way you’ll always get the newest value and won’t need to read multiple times from the FIFO at a lower rate.

On Jun 25, 2019, at 8:24 AM, James Bruton notifications@github.com wrote:

According to the example code it'll read multiple values out of the FIFO when the function is called anyway, so it should never leave anything behind.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.