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
Setting up SITL Environment
For setting up the ArduPilot SITL environment on your Linux device, you need to follow the below steps:1
For setting up the SITL environment, you need to have an active network plan on your device.
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
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
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
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
-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
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
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
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
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
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
Now, you can able to establish the connection between the GCS and ArduPilot SITL simulator.
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.
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!