-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a page on how to setup SITL on Mac OSX #3307
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
.. _setting-up-sitl-on-macosx: | ||
|
||
=========================== | ||
Setting up SITL on Mac OS X | ||
=========================== | ||
|
||
This page describes how to setup the :ref:`SITL (Software In The Loop) <sitl-simulator-software-in-the-loop>` on Mac OS X. The specific commands were tested on macOS Catalina 10.15.7 and macOS Big Sur 11.1. | ||
|
||
Overview | ||
======== | ||
|
||
The SITL simulator allows you to run Plane, Copter or Rover without any | ||
hardware. It is a build of the autopilot code using an ordinary C++ | ||
compiler, giving you a native executable that allows you to test the | ||
behaviour of the code without hardware. | ||
|
||
SITL runs natively on Linux, Windows and Mac OSX. | ||
|
||
.. image:: ../images/SITL_macosx.png | ||
:target: ../_images/SITL_macosx.png | ||
|
||
|
||
Install steps | ||
============= | ||
|
||
This guide assumes that a build environment is already setup for Ardupilot. If that is not the case please follow the available guides to setup the build environment for Mac OSX. The following step provide a condensed versions of the steps to take. | ||
|
||
|
||
Prerequisites | ||
------------- | ||
|
||
The following tools need to be installed to complete the installation. Between brackets the version used by the author at time of writing. | ||
|
||
* Xcode (12.4) | ||
* Xcode commandline tools (12.4) | ||
* Homebrew (3.0.4-52-gbc37074) | ||
|
||
Preparing Python | ||
---------------- | ||
|
||
Install the required python 3 version using homebrew and activate it. If you are familiar with pyenv or virtualenv it might be better to use one of those to setup the environment. This limits potential problems with other tools that require specific versions of python. How to do that is beyond the scope of this document. | ||
|
||
The following steps install python version 3.9.x for system wide usage. | ||
|
||
:: | ||
|
||
brew install [email protected] | ||
export PATH="$(brew --prefix)/opt/python/libexec/bin":$PATH | ||
|
||
pip install wheel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command may require sudo. Best practice to install for the local user is to use the --user option to install for the user only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how much we want to dive into this in the instructions, but in my experience the best is to isolate ArduPilot-related Python dependencies in a virtualenv; what I do is as follows: python3 -m venv .venv
.venv/bin/pip install -U pip wheel future pymavlink mavproxy and then I run everything from the virtualenv. This way I don't mess up the Homebrew-installed Python with random dependencies that are needed for ArduPilot only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure it would help to put this in the instructions. Setting up a workable M1 Mac dev environment should be easy and without clear instructions it's definitely not. When you say "run everything from the virtualenv" - you mean mavproxy.py or waf or both? What I find now is that waf needs a different python environment to mavproxy, but sim_vehicle calls both waf and mavproxy so I can't get sim_vehicle->waf to use a different python from sim_vehicle->maxproxy. For now in order to get sim_vehicle to work, I just run it 'headless', which seems like what @srmainwaring and others are doing but I shouldn't have to do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to admit I don't use So, ultimately my goal was to get the build process running and to be able to run most of the non-GUI scripts from the Edit: I tried the wxPython snapshot builds from here; it seems like they have |
||
pip install future pymavlink mavproxy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Python 3.10 from Python.org for Mac M1 ARM version, this will fail with the following errors: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not totally sure what these lines do, but it seems that there is some code in _nanosvg.c that needs to be fixed. |
||
|
||
Optional: Add the following to the either .bashrc or .zshrc to enable this version of python be default | ||
|
||
:: | ||
|
||
export PATH="$(brew --prefix)/opt/python/libexec/bin":$PATH | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also useful to add ################################################################################
# ARDUPILOT
#
export PATH=$PATH:$HOME/Code/ardupilot/ardupilot/Tools/autotest
export ARDUPILOT_ROOT=$HOME/Code/ardupilot/ardupilot to the shell initialisation scripts while you're at it. I put customisations including the PATH modification for Python in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may cause problems if you run more than one clone in different directories. I often do that. |
||
Optional: Install sfml (used by sitl for audio and osd) | ||
|
||
:: | ||
|
||
brew install sfml | ||
|
||
Note that not all sfml features work on Mac OSX currently. The following error can appear `Cannot create a window from a worker thread. (OS X limitation)`, this is a result of Mac OSX specifics that haven't been catered for in the sitl code yet. | ||
|
||
Start SITL simulator | ||
-------------------- | ||
|
||
.. warning:: | ||
|
||
Due to ideosyncracies with Python and using screens there are limitations when Python needs to use the screen to display a graphical UI. Python 3.9 solves part of the problem by no longer requiring a separate pythonw binary. However the requirement to run on the main display still stands. When observing the error "This program needs access to the screen. Please run with a Framework build of python, and only when you are logged in on the main display of your Mac.", disconnect external displays during startup. When SITL is started the windows can be moved around as normal. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sp. - ideosyncracies
+ idiosyncrasies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't been able to get this to work at all on my M1 Mac. So I just run SiTL with no UI. It works fine and I connect to the running model with with QGroundControl which shows the map and all the messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timtuxworth unfortunately I don't have a M1 to test at present - still Intel based machines for me. When I get round to upgrading my macbook I'll take another look at the UI modules in MAVProxy which seem to be causing the problems. As you suggest it might be worth emphasising the difference between a bare bones SITL install (with alternative GCS) and full MAVProxy support for macOS which should have all the UI elements functioning correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed; it seems like most of the difficulties that arise in installing SITL stuff on an M1 Mac are due to the GUI stuff. I run the SITL without a GUI and I haven't encountered any significant issues. |
||
|
||
To start the simulator first change directory to the vehicle directory. | ||
For example, for the multicopter code change to **ardupilot/ArduCopter**: | ||
|
||
:: | ||
|
||
cd ardupilot/ArduCopter | ||
|
||
The sim_vehicle script checks several environment variables to determine the OS it's running on. For Mac OSX it | ||
requires that DISPLAY is set. | ||
|
||
:: | ||
|
||
export DISPLAY=:0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you need the macOS X environment installed for this to work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've not needed to set the DISPLAY when running SITL (no need for an X server that I'm aware of?) |
||
|
||
Then select the correct python environment (if not enabled by default) | ||
|
||
:: | ||
|
||
export PATH="$(brew --prefix)/opt/python/libexec/bin":$PATH | ||
|
||
Then start the simulator using **sim_vehicle.py**. The first time you | ||
run it you should use the -w option to wipe the virtual EEPROM and load | ||
the right default parameters for your vehicle. | ||
|
||
:: | ||
|
||
sim_vehicle.py -w | ||
|
||
After the default parameters are loaded you can start the simulator | ||
normally. First kill the sim_vehicle.py you are running using Ctrl-C. Then: | ||
|
||
:: | ||
|
||
sim_vehicle.py --console --map | ||
|
||
.. tip:: | ||
|
||
`sim_vehicle.py <https://github.com/ArduPilot/ardupilot/blob/master/Tools/autotest/sim_vehicle.py>`__ | ||
has many useful options, ranging from setting the simulation speed | ||
through to choosing the initial vehicle location. These can be listed by | ||
calling it with the ``-h`` flag (and some are demonstrated in :ref:`Using SITL for ArduPilot Testing <using-sitl-for-ardupilot-testing>`). | ||
|
||
.. tip:: | ||
|
||
If the map tiles don't load, you can temporarily change the map provider in the map window by clicking View/Service. | ||
To keep the new map service between launches, add the following lines to the end of your ".bashrc" (change MicrosoftHyb to the provider you want): | ||
|
||
:: | ||
|
||
export MAP_SERVICE="MicrosoftHyb" | ||
|
||
|
||
Learn MAVProxy | ||
-------------- | ||
|
||
To get the most out of SITL you really need to learn to use MAVProxy. | ||
Have a read of the :ref:`MAVProxy documentation <mavproxy:home>`. Enjoy flying! | ||
|
||
|
||
Next steps | ||
========== | ||
|
||
After installation, see :ref:`Using SITL for ArduPilot Testing <using-sitl-for-ardupilot-testing>` for guidance on flying and testing with SITL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that in order to get ArduPilot to compile using waf on an M1Pro Mac running OSX 12.1 Monterey I had to install Python 3.10 from python.org. But this version of python will not run SITL. To both compile using waf and run SITL the only version (2022 April 3) I have found to work is Anaconda python from anaconda.com.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we need two sub-guides for macOS - one for Intel based machines and one for M1 versions. The default install locations for brew are different for each architecture and I suspect we'll keep seeing more differences as more functionality is documented. For example the instructions for adding other simulators like Ignition will be specialised for each architecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can compile ArduPilot just fine with Python 3.9 on an M1-based MacBook Pro so I don't think you'll need Python 3.10. I'm using Python 3.9 from Homebrew.
Edit: I usually don't install
mavproxy
because it brings lots of dependencies with it that I don't need, so the differences outlined above may be due tomavproxy
dependencies. Also, note that a few months have passed since January so it may be the case that some dependencies ofmavproxy
have published pre-built M1 oruniversal2
wheels on PyPI since then.