Giter Site home page Giter Site logo

Comments (3)

rfetick avatar rfetick commented on June 16, 2024

Hello motedon,

Thank you for this clear description of the issue. Indeed calibration should be able to be performed outside of the setup function. I will check this on my side.

However the library has been designed to work close to the flat regime, since it assumes gravity along the Z axis for calibration. When calibrating in any position, the gravity is not on the Z axis and the angular computations fail.

I think that you should calibrate the MPU6050 in a flat position at the beginning. Then, when the user push a button, you save the current angles given by the library. Then you remove these angles as an offset, see the code below

float angXoffset = 0;
float angYoffset = 0;

void setup(){
  ... // initialize everything
  mpu.calcOffsets(); // calibrate MPU6050 when flat
}

void loop(){
  mpu.update();
  float angX = mpu.getAngleX() - angXoffset;
  float angY = mpu.getAngleY() - angYoffset;
  ... // do whatever you want with the angles

  if(button_pushed){
    angXoffset = mpu.getAngleX();
    angYoffset = mpu.getAngleY();
  }
}

Remember that the library works in the small angle regime, don't approach too much the 90° on the X or Y axis.

Cheers,

Romain

from mpu6050_light.

motedon avatar motedon commented on June 16, 2024

Thank you very much and currently I'm using from -30 to +30 degrees, will probably won't go past 50, so I'm fine. I will try to implement your suggestion and share the results.

from mpu6050_light.

motedon avatar motedon commented on June 16, 2024

Thank you very much Romain, your solution works as expected.

from mpu6050_light.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.