equivalent of rclpy executor.create_task() in rclcpp?

asked 2021-09-19 10:10:06 -0500

flo gravatar image

In rclpy I can add a task to an executor by calling the method create_task(). I understood that a task is a function-call that I only want to call once.

An example for this can be seen here: https://github.com/ros2/rclpy/blob/69...

In my case I now want to do something like that in rclcpp. A slight variation would be, that while I definitely intend to only call the function once, it will run for a longer (/indefinite) time span (aka while(1){;//do_stuff i.e. Serial-device}). So I do not expect any Future to return.

For this use-case I would definitively need to upgrade to a MultiThreadedExecutor in rclcpp as well. But now I do not know how to add a function call like the create_task(), separated in an own thread, preferable as a node with the local scope of the other node to my Executor.

I believe I could misuse a timer callback for that and deactivate the timer right after it is called.

Straight forward fix would be to use just a normal std::thread, but I was wondering if there exists any ros2 tools for that.

Looking forward for your suggestions! :)

edit retag flag offensive close merge delete