Ask Your Question
0

get ROS 2 nodehandle in case of composed nodes

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

Skyking gravatar image

Hello All,

Suppose I am using a Composed node as mentioned in this example(https://github.com/ros2/demos/blob/master/composition/src/talker_component.cpp). 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
0

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

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

Comments

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 imageSkyking ( 2018-09-17 08:04:11 -0600 )edit

You can use https://en.cppreference.com/w/cpp/mem... 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 imageWilliam ( 2018-09-17 11:51:52 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 269 times

Last updated: Jun 29 '18