-
Notifications
You must be signed in to change notification settings - Fork 276
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
Add a convenience function for getting possibly non-existing components. #629
Conversation
Signed-off-by: Martin Pecka <[email protected]>
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.
Thanks for the PR. This is an interesting use case that didn't occur to me before, but thinking of it now it makes sense. It's interesting how similar it is to SetComponentData
but has an important difference.
It initially reminded me of rclcpp::Node::get_parameter_or: "Get the parameter value, or the "alternative_value" if not set, and assign it to "parameter"." (even though that does not "create" (i.e. declare) the parameter if not existent).
And then I remembered sdf::Element::Get, which has pretty much the same behaviour as the function here. So my naming suggestion would be to make this an overload of Component
that accepts a default value.
Thanks for your comment, Louise. If I understood you correctly, adding an overload of I think it might be a bit unintuitive for others, because I myself came to know initializers only recently, but it would allow for calling in the fashion of:
It might be a good compromise between ease of use and compactness. If there are no other ideas, I'll have a look at it over the weekend... |
Good point, I can see how that could make the API a bit less intuitive. I'm not opposed to |
Signed-off-by: Martin Pecka <[email protected]>
Okay, this was actually two weekends, but as no new ideas came, I vouch for the more intuitive API with I applied the style nits. |
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.
Thanks, looks good to me 👍
xref #325 |
* Absolem: Add relative positional control. * Absolem: Added a reference to the issue blocking implementation of the differential. * Absolem: Read flipper velocity and effort limits from the joint limits, too. * Absolem: Preparations for setting max torque in flippers. * Absolem: Simplify interaction with ECM using the new APIs. * Absolem: Added TODO referencing a PR in ign-gazebo that would allow deleting the ECM shim from this package. * Simplify the code with gazebosim/gz-sim#629 .
…ts. (#629) Signed-off-by: Martin Pecka <[email protected]>
…ts. (#629) Signed-off-by: Martin Pecka <[email protected]>
…ts. (#629) Signed-off-by: Martin Pecka <[email protected]>
…ts. (gazebosim#629) Signed-off-by: Martin Pecka <[email protected]> Signed-off-by: Blake McHale <[email protected]>
New feature
Continues in the line of #436 and #378.
Summary
Adds a convenience function
EntityComponentManager::ComponentDefault()
which works asComponent()
, but if the component isn't found, it automatically creates it (using a user-supplied default value).I have an example usage of the function in osrf/subt#551 (which uses a shim until this PR is merged).
I'm not really sure whether
ComponentDefault
is the best name. If you come up with something better, I'll be glad. I was also thinking about adding optional parameters toComponent()
function, but that would actually need two of them - one boolean saying whether the component should be auto-constructed, and then the supplied default value. I felt that wouldn't really be nice to use and it would be less self-descriptive than having a function whose name explicitly states that it can auto-create the component if needed.Test it
A unit test was added.
Checklist
codecheck
passed (See contributing)another open pull request
to support the maintainers
Note to maintainers: Remember to use Squash-Merge