DroneKit has no method for detecting command failure - do we need one?
See original GitHub issueCurrently 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:
- Created 8 years ago
- Comments:18 (10 by maintainers)
Top GitHub Comments
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 @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”.
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.