dronekit-python/docs/guide/debugging.rst at master · flatlevel/dronekit-python · GitHub
Skip to content

Latest commit

 

History

History
89 lines (49 loc) · 2.44 KB

File metadata and controls

89 lines (49 loc) · 2.44 KB

Debugging

DroneKit-Python apps can be debugged in the same way as any other standalone Python scripts. The sections below outline a few methods.

pdb - The Python Debugger

The Python Debugger - pdb can be used to debug DroneKit-Python apps.

The command below can be used to run a script in debug mode:

python -m pdb my_dronekit_script.py

You can also instrument your code to invoke the debugger at a certain point. To do this add set-trace() at the point where you want to break execution:

# Connect to the Vehicle on udp at 127.0.0.1:14550
vehicle = connect('127.0.0.1:14550', wait_ready=True)

import pdb; pdb.set_trace()
print "Global Location: %s" % vehicle.location.global_frame

The available debugger commands are listed here.

pudb - A full-screen, console-based Python debugger

If you prefer a IDE like debug you can use pudb - A full-screen, console-based Python debugger.

pip install pudb

To start debugging, simply insert:

from pudb import set_trace; set_trace()

Insert either of these snippets into the piece of code you want to debug, or run the entire script with:

pudb my-script.py

Print/log statements

The simplest and most common method of debugging is to manually add debug/print statements to the source.

# Connect to the Vehicle on udp at 127.0.0.1:14550
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# print out debug information
print "Global Location: %s" % vehicle.location.global_frame

In addition to printing DroneKit variables, Python provides numerous inbuilt and add-on modules/methods for inspecting code (e.g. dir(), traceback, etc.)

Other IDEs/debuggers

There is no reason you should not be able to straightforwardly use other popular Python IDEs including IDLE and Eclipse.