Vertical axis is the Yaw axis
This leaves two remaining axis
The heading or roll axis points in the direction of travel
The remaining horizontal axis is the pitch axis that points left and right from the heading axis.
To get a heading we use the atan2 function and then adjust to a 0 to 360 degree range
If(ww<0) ww+=360
Atan2 produces values in radians so we define pirate= 180/pi to get degrees
57.29577951
In the following table pay attention to the sign of the axis values
Heading
Roll
Pitch
Pirate*Atan2(Roll,Pitch)
Adjust
North
1
0
0
0
NorthEast
1
1
45
45
East
0
1
90
90
SouthEast
-1
1
135
135
South
-1
0
180
180
SouthWest
-1
-1
-135
225
West
0
-1
-90
270
NorthWest
1
-1
-45
315
*Magnetometer axis usually have an offset that needs to be corrected so that no field produces a zero value. x1= x - xoffset, y1= y-yoffset, z1= z-zoffset;
You must assign the X,Y, and Z axis to the Roll, Pitch and Yaw axis based on the mounting of the magnetometer.
The roll or pitch readings from the mgnetometer may need to be negated to get the proper heading, as the direction of the assigned axis may be reversed from the Roll, Pith and Yaw axis as define in the table.
Use the attached trycompass.js file as a starting point. Attention Puck experimenters!
(still puzzling as to why the markdown table above doesn't display correctly?)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Using a 3-Axis Magnetometer as a compass.
This leaves two remaining axis
57.29577951
*Magnetometer axis usually have an offset that needs to be corrected so that no field produces a zero value. x1= x - xoffset, y1= y-yoffset, z1= z-zoffset;
Use the attached trycompass.js file as a starting point. Attention Puck experimenters!
(still puzzling as to why the markdown table above doesn't display correctly?)
1 Attachment