Working with mavlink in Java

I am starting a new project to experiment with swarm control in Java. So to begin, I am running five SITLs of Copter 4.0 in five separate docker containers.

I am trying to figure out the best way to interact with these SITLs (and later real copters) through Java. I have tried using mavsdk_server https://github.com/mavlink/MAVSDK but it actually causes the SITL program to crash with a floating point error when I connect. So the MAVSDK project seems a bit young and I need to use something more robust. Would any of you have suggestions on how to interface with mavlink over a network in a Java program?

Any suggestions would be great, thank you.

pymavlink can generate Java bindings for you. Try using that. There is a PR that improves pymavlink https://github.com/ArduPilot/pymavlink/pull/341

There’s also this: https://github.com/dronefleet/mavlink
which might be worth looking at.

For whoever comes behind me to read this, I have begun using dronefleet/mavlink which has worked out very well.

Hello Asher. I’m relatively new to drones and Mavlink. Could you please help on how I can use Dronefleet Mavlink in Java from GitHub - dronefleet/mavlink: A Java API for MAVLink communication.
I am trying to create an app for precision dropping of an item from drone and will use these params received from Px4 and use them for deciding the target.
I would be glad if you help me in this regard and get me going?
Appreciate your kind help and support

Configure pymavlink to generate java code output and run it.

It will produce a java library that is able to talk mavlink.

All your code needs to do is call the library appropriately in order to control the drone(s)

Thanks for your reply. Please clarify the pymavlink generator you are referring to is this:
https://mavlink.io/en/getting_started/generate_libraries.html

Using this I need to generate Java version for the dialect and when in android application how I need to call the generated java library and get the result I desire? For example, if I need alt data from Px4?

Appreciate your help

Yes, that is what I meant.

The generated library contains java functions that you must call in order to control the drone. The function names are mostly self explanatory.

For Android programming there are many on-line courses. That is out of scope from this forum.

1 Like


Hello, these are the files generated from mavgenerate.py. I was unable to find any online course that may guide me in the right direction of how I can use these files.
Could anyone please guide me on how I can use these generated files in android studio. Also, is there any other way to communicated with px4 using MavLink with Java.