34 |
35 | {% include 'bottom-scripts.html' %}
36 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/dronekit/test/sitl/test_110.py:
--------------------------------------------------------------------------------
1 | import time
2 | from dronekit import connect, VehicleMode
3 | from dronekit.test import with_sitl, wait_for
4 | from nose.tools import assert_equals
5 |
6 |
7 | @with_sitl
8 | def test_110(connpath):
9 | vehicle = connect(connpath, wait_ready=True)
10 |
11 | # NOTE these are *very inappropriate settings*
12 | # to make on a real vehicle. They are leveraged
13 | # exclusively for simulation. Take heed!!!
14 | vehicle.parameters['FS_GCS_ENABLE'] = 0
15 | vehicle.parameters['FS_EKF_THRESH'] = 100
16 |
17 | # Await armability.
18 | wait_for(lambda: vehicle.is_armable, 60)
19 |
20 | # Change the vehicle into STABILIZE mode
21 | vehicle.mode = VehicleMode("GUIDED")
22 |
23 | # NOTE wait crudely for ACK on mode update
24 | time.sleep(3)
25 |
26 | # Define example callback for mode
27 | def armed_callback(vehicle, attribute, value):
28 | armed_callback.called += 1
29 |
30 | armed_callback.called = 0
31 |
32 | # When the same (event, callback) pair is passed to add_attribute_listener,
33 | # only one instance of the observer callback should be added.
34 | vehicle.add_attribute_listener('armed', armed_callback)
35 | vehicle.add_attribute_listener('armed', armed_callback)
36 | vehicle.add_attribute_listener('armed', armed_callback)
37 | vehicle.add_attribute_listener('armed', armed_callback)
38 | vehicle.add_attribute_listener('armed', armed_callback)
39 |
40 | # arm and see update.
41 | vehicle.armed = True
42 |
43 | # Wait for ACK.
44 | time_max = 10
45 | wait_for(lambda: armed_callback.called, time_max)
46 |
47 | # Ensure the callback was called.
48 | assert armed_callback.called > 0, "Callback should have been called within %d seconds" % (time_max,)
49 |
50 | # Rmove all listeners. The first call should remove all listeners
51 | # we've added; the second call should be ignored and not throw.
52 | # NOTE: We test if armed_callback were treating adding each additional callback
53 | # and remove_attribute_listener were removing them one at a time; in this
54 | # case, there would be three callbacks still attached.
55 | vehicle.remove_attribute_listener('armed', armed_callback)
56 | vehicle.remove_attribute_listener('armed', armed_callback)
57 | callcount = armed_callback.called
58 |
59 | # Disarm and see update.
60 | vehicle.armed = False
61 |
62 | # Wait for ack
63 | time.sleep(3)
64 |
65 | # Ensure the callback was called zero times.
66 | assert_equals(armed_callback.called, callcount,
67 | "Callback should not have been called once removed.")
68 |
69 | vehicle.close()
70 |
--------------------------------------------------------------------------------
/docs/guide/debugging.rst:
--------------------------------------------------------------------------------
1 | .. _debugging:
2 |
3 | =========
4 | Debugging
5 | =========
6 |
7 | DroneKit-Python apps can be debugged in the same way as any other standalone Python scripts.
8 | The sections below outline a few methods.
9 |
10 |
11 |
12 | pdb - The Python Debugger
13 | =========================
14 |
15 | The `Python Debugger - pdb `_ can be used to debug *DroneKit-Python* apps.
16 |
17 | The command below can be used to run a script in debug mode:
18 |
19 | .. code-block:: bash
20 |
21 | python -m pdb my_dronekit_script.py
22 |
23 | You can also instrument your code to invoke the debugger at a certain point. To do this
24 | add ``set-trace()`` at the point where you want to break execution:
25 |
26 | .. code-block:: python
27 | :emphasize-lines: 4
28 |
29 | # Connect to the Vehicle on udp at 127.0.0.1:14550
30 | vehicle = connect('127.0.0.1:14550', wait_ready=True)
31 |
32 | import pdb; pdb.set_trace()
33 | print "Global Location: %s" % vehicle.location.global_frame
34 |
35 |
36 | The available `debugger commands are listed here `_.
37 |
38 | pudb - A full-screen, console-based Python debugger
39 | ===================================================
40 |
41 | If you prefer a IDE like debug you can use `pudb - A full-screen, console-based Python debugger `_.
42 |
43 | .. code-block:: python
44 | :emphasize-lines: 4
45 |
46 | pip install pudb
47 |
48 |
49 | To start debugging, simply insert:
50 |
51 | .. code-block:: python
52 | :emphasize-lines: 4
53 |
54 | from pudb import set_trace; set_trace()
55 |
56 | Insert either of these snippets into the piece of code you want to debug, or run the entire script with:
57 |
58 | .. code-block:: python
59 | :emphasize-lines: 4
60 |
61 | pudb my-script.py
62 |
63 |
64 | Print/log statements
65 | ====================
66 |
67 | The simplest and most common method of debugging is to manually add debug/print statements to the source.
68 |
69 | .. code-block:: python
70 | :emphasize-lines: 4
71 |
72 | # Connect to the Vehicle on udp at 127.0.0.1:14550
73 | vehicle = connect('127.0.0.1:14550', wait_ready=True)
74 |
75 | # print out debug information
76 | print "Global Location: %s" % vehicle.location.global_frame
77 |
78 | In addition to printing DroneKit variables, Python provides numerous inbuilt and add-on modules/methods
79 | for inspecting code (e.g. `dir() `_, `traceback `_, etc.)
80 |
81 |
82 | Other IDEs/debuggers
83 | ====================
84 |
85 | There is no reason you should not be able to straightforwardly use other popular Python IDEs including IDLE and Eclipse.
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/examples/drone_delivery/html/track.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {% include 'head.html' %}
5 |
6 |
7 |