Mag reading not consistent

Posted on
  • After about 10 seconds of mag readings (zero), I bring a magnet close to the puck. As expected the mag readings go up. Then I take the magnet away and the values go back down....a little. They do not go back down to the zero values that I would have expected.

    So the open close door example does not work correctly because we never get back below 1000.

    1v91 Copyright 2016 G.Williams
    41.49698784249
    { "x": -19, "y": 20, "z": 31 }
    41.49698784249
    108.59558002055
    { "x": -83, "y": 70, "z": -2 }
    113.89907813498
    { "x": -84, "y": 74, "z": -21 }
    115.32996141506
    { "x": -88, "y": 74, "z": -9 }
    112.82730166054
    { "x": -88, "y": 69, "z": 15 }
    112.29425630903
    { "x": -87, "y": 71, "z": 0 }
    117.02136557056
    { "x": -93, "y": 71, "z": -2 }
    8429.72300849796
    { "x": -5599, "y": -4602, "z": 4305 }
    8429.72300849796
    1419.88802375398
    { "x": -177, "y": -217, "z": 1392 }
    1341.72426377404
    { "x": -80, "y": -140, "z": 1332 }
    1317.90857042512
    { "x": -79, "y": -131, "z": 1309 }
    1302.96623133525
    { "x": -73, "y": -134, "z": 1294 }
    1320.38592843153
    { "x": -77, "y": -137, "z": 1311 }

    var zero = Puck.mag();
    var doorOpen = false;
    
    function onMag(p)
    {
      p.x -= zero.x;
      p.y -= zero.y;
      p.z -= zero.z;
      
      var magSqrt = Math.sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
      console.log(magSqrt);
      console.log(p);
      
      var open = magSqrt < 1000;
      
      if (open!=doorOpen)
      {
        console.log(magSqrt);
        doorOpen = open;
        digitalPulse(open ? LED1 : LED2, 1,1000);
      }
      
    }
    
    Puck.on('mag', onMag);
    Puck.magOn();
    
    
  • How close did you bring the magnet? If you have a powerful magnet and you bring it really close, you actually magnetise the Puck and/or magnetometer, which knocks off the base reading.

    There's nothing you can do about this - it would be the same in any device - even an old-school compass :)

    edit: just to add the door example would generally work fine because of the distance between the magnet and Puck - but even if not you can just re-calibrate your zero and you'll be fine

  • Yes, it was a strong magnet and it was really close. Thanks for explaining the situation to me.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Mag reading not consistent

Posted by Avatar for Terrence @Terrence

Actions