B4A Library DJI Drones

Status
Not open for further replies.
DJI Drones are very popular and advanced drones. DJI provides an Android app that is used during flights to control the drone.
The Android device connects to the remote controller with a USB cable (USB debug mode should be enabled).

DJI are also providing a feature-rich SDK that allows us, developers, to create alternative applications to control the drone. It is quite amazing to be able to easily program a drone to do all kinds of sophisticated tasks.

The following video is an example created with B4A and the DJI library. On the left side you can see the drone camera feed and various parameters. On the right side there is a standard Google Map. Touching on a point in the map starts a hotspot mission. The drone will rotate automatically around the spot.


How to use

1. Register with DJI: https://developer.dji.com/ and create an app in the User Center page. You will see an App Key that you need to add to the manifest editor.
The bundle identifier must match your app package name.
2. Add this code to the manifest editor:
B4X:
AddReplacement($DJI_KEY$, XXXXXXXXX)
CreateResourceFromFile(Macro, DJI.DJI)
Replace XXXXXXXXXX with your App key.
3. Add to the main activity code:
B4X:
#BridgeLogger: true
#MultiDex: true
#AdditionalJar: dji-sdk-provided-4.16, ReferenceOnly
#AdditionalJar: kotlin-stdlib-1.5.10

4. You might need to install a few components with B4A Sdk Manager: https://www.b4x.com/android/forum/t...droid-attr-lstar-not-found.141799/post-898956
5 Initialize the SDK when the application starts. The RegisteredResult event will be raised. If successful then call sdk.StartConnectionToProduct to start a connection.
6. The ProductConnected event will be raised. If AircraftData is not Null then you are good to go and can initialize the DJIAircraft object and the other features (see how it is done in the example).
7 Most of the operations are asynchronous. They are built to work with the Wait For keyword.
8. Expect disconnections and other errors.
9. New: See the Activity_Resume code in the example. It is needed to handle reconnections.

See the attached example.

Tips & Notes

- Make sure that you are able to connect to the drone with the DJI app. Not all Android devices have proper support for USB connected devices.
- You will see a dialog that asks you whether you always want to start the DJI app when the USB is connected. Click on "This time only". Otherwise you will need to uninstall the DJI app as it will get an exclusive permission to use the USB device.
- Use B4A-Bridge to connect the IDE to the Android device.
- Supported drones: https://developer.dji.com/mobile-sd.../product_introduction.html#supported-products
- Use the simulator to test your app. It works well.
https://developer.dji.com/mobile-sd...on-development-workflow/workflow-testing.html

- Don't fly the drone indoors.
- Check the GPS status. All the nice automatic features will fail without the GPS. Should be 4 or 5.
- Make sure that the home location is set before flight.
- Always be prepared to manually control the drone.


Download the native libraries and copy them to the additional libraries folder:
www.b4x.com/android/files/dji_additional.zip
Note that only 64 bit binary is included inside dji-sdk-4.15.aar. You can download the full aar with both 32 bit and 64 bit binaries here:

During development it will be faster to use the smaller aar file.

Download the attached library and copy it as well.

Updates

- 4.80: Based on SDK 4.16. Requires B4A v11.5+. Please add to Main module:
B4X:
#MultiDex: true
#AdditionalJar: dji-sdk-provided-4.16, ReferenceOnly
#AdditionalJar: kotlin-stdlib-1.5.10
- 4.70: Based on SDK 4.15. Check the updated example and don't miss the Activity_Resume code.
- 4.60: It is based on DJI SDK v4.14-trial1.
It requires B4A v11.5+
The minimum Android version is 5.0.

Start with the attached example. Note that the hotspot mission calls ExitApplication. You must configure a reasonable coordinate before you test it (and remove the ExitApplication).
The example needs to be updated with the attributes mentioned in v4.80 update above.
 

Attachments

  • DJI_Example.zip
    12.8 KB · Views: 724
  • DJI.zip
    39.5 KB · Views: 478
Last edited:

DonManfred

Expert
Licensed User
Longtime User
If you are talking about your airdata.com account then you maybe contact them to ask this question.

http://airdata.com/contact
 
Last edited:

shb777

Active Member
Licensed User
Longtime User
What is airmap credit card?
it asks you for a airmap credit card when you register as a dji developer. i put in my mastercard and it worked. now i have another question. where does the aar file in the library zip go. i'm getting this error when i compile drone

B4A version: 7.01
Parsing code. Error
Error parsing program.
Error description: Unknown type: djisdkmanager
Are you missing a library reference?
Occurred on line: 18 (Main)
Private sdk As DJISDKManager

only gson is showing up in my libraries even though dji_native.jar is in the library directory

steve
 

shb777

Active Member
Licensed User
Longtime User
ok I got it to compile and run. sorry for so many questions. i haven't used b4a since march, so i'm a little rusty. steve

hooked it up to my controller and mavic pro. just have a white, grey and black rectangles.
didn't say registered successfully. but another new dji app i just got, drone harmony, did register and run correctly. steve
 
Last edited:

shb777

Active Member
Licensed User
Longtime User
ok i found out that my application label and package name were different than what I told dji. now it's working. thx erel!
 

shb777

Active Member
Licensed User
Longtime User
hi I'm getting this every time I compile:


Convert byte code - optimized dex. (207.07s)
Optimized dexer failed. Switching to Standard dexer.
Packaging files. (6.10s)
Copying libraries resources (10.36s)
Found 12 resource files.
Signing package file (debug key). (8.88s)
ZipAlign file. (0.14s)
Installing file to device.

so it's taking over 3 minutes to do optimized dex and it's always failing. maybe there's a way i can do standard dexer in the first place.

I want to use my nvidia shield, and it won't fit controller horizontally, but it will fit vertically. I compiled in portrait mode and it worked. so i'm gonna have
three display windows stacked vertically. one for video, one for telemetry and one for the map. steve

i see on your video your getting a map. I'm not getting any map.
 
Last edited:

shb777

Active Member
Licensed User
Longtime User
I've got the drone first working the way i want it. the most important thing missing is RC signal strength. Will that be included in the new SDK you're working on. any rough timetable for that?
Also, when I power on the mavic, the tablet brings up my 4 drone programs. I select the
b4a program, but it doesn't run. if i then run it manually, by it's icon, it runs and connects ok.



Steve
 
Last edited:
Status
Not open for further replies.
Top