Skip to content

Commit

Permalink
Update MPU6050.cpp
Browse files Browse the repository at this point in the history
If the acceleration reading is [0 0 0] at the beginning, it causes the unit vector to return [nan nan nan nan], which causes the ITerm always be nan, leading to unconvergence

Signed-off-by: Zhaosn <[email protected]>
  • Loading branch information
Zhaosn authored Feb 1, 2024
1 parent a19a401 commit fbb3de4
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 @@ -3436,6 +3436,7 @@ void MPU6050_Base::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){
}
}
for (int i = 0; i < 3; i++) {
if (isnan(Reading[i])) {Reading[i] = 0;}
Error = -Reading[i];
eSum += abs(Reading[i]);
PTerm = kP * Error;
Expand Down Expand Up @@ -3492,4 +3493,4 @@ void MPU6050_Base::PrintActiveOffsets() {
Serial.print((float)offsets[3], 5); Serial.print(",\t");
Serial.print((float)offsets[4], 5); Serial.print(",\t");
Serial.print((float)offsets[5], 5); Serial.print("\n\n");
}
}

0 comments on commit fbb3de4

Please sign in to comment.