convertWaypointMissionVectorsToLocationsWithGimbalPitch static method

dynamic convertWaypointMissionVectorsToLocationsWithGimbalPitch({
  1. required FlightElementWaypointMission flightElementWaypointMission,
  2. required FlightLocation droneHomeLocation,
})

Implementation

static convertWaypointMissionVectorsToLocationsWithGimbalPitch(
    {required FlightElementWaypointMission flightElementWaypointMission,
    required FlightLocation droneHomeLocation}) {
  if (flightElementWaypointMission.pointOfInterest == null) {
    developer.log(
      'convertWaypointMissionVectorsToLocations - Waypoint Mission Point of Interest does not exist',
      name: kLogKindDjiFlutterPlugin,
    );
  }

  int unableToComputeLocationBasedOnVector = -1;
  int count = 0;
  for (FlightWaypoint waypoint in flightElementWaypointMission.waypoints) {
    // Compute Location per Vector definition
    if (waypoint.vector != null && waypoint.location == null) {
      waypoint.location = CoordinatesConvertion.vectorToLocation(
          droneLocation: droneHomeLocation,
          pointOfInterest: flightElementWaypointMission.pointOfInterest!,
          vector: waypoint.vector!);

      /// If we weren't able to compute the location - we mark the failure and the parent method will return null
      if (waypoint.location == null) {
        unableToComputeLocationBasedOnVector = count;
      }
    } else {
      /// Location already exists - Keeping the existing waypoint
    }

    /// Compute Gimbal Angle, but only if it doesn't exist
    if (waypoint.gimbalPitch == null && waypoint.location != null) {
      waypoint.gimbalPitch = CoordinatesConvertion.computeGimbalAngle(
          flightElementWaypointMission.pointOfInterest!, waypoint.location!);
    }

    count++;
  }

  if (unableToComputeLocationBasedOnVector > -1) {
    developer.log(
      'convertWaypointMissionVectorsToLocations - Unable to compute Waypoint Location based on Waypoint Vector #$unableToComputeLocationBasedOnVector inputs',
      name: kLogKindDjiFlutterPlugin,
    );
  }

  developer.log(
    'convertWaypointMissionVectorsToLocations - updated waypoints: ${jsonEncode(flightElementWaypointMission.waypoints)}',
    name: kLogKindDjiFlutterPlugin,
  );
}