Skip to content

Commit 4b9dfa8

Browse files
committed
Merge pull request #555 from dronekit/hgw_running_examples
UPdate running examples page and simulation instructions
2 parents 894a3eb + 0688be2 commit 4b9dfa8

File tree

2 files changed

+88
-46
lines changed

2 files changed

+88
-46
lines changed

docs/develop/sitl_setup.rst

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ The `SITL (Software In The Loop) <http://dev.ardupilot.com/wiki/simulation-2/sit
88
simulator allows you to create and test DroneKit-Python apps without a real vehicle (and from the comfort of
99
your own developer desktop!).
1010

11-
SITL can run natively on Linux, Mac and Windows, or within a virtual machine. It can be
11+
SITL can run natively on Linux (x86 architecture only), Mac and Windows, or within a virtual machine. It can be
1212
installed on the same computer as DroneKit, or on another computer on the same network.
1313

1414
The sections below explain how to install and run SITL, and how to connect to DroneKit-Python and Ground
1515
Stations at the same time.
1616

1717

18+
.. _dronekit_sitl:
19+
1820
DroneKit-SITL
1921
=============
2022

21-
DroneKit-SITL is the simplest, fastest and easiest way to run SITL on Windows, Linux, or MAC OSX.
23+
DroneKit-SITL is the simplest, fastest and easiest way to run SITL on Windows, Linux (x86 architecture only), or Mac OS X.
2224
It is installed from Python's *pip* tool on all platforms, and works by downloading and running pre-built
2325
vehicle binaries that are appropriate for the host operating system.
2426

@@ -27,8 +29,12 @@ the `project on Github <https://github.com/dronekit/dronekit-sitl>`_.
2729

2830
.. note::
2931

30-
DroneKit-SITL is still relatively experimental. There are only a few pre-built vehicles and
31-
they have not been as well tested as the native builds.
32+
DroneKit-SITL is still relatively experimental and there are only a few pre-built vehicles.
33+
34+
The binaries are built and tested on Windows 10, Ubuntu Linux, and Mac OS X
35+
"El Capitan". Binaries are only available for x86 architectures. ARM builds
36+
(e.g. for RPi) are not supported.
37+
3238
Please report any issues on `Github here <https://github.com/dronekit/dronekit-sitl/issues>`_.
3339

3440
Installation
@@ -68,42 +74,38 @@ There are a number of other useful arguments:
6874
dronekit-sitl --reset #Delete all downloaded vehicle binaries.
6975
dronekit-sitl ./path [args...] #Start SITL instance at target file location.
7076
71-
72-
.. note::
73-
74-
DroneKit-SITL also `exposes a Python API <https://github.com/dronekit/dronekit-sitl#api>`_, which you can use to start simulation from within your scripts. This is particularly useful for test code!
7577
7678
7779
.. _connecting_dronekit_sitl:
7880

79-
Connecting to (DroneKit-) SITL
80-
------------------------------
81+
Connecting to DroneKit-SITL
82+
---------------------------
8183

82-
SITL waits for TCP connections on ``127.0.0.1:5760``. DroneKit-Python scripts running on the same
84+
DroneKit-SITL waits for TCP connections on ``127.0.0.1:5760``. DroneKit-Python scripts running on the same
8385
computer can connect to the simulation using the connection string as shown:
8486

8587
.. code-block:: python
8688
8789
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True)
8890
89-
If you need to connect to DroneKit-Python and a ground station at the same time you will need to
90-
`install MAVProxy <http://dronecode.github.io/MAVProxy/html/getting_started/download_and_installation.html>`_
91-
for your system.
91+
After something connects to port ``5760``, SITL will then wait for additional connections on port ``5763``
92+
(and subsequently ``5766``, ``5769`` etc.)
93+
94+
.. note::
9295

93-
Then in a second terminal you spawn an instance of *MAVProxy* to forward messages from
94-
TCP ``127.0.0.1:5760`` to UDP ports ``127.0.0.1:14550`` and ``127.0.0.1:14551`` (this is what **sim_vehicle.sh** does
95-
if you build SITL from source):
96+
While you can connect to these additional ports, some users have reported problems when
97+
viewing the running examples with *Mission Planner*. If you need to connect a ground station
98+
and DroneKit at the same time we recommend you use *MAVProxy* (see :ref:`viewing_uav_on_map`).
9699

