0.0.4 • Published 5 years ago

react-native-sensor-fusion v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-native-sensor-fusion

Robust absolute 3D positioning in React Native, using sensor fusion to exploit the superior characterstics of the device Accelerometer, Gyroscope and Magnetometer, whilst mitigating against their negative qualities.

Physical data acquisition is implemented using react-native-sensors. The noise in sampled data is filtered from the input signals using the high quality kalmanjs, and sensor fusion is calculated using ahrs.

🚀 Getting Started

Using npm:

npm install --save react-native-sensor-fusion

Using yarn:

yarn add react-native-sensor-fusion

✍️ Example

import React from 'react';
import { Text } from 'react-native';
import SensorFusionProvider, { useSensorFusion, useCompass, toDegrees } from 'react-native-sensor-fusion';

const Indicator = () => {
  const { ahrs } = useSensorFusion();  
  const { x, y, z, w } = ahrs.toVector();
  return (
    <Text
      children={toDegrees(z)}
    />
  );

const Indicator = () => {
  const { ahrs } = useSensorFusion();
  const { heading, pitch, roll } = ahrs.getEulerAngles();
  const compass = useCompass();
  return (
    <Text>
      Heading: {toDegrees(heading)}°{'\n'}
      Pitch: {toDegrees(pitch)}°{'\n'}
      Roll: {toDegrees(roll)}°{'\n'}
      Compass: {toDegrees(compass)}°{'\n'}
    </Text>
  );
};

export default () => (
  <SensorFusionProvider>
    <Indicator />
  </SensorFusionProvider>
);

📌 Prop Types


PropTypeDefaultRequiredDescription
sampleIntervalnumber60NoThe frequency to sample the device sensors in Hz.
algorithmstring'Mahony'NoChoose from the Madgwick or Mahony filter.
betanumber0.4NoThe filter noise value, smaller values have smoother estimates, but have higher latency. This only works for the Madgwick filter.
kpnumber0.5NoThe filter noise values for the Mahony filter (Proportional).
kinumber0NoThe filter noise values for the Mahony filter (Integral).

✌️ License

MIT