Skip to content

Commit 1b47dab

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 6951a3a + eda039f commit 1b47dab

40 files changed

+966
-312
lines changed

docs/examples/drone_delivery.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Looking at the code
5252
Using attribute observers
5353
-------------------------
5454

55-
All attributes in DroneKit can have observers - this is the primary mechanism you should use to be notified of changes in vehicle state. For instance, `drone_delivery.py <https://github.com/diydrones/droneapi-python/blob/master/example/drone_delivery/drone_delivery.py>`_ calls:
55+
All attributes in DroneKit can have observers - this is the primary mechanism you should use to be notified of changes in vehicle state. For instance, `drone_delivery.py <https://github.com/diydrones/droneapi-python/blob/master/examples/drone_delivery/drone_delivery.py>`_ calls:
5656

5757
::
5858

@@ -84,7 +84,7 @@ Next we'll look at the basics of using the webservice and the local vehicle API
8484
Source code
8585
===========
8686

87-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/example/drone_delivery/drone_delivery.py>`_):
87+
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/examples/drone_delivery/drone_delivery.py>`_):
8888

89-
.. include:: ../../example/drone_delivery/drone_delivery.py
89+
.. include:: ../../examples/drone_delivery/drone_delivery.py
9090
:literal:

docs/examples/flight_replay.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ In this case, we pick some public flight from `Droneshare <http://www.droneshare
1414

1515
You'll notice that the mission number for this flight is 101.
1616

17-
Now we'll launch **flight_replay.py** (/example/flight_replay/flight_replay.py) and ask it to try and 'replay' mission 101. It will ask the web server for representative points from the flight, parse the JSON response and use that data to generate 100 waypoints we would like our vehicle to hit. For safety rather than using the altitude from the original flight we instead ask our vehicle to fly at a height of 30 meters.
17+
Now we'll launch **flight_replay.py** (/examples/flight_replay/flight_replay.py) and ask it to try and 'replay' mission 101. It will ask the web server for representative points from the flight, parse the JSON response and use that data to generate 100 waypoints we would like our vehicle to hit. For safety rather than using the altitude from the original flight we instead ask our vehicle to fly at a height of 30 meters.
1818

1919
One possible use of some variant of this tool to replay your old flights at your regular test field.
2020

@@ -57,7 +57,7 @@ The following simple function asks for the droneshare flight data:
5757
Some comments:
5858

5959
* ``max_freq`` is used to throttle the messages found in the raw flight data to a lower message rate
60-
* ``_decode_dict`` is a utility function found on stack overflow which extracts usable strings from unicode encoded JSON (see `flight_replay.py <https://github.com/hamishwillee/dronekit-python/blob/master/example/flight_replay/flight_replay.py>`_ for its implementation).
60+
* ``_decode_dict`` is a utility function found on stack overflow which extracts usable strings from unicode encoded JSON (see `flight_replay.py <https://github.com/hamishwillee/dronekit-python/blob/master/examples/flight_replay/flight_replay.py>`_ for its implementation).
6161

6262

6363
Setting the new waypoints
@@ -94,7 +94,7 @@ Next we'll work with existing Linux services (gpsd) to add a new drone based fea
9494
Source code
9595
===========
9696

97-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/example/flight_replay/flight_replay.py>`_):
97+
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/examples/flight_replay/flight_replay.py>`_):
9898

99-
.. include:: ../../example/flight_replay/flight_replay.py
99+
.. include:: ../../examples/flight_replay/flight_replay.py
100100
:literal:

docs/examples/follow_me.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Before running this demo you'll need to make sure your computer has the gpsd ser
1818
1919
apt-get install gpsd gpsd-clients
2020
21-
You can then plug in a USB GPS and run the "xgps" client to confirm that it is working. If you do not have a USB GPS you can use simulated data by running *droneapi-python/example/run-fake-gps.sh*.
21+
You can then plug in a USB GPS and run the "xgps" client to confirm that it is working. If you do not have a USB GPS you can use simulated data by running *droneapi-python/examples/run-fake-gps.sh*.
2222

2323
Once your GPS is plugged in you can start follow-me by running the following command inside of MAVProxy:
2424

@@ -42,7 +42,7 @@ Next, take a look at the full :ref:`api_reference` for more information.
4242
Source code
4343
===========
4444

45-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/example/follow_me/follow_me.py>`_):
45+
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/examples/follow_me/follow_me.py>`_):
4646

47-
.. include:: ../../example/follow_me/follow_me.py
47+
.. include:: ../../examples/follow_me/follow_me.py
4848
:literal:

docs/examples/guided-set-speed-yaw-demo.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Once MAVProxy is running and the API is loaded, you can run the example by typin
2525
If you started the DroneKit MAVProxy prompt in a directory containing the example script you can start it using:
2626
``api start guided_set_speed_yaw.py``.
2727
Otherwise you may have to specify the full path (something like):
28-
``api start /home/user/git/dronekit-python/example/guided_set_speed_yaw/guided_set_speed_yaw.py``.
28+
``api start /home/user/git/dronekit-python/examples/guided_set_speed_yaw/guided_set_speed_yaw.py``.
2929

