0
$\begingroup$

Rosanswers logo

TL;DR:

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

Details

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]

Refs

  1. https://github.com/GroupOfRobots/RysROS2/tree/master/src/rys_base
  2. https://github.com/GroupOfRobots/RysROS2/blob/master/src/rys_base/sensor_vl53l0x/src/VL53L0XNode.cpp
  3. https://github.com/GroupOfRobots/RysROS2/blob/master/src/rys_base/motors_controller/src/MotorsControllerNode.cpp
  4. https://github.com/GroupOfRobots/RysROS2/tree/master/src/rys_remote
  5. https://github.com/GroupOfRobots/RysROS2/blob/master/src/rys_base/sensor_vl53l0x/src/main.cpp
  6. https://github.com/GroupOfRobots/RysROS2/blob/master/src/rys_base/motors_controller/src/main.cpp

Edit1: added 'Entry points' section and links


Originally posted by mjbogusz on ROS Answers with karma: 25 on 2017-10-16

Post score: 0


Original comments

Comment by William on 2017-10-16:
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?

Comment by mjbogusz on 2017-10-16:
They're right next to their respective *Node class files - I've updated the question to include links to them.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

https://github.com/GroupOfRobots/RysROS2/blob/1f70d137c5280ea35da5b426d92083129e935225/src/rys_base/motors_controller/src/MotorsControllerNode.cpp#L48-L58

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.


Originally posted by William with karma: 17335 on 2017-10-16

This answer was ACCEPTED on the original site

Post score: 5

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.