2

From the API docs

It might be interesting to note that the gravity of the earth is not removed from the sensoric values. Dependening on the position of the phone you will need to substract this from the values if you are interested in the raw values.

I'm trying to combine react-native-sensors with MaximilianBuegler/node-pedometer but it looks like the data given is not correct for the node-pedometer library, and not sure how to adapt it. Just wondering if the gravity values included in the output is the reason.

Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70

1 Answers1

2

You need to implement the method described in the Android API docs.

This would mean for React Native Sensors that you should be able to do something like this:

new Accelerometer.pipe(scan((acc, curr) => {
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter's time-constant
      // and dT, the event delivery rate

      final float alpha = 0.8;

      const x = alpha * acc.x + (1 - alpha) * curr.x;
      const y = alpha * acc.y + (1 - alpha) * curr.y;
      const z = alpha * acc.z + (1 - alpha) * curr.z;

      return {x,y,z}; 
}, {x:0,y:0,z:0})
Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70