DroneKit-Python apps are run in the context of a MAVProxy console. This can make debugging more challenging:
That said, it is possible to effectively debug DroneKit apps. The main methods are discussed below.
We are actively working to improve debugging on DroneKit-Python! You can track progress and suggestions on Github Issue #118.
The simplest and most common method of debugging is to manually add debug/print statements to the source.
# Get the vehicle api = local_connect() vehicle = api.get_vehicles() # print out debug information print "Location: %s" % vehicle.location
The Python Debugger - pdb can be used to debug DroneKit-Python apps.
To start debugging, add
set-trace() at the point where you want to break execution (as shown below):
# Get the vehicle api = local_connect() vehicle = api.get_vehicles() import pdb; pdb.set_trace() print "Location: %s" % v.location
When you run the app, the code will stop at the marked line:
MAV> api start small_demo.py AUTO> > c:\users\hamis_000\documents\vagranttesting\tmpdeleteme\small_demo.py(20)<module>() -> print "Location: %s" % v.location
Press Enter to bring up the (Pdb) prompt. This is where you can enter the commands to step through the code, show stack traces, etc. For example the console output below shows the w command being used to output the current stack trace.
AUTO> (Pdb) w c:\users\hamis_000\downloads\winpython-64bit-126.96.36.199\python-2.7.6.amd64\lib\threading.py(783)__bootstrap() cAUTO> :\users\hamis_000\downloads\winpython-64bit-188.8.131.52\python-2.7.6.amd64\lib\site-packages\droneapi\module\api.py(321)run() -> self.fn()amis_000\downloads\winpython-64bit-184.108.40.206\python-2.7.6.amd64\lib\threading.py(810)__bootstrap_inner() c:\users\hamis_000\downloads\winpython-64bit-220.127.116.11\python-2.7.6.amd64\lib\site-packages\droneapi\module\api.py(592)<lambda>() -> APIThread(self, lambda: execfile(args, g), args)
Pdb commands must be entered in the (Pdb) prompt. If you press “Enter” in an empty prompt the previous command will be called again. This is helpful if you want to s (step) through every line of code.