Skip to content

Commit

Permalink
It's worth to note that my tests show it's maybe better to keep the c…
Browse files Browse the repository at this point in the history
…ode unchanged and keep the z-axis calibrated upwards, just make sure the z-axis was calibrated upwards. Now all directions can be just as bad, and the calibration error is related to epsilon
  • Loading branch information
Zhaosn committed Jan 31, 2024
1 parent 66c7b9d commit a19a401
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/MPU6050.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3401,6 +3401,7 @@ void MPU6050_Base::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){
uint32_t eSum;
uint16_t gravity = 8192; // prevent uninitialized compiler warning
if (ReadAddress == 0x3B) gravity = 16384 >> getFullScaleAccelRange();
uint16_t epsilon = gravity * 0.001;
Serial.write('>');
for (int i = 0; i < 3; i++) {
I2Cdev::readWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data, I2Cdev::readTimeout, wireObj); // reads 1 or more 16 bit integers (Word)
Expand All @@ -3424,7 +3425,7 @@ void MPU6050_Base::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){
v_rawG.x = rawG[0];
v_rawG.y = rawG[1];
v_rawG.z = rawG[2];
if (v_rawG.getMagnitude() < gravity) {
if (v_rawG.getMagnitude() < gravity + epsilon && v_rawG.getMagnitude() > gravity - epsilon) {
// do nothing
}else {
v_normG = v_rawG.getNormalized();
Expand Down

0 comments on commit a19a401

Please sign in to comment.