You are reading a single comment by @Ollie and its replies. Click here to read the full conversation.
  • I noticed when testing similar code that the first reading after offsetting with zero = Puck.mag(); gives x, y and z values close to zero, as you'd expect, but second and subsequent jump to values that vary (+/-) quite a bit from zero, and actually found it better to do use a later reading as a zero/offset, making a couple of calibration passes as below

    var offset = {x:0, y:0, z:0};
    var calPass = 2;
    
    function readMag(mag){
      if (calPass > 0) {
        // calibration pass
        offset.x = mag.x;
        offset.y = mag.y;
        offset.z = mag.z;
        calPass--;
      } else { 
        // provide reading
        mag.x -= offset.x;
        mag.y -= offset.y;
        mag.z -= offset.z;
        console.log(mag);
      }
    }
    
    Puck.on('mag', readMag);
    Puck.magOn();
    

    I doubt it matters much, as slight changes in orientation of Puck still move values considerably, regardless, but it seems the Puck.mag() reading doesn't quite do the zeroing/reset I expected.

About

Avatar for Ollie @Ollie started