start method Null safety
- {required Flight flight}
Starts the DJI Drone Flight Timeline.
The Dji.start
method receives a Flight Timeline object and commands the Drone to start executing it.
The Flight
class defines the different flight properties (e.g. location, waypoint, etc.) and provides tools to convert from and to JSON.
In the example below, the we first validate that the DroneHomeLocation
exists and then we define our Flight object, which includes several Flight Elements.
A Flight Element has several types:
- takeOff
- land
- waypointMission
- singleShootPhoto
- startRecordVideo
- stopRecordVideo
The waypointMission
consists of a list of waypoints.
Each waypoint can be defined in two ways: location
or vector
.
Location defines a waypoint by Latitude, Longitude and Altitude.
Vector defines a waypoint in relation to the "point of interest". It's defined by 3 properties as follows:
distanceFromPointOfInterest
- The distance in meters between the "point of interest" and the Drone.
headingRelativeToPointOfInterest
- If you imagine a line between the "point of interest" (e.g. where you stand) and the Drone's Home Location - this is heading "0".
- So the value of
headingRelativeToPointOfInterest
is the angle between heading "0" and where you want the Drone to be. - A positive heading angle is to your right. While a negative angle is to your left.
destinationAltitude
- This is the Drone's altitude at the waypoint.
Explanation by example: Imagine you are the "point of interest", holding a "laser pointer". Everything is relative to the "line" between you and the Drone. If you point the laser to the Drone itself - that's "heading 0". If you want the first waypoint to be 30 degrees to your right, at a distance of 100 meters and altitude of 10 meters, you should set:
'vector': {
'distanceFromPointOfInterest': 100,
'headingRelativeToPointOfInterest': 30,
'destinationAltitude': 10,
},
A full example showing how to use the Flight object and use the Dji.start
method:
Future<void> _start() async {
try {
droneHomeLocation = FlightLocation(
latitude: 32.2181125, longitude: 34.8674920, altitude: 0);
if (droneHomeLocation == null) {
developer.log(
'No drone home location exist - unable to start the flight',
name: kLogKindDjiFlutterPlugin);
return;
}
Flight flight = Flight.fromJson({
'timeline': [
{
'type': 'takeOff',
},
{
'type': 'startRecordVideo',
},
{
'type': 'waypointMission',
/// For example purposes, we set our Point of Interest a few meters away, relative to the Drone's Home Location
'pointOfInterest': {
'latitude': droneHomeLocation!.latitude + (5 * 0.00000899322),
'longitude': droneHomeLocation!.longitude + (5 * 0.00000899322),
'altitude': droneHomeLocation!.altitude,
},
'maxFlightSpeed':
15.0, /// Max Flight Speed is 15.0. If you enter a higher value - the waypoint mission won't start due to DJI limits.
'autoFlightSpeed': 10.0,
'finishedAction': 'noAction',
'headingMode': 'towardPointOfInterest',
'flightPathMode': 'curved',
'rotateGimbalPitch': true,
'exitMissionOnRCSignalLost': true,
'waypoints': [
{
// 'location': {
// 'latitude': 32.2181125,
// 'longitude': 34.8674920,
// 'altitude': 20.0,
// },
'vector': {
'distanceFromPointOfInterest': 20,
'headingRelativeToPointOfInterest': 45,
'destinationAltitude': 5,
},
// 'heading': 0,
'cornerRadiusInMeters': 5,
'turnMode': 'clockwise',
// 'gimbalPitch': 0,
},
{
// 'location': {
// 'latitude': 32.2181125,
// 'longitude': 34.8674920,
// 'altitude': 5.0,
// },
'vector': {
'distanceFromPointOfInterest': 10,
'headingRelativeToPointOfInterest': -45,
'destinationAltitude': 3,
},
// 'heading': 0,
'cornerRadiusInMeters': 5,
'turnMode': 'clockwise',
// 'gimbalPitch': 0,
},
],
},
{
'type': 'stopRecordVideo',
},
{
'type': 'singleShootPhoto',
},
{
'type': 'land',
},
],
});
// Converting any vector definitions in waypoint-mission to locations
for (dynamic element in flight.timeline) {
if (element.type == FlightElementType.waypointMission) {
CoordinatesConvertion
.convertWaypointMissionVectorsToLocationsWithGimbalPitch(
flightElementWaypointMission: element,
droneHomeLocation: droneHomeLocation!);
}
}
developer.log(
'Flight Object: ${jsonEncode(flight)}',
name: kLogKindDjiFlutterPlugin,
);
await Dji.start(flight: flight);
developer.log(
'Start Flight succeeded',
name: kLogKindDjiFlutterPlugin,
);
} on PlatformException catch (e) {
developer.log(
'Start Flight PlatformException Error',
error: e,
name: kLogKindDjiFlutterPlugin,
);
} catch (e) {
developer.log(
'Start Flight Error',
error: e,
name: kLogKindDjiFlutterPlugin,
);
}
}
Implementation
static Future<void> start({required Flight flight}) async {
Map<String, dynamic> flightJson = flight.toJson();
await _api?.start(jsonEncode(flightJson));
}