You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mixing float values with functions taking/returning double values means these need to be converted between the two,
(float <-> double). Explicitly using float versions of the respective functions will ensure that the most efficient compilation and execution is achieved. Similarly, expressing literals as typed values is normally best practice (particularly with floating point types) as it makes intent clear and leaves less room for ambiguity.
voidMPU6050::update(){
// retrieve raw datathis->fetchData();
// estimate tilt angles: this is an approximation for small angles!floatsgZ= (float)((accZ>=0.f)-(accZ<0.f)); // allow one angle to go from -180 to +180 degrees//float sgZ = accZ<0.f ? -1.f : 1.f; /* Less obfuscated than above ?? */angleAccX=atan2f(accY, sgZ*sqrtf(accZ*accZ+accX*accX)) * (float)RAD_2_DEG; // [-180,+180] degangleAccY=-atan2f(accX, sqrtf(accZ*accZ+accY*accY)) * (float)RAD_2_DEG; // [- 90,+ 90] degunsigned longTnew=millis();
floatdt= (float)(Tnew-preInterval) *1e-3f;
preInterval=Tnew;
// Correctly wrap X and Y angles (special thanks to Edgar Bonet!)// https://github.com/gabriel-milan/TinyMPU6050/issues/6angleX=wrap(filterGyroCoef*(angleAccX+wrap(angleX+gyroX*dt-angleAccX,180.f)) + (1.f-filterGyroCoef)*angleAccX,180.f);
angleY=wrap(filterGyroCoef*(angleAccY+wrap(angleY+sgZ*gyroY*dt-angleAccY, 90.f)) + (1.f-filterGyroCoef)*angleAccY, 90.f);
angleZ+=gyroZ*dt; // not wrapped (to do???)
}
I hope you find this useful.
The text was updated successfully, but these errors were encountered:
Thanks for your comment, it seems indeed to be a good suggestion. I will look for this in the future developments of the library to improve speed and efficiency.
Hi
Thanks for the library, it has been most useful to me.
A suggestion if I may,
Using float version's of math functions would on some (perhaps even most) platforms result in faster execution and potentially smaller code size.
Function prototypes in
math.h
Mixing
float
values with functions taking/returningdouble
values means these need to be converted between the two,(
float <-> double
). Explicitly usingfloat
versions of the respective functions will ensure that the most efficient compilation and execution is achieved. Similarly, expressing literals as typed values is normally best practice (particularly with floating point types) as it makes intent clear and leaves less room for ambiguity.I hope you find this useful.
The text was updated successfully, but these errors were encountered: