• 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

About

Avatar for Gordon @Gordon started