Skip to content

Blog

Multi SITL on homecloud

|624x312

Hello friends,

You may remember that some time ago, I made a post about multi robot simulation with ArduPilot (see https://discuss.ardupilot.org/t/multi-systems-patrol-simulations/35740/1).

This was during my PhD, I didn't have much time nor funds to push my simulation into a cloud system for larger scale simulation.

Well, that is still not the case! But I got a bunch of small boards that do nothing in my apartment, so I made a small homecloud to make more simulations.

In this video https://www.youtube.com/watch?v=SMISOREe1y4&list=PL6sCNLbHuYxZVRAbnLY5Xxkr5f4rQeJCJ , which is quite long, I tried to explain how to do it.

The demo

This is a demonstration of the simplest group behaviour : follow the leader (or wolf-pack). This demo relies on ArduPilot simulator : SITL (Software In The Loop). The simulation uses the same code as the real vehicle with some simulated sensor. This is quite convenient to work on the code and do testing as the transition to the real vehicle will be easier. ArduPilot supports a large set of behaviour, and lucky me, the follow behaviour already got a library, so it is just a matter of enabling it to use it.

The behaviour is quite simple. We define a leader that will stream its position to the followers. Each follower uses the leader position to calculate its new position.

On ArduPilot, we can choose who the leader is and the position of the follower relatively to the leader. So, in this demo I made a more complex follow the leader behaviour.

My master leader is drone 1. Drone 2 to 4 are following drone 1. Drone 10 is following drone 2. Drone 11 to 13 are following drone 10. Drone 20 is following drone 3, drone 21 to 23 are following drone 20, etc.

|624x451

The result is what we can see on the video, it is not perfect but it is working.

As I am using a simulation, I use a multicast protocol to allow each drone to get the information from the other. That is the equivalent to broadcast mode on a RF-radio.

In order to launch the simulation, I have made a small python script using Pymavlink. Pymavlink is a set of tools to control drones using the MAVLink protocol. That is the main protocol used by open source drone autopilot like ArduPilot. The python script is in charge of putting the drone in Guided mode that is an automatic mode that keeps the drone in position waiting for an order. Then it issues a takeoff when the drone is ready and then setting the Follow mode. Finally, there is a control loop at the end as the follow mode will disengage if the drone to follow goes too far or in case of issue. The control loop is in charge to set it back.

The drone 1 is using the Python script to stay in Guided mode and got some random target position over the CMAC field that is SITL default position (that is in Australia since ArduPilot mains developers are in Australia).

|624x684

Don’t fear my python script, it is quite long but most is useless for this demo. If you look closely you could see that most functions are just copy-paste from the ArduPilot autotest framework (https://ardupilot.org/dev/docs/the-ardupilot-autotest-framework.html).

This script will be added to the Pymavlink repository as an example on how to use Pymavlink for drone programming.

I could have used LUA scripting to achieve the same behavior as ArduPilot support. LUA scripting is a scripting language that can be used directly on drones. I am more at ease with Python and want to demonstrate how to use Pymavlink for simple tasks, so no LUA

Homecloud

|624x468

My homecloud is composed :

  • 1 raspberry pi 3 : that is 4 cores so 4 vehicles

  • 1 odroid C1+ : that is 4 cores so 4 vehicles

  • 1 balena fin (RPI3) : that is 4 cores so 4 vehicles

  • 1 odroid XU4 : that is 4 cores so 4 vehicles + the GUI

That is pretty conservative, most should be able to use 2 vehicles by core. But I prefer to play it safe with my power consumption and heat management ... those are in my living room, so it isn't nice to have some fans at full speed all day long !

System setup

I am not a cloud engineer, so I don't really know the best technology to use. I could have set up each board with their own OS, installed docker or Kubernetes and some VPN but that is really a pain to manage on the long term ... So, my choice was set to BalenaCloud. Their system is quite simple to set up, support docker and project versioning with Git. Bonus that the same system on all boards, so I code only once for all boards and use git push to update them ! They are also offering a cloud GUI, VPN and a public web address to serve a simple web application. That's what I needed. As I put my homecloud on the public web, even through Balena VPN, I have put it behind an isolation router that puts my homecloud on a separate network than the rest of my home equipments.|624x308

Simulation cloud architecture

The system will be quite simple :

  • Each system will be loaded with BalenaOS and the same docker-compose script to spawn the vehicles.

I made a launch script to be able to use their website to control the simulation. Basically, it exposes some SITL parameters and an ON/OFF parameters, to be able to stop the vehicle in need.

  • I made a clean docker image for SITL, as I need to use Python the image is still around 200Mo. That doesn't seem much, but considering that for just SITL the whole docker image is 6,3Mo... it is big. Lightweight docker image is important for simpler and faster deployment (and saves a lot of power on storage and transfer).

  • The GUI : that is a MAVProxy plugin using CesiumJS. MAVProxy is a Python Ground Control Station (GCS) for MAVLink drones. MAVProxy is connected to the multicast port, gets each drone infos and streams them back to the Webbrowser. The web application updates each drone position and displays it.

  • How to handle multiple vehicle connexions to the GCS without doing it one by one ? SITL supports a multicast protocol and most GCS are able to use it ! That means that we only need to set up all vehicles to connect on the same multicast port and the GCS will have all vehicles available ! Unfortunately, the multicast protocol isn't handled well by docker so we need to expose the full network stack to make it work. That isn't an issue for my project as all my boards are on the same network but it could be an issue on a real cloud. A simple solution for this issue could be to use a VPN like Zerotier to make a bridge between the different instances.

  • How to play with the vehicle from the web ? That is where BalenaCloud is nice, and they give a secure link to your instance. The downside is that only http port 80 is enabled. So I bypass this restriction with a proxy to be able to use multiple ports and redirect the connection on port 80 to the right port on the board.

The Docker files for those that want to replicate : https://github.com/khancyr/balena-docker_swarm_follow

CI at ArduPilot

|624x385

At ArduPilot, we are working hard to improve our contribution flow and testing. You could have seen those last years that our Continuous Integration system was greatly improved. We are now testing building against 19 boards for 4 vehicle types (multicopters, submarines, ground and sea vehicles, plane types) in addition to the simulation testing with around 300 functionals tests and unittest !

Those allowed us to bring more change into ArduPilot with greater confidence and allowed us to track down bugs before they reach the codebase.

Nevertheless, working on a large audience open source project can be hard as the code is changing fast and the Pull Requests (code contributions) are often quickly outdated. This brings up two questions : can we still rebase our work on top of the main branch ? How much flash memory the new change will consume ?

ArduPilot is well optimised for microcontroller boards like STM32 brand, but we need to be careful on our flash requirement as we support boards with a 1MB limit.

That is why we just made a slight addition to our CI system. We now have a new rule that will try to do the rebase against the main branch for a representative set of boards : one 1MB limited, one STM32F4 based one's, one STM32H7 based one's. And we also do a binary size comparison. This allows us to directly get access to the change in flash consumption on the CI system.

|624x311

There is still more work to improve our CI and workflow system, if you want to help us, you are welcome to !

Open Source French Drone Identification

Cher·e·s dronistes français, (This news is mostly for french people, you will find english translation at the end of the post)

Vous n'êtes pas sans savoir que l'Arrêté du 27 décembre 2019 définissant les caractéristiques techniques des dispositifs de signalement électronique et lumineux des aéronefs circulant sans personne à bord va rentrer en vigueur prochainement. Cela implique que tous les drones pesant 800 grammes ou plus au décollage doivent être équipés d’un dispositif permettant de signaler électroniquement sa présence.

Ubuntu 20.04 support on ArduPilot

font-ecran-officiel-ubuntu-20-04|690x388

Hello guys,

A small news to announce you that we officially support Ubuntu 20.04 !

Ubuntu 20.04 support

Our installation script (install-prereqs-ubuntu.sh) has been heavily clean up and updated for this release without dropping support on old Ubuntu versions. You can also see that more comments and versatility have been added to be able to understand what it does and setup only the things you need. The default behavior isn't changed and will install everything. We also fix some minor configuration issues, and you should see some compilation speed up for STM target like CubeBlack or Pixhawk1 since the ccache configuration has been corrected (see my previous blog post for brief explanations https://discuss.ardupilot.org/t/speeding-up-compilation/52551)

This version won't bring anything new for ArduPilot. But you must be aware that Python2 was dropped as default python interpreter. Thus, Python3 is the default on 20.04. Hopefully, most of our tools are working on Python3, so you won't notice it.

Docker improvements

On other news, we have updated the docker image for development we provide for faster and simpler development. The image has been update to allow you to build all the firmware from Docker and use SITL. By default the graphic environment isn't installed to reduce the docker container size to the bare minimal (or close to).
You can find the instruction on how to use the docker image here : https://ardupilot.org/dev/docs/building-setup-linux.html#id1 . If you want to use only SITL for cloud stuff or swarming with docker, please use the multi-stage image building. SITL binaries only have libc as dependency allowing you to have a minimal sized container for SITL testing ! I will show you some examples next week.

The docker workflow works like that : - You build a base image on Ubuntu 18.04 (we will migrating when 20.04 will be fully tested) with all our development tools installed. You can see in the Dockerfile some new environment variables :

SKIP_AP_EXT_ENV=1 SKIP_AP_GRAPHIC_ENV=1 SKIP_AP_COV_ENV=1 SKIP_AP_GIT_CHECK=1

Those are passed to our install-prereqs-ubuntu.sh to skip installation of some packages like GUI stuff and coverage. You can still modify the variable to install them.

  • You launch the image and mount the ArduPilot git directory in the container. This allows you to have a clean image and share the same directory between your computer and the container. It also allows to be able to get back the built binary out of the docker container as you won't be able to flash your board directly from docker (I may be wrong, if a docker master wants you show use how to do it, please comments !).
  • From the docker container, you can use all waf commands and tools like sim_vehicle.py. As said previously, you don't have GUI inside this docker image so Mavproxy won't have Map and Console modules for example.

Completion improvements

Another improvement is the installation of our Bash completion system on the installation. This allow you to use TAB key to have suggestion of commands on tools like waf and sim_vehicle.py. for those that already have setup their environment, you can still look into the install script how to setup the completion, or check my blog post about completion here. By default we only install completion for Bash, for Zsh user please check the blog post or Tools/completion/completion.md for instructions.

Shell completion for Tools

https://youtu.be/UpY7SZ6FXi8 Hello friends,

What has always bother me on ArduPilot development was the lack of completion on the tools we used. Our command-line commands can be quite long and memorizing them when we aren't using them every day could be a pain.

To reduce this pain and allow newcomers to have some more help, I have made some shell completion for waf and sim_vehicle.py. For those that don't know what it is, the completion system allows you type the start of a word or command and let the system complete it, by double press TAB key ! When you use a terminal that is a very convenient feature, plenty of software have some completion.

The completion scripts are now in master branch, but they should appear on 4.x series on each vehicle soon. Otherwise, I will make some documentation to put the scripts on the system to allow completion to work on each branch.

I made completion for two shell : Bash and Zsh. Most users should be on Bash, as it is the default shell on Debian like system (like Ubuntu).

on Bash

To install the completion, you should either, source the main script on your current terminal or source the main script on your bash configuration.

Direct use

From ArduPilot root directory, simply use :

source ./Tools/completion/completion.bash
And now completion works from your terminal instance. If you close the terminal, the completion feature is removed.

Permanent use

Edit you .bashrc file, it is on your Home directory but it is a hidden file (CTRL+H on Ubuntu to reveal them). Then put at the end of the file :

source PATH_TO_ARDUPILOT_DIRECTORY/Tools/completion/completion.bash
where PATH_TO_ARDUPILOT_DIRECTORY is the path to ArduPilot directory (simple :crazy_face:)

Usage

You can now abuse of your TAB key on waf and sim_vehicle.py call ! See the video at the end.

On ZSH

Zsh don't allow live loading of completion. So you have to source the completion script in your .zshrc file. Like for Bash, you will find it hiding on your home ! Put at the end of the file :

source PATH_TO_ARDUPILOT_DIRECTORY/Tools/completion/completion.zsh
where PATH_TO_ARDUPILOT_DIRECTORY is the path to ArduPilot directory (simple :crazy_face:). Notice the difference, the extension is .zsh !

Video

I have made a simple video to show usage of completion : https://youtu.be/UpY7SZ6FXi8

Future improvements

I am not a command-line wizard so I tried my best to get a maintainable completion feature. Not all features are available yet, but most used one's are implemented. If some magician knows how to make the completion faster/better, feel free to submit a PR !

Multi systems patrol simulations

https://www.youtube.com/watch?v=YLDb-ti9bjU

Hello everyone,

I am often asked about what can be done with ArduPilot or with ROS, and my answers are always : you can do just about anything you’d like to do! ArduPilot is not just an autopilot for drones, it is also a well-grown robotic platform ! It is not the same as ROS, in the sense that ROS concentrates more on the high level tasks, whereas ArduPilot focuses on low-level vehicles control ! Both have strengths and drawbacks. And by using both, you will be able to create incredible robots !

During my PhD, I tried to focus my work on multi-robots systems, which are also known as swarms (from an academic perspective, swarms are just a special case of multi-robots systems). ROS by itself can excel for single robot design, but is difficult to use on multi-robots systems and flying robots like multi-rotors. On the other hand, ArduPilot allows to use multi-rotors more simply, and with safe behaviors.

In order to demonstrate the usefulness of multi-robots systems and be able to evaluate the global performance of the system, I set up some identical simulations with ROS and ArduPilot. The goal was to demonstrate the performance of a multi-robot system with various numbers of quadcopters, and rovers on patrolling tasks. I then simulated systems with 1 to 20 quadcopters, and 1 to 20 rovers and system with the same number of quadcopters and rovers. Those were simulated with SITL from ArduPilot, and I will detail at the end the few modifications that I made and that I am pushing into ArduPilot. The patrolling task was done with ROS. Each vehicle got a Mavros instance (that is, a ROS program that makes the bridge between ROS language and MAVLink), a simple python script that handles the patrolling behavior, and a master python script that controls the group. But that was too simple ! So I implemented 3 patrolling behavior, that are quite simple :

  • Random patrol (RANDOM). It is a decentralized algorithm. Each robot will go at a random patrolling point

  • Reactive patrol (HIGHEST). It is a centralized algorithm. When a robot arrived at his destination, it notifies the master script (like a base) and gets the next patrol point.

  • Cyclique patrol (CYCLE). It is a decentralized algorithms. At start, each robot create a patrol cycle.

For the full detail of the simulation models and hypothesis, please refer to my PhD manuscript and/or directly the code !

image|690x193

The results were those graphs for 1 hour of patrolling on this field, the number represent the patrol points : image|402x500

For copter only:

image|499x500

For rover only:

image|507x499

For rover and copter :

image|690x419 image|690x330

All on same graphs : image|494x500 image|523x500 image|524x500

You can see a video here of the patrolling : https://www.youtube.com/watch?v=YLDb-ti9bjU

I won't discuss the results here, but you should be worried by SKYNET ^^ as the group behavior outperform largely the single robot patrolling ! But what it was really interesting, it is that I could make all those simulation on my own laptop : just a i5 + 8go RAM and with simulation accelerated 10 times ! Right ! (If I find the budget to build 20 quads and 20 rovers, I would be able to confirm the simulation with the real platform)

ArduPilot allows to simulate entire fleets of robots with the same code that will be embedded and at a small cost ! That is right, for those kind of behavior, you don't need to use big simulator like Gazebo on big 32 cores servers. Simulate simply with SITL !

I don't say that you should use Gazebo or other well known robotic simulator, but when it comes to simulate only behavior without worrying about collision, SITL with excel !

All these were permitted thanks to OPEN SOURCE and numerous contributions ! PR welcome !

F.A.Q

Where is your code :

Github ardupilot https://github.com/ArduPilot/ardupilot and branch PhD on my fork https://github.com/khancyr/ardupilot/tree/PHD : I am currently getting back those changes into ardupilot master.

Modifications done : - allow to set sysid at the start of SITL (PR in master)

  • disable mavlink routing on a channel. Finally I didn’t use this, this was intend to prevent mavlink spam on a broadcast channel for the monitor. I still believe that we need a way to stop mavlink routing explicitly on some channel, as on swarm configuration, there is to much spam.

  • clear battery failsafe : I didn’t use this, I got another code that I will push to allow to refill the battery and clear the failsafe. On my code, the ROS part is monitoring the battery and decide when to go on base to change the battery.

  • disable MSG_POSITION_TARGET_GLOBAL_INT sending, as there is a bug in MAVROS. It has been reported and I need to make a fix on MAVROS.

  • Disable some stream and unused features. This won’t be push back on master.

  • Prevent switching in guided is EKF is not ready for Rover. (Need a PR)

  • disarm rover at the end of RTL : I am not sure we want this into master, maybe with a parameter.

  • correct battery estimation for rover : PR done.

ROS :

https://github.com/khancyr/patrol

I want to do the same with Gazebo :

If you need only a 3d visualization see https://github.com/khancyr/gazebo_ardu . This can be adapted to any 3D framework you want.

To use the gazebo plugin : https://github.com/khancyr/ardupilot_gazebo . Beware, the simulation of rover isn't simple yet as the ground contacts are a pain and the friction gives a hard time to make a skid steering rover.

Why use ArduPilot over PX4:

PX4 don't support rover and surface vehile like boat and sub. Moreover, the governance of ArduPilot is open whereas PX4 is money dronecode driven

I don't understand anything but the colors were nice :

Thanks you.