Servers by jDrones

Tutorial for running SITL Simulator on MacOS with Vagrant + XQuartz


(Dr Nic Williams) #1

I wanted to see the SITL simulator running on my MacOS. The wiki vagrant instructions got me a fair way, but I discovered I needed some extra flags (vagrant ssh -- -X) and dependencies (XQuartz).

I’ve written up a short guide to installing & running SITL on MacOS:

If anyone has any optimizations/improvements, please let me know. I’m still learning how all the ground control + SITL + firmware works together.

Run Simulator SITL using pre-built Docker image with your GCS (MacOS/XQuartz tutorial)
(Dr Nic Williams) #2

Towards running SITL within Docker, looks to be a good set of instructions for X11 forwarding + docker.

And for some OS X instructions for socat.

To run firefox, as per the blog post, I needed to first run socat:

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &

The run the X11 app in a docker container, passing thru $DISPLAY to that socat port:

docker run -d --name firefox -e DISPLAY=$IP:0 -v /tmp/.X11-unix:/tmp/.X11-unix jess/firefox

(Mike Boland) #3

Am I missing something with vagrant?
It complains about a default provider when vagrant up is initiated.

(Dr Nic Williams) #5

@mboland I’m sorry if I’ve missed some “getting started with vagrant” steps. Can you let me know what the error output looks like and I’ll help hunt down how to setup vagrant etc and fix up the instructions for you.

(Mike Boland) #6

Thanks for taking the time.
the error message is:
No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as
“providers”, to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.

If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn’t working by forcing usage with
vagrant up --provider=PROVIDER, which should give you a more specific
error message for that particular provider.

So which provider do I need to specify?
Have I neglected to install something?

(Dr Nic Williams) #7

Ok I’ve added a link to download VirtualBox.

AFAIK you shouldn’t need to pass vagrant up --provider virtualbox – I’m not seeing that on any of their “getting started” guides

From this page it seems to confirm that Virtualbox is the default

So try installing VirtualBox and running vagrant up aagain.

(Mike Boland) #8

I don’t seem to be having much luck following this install :roll_eyes:
Have all the listed components installed, XQuartz, Vagrant, VirtualBox.
Have cloned Ardupilot following each command.
I get to Vagrant up:
Michaels-Mac-Pro-2:vagrant michaelboland$ vagrant up
Bringing machine ‘bionic64’ up with ‘virtualbox’ provider…
==> bionic64: Checking if box ‘ubuntu/bionic64’ version ‘20190212.1.0’ is up to date…
==> bionic64: Machine already provisioned. Run vagrant provision or use the --provision
==> bionic64: flag to force provisioning. Provisioners marked to run always will still run.
I have the VirtualBox running with a login prompt

Then when I give the command:
vagrant ssh -c " -j 2 --console --map --out=:14550 -v ArduPlane " – -X
waf builds successfully, with the summary, then:
Build commands will be stored in build/sitl/compile_commands.json
‘build’ finished successfully (18.074s)
SIM_VEHICLE: Using defaults from (/vagrant/Tools/autotest/default_params/plane.parm)
SIM_VEHICLE: Run ArduPlane
SIM_VEHICLE: “/vagrant/Tools/autotest/” “ArduPlane” “/vagrant/build/sitl/bin/arduplane” “-S” “-I0” “–home” “-35.363261,149.165230,584,353” “–model” “plane” “–speedup” “1” “–defaults” “/vagrant/Tools/autotest/default_params/plane.parm”
SIM_VEHICLE: “” “–master” “tcp:” “–sitl” “” “–out” “” “–out” “” “–out” “:14550” “–map” “–console”
RiTW: Starting ArduPlane : /vagrant/build/sitl/bin/arduplane -S -I0 --home -35.363261,149.165230,584,353 --model plane --speedup 1 --defaults /vagrant/Tools/autotest/default_params/plane.parm
Connect tcp: source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Failed to connect to tcp: : [Errno 111] Connection refused
SIM_VEHICLE: MAVProxy exited
SIM_VEHICLE: Killing tasks
Connection to closed.

