Accelerometer returned values...

Posted on
  • I'm puzzled by what I'm seeing... I have a Puck programmed up to display the values coming back from the accelerometer :

    require("puckjsv2-accel-movement").on();­
    var idleTimeout;
    Puck.on('accel',function(a) {
      LED.set();
      if (idleTimeout) clearTimeout(idleTimeout);
      else {
        // print("Motion", a);
        var s = "{'type': 'M', 'x':" +  a.acc.x + ", 'y':" + a.acc.y + ", 'z':" + a.acc.z + ", 'gx': " + a.gyro.x + ", 'gy':" + a.gyro.y + ", 'gz':" + a.gyro.z + "}";
        Bluetooth.println(s);
      }
      idleTimeout = setTimeout(function() {
        idleTimeout = undefined;
        LED.reset();
      },500);  
    });
    

    It certainly reports numbers, but they don't seem to bear much relationship to the magnitude of the movement. A small tap on the table produces : {'type': 'M', 'x':-644, 'y':133, 'z':14235, 'gx': -675, 'gy':-2386, 'gz':1043} and a major movement produces : {'type': 'M', 'x':2926, 'y':402, 'z':19069, 'gx': -675, 'gy':-2386, 'gz':1043}

    what are the units?

    TIA

    Martin

  • Yo @maby - I've tried subtracting the offsets from zero but they're not super consistent, I'm at a bit of a loss trying to figure out how to normalise the values myself.

  • Hi - there's a bit of info on: http://www.espruino.com/Reference#l_Puck­_accel

    Basically acc.x/y/z are the values off the chip, which will be the acceleration in G's multiplied by 8192 (unless you've configured the chip for something else - see below).

    If you run this code with the Puck.js flat on the table, you should expect x and y to be pretty much 0, and z to be around 8192 (1g).

    Puck.on('accel',print);
    Puck.accelOn();
    

    However in your example you're detecting movement. This configures the accelerometer to sit there looking at x/y/z values to see if they vary by a lot, and to then flag up any movement. The acceleration reported is just the current acceleration at the time movement is reported, so if you're moving slow it's more or less the angle of the Puck, but if you're moving fast it's not really a useful value.

    One thing to add here is puckjsv2-accel-movement configures the accelerometer in the 2g mode (default is 4g) so now the acceleration figures need to be divided by 16384 to get Gs.

    So basically require("puckjsv2-accel-movement") won't give you one instantaneous value that shows you how much the device has moved. You'll need to look at several of the reported Puck.on('accel' events and see the difference between them.

  • I think the light may be dawning - is it the case that whichever axis is vertical will always show a background value in the region of 16000 which is the acceleration due to gravity? I was assuming that the values are instantaneous acceleration as in change in velocity rather than "static" acceleration which shows gravity... In my tests, I had the Puck laying flat on the table and jogged it slightly sideways - I expected the Z acceleration to be zero, not 16000. I've now just tried standing it up on one side and jogging it slightly - and I'm seeing an X or Y axis acceleration of about 16000.
    Martin

  • is it the case that whichever axis is vertical will always show a background value in the region of 16000 which is the acceleration due to gravity?

    Yes, that's correct. I believe it is possible to configure the accelerometer to do a 'high pass filter' to discount any acceleration due to gravity, but that has its own side effects (twisting the Puck will then show 1g acceleration until the filter updates)

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

Accelerometer returned values...

Posted by Avatar for maby @maby

Actions