Softivation

ArduPilot SITL setup guide

SITL runs the ArduPilot firmware from the flight controller on your computer. You test your mission code without flying a drone and spot crash risks at your desk. The commands are the same ones we use in our blog posts and courses.

H123$ ./arducopter -S -I0SERIAL0 on TCP port 5760Waiting for connection ....$ python3 gorev.pyheartbeat: sysid 1

Choose your path

  1. No install needed

    In the browser

    Nothing to install on your computer: Python, pymavlink, MAVProxy and SITL come ready. It uses your GitHub account's free allowance.

    Open in Codespaces
  2. Ubuntu

    One command: downloads the prebuilt SITL binary and starts the vehicle on port 5760.

    Step by step
  3. Windows: WSL

    Open PowerShell as administrator, paste the command and restart the computer. Then run the single command in Ubuntu.

    Step by step
  4. Windows: ready-made virtual machine

    You open an Ubuntu image with SITL, Gazebo, ROS and Python preinstalled in VMware and start it.

    Ready-made virtual machine Set it up yourself

Quick setup on Ubuntu: a prebuilt SITL binary

You don't need to compile ArduPilot to test your Python code and your Mission Planner connection. The code in our blog posts runs on this setup. The same commands work in Ubuntu on WSL and on a virtual machine.

  1. Download the files

    The Linux SITL binary of the stable Copter release and the default parameters:

    Shell
    mkdir -p ~/sitl && cd ~/sitl
    curl -sL -o arducopter \
      https://firmware.ardupilot.org/Copter/stable/SITL_x86_64_linux_gnu/arducopter
    chmod +x arducopter
    curl -sL -o copter.parm \
      https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/autotest/default_params/copter.parm
  2. Start the vehicle

    Shell
    ./arducopter -S -I0 --model + --speedup 1 --defaults copter.parm \
      --sysid 1 --home 37.1591,38.7969,500,0

    -I0 is the instance number and sets the ports. --home gives the home point as latitude, longitude, altitude and heading. --speedup 1 runs the simulation in real time; you need it if you're going to measure message rates in Hz.

    When you see the Waiting for connection .... line in the terminal, the vehicle is waiting for its first client. Leave this terminal open.

  3. Install pymavlink for Python

    In a separate terminal, install pymavlink in a virtual environment. Your mission code connects to tcp:127.0.0.1:5760.

    Shell
    sudo apt install python3-venv
    python3 -m venv ~/sitl/venv
    source ~/sitl/venv/bin/activate
    pip install pymavlink
    In the course: connecting to the vehicle, requesting data streams, attributes and first commands, with sample code. Drone Control with Python from Scratch: the Connecting to the Vehicle and Vehicle Class Attributes lesson.
  4. Connect Mission Planner

    Choose TCP as the connection type, enter 127.0.0.1 as the address and 5762 as the port. While your mission code is using 5760, don't point Mission Planner at the same port: SITL accepts only one client per port at a time.

    In the course: port layout, starting a second and third vehicle, swarm simulation. AI and Drone Simulation Course: the Drone Swarm Simulation lesson.

Full development environment: sim_vehicle.py and MAVProxy

If you want the map, the MAVProxy console, plane and VTOL airframes or the Gazebo plugin, install ArduPilot from source. This is the route the AI and Drone Simulation course takes.

  1. Clone the repository with its submodules

    Shell
    sudo apt-get update
    sudo apt-get install git
    git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git
    cd ardupilot
  2. Install the required packages

    Shell
    Tools/environment_install/install-prereqs-ubuntu.sh -y
    . ~/.profile

    According to ArduPilot's documentation, this script doesn't work on Ubuntu releases past the end of standard support; the docs give 20.04 as an example. For a new install, pick an LTS release that's still supported. If you've upgraded Ubuntu, run the script again.

  3. Start the simulation

    On the first run, -w wipes the saved parameters and loads the defaults:

    Shell
    cd ~/ardupilot/ArduCopter
    sim_vehicle.py --console --map -w
    In the course: plane, VTOL and boat airframes; simulation with camera, lidar and sonar in Gazebo. AI and Drone Simulation Course: the Plane Simulation lesson.
  4. Connect the ground station

    MAVProxy broadcasts the vehicle on UDP 14550. Connect Mission Planner on the same computer to UDP 14550.

    In the course: streaming to a ground station on another computer, the MAVProxy console and map, the simulation's first flight. AI and Drone Simulation Course: the Running ArduPilot SITL lesson.

Windows: installing with WSL

You need Windows 10 version 2004 or later, or Windows 11. Mission Planner runs on Windows, and SITL runs in Ubuntu inside WSL.

  1. Install WSL and Ubuntu

    Open PowerShell as administrator. The command enables WSL and installs Ubuntu. When it's done, restart the computer, open Ubuntu and set a username and password.

    Shell
    wsl --install
  2. Follow the Ubuntu steps inside WSL

    Quick setup or full environment, the commands are the same. Clone the ArduPilot repository into WSL's own file system (e.g. ~/ardupilot), not into Windows folders. Builds are much faster that way.

    On Windows 11 the map and console windows open on their own. On Windows 10, install an X server such as VcXsrv and start it with the "Start no Client" and "Disable access control" options.

  3. Connect Mission Planner

    Shell
    cd ~/ardupilot/ArduCopter
    ../Tools/autotest/sim_vehicle.py --map --console

    Start Mission Planner once the MAVProxy console and map are open. It usually connects by itself. If it doesn't, choose UDP and connect to 14550. If you've turned on WSL2's "mirrored" networking mode, add --no-wsl2-network to the command.

    By default WSL2 doesn't see USB, so you can't connect the flight controller from inside WSL. When working with the board, use Mission Planner on Windows.

Windows: installing with a virtual machine

In the course we install Ubuntu inside VMware. The virtual disk needs at least 20 GB of free space; we recommend 50 GB.

  1. Set up the virtual machine

    Install VMware, install Ubuntu in the virtual machine, then follow the Ubuntu steps above inside it.

    If you'd rather skip the setup, the ready-made virtual machine copy comes with ArduPilot SITL, Gazebo 11, ROS Noetic, DroneKit and pymavlink installed on Ubuntu 20.04.

  2. Connect Mission Planner on the host machine

    SITL's TCP ports listen on every network interface, not just 127.0.0.1. If networking is in bridged mode, open a TCP connection from Mission Planner straight to the virtual machine's address (5760, or 5762 if that one's free). Find the address on the virtual machine:

    Shell
    hostname -I

    If you're using sim_vehicle.py, add UDP 14550 to the Windows address in MAVProxy with output add.

Common errors

What each message means and what to check first are in the error message glossary. Tracking down step by step why the connection drops is in the course: Mission Planner says it's connected, but not a single byte arrives.

Continued in the courses

After setup: a camera drone in Gazebo, swarm simulation and mission code.

We'll email it to you as a PDF

To take to the field, the workshop or a teammate. Leave your name and email and we'll send the setup guide as a PDF.

In the print dialog, choose "Save as PDF" as the destination.

We process your name and email to send the PDF, as described in the privacy notice.