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

PABLO2013

Well-Known Member
Licensed User
Longtime User
Regards
First the application can not be installed on android 6 (lG stylus 2)...now yes, I think they are missing permissions.

The application screen google and panelcamera are "White" and says "disconnected !!".

I give it in button stopmission and it does nothing.

The original application of the factory dji initially asks you to connect the wifi network (wifi DJI PHANTOM3), once in the application and for the first time you must enter the key (defaul: 12341234) and you will be select the model and with that, You have access to the drone.

--------------------------------------------------------------------------------------
Log 1(When I connect to the normal wifi network): The metadata received from server is invalid, please reconnect to the server and try.

Log 2(When i connect to wifi phantom3): For first time registration, app should be connected to the Internet.

.....At this point the problem is that I can only connect one network or another both not.
--------------------------------------------------------------------------------------

As I say the connection is via wifi, unless this is very wrong the application and the library does not have this connection?

---------------------------------------------------------------------------------------
These are the keys manifiest:
Android: value = "1c1b41ab9b5b379bddf....." /> // TODO:
Enter your app key here Android: name = "com.google.android.geo.API_KEY" Android: value = "AIzaSyCmFxxxxxxxxxyps.....TCSrjFVg-Q" />
 

Attachments

  • dji.png
    dji.png
    77.2 KB · Views: 393
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
regards
For the moment I have properly register the application "Drone", the second step will be the connection ... apology that insists maybe this is wrong but the communication is via wifi production by my radio (phantom....), the control the bottom has a micro usb but this is for charging the battery (only)... I send an image with some details, it would be possible to implement the part of the library that allows the communication via wifi .... the other would buy a dji pro ... but they are very expensive ... the phanton 3 are a quasi-pro option at a low cost .... thanks
 

Attachments

  • REGISTRO.png
    REGISTRO.png
    147.3 KB · Views: 397
  • REGISTRO1.PNG
    REGISTRO1.PNG
    11 KB · Views: 372
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
TKS :
**Registered is succesfully!
**No connected product
 

Attachments

  • REGISTRO.png
    REGISTRO.png
    10 KB · Views: 370

PABLO2013

Well-Known Member
Licensed User
Longtime User
Regards...
If using the Android Studio the application works as it was ... so if you based your code in the example can be implemented to read the wifi dron in b4a ... I would appreciate if you could expand the library the connection Via wifi, thanks
 

Attachments

  • Screenshot_2017-02-07-15-11-01.png
    Screenshot_2017-02-07-15-11-01.png
    20 KB · Views: 387
  • Screenshot_2017-02-07-15-12-45.png
    Screenshot_2017-02-07-15-12-45.png
    28.5 KB · Views: 389
  • Screenshot_2017-02-07-15-14-08.png
    Screenshot_2017-02-07-15-14-08.png
    16 KB · Views: 387

jchal

Active Member
Licensed User
Longtime User
dear all
i would like to raize a question is it possible to control the drone from far away , for example i have the drone in howse and i have my mobile phone in office and control it from there? but not via team viewer but by writing some code in b4A?
also is there some thing simmilar for parrot as it has sdk as well
i am aware that you alwas have to get it to maunal if nessesary , i am just asking
 
Last edited:

aarondc

Member
Licensed User
Longtime User
There are a lot of functions in the DJI libraries that do not appear to be in this library.
Is it difficult to add them? I am keen to write an Android app to control and/or connect to my Mavic Pro, and camera, etc, functions, would be a priority for my development effort.
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings, Aarondc
we would have to convince Erel to help us to expand the library ... I use the only mode that exists in a ph3pro and works very well ...
 

gvoulg

