Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glitches on Gyro data #105

Open
mmcgraw74 opened this issue Mar 22, 2022 · 8 comments
Open

Glitches on Gyro data #105

mmcgraw74 opened this issue Mar 22, 2022 · 8 comments

Comments

@mmcgraw74
Copy link

I ran your i2c example, but I added Serial print statements for Arduino Serial Plotter labels, adding offsets so the traces don't overlap.

if (imu.Read()) {

        Serial.print("Max:250,");    
        Serial.print("NewIMU:");    
        Serial.print(imu.new_imu_data()*150);
        Serial.print(",");
        
        Serial.print("NewMAG:");    
        Serial.print(imu.new_mag_data()*100);
        Serial.print(",");

        Serial.print("AccX:");    
        Serial.print(imu.accel_x_mps2());
        Serial.print(",");
        
        Serial.print("AccY:");    
        Serial.print(imu.accel_y_mps2()-20);
        Serial.print(",");
        
        Serial.print("AccZ:");    
        Serial.print(imu.accel_z_mps2()-40);
        Serial.print(",");
        
        Serial.print("GyrX:");    
        Serial.print(imu.gyro_x_radps()-20);
        Serial.print(",");
        
        Serial.print("GyrY:");    
        Serial.print(imu.gyro_y_radps()-40);
        Serial.print(",");
        
        Serial.print("GyrZ:");    
        Serial.print(imu.gyro_z_radps()-60);
        Serial.print(",");
        
        Serial.print("MagX:");    
        Serial.print(imu.mag_x_ut());
        Serial.print(",");
        
        Serial.print("MagY:");    
        Serial.print(imu.mag_y_ut()-20);
        Serial.print(",");
        
        Serial.print("MagZ:");    
        Serial.print(imu.mag_z_ut());
        Serial.println("Min:-250");    
                    
        //Serial.print(imu.die_temp_c());
        //Serial.print("\n");

when I run this example with my ESP32 Dev Board and MPU9250 board, I use Arduino Serial Plotter and get the following plot:

Gyro glitches

Searching the web - I found this post about gyro glitches:
https://forums.adafruit.com/viewtopic.php?f=19&p=531590

I wonder if the issue is similar - the code is getting interrupted between individual MPU register reads, and should read whole blocks of MPU i2c registers to prevent this kind of issue.

@mmcgraw74
Copy link
Author

The glitches appear on different sensors at random intervals. I had tried filtering algorithms on the data but the glitches are large magnitude.

@mmcgraw74
Copy link
Author

The green spikes are the plot of the boolean imu.new_mag_data(), which looks correct - and is not the issue I'm describing.

The issue in the plotter output above is on the imu.mag_y_ut() output.

@mmcgraw74
Copy link
Author

Here is one more snapshot - I commented out the New Mag signal.
You can see a glitch on MagX followed later by a glitch on MagY.
Gyro glitches4

@mmcgraw74
Copy link
Author

Sorry, same plot as before.
Here is the other plot:
Gyro glitches3

@flybrianfly
Copy link
Contributor

Can you post the full code that you are running and confirm that you are running the newest version of this library (i.e. v5.6.0)? We burst read the IMU, but we have had issues in the past with the ESP32 not working with the I2C repeated start. I don't have an ESP32 board to test, but will try to see if I can replicate the issues on the Teensy boards that I have. Is there any potential to try reading the sensor with SPI? That might help us determine if it's an issue with the I2C communication or something else.

@mmcgraw74
Copy link
Author

I'm running your MPU9250 i2c.ino example with only the print statements modified to add sensor labels and use sensor offsets to separate the traces for Arduino Serial Plotter:

`/*
Brian R Taylor
brian.taylor@bolderflight.com

Copyright (c) 2021 Bolder Flight Systems Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

*/

#include "mpu9250.h"

/* Mpu9250 object */
bfs::Mpu9250 imu;

void setup() {
/* Serial to display data /
Serial.begin(115200);
while (!Serial) {}
/
Start the I2C bus /
Wire.begin();
Wire.setClock(400000);
/
I2C bus, 0x68 address /
imu.Config(&Wire, bfs::Mpu9250::I2C_ADDR_PRIM);
/
Initialize and configure IMU /
if (!imu.Begin()) {
Serial.println("Error initializing communication with IMU");
while (1) {}
}
/
Set the sample rate divider */
if (!imu.ConfigSrd(19)) {
Serial.println("Error configured SRD");
while (1) {}
}
}

void loop() {
/* Check if data read */
if (imu.Read()) {

        Serial.print("Max:250,");    
        Serial.print("NewIMU:");    
        Serial.print(imu.new_imu_data()*150);
        Serial.print(",");
        /*
        Serial.print("NewMAG:");    
        Serial.print(imu.new_mag_data()*100);
        Serial.print(",");

*/
Serial.print("AccX:");
Serial.print(imu.accel_x_mps2());
Serial.print(",");

        Serial.print("AccY:");    
        Serial.print(imu.accel_y_mps2()+40);
        Serial.print(",");
        
        Serial.print("AccZ:");    
        Serial.print(imu.accel_z_mps2()-40);
        Serial.print(",");
        
        Serial.print("GyrX:");    
        Serial.print(imu.gyro_x_radps()-20);
        Serial.print(",");
        
        Serial.print("GyrY:");    
        Serial.print(imu.gyro_y_radps()-40);
        Serial.print(",");
        
        Serial.print("GyrZ:");    
        Serial.print(imu.gyro_z_radps()-60);
        Serial.print(",");
        
        Serial.print("MagX:");    
        Serial.print(imu.mag_x_ut());
        Serial.print(",");
        
        Serial.print("MagY:");    
        Serial.print(imu.mag_y_ut()-20);
        Serial.print(",");
        
        Serial.print("MagZ:");    
        Serial.print(imu.mag_z_ut()-40);
        Serial.println("Min:-250");    
                    
        //Serial.print(imu.die_temp_c());
        //Serial.print("\n");
    
}

}
`

I will look into connecting to the MPU9250 with SPI instead of i2c and retrying with the SPI example.

@mmcgraw74
Copy link
Author

I confirm I'm running Blolder Flight Systems MPU9250 v 5.6.0 Arduino library.

@mmcgraw74 mmcgraw74 reopened this Mar 23, 2022
@mmcgraw74
Copy link
Author

I rewired my board to use ESP32 VSPI with the MPU-9250 board instead of i2c.

I ran your SPI example and didn't see any glitches (left running for 45 minutes. Here is the serial plot:

Bolderflight_MPU9250_spi_example_plot

I also tried the fifo_SPI example and it looks like LOTS of spikes:

Bolderflight_MPU9250_fifo_spi_example_plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants