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: 891
  • DJI.zip
    39.5 KB · Views: 640
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
many many tks

I will review the information and then upload the evidence, thank you
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings I wanted to know if this link is the new sdk, tks +1000



Download the native libraries and copy them to the additional libraries folder:
www.b4x.com/android/files/dji.zip
Download the attached library and copy it as well.

Version 2.0 is released. It is based on DJI SDK v4.0. It supports waypoint missions.
It requires B4A v7+.
 

DonManfred

Expert
Licensed User
Longtime User
yes
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings
I wanted to know, I see that the waypoints and their actions are created as a kind of list that is then executed ....
but for that this point is defined (<-----------)


B4X:
builder.AddWaypoint(CreateWaypoint(32.8373372, 35.26967794, 40))  (<----------)
    Dim wp As DJIWaypoint = CreateWaypoint()
    wp.AddAction()
    wp.AddAction()
    wp.AddAction()
    builder.AddWaypoint(wp)
    wp = CreateWaypoint()   
    wp.AddAction()
    wp.AddAction()
    builder.AddWaypoint(wp)


The query is in what is the difference or utility of these two lines of code .... what is the difference or its use .... you could be more clear, thanks

B4X:
builder.AddWaypoint(CreateWaypoint(32.8373372, 35.26967794, 40))
    Dim wp As DJIWaypoint = CreateWaypoint(32.83850007, 35.26828855, 30)


The main idea is that only waypoints are created and the points of interest are created with the actions of the drone .... or you can create both (see picture)





joke....Sleep(1000) '<--- required. Otherwise it will fail ¿Drone?
 

Attachments

  • punto.png
    punto.png
    20.2 KB · Views: 382
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The CreateWaypoint sub is a simple utility sub that creates a DJIWaypoint object.
If you don't need to add actions then you can write it like this and add the waypoint directly to the list:
B4X:
builder.AddWaypoint(CreateWaypoint(32.8373372, 35.26967794, 40))
You can also write it like this:
B4X:
Dim wp As DJIWaypoint = CreateWaypoint(32.8373372, 35.26967794, 40)
builder.AddWaypoint(wp)
There is no difference between the two.
 

gvoulg

Member
Licensed User
Longtime User
Thanks Erel for the new version
Start testing it next days.
Looking at the new lib , the Hotspotmission is not there anymore.
Can we accomplish this with the new tools?
Regards
George
 

DonManfred

Expert
Licensed User
Longtime User
V2.00 is released. It is based on the new SDK.
Thank you very much for the new version including source! I really appreciate :)

I took your source, took the newest V4.1 release, build the AAR with android studio. Changed the AAR to not include the native .so files. I took your native jar, replaced the so´s from 4.1 and implemented my old try to use the UI-Library too.

It ends up in a new AAR, a new native jar, a new sdk jar and for sure in a new Library as i´ve added a lot of things.

Screenshot_2017-05-28-11-37-07.png


First try without Drone connected....



DroneConnected003.png


So far it looks like it is working :D

Did not try to run the app outside (with GPS available) but i´m very happy with the results so far. :)

PD: As Erel already delivered the WaypointMission (BIG THANX :)) i´ve added the Hotpointmission in my Version. But as all i added; not tested as yet :)
 
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings DonManfred ... is it only available for Android studio?, tks.

Your application looks fantastic, I hope you could have it for b4a, thanks.
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings I wanted to know if the current wrapping is compatible with the new version 3.3 of dji-sdk These are the first impressions since my new p4pro of the moment the initial tests look good, this weekend I will do used it in a great field, thanks


Dear Developer,

We are pleased to announce the release of DJI Onboard SDK(OSDK) 3.3 — a full re-write of the DJI Onboard SDK that enhances ease of use, extensibility, robustness, along with some great new features.


The new release completely revamps the structure of the SDK, improving access to the APIs while abstracting away other parts of the SDK. An all new API layer with a Vehicle Class Encapsulation allows users to build DJI Onboard SDK applications with a single file, and the significantly improved Doxygen documentation makes it much easier to use OSDK APIs
 

Attachments

  • Screenshot_2017-06-22-09-53-26.png
    Screenshot_2017-06-22-09-53-26.png
    97.2 KB · Views: 387
Status
Not open for further replies.
Top