Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tockn committed Jun 16, 2018
1 parent f7fa4c1 commit 917f12a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/MPU6050_tockn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ void MPU6050::update(){
gyroY -= gyroYoffset;
gyroZ -= gyroZoffset;

interval = millis() - preInterval;
interval = (millis() - preInterval) * 0.001;

angleGyroX += gyroX * (interval * 0.001);
angleGyroY += gyroY * (interval * 0.001);
angleGyroZ += gyroZ * (interval * 0.001);
angleGyroX += gyroX * interval;
angleGyroY += gyroY * interval;
angleGyroZ += gyroZ * interval;

angleX = (gyroCoef * (angleX : gyroX * (interval * 0.001))) + (accCoef * angleAccX);
angleY = (gyroCoef * (angleY + gyroY * (interval * 0.001))) + (accCoef * angleAccY);
angleX = (gyroCoef * (angleX + gyroX * interval)) + (accCoef * angleAccX);
angleY = (gyroCoef * (angleY + gyroY * interval)) + (accCoef * angleAccY);
angleZ = angleGyroZ;

preInterval = millis();
Expand Down
3 changes: 2 additions & 1 deletion src/MPU6050_tockn.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class MPU6050{

float angleX, angleY, angleZ;

long interval, preInterval;
float interval;
long preInterval;

float accCoef, gyroCoef;
};
Expand Down

0 comments on commit 917f12a

Please sign in to comment.