3030
The program will automatically arm the vehicle and start the demo. First it waits for a GPS lock
3131
(``Waiting for GPS...``), then to receive a location update (``Waiting for location...``) and finally
@@ -49,7 +49,7 @@ After starting the simulator, the console output should look something like:
4949
-> module load droneapi.module.api
5050
DroneAPI loaded
5151
Loaded module droneapi.module.api
52-
-> api start /home/user/git/dronekit-python/example/guided_set_speed_yaw/guided_set_speed_yaw.py
52+
-> api start /home/user/git/dronekit-python/examples/guided_set_speed_yaw/guided_set_speed_yaw.py
5353
Waiting for GPS...
5454
Loaded module console
5555
Loaded module map
@@ -198,7 +198,7 @@ At the time of writing, the acceleration and yaw parameters of
198198
Source code
199199
===========
200200

201-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/example/guided_set_speed_yaw/guided_set_speed_yaw.py>`_):
201+
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/examples/guided_set_speed_yaw/guided_set_speed_yaw.py>`_):
202202

203-
.. include:: ../../example/guided_set_speed_yaw/guided_set_speed_yaw.py
203+
.. include:: ../../examples/guided_set_speed_yaw/guided_set_speed_yaw.py
204204
:literal:

docs/examples/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ during missions and outside missions using custom commands.
1313
:maxdepth: 1
1414

1515
running_examples
16+
Vehicle State <vehicle_state>
1617
Simple Goto <simple_goto>
1718
Follow Me (Linux only)<follow_me>
1819
Drone Delivery <drone_delivery>

