-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create setter functions rather than setting attributes directly #566
base: master
Are you sure you want to change the base?
Conversation
@peterbarker This is the first draft of the API and example code changes required for the attribute setters functions. I still have to update more examples, add test code, and update the docs. Before I do so I want to confirm the new methods are OK. Please review, comment, but don't merge. |
To clarify, no methods or backcompat features should be removed until a theoretical 3.0, in keeping with semver. It makes a good guarantee for end users they can use any 2.x without code breaking. I strongly recommend we drop the |
@tcr3dr Yes, we don't plan on removing any time soon, but certainly updating would be a major version change. That said, I'm not sure that it really conveys what we wanted. Originally I had |
I stand by my original assessment. Unless set_home_location blocks, it can't throw an exception on failure. send_set_mode_message (which I think I had previously suggested) pre-supposes that you are setting modes by sending messages, something which can be hidden from the user. I guess another option is to make "set_home_location" non-void. It returns true if your mode is already what you're trying to set it to. This is going to break down in the cases where you can't tell what the current value actually is.... |
@peterbarker Sure we can't enforce exceptions on fail and we don't even try to in the non waiting mode. But |
@mrpollo Any thoughts on API naming here - Peter and I are in deadlock over the prefix "try_" |
vehicle.try_set_mode(VehicleMode("GUIDED")) | ||
|
||
# Set the mode using a string | ||
vehicle.try_set_mode("STABILIZE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we think a string is a valid option here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? For a user a mode really is just a name.
I agree that we might need to further clarify the interfaces, the def try_set_mode(mode):
# ... retry logic
return set_mode(mode) Ideally we should aim to be more "event" based, while this API is going to clear up lots of confusion when talking back to the autopilot and the expectancy of an immediate result, I'm worried we are also painting a picture of a more linear based programming pattern where we don't need callbacks. I say we go ahead with this change, but we sail carefully when creating more example apps and show the real power of our event based patterns. Great work guys. |
@mrpollo . I take your point. How about we split into two functions - syncrhonous and asyncrhonous. and use those in the name? That works for me, because an asyncronous API is not guarantee to complete. So your code would be:
That is a bit more complicated that the "wait" API, but a lot simpler for users and for testing - and also removes the concern that "just one paradigm here" is overly pushed. |
:param float speed: The target speed. | ||
""" | ||
if wait_ready == True: | ||
raise APIException('try_set_target_groundspeed() must be called with wait_ready=True (False not supported).') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really like this idea
@hamishwillee big delay here, I don't want to use much of your time, but this is a great changeset we should merge, I would say we opt to async as default which means we don't prepend |
@mrpollo Happy to update as you have suggested, but I can't get this back in sync in its current state with the master branch. Cursed git keeps pushing me in circles after rebase. So if you can rebase, I can do the work to fix as discussed? |
@mrpollo Belay that. I did a crappy "normal merge". No idea why rebase was being difficult but back to normal now. |
@mrpollo I've modified the mode setters in the way I believe you wanted. Before I go and roll out to other cases can you confirm that it is what you wanted? Basically there are now two setters:
@peterbarker will not be completely happy but hopefully happy enough. What do you both think? |
On Wed, 13 Apr 2016, Hamish Willee wrote:
:-) "try_set_mode". Wait, where's my ship?
Yes, absolutely. If I set a variable I expect it to be set, damnit! :-)
+1 |
@mrpollo @peterbarker OK, I've updated the methods as discussed, and also the documentation and some tests (I don't plan on adding extra tests for the Please review. If you're OK with this then feel free to merge. |
@mrpollo @peterbarker Any chance to review and merge? I'm not keen to re-merge these changes yet again. |
@peterbarker @mrpollo Can we get these reviewed. VERY OLD CHANGES now, but the original justifications still exist. |
@peterbarker @mrpollo Can we get these reviewed. VERY OLD CHANGES now, but the original justifications still exist. |
This adds setter functions for mode, armed, home_location, airspeed and groundspeed attributes and adds documentation to mark the old attributes as deprecated.
The reason for this change is that the attribute setters have unexpected behaviour (for users) - specifically, setting the value of these attributes does not change the value immediately and may or may not work.
By adding appropriately named setter functions we make it clear that the messages may or may not be received and we've added waiting versions that will make best effort to verify the success of the message.
Overall these methods are safer and easier than the attributes, and reduce the amount of code that developers need to write.
The attribute setters will be removed in a future version.