Puck.js magnetometer as a compass ? #4312
Replies: 1 comment
-
Posted at 2024-04-24 by user158028 this is the simplest code that I am using:
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. Posted at 2024-04-25 by @gfwilliams Hi - what you've got there looks pretty good to me. The magnetometer has a DC offset on it, so you need to account for that with min/max which is what you're doing. Are you sure that when you upload this you're turning the Puck 360 degrees around (and maybe rolling at different angles as well) first? That allows min/max to be calibrated and will give you much more accurate readings. You'd hope that when you do this, edit: just to add the Puck would also need to be held perpendicular to the magnetic field when using Posted at 2024-04-25 by user158028 here's a video of one sample rotation after calibration. Attachments: Posted at 2024-04-26 by @gfwilliams One thing I notice from that is that the values in However the values for min/max are anywhere from 1000 to 1600 apart, so basically however you calibrated it, it must have been near a much bigger magnetic field somehow so the min/max values (and hence the center) are way out. If you do Getting the compass calibrated is a right pain - it's why even on phones where they've got sometimes billions in R&D budget the phone still occasionally asks you to rotate it in circles to recalibrate. If you know the field strength where you are (looks like ~160ish for you?), you can effectively just keep track of the center point (rather than min/max) and then if the reading is ever more than 160 away from the center point you just update the center point. Posted at 2024-04-26 by user158028 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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2024-04-24 by user158028
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 ?
Beta Was this translation helpful? Give feedback.
All reactions