ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

get ROS 2 nodehandle in case of composed nodes

asked 2018-06-29 00:57:00 -0500

Skyking gravatar image

Hello All,

Suppose I am using a Composed node as mentioned in this example( Now I need to pass a rclcpp::Node::SharedPtr of this composed Node to another class. In case of ROS 1 nodeletes, this can be done using getNodeHandle(). Is there any similar way of doing this in ROS 2 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-29 16:24:03 -0500

dhood gravatar image

Depending on what you need it for, you might be looking for get_node_base_interface() and/or one of the other interfaces an rclcpp Node has: there's more context around them in this PR.

We don't use that function in many of our ROS 2 demos but this is one example (others are in rclcpp's testing code).

edit flag offensive delete link more


get_node_base_interface() is fine for node spinning, but what if I want to use the get_parameter() functionality of the rclcpp::Node class ?

My intention is that I create a composable ros2 Node class and I want to pass the shared_ptr of that Node class as an argument to another object inside it.

Skyking gravatar image Skyking  ( 2018-09-17 08:04:11 -0500 )edit

You can use since the Node class inherits from it already. But you can also get each interface you want and pass those (more flexible), e.g. get_node_parameter_interface().

William gravatar image William  ( 2018-09-17 11:51:52 -0500 )edit

Question Tools



Asked: 2018-06-29 00:57:00 -0500

Seen: 3,003 times

Last updated: Jun 29 '18