97-
.. code-block:: bash
98100

99-
mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551
100101

101-
You can then connect to a ground station using one UDP address, and DroneKit-Python using the other.
102-
For example:
102+
.. _dronekit_sitl_api:
103103

104-
.. code-block:: python
104+
DroneKit-SITL Python API
105+
------------------------
106+
107+
DroneKit-SITL `exposes a Python API <https://github.com/dronekit/dronekit-sitl#api>`_, which you can use to start and control simulation from within your scripts. This is particularly useful for test code and :ref:`examples <example-toc>`.
105108

106-
vehicle = connect('127.0.0.1:14550', wait_ready=True)
107109

108110

109111

@@ -117,7 +119,14 @@ Building from source is useful if you want to need to test the latest changes (o
117119
a version for which DroneKit-SITL does not have pre-built binaries).
118120
It can also be useful if you have problems getting DroneKit-SITL to work.
119121

120-
The following topics from the ArduPilot wiki explain how:
122+
SITL built from source has a few differences from DroneKit-SITL:
123+
124+
* MAVProxy is included and started by default. You can use MAVProxy terminal to control the autopilot.
125+
* You connect to SITL via UDP on ``127.0.0.1:14550``. You can use MAVProxy's ``output add`` command to add additional ports if needed.
126+
* You may need to disable arming checks and load autotest parameters to run examples.
127+
* It is easier to `add a virtual rangefinder <http://dev.ardupilot.com/wiki/using-sitl-for-ardupilot-testing/#adding_a_virtual_rangefinder>`_ and `add a virtual gimbal <http://dev.ardupilot.com/wiki/using-sitl-for-ardupilot-testing/#adding_a_virtual_gimbal>`_ for testing.
128+
129+
The following topics from the ArduPilot wiki explain how to set up Native SITL builds:
121130

122131
* `Setting up SITL on Linux <http://dev.ardupilot.com/wiki/setting-up-sitl-on-linux/>`_
123132
* `Setting up SITL on Windows <http://dev.ardupilot.com/wiki/simulation-2/sitl-simulator-software-in-the-loop/sitl-native-on-windows/>`_
@@ -129,24 +138,38 @@ The following topics from the ArduPilot wiki explain how:
129138
Connecting an additional Ground Station
130139
=======================================
131140

132-
You can connect a ground station to an unused port to which messages
133-
are being forwarded. You can forward messages to additional ports
134-
when you start *MAVProxy* using the using ``-out``
135-
parameter (as shown :ref:`above <connecting_dronekit_sitl>`).
141+
You can connect a ground station to an unused port to which messages are being forwarded.
136142

137-
Alternatively, once *MAVProxy* is started you can add new output ports in the *MAVProxy* console using: ``output add``:
143+
The most reliable way to add new ports is to use *MAVProxy*:
138144

139-
.. code:: bash
145+
* If you're using SITL built from source you will already have *MAVProxy* running.
146+
You can add new ports in the MAVProxy console using ``output add``:
140147

141-
output add 127.0.0.1:14552
148+
.. code:: bash
142149
143-
.. note::
150+
output add 127.0.0.1:14552
151+
152+
* If you're using Dronekit-SITL you can:
153+
154+
* `Install MAVProxy <http://dronecode.github.io/MAVProxy/html/getting_started/download_and_installation.html>`_
155+
for your system.
156+
* In a second terminal spawn an instance of *MAVProxy* to forward messages from
157+
TCP ``127.0.0.1:5760`` to other UDP ports like ``127.0.0.1:14550`` and ``127.0.0.1:14551``:
158+
159+
.. code-block:: bash
144160
145-
Instead of the loopback address you can also specify the network IP address of your computer
146-
(On Windows you can get this by running *ipconfig* in the *Windows Command Prompt*).
161+
mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551
147162
163+
Once you have available ports you can connect to a ground station using one UDP address, and DroneKit-Python using the other.
148164

