UPDATE: please see @LuisVale comment about running
sim_vehicle.py
natively within MacOS. I didn’t know this when I wrote the Docker image nor this tutorial. Hurray for better information!
For MacOS we have several ground control GCS options including APM Planner 2 and QGroundControl, unfortunately neither offer in-built Simulator In The Loop (SITL) like the Windows-only Mission Planner.
Fortunately SITL can be run standalone from the ardupilot github project, and the GCS can automatically discover SITL. Unfortunately it is a relatively lengthy sequence of steps for MacOS users via Vagrant. For MacOS users I wrote up a Tutorial for running SITL Simulator on MacOS with Vagrant + XQuartz.
I wondered if it would be a nice UX for people to use Docker and a pre-built Docker image. And it sort of is nice. Except for the 3G+ size of the Docker image layers, which hopefully we can improve on in future.
To get started on MacOS, install Docker, and Xquartz.
To configure and run Xquartz, download the pre-built Docker image drnic/ardupilot-sitl
, and run your favourite simulator robot:
HOST_IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $HOST_IP
docker run -ti -e HOST_IP=$HOST_IP -e DISPLAY=$HOST_IP:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix -p 14550:14550 \
drnic/ardupilot-sitl \
Tools/autotest/sim_vehicle.py \
--no-rebuild --console --map --out=$HOST_IP:14550 \
-v APMrover2 -L Kingaroy
The first time you run docker run ... drnic/ardupilot-sitl ...
it will download all the layers of the Docker image. This is currently 3G+. Sorry about that.
You should see two windows appear with the ArduRover simulator centered on Kingaroy airport. I can feel the speed already along that tarmac.
You can replace -v APMrover2
with -v ArduPlane
, -v ArduCopter
, -v Helicopter
; and could replace -L Kingaroy
with -L <location>
from https://github.com/ArduPilot/ardupilot/blob/master/Tools/autotest/locations.txt
Any tutorial in http://ardupilot.org/dev/docs/sitl-simulator-software-in-the-loop.html should “just work”.
You can pass the -h
flag to the end and see the sim_vehicle.py
flag options, such as:
Usage: sim_vehicle.py
Options:
-h, --help show this help message and exit
-v VEHICLE, --vehicle=VEHICLE
vehicle type (ArduCopter|AntennaTracker|APMrover2|Ardu
Sub|ArduPlane)
-f FRAME, --frame=FRAME
set vehicle frame type
ArduCopter: octa-quad|cwx|singlecopter|gazebo-
iris|calibration|hexa|tri|+|heli-compound|djix
|dodeca-hexa|heli-
dual|coaxcopter|X|y6|quad|bfx|IrisRos|heli|octa
AntennaTracker: tracker
APMrover2: rover|rover-
skid|calibration|sailboat|balancebot|gazebo-rover
ArduSub: gazebo-bluerov2|vectored
ArduPlane: quadplane-
tilttrivec|firefly|jsbsim|calibration|CRRCSim
|plane-elevon|plane|last_letter|plane-vtail|plane-
tailsitter|gazebo-zephyr|quadplane-tilthvec
|quadplane-tri|quadplane-cl84|plane-dspoilers
|quadplane-tilttri|quadplane
-C, --sim_vehicle_sh_compatible
be compatible with the way sim_vehicle.sh works; make
this the first option
-H, --hil start HIL
...
SITL, whilst running inside Docker, still exposes MAVProxy to your local machine on port 14550.
This means you can now launch your GCS - APM Planner 2, QGroundControl, etc - and they should immediately connect to your simulator.
Very exciting. Our MacOS GCS has a locally running SITL.
The pre-built Docker image is currently a fork of upstream ardupilot, with the image regularly rebuilt from any changes to upstream (see Concourse CI pipeline).
Re-pull the image to get new SITL/ardupilot updates (about 300M update each time):
docker pull drnic/ardupilot-sitl
If you have any troubles with this tutorial or the Docker image please let me know below and I’ll try to resolve it or help you out. I enjoyed seeing SITL + GCS working over Docker/Xquartz and hopefully its useful to others.