Skip to content

Instantly share code, notes, and snippets.

@drnic
Last active April 1, 2024 18:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drnic/7684ce449ef5cfa965166ddd907dd36a to your computer and use it in GitHub Desktop.
Save drnic/7684ce449ef5cfa965166ddd907dd36a to your computer and use it in GitHub Desktop.
Instructions for running Ardupilot Simulation SITL within MacOS using XQuartz and Vagrant

Ardupilot Simulation (SITL - Simulation In The Loop) allows for safe testing of experimental code and settings and crashing virtual vehicles is a lot cheaper than crashing real ones!

It was written for X11/Linux. Fortunately thanks to Vagrant and XQuartz it can be run on MacOS.

demo

Clone ardupilot and submodules:

git clone --recursive https://github.com/ardupilot/ardupilot
cd ardupilot

If you already develop Ardupilot, you may need to clean out some folders modified within Vagrant:

rm -rf build

Edit Vagrantfile to setup X11 forwarding:

 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   config.ssh.forward_x11 = true

Startup Vagrant/Virtualbox, using the ssh -X flag (via -- -X at the end of the command) to enable X11 forwarding:

cd Tools/vagrant
vagrant up

Perhaps the provision step fails; it might not matter. Carry on.

HOST_IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $HOST_IP
vagrant ssh -c "sim_vehicle.py -j 2 --console --map --out=$HOST_IP:14550 -v ArduPlane " -- -X

The SITL program should launch on your host machine (MacOS) within XQuartz. XQuartz will be launched for you when you run the xhost command above.

Host access to MAVLink

From your MacOS, you can now access the MAVLink traffic on port 14550.

For example, MAVProxy can connect:

mavproxy.py --master=0.0.0.0:14550

Similarly QGroundControl will immediately picked up the location of the plane from the simulator:

qgroundcontrol

Suspending between sessions

Since it takes a while to run vagrant up the first time, you might like to use vagrant suspend to shutdown the VM between uses.

@khancyr
Copy link

khancyr commented Feb 11, 2019

use waf clean or waf distclean instead of rm -rf build .
The provision step shouldn't failed otherwise you will miss something..
don't pass -j 2 as waf will scale itself to available proc in the VM.

@TessaRHartmann
Copy link

Hi, I'm attempting to run SITL on macOS (Intel Processor) and I continue to get the error:

bash: sim_vehicle.py: command not found
Connection to 127.0.0.1 closed.

@ben-xD
Copy link

ben-xD commented Mar 29, 2024

I was thinking about how this would work on M1/ARM macs. Vagrant wants a provider, and in this case the author is using it with VirtualBox. Since VirtualBox doesn't work well on ARM macs, people have been suggesting avoiding that. Therefore, I think it makes more sense to run SITL in docker. As in https://github.com/radarku/ardupilot-sitl-docker. It is a bit outdated though (Ubuntu 18.04), however you can update it pretty easily.

Edit: I've setup a dockerfile so we can still use the Ardupilot console and MAVProxy UI's through docker. See https://github.com/ben-xd/ardupilot-sitl-docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment