Home How to set up ArduPilot SITL on Linux?
Post
Cancel

How to set up ArduPilot SITL on Linux?

Setting up the ArduPilot’s Software In The Loop (SITL) simulation environment on your Linux machine is not hard as you think. In fact, all you need to do is, executing a few simple commands on your terminal to set up the SITL build environment on your device.

ArduPilot - Directory ArduPilot - Directory

Setting up SITL Environment

For setting up the ArduPilot SITL environment on your Linux device, you need to follow the below steps:1

  1. Install Git
  2. Clone ArduPilot Repository
  3. Install Necessary Requirements

For setting up the SITL environment, you need to have an active network plan on your device.

Installing Git

ArduPilot’s codebase is managed using Git. Git is a free and open-source distributed version control system designed to handle small to large projects with speed and efficiency. Git is available on all major OS platforms, and a variety of tools exist to make it easier to get started.

For installing Git on your Linux machine, execute the following commands on your terminal:

1
2
$ sudo apt-get update
$ sudo apt-get install git

You can also open the terminal window using the keyboard shortcut Ctrl + Alt + T

Advertisement

Clone ArduPilot Repository

Cloning is git’s terminology for making a local copy of a remote repository. ArduPilot software/build is hosted as a repository in GitHub. So, you need to download (clone) that repository on your device to set up the SITL environment on your device.

ArduPilot - GitHub Repository ArduPilot - GitHub Repository

Open a new terminal window on your device, and execute the below command for cloning the ArduPilot repository from GitHub:

1
$ git clone https://github.com/ArduPilot/ardupilot

You can also fork the main ArduPilot repository to your GitHub account and clone that repository if you want.

After cloning the ArduPilot repository, install the submodules by executing the following commands on the same terminal window:

1
2
$ cd ardupilot
$ git submodule update --init --recursive

Video Credits: ArduPilot

Note

If your firewalls do not allow ssh access, which can cause the above submodule updates to fail, in this instance, you can tell git to unilaterally use HTTPS through the following command:

1
$ git config --global url."https://"

to use HTTPS protocols instead of the default git:// prefix.

Install Necessary Requirements

If you are using Debian based system like Ubuntu or Mint, you can execute the install-prereqs-ubuntu.sh script present on the Tools directory of the ArduPilot repository. Executing this script will automatically install the required packages.

In the same terminal window (ArduPilot directory), execute the following commands:

1
$ Tools/environment_install/install-prereqs-ubuntu.sh -y

The above action will lead to the installation of other required packages. After that, execute the following command on your terminal to reload the path (log-out and log-in to make permanent):

1
$ . ~/.profile

Voila, you’ve completed the setup of the Ardupilot SITL simulation environment on your Linux Machine!!!

Starting SITL Simulator

ArduPilot project supports different types of vehicles such as,

  • Multicopter (ArduCopter)
  • Fixed-Wing (ArduPlane)
  • Submarine (ArduSub)
  • Rover (Rover)

To start the simulator, change the directory to the vehicle directory.2 For example, to simulate the multi-copter, change the directory to ardupilot/ArduCopter, by executing the following command on your terminal:

1
$ cd ardupilot/ArduCopter

Then start the simulator using sim_vehicle.py. For the first time, execute the sim_vehicle.py with -w to wipe the virtual EEPROM and to load the default parameters for your vehicle.

1
$ sim_vehicle.py -w

You’ll see something like below after executing the above commands on your terminal:

SITL - First Run SITL - First Run

After the default parameters are loaded, you can start the simulator normally by executing the following command on your terminal. But, Before that, kill the sim_vehicle.py you are already running, using the keyboard shortcut Ctrl + C and then:

1
$ sim_vehicle.py --console --map

Advertisement

Forwarding to Mission Planner

You can able to connect the vehicle which you’ve simulated to any mavlink supported Ground Control Station (GCS) software like QGroundControl or Mission Planner. For connecting the vehicle to GCS, you need to forward the mavlink packets to a new port and connect that port in GCS.

