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

What is the rclcpp::node_interfaces::NodeBaseInterface for?

asked 2020-02-12 12:09:46 -0500

ignacio gravatar image

updated 2020-02-12 17:07:45 -0500

This question came up for not knowing when I should run spin using node or node_base_interface. Perhaps answering when to use node_base_interface might help too.

In C++, it seems that I may use spin with:

RCLCPP_LIFECYCLE_PUBLIC
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
get_node_base_interface();

as in

rclcpp::executors::SingleThreadedExecutor exe;
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> node = std::make_shared<SomeClass>();
exe.spin_node_some(node->get_node_base_interface());

or I could also use

std::shared_ptr<rclcpp::Node> node = std::make_shared<SomeClass>();
exe.spin_node_some(node);
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2020-02-12 15:50:58 -0500

William gravatar image

Please add more context to your questions in the future. There's no links to which functions you're talking about, no mention of which language you're using nor what your use case is (what it is that you were trying to accomplish when you ran into this).


I guess you mean "what is the rclcpp::node_interfaces::NodeBaseInterfacefor"? (https://github.com/ros2/rclcpp/blob/7...)

The rclcpp::Node class has lots of functionality in it, and that functionality is broken into a few pieces to make testing easier (mocking the "node base interface" is a lot easier than mocking the entire node interface) and to make supporting new kinds of nodes easier (the rclcpp_lifecycle::LifecycleNode is similar but different from the rclcpp::Node). The NodeBaseInterface has the most basic functionality of a node in it, like getting the node name or namespace, etc...

This question came up for not knowing when I should run spin using node or node_base_interface.

Again, guessing since there's no links, I guess you mean these functions:

https://github.com/ros2/rclcpp/blob/7...

You should always just use the second signature, which takes a rclcpp::Node, if possible.

Like this:

auto node = std::make_shared<rclcpp::Node>(...);
rclcpp::spin(node);

As is the case in the examples and demos, e.g.:

https://github.com/ros2/examples/blob...


However, if you are using something other than rclcpp::Node which provides a NodeBaseInterface pointer, then you may use the second signature, but this should only be exceptional cases, and normal users should never need to interact with any of the interfaces under normal circumstances. There are still cases where this isn't true, but we're working towards eliminating those cases.

edit flag offensive delete link more
1

answered 2020-02-12 15:34:01 -0500

Hi,

I know this topic is large and can be relatively confusing, but, rclcpp nodes have a bunch of interfaces. They're around for things like loggers, clocks, graph, etc (https://github.com/ros2/rclcpp/tree/m...) to allow extensions to be created in the future or switch out methods.

The node base interface is one such interface that alot of the implementations require to do their job. Its one of the common building blocks that allow a ROS node to function. When you throw this to an executor (or spin), that's the thing that's going to spin to allow processing of callbacks.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-02-12 12:09:46 -0500

Seen: 2,381 times

Last updated: Feb 12 '20