Difference between revisions of "Algorithms"

From Wiki at Neela Nurseries
Jump to navigation Jump to search
m (Add link to article regarding calculation of compass directions)
m (Add link and note about how to calculate pitch and roll)
Line 14: Line 14:
  
 
*  https://digilent.com/blog/how-to-convert-magnetometer-data-into-compass-heading/
 
*  https://digilent.com/blog/how-to-convert-magnetometer-data-into-compass-heading/
 +
 +
To figure pitch and roll:
 +
 +
*  https://forum.arduino.cc/t/sensing-tilt-using-accelerometer-alone/135717/5
 +
 +
<!--
 +
johnwasser
 +
Karma: 2000+
 +
Dec 2012
 +
post #6
 +
When you tilt the X axis up past 90 degrees, the Z axis goes through zero and then starts going positive. Since yrot is based on the X and Z measurements, when Z goes from negative to positive you get a different answer, even though Y is staying near zero.
 +
 +
To get pitch and roll, try:
 +
 +
pitch=atan2(ax,sqrt((ay*ay)+(az*az)))
 +
roll=atan2(ay,sqrt((ax*ax)+(az*az)))
 +
Note that the result is in Radians so if you want degrees you still have to convert. You shouldn't get a problem with both arguments to atan2() being zero unless your accelerometer is in free-fall. 
 +
 +
-->

Revision as of 05:51, 9 February 2026

Integer division:

Link to Algorithmica dot org article on integer division:

Possible Rust crate for integer math functions, does not presently require use of Rust `std` crate:

Figuring compass directions:

To figure pitch and roll: