dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.59k stars 1.44k forks source link

Improve DroneKit-Python Debugging #118

Open hamishwillee opened 9 years ago

hamishwillee commented 9 years ago

DroneKit-Python currently allows debugging using print/log statements and with the command line pdb debugger. It is not particularly easy to use because the console interleaves MAVProxy messages and script print output with the debugging information. In addition, there is no way to launch the script in debug mode - the script has to be modified to include statements that start the debugger once it is running.

We would like to improve the debugging experience. Some ideas include:

Ideas/suggestions/implementations welcome.

tcr3dr commented 8 years ago

We can use pdb now. I'm not sure how in-depth to go with this, but python -m pdb my_dronekit_script.py lets you debug code straightforwardly.

hamishwillee commented 8 years ago

Thanks! I'll have a play with this at some point soon. In the meantime I'll make a small modification to remove any statements related to the old situation.

@tcr3dr One thing, is any logging done automatically? A lot of times on SITL my system is sitting around not arming for no apparent reason. If I was user I'd be a bit clueless on the cause when I got the system back - what would be nice is to be able to get my normal console output. What's the "right thing" to say here.here?

hamishwillee commented 8 years ago

410 fixes this - basically makes it clear that debugging DK-Python is the same as any other debugging task. It uses the example of pdb though.

Before I close this, would appreciate response about logging - https://github.com/dronekit/dronekit-python/issues/118#issuecomment-153257402 . Maybe we should mention the mav data logs at least.

tcr3dr commented 8 years ago

@tcr3dr One thing, is any logging done automatically? A lot of times on SITL my system is sitting around not arming for no apparent reason. If I was user I'd be a bit clueless on the cause when I got the system back - what would be nice is to be able to get my normal console output. What's the "right thing" to say here?

Are you referring to logging done by MAVProxy in this case? I assumed that is usually what is spit out by SYSTEM_TEXT which we print out by default via >>> ...

I'm not too sure what to recommend programmatically, since there are no logs which we can monitor. One handy mechanism would be just watching specific values, which may be a useful abstraction:

@vehicle.on_attribute('armed')
def listener(vehicle, name):
    print '>>> Vehicle arm status: %' % vehicle.armed

Have any ideas?

mrpollo commented 8 years ago

@tcr3dr if this is for development, why not launch a MAVProxy instance just to listen?

tcr3dr commented 8 years ago

If that works, sure.

hamishwillee commented 8 years ago

@tcr3dr @mrpollo So this was a very general question: "What logging is recommended".

When I watch an example on SITL sometimes a script will randomly fail - perhaps it takes off but then does not head towards a waypoint. Other times it might not arm, or it might arm, not take off and then disarm. The same code works next time I run it.

Now on SITL I see that on the console, but how can I observe the DK output when connected to a real device:

Nothing will piss me off more than the drone simply sitting there, and no log information being available.

So essentially I'm looking at best way to do post morten debugging and live debugging of what a script is doing on a real device. Thoughts?