docs/examples/running_examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The easiest way to get the DroneKit example source code is to clone the **dronek
1717
1818
git clone http://github.com/diydrones/droneapi-python.git
1919
20-
The examples are stored in the subdirectories of **/dronekit-python/example/**.
20+
The examples are stored in the subdirectories of **/dronekit-python/examples/**.
2121

2222

2323

docs/examples/simple_goto.rst

Lines changed: 116 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,139 @@
1-
========================
2-
Example: Simple Go To
3-
========================
1+
.. _example_simple_goto:
42

5-
This little demonstration just tells the vehicle to fly to a couple of different locations in the world. You can edit the code to pick a latitude and longitude close to your position.
3+
==============================
4+
Example: Simple Go To (Copter)
5+
==============================
66

7-
Running the example
8-
===================
7+
This example demonstrates how to arm and launch a Copter in GUIDED mode, travel to a number of waypoints, and then return
8+
to the home location. It uses :py:func:`Vehicle.commands.takeoff() <droneapi.lib.CommandSequence.takeoff>`,
9+
:py:func:`Vehicle.commands.goto() <droneapi.lib.CommandSequence.goto>` and :py:attr:`Vehicle.mode <droneapi.lib.Vehicle.mode>`.
10+
11+
The locations used are centred around the home location when the :ref:`Simulated Vehicle <vagrant-sitl-from-full-image>` is booted; you can edit the latitude and longitude
12+
to use more appropriate positions for your own vehicle.
13+
14+
.. note::
915

10-
Once Mavproxy is running and the API is loaded, you can run this small example by typing: ``api start simple_goto.py``
16+
This example will only run on *Copter*:
1117

12-
It will tell your vehicle to start flying to a particular latitude and longitude stored in the file (though for safety the take-off command is not included - you must manually tell vehicle to fly). On the mavproxy console you should see:
18+
* *Plane* does not support ``takeoff`` in GUIDED mode.
19+
* *Rover* will ignore the ``takeoff`` command and will then stick at the altitude check.
20+
1321

14-
::
1522

16-
STABILIZE> api start simple_goto.py
17-
STABILIZE> Got MAVLink msg: MISSION_ACK {target_system : 255, target_component : 0, type : 0}
18-
GUIDED> Mode GUIDED
19-
APIThread-0 exiting...
20-
Got MAVLink msg: MISSION_ACK {target_system : 255, target_component : 0, type : 0}
23+
Running the example
24+
===================
25+
26+
The vehicle and DroneKit should be set up as described in the :ref:`quick-start` or :ref:`get-started`.
27+
28+
If you're using a simulated vehicle, remember to :ref:`disable arming checks <disable-arming-checks>` so
29+
that the example can run.
30+
31+
Once MAVProxy is running and the API is loaded, you can start the example by typing: ``api start simple_goto.py``.
32+
33+
.. note::
34+
35+
The command above assumes you started the *MAVProxy* prompt in a directory containing the example script. If not,
36+
you will have to specify the full path to the script (something like):
37+
``api start /home/user/git/dronekit-python/examples/simple_goto/simple_goto.py``.
38+
39+
.. tip::
40+
41+
It is more interesting to watch the example above on a map than the console. The topic :ref:`viewing_uav_on_map`
42+
explains how to set up *Mission Planner* to view a vehicle running on the simulator (SITL).
43+
44+
On the *MAVProxy* console you should see (something like):
45+
46+
.. code-block:: python
47+
48+
MAV> api start simple_goto.py
49+
STABILIZE> Basic pre-arm checks
50+
Arming motors
51+
Waiting for arming...
52+
Waiting for arming...
53+
APM: ARMING MOTORS
54+
APM: GROUND START
55+
Waiting for arming...
56+
Waiting for arming...
57+
GUIDED> Mode GUIDED
58+
APM: Initialising APM...
59+
Got MAVLink msg: COMMAND_ACK {command : 400, result : 0}
60+
Waiting for arming...
61+
ARMED
62+
Taking off!
63+
Altitude: 0.0
64+
Got MAVLink msg: COMMAND_ACK {command : 22, result : 0}
65+
Altitude: 0.10000000149
66+
Altitude: 0.620000004768
67+
...
68+
Altitude: 19.25
69+
Reached target altitude
70+
Going to first point...
71+
Got MAVLink msg: MISSION_ACK {target_system : 255, target_component : 0, type : 0}
72+
Going to second point...
73+
Got MAVLink msg: MISSION_ACK {target_system : 255, target_component : 0, type : 0}
74+
Returning to Launch
75+
APIThread-0 exiting...
76+
77+
.. tip::
78+
79+
If you get stuck in ``Waiting for arming...`` it is very likely that the vehicle did not pass all pre-arm checks.
80+
On a real device you can view the controller LEDs to determine likely issues. On the Simulator console you
81+
can disable the checks if needed:
82+
83+
.. code-block:: bash
84+
85+
STABILIZE>param load ../Tools/autotest/copter_params.parm
86+
STABILIZE>param set ARMING_CHECK 0
2187
2288
2389
How does it work?
2490
=================
2591
26-
The key code in this demo is the following:
92+
The code has three distinct sections: arming and takeoff, flight to a specified location, and return-to-home.
93+
94+
Takeoff
95+
-------
96+
97+
To launch *Copter* you need to set the mode to ``GUIDED``, arm the vehicle, and then call
98+
:py:func:`Vehicle.commands.takeoff() <droneapi.lib.CommandSequence.takeoff>`. The takeoff code in this example
99+
is explained in the guide topic :ref:`taking-off`.
100+
101+
102+
Flying to a point - Goto
103+
------------------------
104+
105+
The vehicle is already in ``GUIDED`` mode, so to send it to a certain point we just need to
106+
call :py:func:`Vehicle.commands.goto() <droneapi.lib.CommandSequence.goto>` with the target location,
107+
and then :py:func:`flush() <droneapi.lib.Vehicle.flush>` the command:
108+
109+
.. code-block:: python
110+
111+
point1 = Location(-35.361354, 149.165218, 20, is_relative=True)
112+
vehicle.commands.goto(point1)
113+
vehicle.flush()
114+
115+
# sleep so we can see the change in map
116+
time.sleep(30)
27117
28-
::
118+
Without some sort of "wait" the next command would be executed immediately. In this example we just
119+
sleep for 30 seconds - a good opportunity to observe the vehicle's movement on a map.
29120
30-
vehicle.mode = VehicleMode("GUIDED")
31-
origin = Location(-34.364114, 149.166022, 30, is_relative=True)
32121
33-
commands.goto(origin)
34-
vehicle.flush()
122+
RTL - Return to launch
123+
------------------------
35124
36-
It tells the vehicle to fly to a specified lat/long and hover at that location (30 meters in the air). ``is_relative=True`` is the default and is recommended - it means that the altitude (30 meters) is *relative* to the vehicle home location. If you had set ``is_relative`` to ``false``, it would have told the vehicle to fly to a specified mean-sea-level which is probably not what you want unless you are next to an ocean.
125+
To return to the home position and land, we set the mode to ``RTL``:
37126
127+
.. code-block:: python
38128
39-
Building on the basic vehicle control you just learned, we now show how to write a small web application that allows you to command a drone to fly to a particular location.
129+
vehicle.mode = VehicleMode("RTL")
130+
vehicle.flush()
40131
41132
42133
Source code
43134
===========
44135
45-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/example/simple_goto/simple_goto.py>`_):
136+
The full source code at documentation build-time is listed below (`current version on github <https://github.com/diydrones/dronekit-python/blob/master/examples/simple_goto/simple_goto.py>`_):
46137
47-
.. include:: ../../example/simple_goto/simple_goto.py
48-
:literal:
138+
.. literalinclude:: ../../examples/simple_goto/simple_goto.py
139+
:language: python

0 commit comments

Comments
 (0)