Software Communication

Hi

I have 2 software programs, C++ on RPI2, and Java on ground station. I have several questions:
(1) C++ app gets the video from the camera, and makes decisions based on the input (eg object recognition). Once it has decided what to do, eg move to waypoint lat/long, how can it instruct ArduCopter to perform that action? Can it send a message to ArduCopter to execute some predefined actions (eg move to location lat/long, go into loiter mode, etc)?

(2) C++ app gets the GPS data from the output of RTKLIB, so it does not conflict with ArduCopter which is accessing the SPI port. With ArduCopter running, how can it share other sensor data (eg barometer)? I can look into integrating the C++ app into ArduCopter, but would like to look sensor sharing option first.

(3) Java app on ground station also makes certain decisions based on data on the ground station, how does it tell the ArduCopter app running on RPI2 to perform a certain action, ie same as question (1), but from ground station. Can it instruct APM/Mission Planner to send a message to the Copter to execute the task? Alternatively, if question (1) is possible, I can send a tcp from Java to C++ and get the C++ app to tell ArduCopter what to do.

2 Likes

Looks like I have found the answer, to all the questions, DroneKit. Somehow I missed that out while going through all the online docs.

The answer to all your questions is “MAVLink” :wink:

It’s already sending sensor data down to the ground station and you can tap into it locally on the drone either via a loop-back IP address or by installing MAVProxy for more complex distributions (but usually the more simple approach is via the logical serial port). Check the documentation and many other forum posts about that.

If you wanted to go deeper, the next step would be to write a “hook” in the APM HAL. Perhaps the DroneKit stuff is a bit too far abstracted for what you want to do. I’m not sure that runs on top of Navio but if it does I suppose your code should also run on Pixhawk too. But then so does MAVLink.

Brilliant!

I have tested with this:

SITL (for testing) -> local mavproxy -> ground station mavproxy -> ground station Mission Planner

From this, the SITL can be controlled by all 3 apps, ie local mavproxy, ground station mavproxy or Mission Planner. I will look into getting the C++ app to talk to the local mavproxy, and the Java app to talk to the ground station mavproxy, but I don’t think that’ll be a problem, I have all the ingredients to make it all work.

You are also correct that dronekit may be too abstracted, but it has examples of higher level operations which will eventually help (from a knowledge perspective).

Yes, I have seen the code in Ardupilot on the HAL stuff, good place to dig deeper once I get to that stage…

Fun stuff!

I’m slightly confused by the relation between DroneKit and the Navio+. I have seen a lot of names so far (MAVLink, Arducopter, APM, …) but I barely know where to place them. DroneKit seems to provide an easy framework, but is it ‘compatible’ with the Navio+, or am I thinking about this wrong? (And if DroneKit is perfectly compatible with the Navio+, why isn’t this advertised in some way? It would seem dumb not to do so.)

What I need is a link to my laptop (through WiFi) so I can see sensor data etc, but also a way to just execute programs locally on the drone.

APM is the new name of ArduPilot which was the first Arduino based autopilot which won some award and became popular. It actually runs on a small STM32 processor now and with the help of 3DRobotics the Pixhawk arrived (I don’t know the history completely, if 3DR made the Arduino thing too, perhaps).

Anyway, since then we’re on the next next generation and even Pixhawk is “old”. The original Arduino based boards (APM 2.x) are officially no longer supported. And 3DR appear to be going in the direction of DJI, making expensive, consumer (plug and play) drones, namely the “Solo”. The Solo actually is something like a Navio, and that brings us here…

So all the APM guys are left a bit high and dry here… 3DR making their 1000 euro non open source drone. With Navio and other Linux based autopilots, APM seems to have a next gen future even if 3DR don’t release any open source successor to the Pixhawk.

So DJI announce a software development kit, and not surprisingly 3DR follow with “DroneKit”. This is totally designed for their Solo I think from a marketing perspective at least. I really have no idea if 3DR want or allow this to run on Pixhawk. Now there are two firmwares for Pixhawk, the one from 3DR and the one from the open source APM team.

So I’d guess DroneKit only runs on 3DR’s Pixhawk firmware if it runs on Pixhawk at all. Anyone else know that?

To be honest, I totally avoided all the “DroneKit” stuff as soon as I relealized is is just a marketing trick. I mean if you have a truly open source autopilot you should be able to hack right down as low as you want. DJI is a closed product and their API seems like an attempt to claim some kind of open source.

So really, what do you think? Do you really want to use some commercial “API” they “allow access to functions” rather than directly programming something and deciding if you interact with MAVLink or direct code in a “hook”.

So MAVLink… is the only real low level API besides the HAL. The HAL is just to get APM running on different hardware. MAVLink is like a publisher/subscriber API where you send it a message to register for events then it keeps sending you back information at the required interval. So it’s used for OSDs, ground station and everything like that. It also has a limited command set (but already quite powerful) so you can tell the quadcopter what to do. But it doesn’t cover all scenarios, e.g. telling it what an external sensor value is, it presumes all the data is already on the inside and you are just listening or sending a few commands (e.g. go to position, change mode, etc…).

MAVLInk is extremely easy to get into, because it’s a very basic protocol and you can connect via serial or network. But if you really need to inject data in which MAVLink has no command for, or you need to listen to data so fast that too much processor time is lost converting to/from MAVLink messages, the HAL “hook” appears to be the last resort.

1 Like

Judging from the DroneKit docs, I think you are underestimating the opensource-ness of the DroneKit project. It clearly states as being an opensource project, and compatible with anything using MAVLink. So it appears to me that, at least the ‘Air’ part of DroneKit, just uses MAVLink commands like you said and provides an extra abstraction layer over MAVLink (which would be the first thing I would make if a sending MAVLink commands is all I can do).

PS: Your replies are very appreciated :smiley:

Fair comment. Looks okay if Python is your preferred language. I see there are other Python MAVLink examples and libraries already out there. If it’s adding value/saving time without adding any limitations then it should be okay.

If you are a C++ and Java guy though then maybe you’d prefer to work directly with the MAVLink headers or some other Java wrapper for MAVLink. If you want to go super abstract there is even a ROS implementation of MAVLink. Certainly lots of choices!