And it all stops.
Now I know I must not be holding my tongue right, or failed to install something, but I am trying to faithfully follow your Tutorial.
Any advice would be appreciated.

(Dr Nic Williams) #9

On the contrary you’re moving forward to all new issues :slight_smile:

I don’t know why the Vagrantfile is configured to have a visible virtualbox terminal window; I’ve never seen this with Vagrantfiles before. So I ignore that window myself; and vagrant ssh to get a clean ssh terminal.

If I remember from when I was trying to get this all working, that error was related to xquartz not running or not accessible. I’ll go and try to reproduce it myself.

(Dr Nic Williams) #10

Ok I was able to reproduce your error output and fortunately I learned the fix to this whilst working on a Dockerfile + instructions.

I’ve updated the vagrant ssh -c "..." command in the gist to the following:

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

The xhost... command will launch Xquartz.

Fingers crossed this all works for you now! Thanks for trying out the instructions and helping me debug them.

(peterbarker) #11

Yes, well. That’s a relatively recent occurance. The concept was to give
people a desktop environment they could work in so as not to have to muck
around with remote X etc etc.

Sadly, we didn’t get to that.

I did have work around here that gave us “-nox” variants without the
windowing, and a desktop environment. What I couldn’t get working was
instant-login of the user without rebooting the Vagrant instance. Really
wish I could find that work right now :slight_smile:

(Dr Nic Williams) #12

Thanks Peter, I appreciate the backstory/history.

Was running vagrant ssh an unpleasant experience that you were trying to avoid? Or did you want the initial ssh window to do something specific on start?

I’ll submit a PR to quieten the virtualbox window for now until you/someone comes back to the idea. And/or perhaps I can add some features whilst I’m dabbling with Vagrantfile/Dockerfiles at the moment.

(Mike Boland) #13

Thanks for all your help @drnic,

I have had some success.
If I start from scratch I get the same ‘sleeping’ error as above.
So I just retried the

vagrant ssh -c " -j 2 --console --map --out=$HOST_IP:14550 -v ArduPlane " – -X

and I was able to get what appears to be the SITL environment working.

There seems to be a LOT of different instructions for SITL on the websites ‘discuss’ and ‘github’
But it’s always a learning curve.

(Dr Nic Williams) #14

And then we discover we should first just try running directly on our local machine first before trying vagrant/docker :slight_smile:

(Mike Boland) #15

Can you be a bit more specific on the syntax for running the

What directory do I need to be in?
Do I need XQuartz open?

Sorry to sound like a dummy with this but I have only basic terminal knowledge, just enough to get me into trouble.

(Dr Nic Williams) #16

See Run Simulator SITL using pre-built Docker image with your GCS (MacOS/XQuartz tutorial) for some commands to try running on your local machine, without vagrant etc

(Luís Vale Gonçalves) #17

help is there

Moon:ardupilot luis$ ./Tools/autotest/ --help

I usually start it from the Ardupilot root dir but you can be anywhere and invoke it from its directory

./Tools/autotest/ --help

Not even installed (xQuartz) here on Mojave :slight_smile:

don’t worry :slight_smile: I’m just half step ahead of you :wink:

(Mike Boland) #18

Thanks for that it seemed to work.
Although all that was running was XQuartz with no window, another terminal window popped up with:

Loaded defaults from /Users/michaelboland/ardupilot/Tools/autotest/default_params/copter.parm
bind port 5762 for 2
Serial port 2 on TCP port 5762
bind port 5763 for 3
Serial port 3 on TCP port 5763
Smoothing reset at 0.001
Loaded defaults from /Users/michaelboland/ardupilot/Tools/autotest/default_params/copter.parm
Unable to fetch Log File Size: No such file or directory

Assuming that was a success I opened APM Planner and it automatically connected Copter and showed data:

It would arm, set mode, but I could not get it to obey other commands like start mission etc.
Getting there, but obviously I have a lot more reading to do about SITL.

Thanks guys for all the assistance.