ROS2 Composition

I’m new to ROS2. How Can I spin the node using composition techniques. In the case of publishers, examples shows use of timer to bind the callback function. Is there any other way of continuously sniping the node without binding it to timer.

In composition example.:
// Use a timer to schedule periodic message publishing.
timer_ = create_wall_timer(1s, std::bind(&Talker::on_timer, this));

My use case application is creating a video/image (OpenCV) publisher.

Regards,
MJay

In the composition case none of the nodes is in charge of the main function / main thread. Therefore you either have to use a timer to get notified in regular intervals or start your own thread (with all the implications for locking / thread safety).

@dirk-thomas Just a query regarding future composition related work…Will there be anything like the onInit() function (like that of nodelets) in future ros 2 releases…Or will all composed nodes in ros 2 be initialised at the constructor of the class ??

You might want to consider to use a managed node. The current implement matches the design document which describes how the life cycle of managed nodes works: http://design.ros2.org/articles/node_lifecycle.html

There are currently no plans for changing anything in the life cycle itself. The configure step might be the right callback to perform your initialization.

Thanks @dirk-thomas. I was wondering how composition would support runtime polymorphism (like those supported by pcl_nodelets in pcl_ros) if all initialization were done at the constructor , instead of the the virtual onInit() function given in the nodelets.

I am sorry - I don’t understand the question. Maybe you can elaborate on it and provide more context.