Member
Licensed User
Longtime User
from DJI site
"We are excited to announce the release of the DJI Mobile SDK 4.0. You can find it on our developer site at https://developer.dji.com/mobile-sdk/downloads/.
This version of the SDK introduces many major improvements, including a general API refactor, complete mission manager overhaul, new API reference documentation, and more."
and this
"Dear Developer,
We are excited to announce the release of the DJI Mobile UI Library 1.0, which is a part of DJI’s Mobile SDK 4.0.1 for iOS and Android. You can find it on our developer site at https://developer.dji.com/mobile-sdk/downloads/.
By providing you with a rich set of pre-made UI elements in a UI library, we believe app development will be more efficient. Many developers will be able to use the elements as-is, with no further customization, when building their apps.
To those of you who participated in the DJI UI Library Public Beta program, thank you! We’ve incorporated your feedback into this release.
UI Library 1.0 provides:
  • UI widgets for aircraft state seen typically on an FPV screen (e.g. Battery icon)
  • UI widgets for some automated controls (e.g. auto take-off)
  • UI panels for camera settings (exposure and others)
  • A preflight checklist panel
  • Elements with assets and logic tied to the SDK
  • Elements which are more responsive to settings changes than in the public beta"

That means we have a new release for the SDK and more

Erel I am personaly interested more for mission planning with waypoints and the ability to take pictures at spesific time interval or spesific position.
Is it possible to wrap the new SDK ?
Best Regards
George
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
regards

I do not pretend to be abusive or disrespectful but I wanted to know if it is possible to incorporate b4a-dji with the mission of Waypoint, as for me it is of the useful functions, and although the other missions are useful they are for fun.

For example in the case of Waypoint mission could be sent the drone to make mapping of farms combined with other map libraries like b4a-osm, etc .... and although there are applications like pix4d, these do not allow incorporation geographic information and we have in b4a lot of code that could be implemented with b4a-dji-waypoint mission .....

Currently I use a dji-phanton 4, which allows to separate the part of the communication and the wifi .... in a previous post I did with a phantom 3 standard and although it works well But I have to uninstall applications as dji-go as they generate locks And i have to deal with being switched between different wifi networks available ... this I say by way of experience ...

I tried to add the waypoint mission but can not connect it properly and it did not work ... so if it is possible .... I would be grateful

I add a general idea of how this mission works ....

Waypoint

Waypoint mode allows you to setup classic waypoint missions as well as advanced camera moves such as Self and Cable Cams.
Place multiple waypoints on a map however you want and the aircraft will fly from waypoint to waypoint and complete the mission even if the signal is lost.
The maximum aircraft speed in this mode is 15m / s (no wind).
Enter the Waypoint mode by pressing the Flight Mode icon at the top left of the Litchi screen. Select "Waypoint". You can then start editing missions.

Thank you
 

Attachments

  • waypoint.PNG
    waypoint.PNG
    200.9 KB · Views: 378
Last edited:

DonManfred

Expert
Licensed User
Longtime User
That means we have a new release for the SDK and more
I wrote wrappers for all of the (from the "old" SDK) missions included in the SDK a few weeks ago. Including Custom Mission and all MissionSteps.
But then i lost my Development-HDD and all sources are lost.

I started again using the V4 SDK jar a week ago.

I rewrote all exiting Classes to match the new SDK. Mostly Obectnames did changed.

I wrapped so far (as of yet (work in progress))
- MissionControl (including getters for references to all of the "Operators" possible. But the Operators are not wrapped at this time)
- WaypointAction
- WaypointMission
- Waypoint

I extended the SDKManager to give references to MissionControl (already wrapped) and FlyZoneManager (not yet wrapped)

I plan to rewrite the library based on the new SDK
I just tried to use the V4 jar and rewrote (changed objectnames and reference...) all of the exiting Classes to match the new SDK. Except DJICameraWrapper. I was not able to fix this class.
Away from that i think it looks ok.

At this time i can not say if all that worked... Did not compiled as yet and even not run the new Library as i don´t know if the Manifestcode need a change too.

Development of the wrapper is still in progress ;-)
 
Last edited:

PABLO2013

Well-Known Member
Licensed User
Longtime User
Regards, DonManfred : thanks for your work ... i will be waiting ... it hurts the hdd ... but I personally believe that with the use of the functionalities of the drones: camera, gimbal, and all the telemetry of the drones dji and The mission of WaypointAction, WaypointMission, Waypoint, would be very great your contribution...

I have tried other missions and although they are very interesting ... I think they are of little benefit

In my case I would like to do photogrammetry (I do it with pix4d) but cant allows to incorporate other information that is personalized ... in b4a we have much much that through you and Other libraries could be incorporated ....

Thanks in advance. DonManfred.
 
Last edited:
Status
Not open for further replies.
Top