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

Resolution calculation when setting range #93

Open
RobotGrrl opened this issue Feb 24, 2025 · 0 comments
Open

Resolution calculation when setting range #93

RobotGrrl opened this issue Feb 24, 2025 · 0 comments
Assignees

Comments

@RobotGrrl
Copy link

Problem:

accelerationResolution / gyroscopeResolution are calculated in MPU6050_Base::initialize, however these values are not updated when calling setFullScaleAcceRange / setFullScaleGyroRange. This is seen when calling get_acce_resolution / get_gyro_resolution, as it does not have the updated value from setFullScaleAcceRange / setFullScaleGyroRange.

In the steps to reproduce, the problem is seen at step 9.

Setup:

  • Library version 1.4.1
  • MPU6050 breakout board
  • ESP32 WROOM microcontroller
  • Wire I2C
  • ESP boards version 2.0.4 (outdated, but I don't think it effects this problem)

Steps to reproduce:

  1. Open the MPU6050_raw.ino sketch

  2. Comment out the other Serial.print's in loop

  3. Add this snippet to loop:

Serial.print("accel range: \t");
Serial.print(mpu.getFullScaleAccelRange());
Serial.print("\t resolution: \t");
Serial.println(mpu.get_acce_resolution(),8);

Serial.print("gyro range: \t");
Serial.print(mpu.getFullScaleGyroRange());
Serial.print("\t resolution: \t");
Serial.println(mpu.get_gyro_resolution(),8);

delay(500);

  1. Compile and Upload

  2. The Serial Monitor says:

    accel range: 0 resolution: 0.00012207
    gyro range: 0 resolution: 0.01525879

The range is correct based on the default.
The resolution is correct based on the default.

  1. Check the math...

    accel resolution: 2.0 / 16384.0 = 0.00012207
    gyro resolution: 250.0 / 16384.0 = 0.015258789

This result passes.

  1. Add these two lines at the end of setup:

mpu.setFullScaleAccelRange(MPU6050_ACCEL_FS_4);
mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_500);

  1. Compile and Upload

  2. The Serial Monitor says:

    accel range: 1 resolution: 0.00012207
    gyro range: 1 resolution: 0.01525879

The range is correct based on the changes in step 7.
The resolution is not correct, and gives the same result as step 5.

This result does not pass.

  1. Comment out the two lines from step 7

  2. Comment out initialise in setup

    // mpu.initialize();

  3. Add this below the line for step 11:

    mpu.initialize(ACCEL_FS::A4G, GYRO_FS::G500DPS);

  4. Compile and Upload

14: The Serial Monitor says:

accel range: 	1	 resolution: 	0.00024414
gyro range: 	1	 resolution: 	0.03051758

The range is correct based on the paramaters passed to initialise.
The resolution is correct based on the paramaters passed to initialise.

  1. Check the math...

    accel resolution: 4.0 / 16384.0 = 0.00024414
    gyro resolution: 500.0 / 16384.0 = 0.030517578

This result passes.

Solution:

  • Added switch statement to setFullScaleAccelRange / setFullScaleGyroRange that sets accelerationResolution / gyroscopeResolution based on the range.

  • Removed accelerationResolution / gyroscopeResolution lines in the switch statements in both initialize functions

Validation:

  1. Follow Steps to Reproduce step 1 - 8 inclusive

  2. The Serial Monitor says:

    accel range: 1 resolution: 0.00024414
    gyro range: 1 resolution: 0.03051758

  3. Check the math...

    accel resolution: 4.0 / 16384.0 = 0.00024414
    gyro resolution: 500.0 / 16384.0 = 0.030517578

This result passes.

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

No branches or pull requests

2 participants