• Thanks! Yeah, calibrating is a real pain. I've even noticed with the Pucks that if you bring a magnet too close (<2cm from the case) then it can partially magnetise something on the Puck and you have to recalibrate!

    For working out the heading, have you come across Math.atan2? It's amazingly helpful.

    I really quick hack would be something like this:

    if (is_biggest(accel.x)) return sign(accel.x)*Math.atan2(mag.y, mag.z);
    if (is_biggest(accel.y)) return sign(accel.y)*Math.atan2(mag.z, mag.x);
    return sign(accel.z)*Math.atan2(mag.x, mag.y);
    

    But I guess to do it properly you want to do it better than the nearest 90 degrees :)

About

Avatar for Gordon @Gordon started