state property

Stream<TelloState> get state

Implementation

Stream<TelloState> get state =>
    rawDataStream?.map<TelloState>((String currentState) {
      // Thanks to ryze_tello
      RegExp telloStateRegex = RegExp(r"((pitch:)(.+)(;roll:)(.+)(;yaw:)(.+)(;vgx:)(.+)(;vgy:)(.+)(;vgz:)(.+)(;templ:)(.+)(;temph:)(.+)(;tof:)(.+)(;h:)(.+)(;bat:)(.+)(;baro:)(.+)(;time:)(.+)(;agx:)(.+)(;agy:)(.+)(;agz:)(.+)(;))");

      RegExpMatch matches = telloStateRegex.firstMatch(currentState)!;

      return TelloState(
        ImuAttitude(int.parse("${matches[3]}"), int.parse("${matches[5]}"), int.parse("${matches[7]}")),
        ImuVelocity(int.parse("${matches[9]}"), int.parse("${matches[11]}"), int.parse("${matches[13]}")),
        ImuAcceleration(double.parse("${matches[29]}"), double.parse("${matches[31]}"), double.parse("${matches[33]}")),
        (double.parse("${matches[15]}") + double.parse("${matches[17]}")) / 2,
        int.parse("${matches[19]}"),
        int.parse("${matches[21]}"),
        int.parse("${matches[23]}"),
        double.parse("${matches[25]}"),
        int.parse("${matches[27]}"),
      );
    }) ??
    Stream.empty();