Customizing the way you fly DJI drones.

Abhishek Maharajpet.
5 min readNov 30, 2018

--

Drones have revolutionized the way you capture, transport, explore and much more. DJI has been a key player in the industry building drones for both consumer and enterprise. They support your drone with DJI GO 4 application allowing you to take the maximum benefit out of your drone.

When to customize?

The DJI GO 4 app provides a wide range of intelligent flight modes like home lock, course lock, terrain follow, tripod mode, waypoint mission, active track mission etc [Refer DJI tutorials on youtube for more details on intelligent modes]. You can fly the drone on specific coordinates, follow a moving object and so on. But let us consider a scenario where you want the drone to take off, rotate continuously, move forward and capture photos and videos in a specific time interval and land. Well, to achieve this manually is a serious trouble. These can be achieved programmatically.

The DJI SDK is available for the public to develop your own applications. Further we take a tour on how to Start off with the SDK, implementing basic functions like Take off, Land, Live feed, and some Advanced controls. Ready to build an app that allows you to customize the way you fly? Let’s get started.

The basic procedure to set up a connection to the drone from your Android app is well explained in the documentation with clear steps along with a readily usable GitHub project. All you need is an API key that can be created by signing up to their developer portal.

Sample App:

Step by step guide to start building your own application:

  1. Register as DJI developer.[Use this link]

2. Generate an API key once you log in. Use the same package name that you are about to give to your new application.

3. Create an Android App with the same package name by following the steps in the link below.

4. Paste the API key in your manifest file and run the application. (You should be connected to the internet and “Register success” message is shown as you launch the app)

Take off:

Once you are done with the registration, let’s accomplish the most basic aspect of flying , the “TAKE OFF”:

  1. Use the following code with some button click listener.
Aircraft aircraft = (Aircraft) DJISDKManager.getInstance().getProduct();
aircraft.getFlightController().startTakeoff(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {

}
});

Note: The “djiError” will be null if the SDK did not encounter any error while executing the function.

2. Run the app to an Android phone.

3. Switch on the Aircraft and Remote Controller. Connect the remote controller to your phone. You should be seeing a USB access pop up. Select your application.

3. Keep the drone in an open space (preferably playground). Click on the “Take off” button in your android app. The drone takes off and stands still at a vertical distance of around one meter from the ground.

Similarly, you can land, shoot photos and videos programmatically.

aircraft.getFlightController().startLanding(...);
aircraft.getCamera().startRecordVideo(...);
aircraft.getCamera().startShootPhoto(..);

Refer the API doc link below for more functionalities.

Live View:

In order to show the live video feed from the drone add the UX SDK dependency in your build gradle.

compile 'com.dji:dji-uxsdk:4.7.1'

Add the following widget in your layout file.

<dji.ux.widget.FPVWidget
android:layout_width="match_parent"
android:layout_height="match_parent" />

Refer the following link for more widgets.

Advanced control:

This part explains how to control the movement of aircraft through your phone. DJI provides APIs to control the drone programmatically by enabling the virtual sticks.

Note: Using the virtual stick is pretty dangerous. DJI provides an assistant software wherein you can connect the drone to a PC and fly the drone in a simulator. Test your app in the simulator before an outdoor flight. Download the simulator from the link below. After installing the simulator switch on the drone and connect to the PC.

Link to DJI Assistant for Mac.

Link to DJI Assistant for Windows.

Follow the steps below to achieve a similar scenario.

  1. Enable the virtual sticks.

Note: Once you enable the virtual stick, you can no longer use the remote controller to control the aircraft. Make sure you disable it programmatically as soon as the job is done.

aircraft.getFlightController().setVirtualStickModeEnabled(true,...);

2. Create the necessary flight control data based on the requirement. Refer the API documentation on the parameters that have to be passed for creating flight control data.

FlightControlData flightControlData = new FlightControlData(......);
flightController.setVerticalControlMode(...);
flightController.setYawControlMode(...);
flightController.setRollPitchControlMode(...);

3. Send the flight control data to the aircraft.

aircraft.getFlightController().sendVirtualStickFlightControlData(flightControlData, ...);

4. Play around with the flight control data to achieve the necessary movement. Make sure the virtual stick is disabled at the end of your execution.

5. Run the app. Connect to the remote controller and execute. (Make sure drone is connected to the simulator in your PC. Fly and test inside the simulator before an outdoor flight)

Once you feel the code is executed right you can go ahead and execute the mission outdoors. Now you can create more advanced missions with the help of the DJI APIs according to your requirements.

--

--