First, change the vehicle directory that you want to simulate by executing the following command (assuming that you’re using ArduCopter):

1
$ cd ardupilot/ArduCopter

Ignore the above step if you’re already in the vehicle directory.

Now, we need to forward the mavlink packets to a new UDP port. For example, forward to UDP port 14551 in localhost:

1
$ sim_vehicle.py --out=udpout:127.0.0.1:14551

Open Mission Planner, it’ll auto-connect vehicle since we’ve forwarded to the port 14551, if it’s not connecting automatically you can connect to the vehicle by clicking on the CONNECT button on the top right corner of the Mission Planner main window.

Mission Planner - Connect Button Mission Planner - Connect Button

A dialog box will open once after clicking on the CONNECT button, where you can enter the port number for establishing the mavlink connection between the vehicle and the system.

Listern Port (Dialog Box) - Mission Planner Listern Port (Dialog Box) - Mission Planner

After clicking the OK button on the dialog box, the intended vehicle will be connected to the Mission Planner. As you can able to see, the vehicle is in STABILIZE mode.

Vehicle Connected - Mission Planner Vehicle Connected - Mission Planner

Advertisement

Now, check the vehicle responsiveness by changing the mode to GUIDED in the SITL window using the following command:

1
mode GUIDED

Guided Mode - Mission Planner Guided Mode - Mission Planner

Now, you can able to establish the connection between the GCS and ArduPilot SITL simulator.

Note

There is no native support for Mission Planner on Linux. But can able to run Mission Planner on Linux using a cross compiler called Mono.

Conclusion

In this article, I’ve tried to explain how to set up the ArduPilot’s Software In the Loop (SITL) simulation on Linux. I’m expectantly waiting for your valuable feedback and suggestions regarding this topic.

At last, Sharing is Caring, feel free to share with your friends if you’ve liked this article. Thank you!

References

Advertisement

This post is licensed under CC BY-SA 4.0 by the author.

Advertisement

Contents

Advertisement

Dhulkarnayn - Elucidate Drones

Dhulkarnayn

I am 25 years old drone developer, holds a postgraduate degree in Avionics. I've worked on a few complex projects like drone swarms, drone light shows, autonomous landing of drones using computer-vision algorithms, etc. Since childhood, I'm much passionate about electronics, aerospace & engineering.

Please consider supporting this project!

If this article has been of help to you, and you feel generous at the moment, don’t hesitate to buy me a coffee. ☕

Buy me a coffee

Drone Programming - Is it Hard to Program a Drone?

How to change Home Location on ArduPilot SITL simulation?


Comments

Thank you for your reply. No, the sudo command does not work. Its use is not recommended. Perhaps the problem is related to different versions of Python. But how to check it? Is there a list of packages required for installation? I’ll try to install them manually.

Author Dhulkarnayn May 18th, 2022 20:05

Hi Taras, we can able to get the list from the install-prereqs-ubuntu.sh file. I’ve one doubt, you’re using the Ubuntu or Debian based OS, right?
Or, you’re using Arch Linux Based?

Author Dhulkarnayn May 18th, 2022 20:32

Taras, Instead of manually installing the packages, Try to execute the sim_vehicle.py -v ArduCopter from /ardupilot/Tools/autotest/ and it’ll directly build from there and will ask for the required packages for building


Thank you for your article! Running the instructions on Ubuntu 20.04 and ran into a problem. When running the command Tools/environment_install/install-prereqs-ubuntu.sh -y I get message Tools/environment_install/install-prereqs-ubuntu.sh: line 41: /usr/bin/sudo: Operation not allowed What could be the problem? What packages need to be installed in manual mode to work?

Author Dhulkarnayn May 8th, 2022 17:59

Taras, I’m pleased you found this article helpful. Did you tried with sudo? I hope, adding sudo before the command will resolve your issue: sudo Tools/environment_install/install-prereqs-ubuntu.sh -y