4

In Android I can get the device yaw, roll and pitch using a GAME_ROTATION_VECTOR sensor.

I need to do the same thing in Flutter, but I haven't been able to find anything but the sensors package, which only gives access to accelerometer & gyroscope sensors.

What can I do? Do I need to calculate the orientation myself from the accelerometer and gyro?

Hexwell
  • 89
  • 5
  • 10
  • 1
    You could use `plaform_channel` to call android methods and fetch the result from flutter – Rémi Rousselet Aug 08 '18 at 14:34
  • @RémiRousselet Can I do the opposite? Like call Flutter functions from Android? Because that will solve my problem better – Hexwell Aug 08 '18 at 14:40
  • 2
    Yes, see [How to call methods in Dart portion of the app, from the native platform...](https://stackoverflow.com/questions/50187680/flutter-how-to-call-methods-in-dart-portion-of-the-app-from-the-native-platfor) – Richard Heap Aug 09 '18 at 02:29

1 Answers1

4

Don't know if this is still relevant, as the question wasn't closed, but for those seeking the answer... there is now a Flutter Sensors package which does all the magic for you.

You'll have to subscribe to the streams to get the current values of the accelerometers and gyroscopes, of course.

For example:

  @override
  void initState() {
    super.initState();
    _streamSubscriptions
        .add(accelerometerEvents.listen((AccelerometerEvent event) {
      setState(() {
        _accelerometerValues = <double>[event.x, event.y, event.z];
      });
    }));
    _streamSubscriptions.add(gyroscopeEvents.listen((GyroscopeEvent event) {
      setState(() {
        _gyroscopeValues = <double>[event.x, event.y, event.z];
      });
    }));
    _streamSubscriptions
        .add(userAccelerometerEvents.listen((UserAccelerometerEvent event) {
      setState(() {
        _userAccelerometerValues = <double>[event.x, event.y, event.z];
      });
    }));
  }
benPesso
  • 79
  • 3
  • Unfortunately the yaw (Azimut) is not available with this package – Bil5 May 21 '19 at 15:15
  • Umm, Yaw is the Z axis. (Y - Pitch, X - Roll) – benPesso May 23 '19 at 07:28
  • 2
    Sorry I was talking about https://github.com/aeyrium/aeyrium-sensor/ package, concerning the 'sensors' package, it's not very handy as you can only get a delta and not current values at a time, which means that you have to track values from a starting 'basis' position, which is not the case with the aeyrium-sensor package but which unfortunately lacks the yaw value. – Bil5 May 23 '19 at 08:12
  • 1
    From what the documentation says about the Flutter package, these are "current" values of acceleration. Not deltas. For example: "Acceleration force along the x axis (including gravity) measured in m/s^2." See more here: https://github.com/flutter/plugins/blob/master/packages/sensors/lib/sensors.dart – benPesso May 27 '19 at 17:53