149-
Then connect Mission Planner to this UDP port:
165+
For example, first connect the script:
166+
167+
.. code-block:: python
168+
169+
vehicle = connect('127.0.0.1:14550', wait_ready=True)
170+
171+
172+
Then connect Mission Planner to the second UDP port:
150173

151174
* `Download and install Mission Planner <http://ardupilot.com/downloads/?did=82>`_
152175
* Ensure the selection list at the top right of the Mission Planner screen says *UDP* and then select the **Connect** button next to it.
@@ -159,3 +182,12 @@ Then connect Mission Planner to this UDP port:
159182

160183
After connecting, vehicle parameters will be loaded into *Mission Planner* and the vehicle is displayed on the map.
161184

185+
.. tip::
186+
187+
If you're using the :ref:`dronekit_sitl_api` then you will instead have to
188+
connect to SITLs TCP port (as there is no way to set up MAVProxy in this case).
189+
So if DroneKit is connecting to TCP port 5760, you would connect your GCS to 5763.
190+
191+
Note that a few examples may not behave perfectly using this approach. If you need to
192+
observe them in a GCS you should run SITL externally and use MAVProxy to connect to it.
193+

docs/examples/running_examples.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
Running the Examples
55
====================
66

7-
General instructions for running the `example source code <https://github.com/dronekit/dronekit-python/tree/master/examples>`_ are given below.
7+
General instructions for running the `example source code <https://github.com/dronekit/dronekit-python/tree/master/examples>`_ are given below. More explicit instructions are provided within the documentation for each example (and within the examples themselves by passing the ``-h`` (help) command line argument).
88

99
.. tip::
1010

11-
More explicit instructions may be provided within the documentation for each example, and on the command line using the ``-h`` (help) parameter.
11+
The examples all launch the :ref:`dronekit-sitl <dronekit_sitl>` simulator and connect to it by default. The ``--connect`` argument is used to instead specify the :ref:`connection string <get_started_connect_string>` for a target vehicle or an externally managed SITL instance.
12+
13+
To run the examples:
14+
15+
#. :ref:`Install DroneKit-Python <installing_dronekit>` if you have not already done so! Install :ref:`dronekit-sitl <dronekit_sitl>` if you want to test against simulated vehicles.
1216

1317
#. Get the DroneKit-Python example source code onto your local machine. The easiest way to do this
14-
is to clone the **dronekit-python** repository from Github. On the command prompt enter:
18+
is to clone the **dronekit-python** repository from Github.
19+
20+
On the command prompt enter:
1521

1622
.. code-block:: bash
1723
@@ -22,24 +28,28 @@ General instructions for running the `example source code <https://github.com/dr
2228
#. Navigate to the example you wish to run (or specify the full path in the next step). The examples are all stored in
2329
subdirectories of **dronekit-python\\examples\\**.
2430

25-
To run the :ref:`vehicle_state <example-vehicle-state>` example, you would navigate as shown:
31+
For example, to run the :ref:`vehicle_state <example-vehicle-state>` example, you would navigate as shown:
2632

2733
.. code-block:: bash
2834
2935
cd dronekit-python\examples\vehicle_state\
3036
3137
32-
#. Start the example, passing the :ref:`connection string <get_started_connect_string>` you wish to use in the ``--connect`` parameter:
38+
#. Start the example as shown:
3339

34-
.. code-block:: bash
40+
* To connect to a simulator started/managed by the script:
41+
42+
.. code-block:: bash
3543
36-
python vehicle_state.py --connect 127.0.0.1:14550
44+
python vehicle_state.py
3745
38-
.. note::
46+
* To connect to a specific vehicle, pass its :ref:`connection string <get_started_connect_string>` via the ``connect`` argument.
47+
For example, to run the example on Solo you would use the following command:
3948

40-
The examples all use the ``--connect`` parameter to pass the :ref:`connection string <get_started_connect_string>` into the script.
41-
The command above would be used to connect to :ref:`SITL <sitl_setup>` running on the local machine via UDP port 14550.
42-
49+
.. code-block:: bash
50+
51+
python vehicle_state.py --connect udpin:0.0.0.0:14550
52+
4353
4454
.. warning::
4555

0 commit comments

Comments
 (0)