question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DroneKit has no method for detecting command failure - do we need one?

See original GitHub issue

Currently our instructions suggest that you change the mode like this:

v.mode = VehicleMode("AUTO")
v.flush() # After this, write to vehicle has been made

The problem is that after this code the write has succeeded, but the mode may not actually have been changed (and if you read back v.mode.name it may well be the old name). A better coding paradigm is to not proceed to the next step until all your conditions are met:

print " Get ready to take off" 
v.mode = VehicleMode("AUTO")
v.armed= True
v.flush() # After this, write to vehicle has been made, but no guarantee change succeeded.
while not v.mode.name=='AUTO' and not v.armed==False and not api.exit:
    print " Waiting for AUTO and ARMED..."
    time.sleep(1)
print "Ready to take off"

Note: I will change our docs and examples to show the above.

There are two problems with this. Firstly it involves polling, which I object to on principle. Secondly, this will sit in a loop forever if the arming/mode change fails. This can happen because it is not possible to set modes/armed from certain states. We don’t process the message that tells us if the other commands failed, so there is no way of determining what is going on.

So the question is, can/should we process command failure, and if so how?

The easiest way would probably be to make the flush() api synchronous and wait on responses to all preceding set messages (leaving exception if they fail). I wouldn’t like to do it using callbacks because that is very messy code. We could just live with the code above.

@mrpollo - any ideas?

P.S. Don’t know if it is possible in Python, but .NET does this quite nicely - you can make asynchronous requests and (at some point) wait on the result synchronously. This would allow us to write the code above without polling, and still return a value on failure. This is the problem with spending time in other languages, you learn about things you wish you had 😃

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
zlitecommented, May 18, 2015

Adding Fredia, the Droidplanner/Tower lead, who has been thinking about the same thing. On May 17, 2015 7:33 PM, “ggregory8” notifications@github.com wrote:

Hi, I agree there should be some method to identify whether a command has failed.

Another common example is arming failing. As mentioned above an easy workaround is issuing the command then polling the state until it is set, an timeout would allow you to detect this has failed but is messy also.

Are there currently any functions to handle command acknowledges?

— Reply to this email directly or view it on GitHub https://github.com/diydrones/dronekit-python/issues/114#issuecomment-102899117 .

0reactions
hamishwilleecommented, Apr 11, 2016

Hi @waTeim

It just so happens I’m between contracts 😃 Hence the speed of reply.

So I’ve looked into this topic quite extensively when thinking about creating safe “synchronous” functions for setting attributes - #566 (ie that either return when command has succeeded or raise and exception on failure). The conclusion I’ve come to is that at the moment it is not possible to create robust functions in all cases. It is easy enough in cases like mode changes where the value changes quickly and you can read a value to detect success within a second or so, but not so good for cases like velocity control.

In the case of position, velocity and yaw this is problematic if your changes are rapid so measuring the response takes too long, or if the delta itself is small or within normal deviation for the measured value. You might be able to do it in your specific case, but I haven’t been able to do “generically”.

Is the autopilot capable of processing many things in parallel?

I don’t know. My understanding though is that it does only 2 or three “known things” in parallel - a movement commands and a yaw or gimbal command can be done in parallel. Essentially the autopilot loop runs over incoming messages and sets the target yaw. The system then decides if it is in a state where it can yaw (ie it can only do so after the first movement command has been issued) and then does so.

Hope that helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dronekit/dronekit-python - Gitter
I see a solution as something more like what you mentioned in that pull request: just a method to quickly find out about...
Read more >
DroneKit-Python API Reference
A waypoint object. This object encodes a single mission item command. The set of commands that are supported by ArduPilot in Copter, Plane...
Read more >
Can't Connect to MAVProxy or Dronekit? Do This To Resolve ...
The following guide is a comprehensive checklist of things to do when you have connection issues between your flight controller and your ...
Read more >
Dronekit doesn't connect - Raspbian - Emlid Community Forum
I tried finding a solution on the github dronekit issues ... but the problems others encountered should not be the same with using...
Read more >
Dronekit-Python Error with Raspberrypi4-Ubuntu20.04 ...
In the terminal output that you posted, there is a Timeout exception at the line which reads vehicle = connect('/dev/ttyAMA0', baud=921600, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found