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

ROS2: subscription/service/timer callbacks not being called

asked 2017-10-16 13:23:17 -0600

mjbogusz gravatar image

updated 2017-10-16 15:47:13 -0600


rclcpp::Node-inheriting class registers some subscribers, services and a timer in its constructor; not a single callback is being called (apparently).


I've recently refactored a working (4 nodes, C++) but non-composable code [1] (global function callbacks etc) into rclcpp::Node-inheriting classes, so that they can be run together.

The code structure is just like in demos/examples - nodes pass their names to super constructors, initialize whathever they're responsible for (e.g. sensors) and register subscriptions, services and timers. For running them separately I've created simple entry points just like in the examples - auto node = std::make_shared<NodeClass>(args...) and then rclcpp::spin(node).

Now, while one of the nodes [2] that only publishes data works as intended, the other one [3] that listens for data/requests does not (note that both register a timer!). As you can see in the code, I've added couts in the beggining of every callback function.

The expected behaviour would be some outputs from the node's constructor and at least one output from the timer callback (Loop!), however, the latter does not happen. There's no output from any subscription/service callback either (they're called from a separate control app/node [4]).

I've tried disabling most callbacks to reduce the case to the simplest one, but it didn't solve the issue.

More info

C++ nodes are being run on a BeagleBone Green Wireless, Python node is being run on a x86_64 laptop, both connected to the same WiFi.

In both cases I'm using ROS2 Beta 3 compiled from source.

Entry points

They're located in main.cpp files of their respective packages, right next to the Node class files.

  1. Working node [5] (rclcpp::shutdown() was disabled for testing only)
  2. Not working node [6]



Edit1: added 'Entry points' section and links

edit retag flag offensive close merge delete


It sounds like you're not spinning the nodes, do you have a link to the main function for one of your executables or are you using our composition demo perhaps?

William gravatar image William  ( 2017-10-16 13:52:57 -0600 )edit

They're right next to their respective *Node class files - I've updated the question to include links to them.

mjbogusz gravatar image mjbogusz  ( 2017-10-16 15:48:49 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-16 16:10:53 -0600

William gravatar image

The problem (I think) is that you're subscriptions and timers are only being stored locally, e.g.:

The shared pointers returned from functions like create_subscription are "scoped" meaning that when that returned shared pointer goes out of scope (gets reset or deleted) then the subscription will be removed too. You'll need to keep them as class members to extend their lifetime to that of the class or at least longer than the constructor.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-10-16 13:23:17 -0600

Seen: 2,920 times

Last updated: Oct 16 '17