ROS 2 node interface examples

asked 2020-04-06 13:02:36 -0500

tbh gravatar image

I am porting a few packages from ROS 1 to ROS 2 (Eloquent).

The first package has library objects that need to do things such as creating subscriptions and timers and using the logging system. In ROS 1, I would declare a ros::NodeHandle in the object and from that, I could subscribe and get parameters and things would just "magically" work when I used the object inside other classes.

In my first stab at porting this library to ROS 2, I added a rclcpp::Node::SharedPtr parameter to the constructor, save that in the object, and all is well; I can subscribe and log and such from that.

However, when I try to use my library in a rclcpp_lifecycle::LifecycleNode, I find that LifecycleNode is not a subclass of rclcpp::Node as I would expect. Instead it re-implements all or most of the functions from Node so they look similar in the demos, but my library will not work.

I see all the functions in Node that return interfaces (base, clock, graph, logging, timers, topics, services, waitables, parameters, and time_source) and I haven't started digging yet, but I am now guessing that the real work is done from those and that I should pass the interfaces I need to objects of my library instead of a Node pointer even though that seems more tedious.

Are there any examples of using the base interfaces or examples of creating libraries with the interfaces or perhaps best practice guides for my scenario?


edit retag flag offensive close merge delete