I am using the following code to try and initialise a Waypoint Mission and load it to the aircraft ( a DJI Mavic Air).
I first check the state of the waypoint handler, then initialise a waypoint, add it to the list, then include the list in the initialised waypoint mission. The method for loading the waypoint mission to the aircraft is then run and the state checked afterwards. The output from the debugs is seen below:
Waypoint state = READY_TO_UPLOAD;
New waypoint location - 55.555549621582,0.555555522441864
Load mission return value - INVALID_REQUEST_IN_CURRENT_STATE
Waypoint state = READY_TO_UPLOAD
The state of READY_TO_UPLOAD suggests that it is in a suitable state to upload the waypoint mission according to the Windows SDK documentation, however clearly the upload fails and the state remains unchanged.
What needs to be changed in order for the waypoint mission to successfully load so it can be run by the aircraft?
//Check the initial state of the waypoint handler
var currentState = DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).GetCurrentState();
Debug.WriteLine("Waypoint state = {0}", currentState);
//Initialise new location coordinate
randomLocation.X = 55.55555;
randomLocation.Y = 0.55555555;
Debug.WriteLine("New waypoint location - {0},{1}", randomLocation.X, randomLocation.Y);
LocationCoordinate2D waypointLocation = new LocationCoordinate2D { latitude = randomLocation.X, longitude = randomLocation.Y };
// Create a waypoint instance and add to waypoint list
Waypoint waypoint = new Waypoint { location = waypointLocation };
waypointList.Add(waypoint);
//Create new waypoint mission instance and load in the waypoint list
WaypointMission waypointMission = new WaypointMission
{
waypointCount = 1,
autoFlightSpeed = 2.5,
finishedAction = WaypointMissionFinishedAction.NO_ACTION,
headingMode = WaypointMissionHeadingMode.USING_WAYPOINT_HEADING,
flightPathMode = WaypointMissionFlightPathMode.CURVED,
repeatTimes = 0,
waypoints = waypointList,
missionID = 1
};
//load the waypoint mission to the aircraft and check the current state
var load_retval = DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).LoadMission(waypointMission); ;
Debug.WriteLine("Load mission return value - {0}", load_retval);
currentState = DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).GetCurrentState();
Debug.WriteLine("Waypoint state = {0}", currentState);
After a long time of trail and error I figured out the steps needed to start a waypoint mission:
Setting the SDK into ground station mode
First you have to set the SDK into ground station mode with the following method:
DJISDKManager.Instance.ComponentManager.GetFlightControllerHandler(0, 0).SetGroundStationModeEnabledAsync(new BoolMsg() { value = true })
Loading the mission
Second you have to load your waypoint mission to the SDK, using the following method:
DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).
LoadMission(waypointMission)
Where waypointMission
could bethe waypoint mission in your question. This waypoit mission have to follow some restrictions. For example the total distance can't be to long(not sure what the exact number is). This methode will return an SDKError if there is something wrong with the mission.
Uploading the waypoint mission to the drone
After the mission is loaded to the SDK it still has to be uploaden to the drone. This is done with the following method:
DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).
UploadMission()
(optional) Stating the simulator
At this point you could start simulation mode if you don't want your drone to actually take off. This can be done with the following code:
FlightControllerHandler _flightControllerHandler = DJISDKManager.Instance.ComponentManager.GetFlightControllerHandler(0, 0);
var simSettings = new SimulatorInitializationSettings()
{
latitude = 0,
longitude = 0,
satelliteCount = 12
};
await _flightControllerHandler.StartSimulatorAsync(simSettings);
It's important that the satelliteCount
is above 10. Else the SDK wil give and error about the GPS signal strength not being good enough.
Starting the mission Finaly you can start the waypoint mission as follows
DJISDKManager.Instance.WaypointMissionManager.GetWaypointMissionHandler(0).StartMission()
Other things to note:
async
and are best awaited.Even if you await the calls I noticed uploading the mission would not be finished at the time the method finished. So if you would call StartMission()
right after UploadMission()
this could result in a INVALID_REQUEST_IN_CURRENT_STATE
I worked around this by having a seperate button for loading and starting the mission.This way I can wait for the mission to be uploaded before I start the mission.
All of the above methods return a SDKError
type. If all went well this would be a NO_ERROR
it's important to check if this is the case for every call.