-
-
this is the simplest code that I am using:
var Vec3 = require("Vec3"); var vmin = new Vec3(Puck.mag()); var vmax = vmin; function onMag(xyz) { vmin = vmin.min(xyz); vmax = vmax.max(xyz); var c = vmin.add(vmax).mul(0.5).sub(xyz); var a = (Math.atan2(c.x,c.y)*180/Math.PI); if(a <0) a+=360; console.log( vmin); console.log( vmax); console.log( c); console.log( a.toFixed(0) ); } Puck.on('mag', onMag); Puck.magOn(10);
I get consistent 0 to 360 degree measurements, but with 0 to 270 actually between 0 and 350 and 270 to 360 occuring in the last 10 degrees.
-
I have been trying to use the magnetometer to accurately compute compass heading . However, I seem to be getting results that render the measurement somewhat useless. After I compute the Atan of mag.x and mag.y then calculate for 360 degrees, I find that my puck is very quickly jumping past 270 to 360 and relatively slowly projecting 0 to 270. Sort of like 90 degrees measurement occurs in 10 degrees of rotation and 270 degrees measurement occurs in 350 degrees rotation. I have tried moving the puck into an entirely demagnetized space away from every possible external magnet source and still get these ranges. I’m trying to lay the puck flat on the table and turn the puck as if it were a volume knob.
Is the magnetometer not capable of being used as a compass ?
Got it. I tried to remove all magnetic fields from my environment. But there must just be too many magnets inside of every computer, tablet, and camera in my room, or the earth is just annoyingly uncentered at my altitude/long/lat.