Problem in the frequency of reading of the raw data

I am running a python code on RP3 which is running two threads in parallel:
1- Thread for taking images with a frequency of about 60Hz and saving them
2- Thread to read the IMU data with a frequency of 300 Hz and store them in a file
Then I transfer the IMU log file to my computer to calculate the board’s attitude using recorded data.
I saw that IMU data is stored with the frequency of 300 Hz most of the time but at some time intervals no data is received from IMU and the frequency decreased to zero. These time intervals (with zero frequency) can be between 500-1000 milliseconds. I don’t know why this happens or if is this normal or not.

Hi Yaser,

Welcome to our forum!

What Reach do you read the IMU data from? Have you checked that your data stream is stable?

I am not professional on hardware. I just installed Navio2 on RP3. My code is based on the example code presented by Emlid in python (if I remember truely I am reading acceleration vector, angular velocity vector and magnetic field vector from IMU (here MPU) and storing time and these parameters in a file in a while loop

Hi Yaser,

Ah, I see! I just thought that you work with our GNSS receivers, not Navio2. Sorry for the confusion.

Do you notice the same issue with zero values when running our initial script only?

The values got from the sensors in none of the initial script and the version I changed, was zero. The problem was about the frequency which reaches zero in some periods. I found the source of the problem. In my code, I first opened a file to write data and then in a while loop, I read data from IMU and wrote them in the file. The problem was writing in a file which sometimes caused a lag in reading data. I solved the problem by storing data in an array (instead of writing) and writing them to the file when closing the program.

Hi Yaser,

Thanks for sharing your solution! You did good investigation. It may help the users who will encounter a similar challenge.