Ask Your Question

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:


as in

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

or I could also use

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

2 Answers

Sort by ยป oldest newest most voted

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"? (

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:

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

Like this:

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

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

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

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


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 ( 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

Your Answer

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

Add Answer

Question Tools



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

Seen: 1,017 times

Last updated: Feb 12 '20