-
• #2
Hi - that sounds great! It's a really nice idea to add in some extra control methods for kids.
I think it's possible that what's happening is the Madgwick is expecting relative magnetometer values, but what you're getting are the absolute (effectively uncalibrated) ones.
Actually getting good, calibrated values from the magnetometer itself can be a total pain as it can change even if you move away from a metal desk or so on, but what I'd suggest is you do is store min/max values, work out a central value from those and then subtract that:
var Vec3 = require("Vec3"); var magMin = new Vec3(); var magMax = new Vec3(); Puck.magOn(); Puck.on('mag', function(xyz) { //console.log(xyz); // {x:..., y:..., z:...} var v = new Vec3(xyz); magMin = magMin.min(v); magMax = magMax.max(v); var diff = v.sub(magMax.add(magMin).mul(0.5)); // ... diff contains the value you want });
If you then pass that value in, you might find that works well - but you will have to roll the Puck around and around a bit when you start so that the min/max values get set up right
Hi there! I'm Bre, a game developer at a children's hospital. I'm exploring using Puck.js as a game controller for MakeCode Arcade games, so that we can use them for adaptive gaming, procedure support, etc. I'd like to show you guys what I've done so far, and see if I can get a little help as well.
You can try the following examples I've put together - just click "Connect Puck.js" at the bottom of the page to connect the Puck, and then tilt the Puck to play.
Space Destroyer - tilt Puck left/right (about accelerometer X axis) to move left right, tilt forward (about accelerometer Y axis) to shoot.
Hot Air Balloon - tilt Puck forward (about accelerometer Y axis) to move the hot air balloon up.
I'm using the Madgwick AHRS algorithm to estimate orientation, but only using the accelerometer/gyroscope data as input. Here's a demo that rotates a 3D model from the Puck accel/gryo data only. I'm pretty happy with the pitch/roll calculations, but heading has always been off. I was hoping to use the magnetometer to improve my orientation calculations.
If I add in the magnetometer data to the Madgwick algorithm like I do in this example, the orientation is way worse. The heading always seems to want to drift to the same direction, regardless of what direction it's pointing. I've been searching datasheets and documentation and code for answers, but for the life of me, I cannot get the magnetometer and accelerometer data to play well together.
Has anyone been able to combine the accel/gyro/mag data to estimate orientation? I have the Puck v2.1a, just FYI. I don't really know much about sensor fusion and I've been trying to figure this out for a while, so any help would be much appreciated! Thank you!