Secondary development of UAV SDK based on Dajiang

Keywords: Android SDK Mobile network Google

;

Secondary development of UAV SDK based on Dajiang

In the near future, the company needs to develop a mobile APP based on the Dajiang UAV SDK to cooperate with the background to realize the management of UAV. Of course, Dajiang itself also provides us with a management platform --- Dajiang Sikong. Through the official APP of Dajiang and the background management system of Dajiang Sikong, the management of UAV can be realized. However, the cost of Sikong is too high. The advanced version costs 19999 for one year. Therefore, we need to develop our own mobile APP to transmit information about UAV to the background.

The following is a summary of some points that need to be paid attention to in the development process to avoid future generations stepping on the pit.

Links to related materials

Here is a link to the materials used:

Download Center

Through the download center, we can download the UAV operation manual, quick start manual and different app versions to provide us with convenient software tools and so on.

Official Demo

There are many demos here. Different demos are used to introduce different function points. Remember to follow the code in the demo when developing, not the official documents. You may not be able to run the program according to the official documents.

Shopping Mall

In the mall, you can understand the characteristics of relevant products and develop them better

File

The document is still to be looked at, especially for novices who have not been exposed to drones. The documents are all in English, which is easy to understand. I really don't know how to translate documents into Chinese through Google browser's translation function. It is suggested to check the original text with Chinese.

API

API can be used as a supplement in the development process. If you don't know that method, you can search directly here. The search function of API is very powerful. You only need to enter different method names or class names. The explanations in API are relatively detailed.

Enter text

First of all, if you want to develop Dajiang UAV APP, you need to meet the following conditions:

If the above conditions are met, you can start development. Just like using the third-party SDK, you need to create an APP in the developer account. Here, you need to note that the package name of the APP must be the same as the real package name, or it will not run successfully!

The basic contents about how to import dependency and how to create APP will not be repeated here. The documents are all used. It should be noted that the dependency in the documents is not complete. What you need to do is download the demo, and then copy all the dependencies in the demo to your project

To be more specific, this part of the document is incomplete. You need to add:

    packagingOptions {
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        doNotStrip "*/*/libDJICommonJNI.so"
        doNotStrip "*/*/libDJICSDKCommon.so"
        doNotStrip "*/*/libDJIUpgradeCore.so"
        doNotStrip "*/*/libDJIUpgradeJNI.so"
        exclude 'META-INF/rxjava.properties'
    }
    //To replace those written in the document

OK, dependency has also been introduced successfully, so we can develop it.

Here is a brief introduction to the steps of using the sdk, with the emphasis on the areas that need special attention for acceptance.

First of all, you need to register the sdk, and then call login in the successful callback

 if (isRegistrationInProgress.compareAndSet(false, true)) {
            AsyncTask.execute(() -> DJISDKManager.getInstance()
                    .registerApp(MainActivity.this.getApplicationContext(),
                            new DJISDKManager.SDKManagerCallback() {
                                @Override
                                public void onRegister(DJIError djiError) {
                                    // If there is no problem with the configured package name and API key, then the registration is successful
                                    if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
                                        DJISDKManager.getInstance().startConnectionToProduct();
                                       	// Log in
                                        loginAccount();
                                    }
                                }

                                @Override
                                public void onProductDisconnect() {
                                    Log.e(TAG, "onProductDisconnect");
                                    notifyStatusChange();

                                }

                                @Override
                                public void onProductConnect(BaseProduct baseProduct) {
                                    Log.e(TAG, String.format("onProductConnect newProduct:%s",
                                            baseProduct));
                                    notifyStatusChange();
                                }

                                @Override
                                public void onComponentChange(BaseProduct.ComponentKey componentKey,
                                                              BaseComponent oldComponent,
                                                              BaseComponent newComponent) {

                                }

                                @Override
                                public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {

                                }

                                @Override
                                public void onDatabaseDownloadProgress(long l, long l1) {

                                }
                            }));


        }

The above step is a necessary step for the APP to start, otherwise you will not be able to control the UAV.

This step requires attention:

  • The above callback content is not in the main thread, so if you want to operate the interface content, you need to operate in the main thread
  • You need network support to register SDK and login account for the first time, and then you don't need network.
  • Login must be called after successful registration of SDK, otherwise the login interface will not be loaded.

OK, after the above steps are completed, we are waiting for the UAV to connect. When the UAV is connected, it will trigger a callback. When the UAV is connected, we can carry out real development.

During the development, I mainly used several classes in the SDK, and their methods are well understood.

DJISDKManager

This class is very critical. It is the entry to use SDK and Dajiang UAV.

This class is used to register SDK and obtain UAV objects.

After acquiring the UAV object (Aircraft) through SJISDKManager, you can use the Aircraft to obtain the corresponding objects of each component of the UAV, such as: flight controller (this is the core component of the UAV, which controls the flight of the UAV, the position information and status information of the UAV), Battery, Camera, cloud platform Gimbal, etc , RemoteController, and so on. See COMPONENT CLASSES for details

At the same time, we can also introduce UX SDK address To help us develop quickly.

The UX SDK mainly provides some thread controls that we can use when we put them in the UI, and they are not static UI, they have data, and we do not need to do any processing.

For example: dji.ux.widget.FPVWidget component, you just need to put it in the layout to display the picture of UAV camera.

Attention content

Live broadcast:

if (!DJISDKManager.getInstance().getLiveStreamManager().isStreaming()) {
                    new Thread() {
                        @Override
                        public void run() {
                            fpv.registerLiveVideo(VideoFeeder.getInstance()
                                            .getSecondaryVideoFeed(),
                                    true);
                            DJISDKManager.getInstance().getLiveStreamManager().setLiveUrl(
                                    "rtmp://x.x.x.x/x");
                            DJISDKManager.getInstance().getLiveStreamManager()
                                    .setVideoEncodingEnabled(true);
                            int result =
                                    DJISDKManager.getInstance().getLiveStreamManager()
                                            .startStream();
                            L.e("startLive:" + result + DJISDKManager.getInstance()
                                    .getLiveStreamManager().isStreaming() +
                                    "\n isVideoStreamSpeedConfigurable:" + DJISDKManager
                                    .getInstance().getLiveStreamManager()
                                    .isVideoStreamSpeedConfigurable() +
                                    "\n isLiveAudioEnabled:" + DJISDKManager.getInstance()
                                    .getLiveStreamManager().isLiveAudioEnabled());
                        }
                    }.start();
                }

A simple setLiveUrl() and then start live broadcasting will not succeed. You need to register the live video in the previous step. The fpv in the code is the dji.ux.widget.FPVWidget control.

The method of acquiring UAV position

// Active acquisition
Aircraft aircraft1 = (Aircraft) DJISDKManager.getInstance().getProduct();
FlightControllerState state = aircraft1.getFlightController().getState();
L.e("==altitude:" + state.getAircraftLocation().getAltitude() + "latitude:" + state.getAircraftLocation().getLatitude() + "longitude:");

// Of course, you can register the callback function
void setStateCallback(@Nullable FlightControllerState.Callback callback);

Layout name pit

Do not display the dialog login name in the layout, because it already exists in the SDK of Dajiang. When you are adding a dialog login name, calling the login API will report a null pointer error.

If there is an unexplained layout null pointer exception, it is likely that our own layout and the layout name in the Dajiang SDK are duplicate.

Most callbacks are not in the main thread

Most of the callbacks in the Dajiang SDK are not in the main thread, which needs to be noted

Posted by n00byboy on Thu, 07 May 2020 01:28:29 -0700