-
Notifications
You must be signed in to change notification settings - Fork 413
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
template node type for rclcpp action server and clients #892
Conversation
Signed-off-by: stevemacenski <stevenmacenski@gmail.com>
Why not templating it to any pointer type? There is a type trait within rcpputils which could be used for a static assert. EDIT: Also I feel the tests should be enhanced to actually create a actionclient/server from a node constructor. |
@Karsten1987 looking across the repo, all instances I can find of node and message type templating are all base types that are later called with A few examples:
rclcpp/rclcpp/include/rclcpp/executor.hpp Line 169 in dfb144d
Similarly, I'm not seeing anywhere in here doing a Similar statements for the I'm trying to resolve the missing feature of |
+1 for a more generic template type. E.g. similar to rclcpp/rclcpp/include/rclcpp/create_publisher.hpp Lines 37 to 50 in 8e69b7d
Which passes the node to rclcpp/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp Lines 120 to 124 in 8e69b7d
rclcpp/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp Lines 133 to 138 in 8e69b7d
Assuming the proper template functions already exist for the various interfaces, we should be able to make the change: - rclcpp::Node::SharedPtr node,
+ NodeT node And you can default I haven't tried it, but maybe we have to use free functions for getting the interfaces instead of the node methods (edit: I think we certainly will if we also want to support passing nodes by reference), e.g. get_node_base_interface(node); instead of node->get_node_base_interface(); |
@jacobperron I've read that a few times and I'm not entirely certain if you're suggesting a change or expressing a line of thought. Is there something specific you'd like me to do? I'm hearing maybe change from I intentionally didn't template the |
Sorry, I guess it was a bit of both. I'm no wizard with templates, but I would expect the following definition to work not only for shared pointers, but a variety of pointer and reference types for node-like objects (ie. objects that implement the required node interfaces): template<typename ActionT, typename NodeT>
typename Client<ActionT>::SharedPtr
create_client(
NodeT node,
const std::string & name,
rclcpp::callback_group::CallbackGroup::SharedPtr group = nullptr)
{
return create_client<ActionT>(
rclcpp::node_interfaces::get_node_base_interface(node),
rclcpp::node_interfaces::get_node_graph_interface(node),
rclcpp::node_interfaces::get_node_logging_interface(node),
rclcpp::node_interfaces::get_node_waitables_interface(node),
name,
group);
} Then, I think template argument deduction will make it so we don't need to worry about specifying the template type. E.g. // 'node' is a node-like thing that could be a pointer or passed in by reference
auto client = rclcpp_action::create_client<MyAction>(node, "action_name"); I'd like to see the |
I just realized that to do what I proposed requires the existence of the following functions:
I guess we could add those missing free functions. |
I leave it up to you, if you feel that's necessary to merge this I can take a crack at it. I wanted to get this in before the Friday freeze so I scoped it pretty low. I can file a ticket to implement the other free methods and revisit this topic as well at a later time. I am also not a templating wizard, but I'm willing to try to become one ;-) |
Alright cool sounds like I have the concrete action items 👍 |
Signed-off-by: stevemacenski <stevenmacenski@gmail.com>
@jacobperron changes made. Everything seems to be fine. CI failures unreleased to this |
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.
LGTM, just one last nitpick.
Signed-off-by: stevemacenski <stevenmacenski@gmail.com>
Real stickler. I like it. This should be squashed now with these many small commits |
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.
@SteveMacenski Thanks for iterating!
I think the PR CI jobs will continue to fail until the latest changes in rclcpp are released into Eloquent.
I'll trigger CI manually:
Note, I expect some pub/sub communication tests to fail due to a known issue.
We typically do a squash merge 👍 |
Addresses #846and has therclcpp::Node
as the default template argument so it shouldn't break users of it.I'd add a second test to work with lifecycle nodes, but I didn't want to add lifecycle as a dependency to actions.