universam1 / iSpindel

electronic Hydrometer
http://www.ispindel.de
Other
827 stars 322 forks source link

Possible division by Zero in tilt calculation #469

Closed pppedrillo closed 3 years ago

pppedrillo commented 3 years ago

For bad/dodgy gyro/accel modules it is possible that all the readings (ax, ay and az) are all zeroes. In that case calculateTilt() returns NaN. *_az / (sqrt(_ax _ax + _ay _ay + _az _az))** --> division by 0.

The same possible issue with void setup() function, when USE_DMP defined - the same calculations copy-pasted there.

iSpindel.cpp

float calculateTilt() { float _ax = ax; float _ay = ay; float _az = az; return acos(_az / (sqrt(_ax _ax + _ay _ay + _az _az))) 180.0 / M_PI; }

void setup() {

Serial.begin(115200);

.... ax = euler[0]; ay = euler[2]; az = euler[1];

float _ax = ax;
float _ay = ay;
float _az = az;
Tilt = acos(_az / (sqrt(_ax * _ax + _ay * _ay + _az * _az))) * 180.0 / M_PI;

}

endif

... }

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.