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

rclcpp::WaitSet vs rclc executor?

asked 2023-03-05 06:04:59 -0500

vutran1410 gravatar image

Hi all,

I'm doing a comparision between the rclcpp and rclc executors, and have some questions:

  1. What are the differences between using the rclcpp::WaitSet vs using the rclc executor? The rclc executor is claimed to be more determinisitc by having user-defined callback processing order and trigger conditions, but the rclcpp::WaitSet can also provide those functionalities.
  2. The rclcpp wait-set approach and rclcpp executor seem to be 2 different approaches (proactor vs reactor approach). What are the advantages of using one over another? When is the wait-set approach is preferred and vice versa?

Thank you, Vu

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-03-07 08:10:34 -0500

JanStaschulat gravatar image

updated 2023-03-07 10:16:12 -0500

Hi @vutran1410. I have written the rclc-Executor, so I can only comment on the first question:

  1. What are the differences between using the rclcpp::WaitSet vs using the rclc executor? The rclc executor is claimed to be more determinisitc by having user-defined callback processing order and trigger conditions, but the rclcpp::WaitSet can also provide those functionalities

To which documentation are you referring to, when writing: "...but the rclcpp::WaitSet can also provide those functionalities". Could you add a link to a paper/header file/documentation?

In short, the rclcpp::WaitSet is just an abstraction of the RCL wait_set container in C++ programming language. It is not an Executor, that is, does not have the functionality of checking for new data and calling the corresponding callbacks. The rclc-Executor is an Executor written in the C programming language, that uses also the RCL wait_set container.

Details:

rclc-Executor:

  • uses rcl_wait_set_t to configure the entities to wait for.
  • is an Executor, comparable to rclcpp::SingleThreadedExecutor class but written in C programming language. It is responsible for the execution management,that is, if an event for entity occurs (new data available for a subscription, timer ready), the corresponding callback of the entity will be called.
  • the user-defined callback processing order is defined by the order the entities are added to the Executor
  • trigger condition can be used to synchronize between different events, e.g. wait until data is available for multiple subscriptions, and only then start processing these and other callbacks. This trigger can be used to construct deterministic execution order of callbacks of larger applications (e.g. sensor fusion)
  • no dynamic memory allocation at runtime. All memory is allocated at configuration phase
  • dispatcher-Executor concept to configure scheduling parameters of subscription callbacks.

rclcpp::WaitSet:

  • is an abstraction of rcl_wait_set_t
  • provides an interface to the wait_set, but does not manage the execution of callbacks. You have to do this by your own. The rclcpp::WaitSet is not an executor. See an example here.
  • the WaitSet does not provide functionality of sequential processsing. With just the WaitSet you cannot determine the processing order, because this is out-of-scope of the WaitSet. The WaitSet can be used to create such an ordering or anything special you like to have, but it is only the C++ equivalent of the underlying RCL wait_set container.
  • the WaitSet does not provide functionality of trigger
  • The SingleThreadedExecutor, MultiThreadedExecutor, StaticExecutors are using dynamic memory allocation at runtime.

References regarding comparison between different ROS 2 Executors:

edit flag offensive delete link more

Comments

Hi @JanStaschulat, thank you for your answer. I wasn't clear when I said "rclcpp::WaitSet can also provide those functionalities". What I meant is the user can implement the message handling with rclcpp::WaitSet, which can be seen in the [example], which has the same logic as the SingleThreadedExecutor based on the documentation and the trigger condition can be achieved using sub1_has_data, sub2_has_data, sub3_has_databoolean variables. (https://github.com/ros2/examples/blob...) So please correct me if I'm wrong, is the rclcpp::WaitSet example actually what happened in the underlying code of the rclc executor with the exception that the memory allocation is static?

vutran1410 gravatar image vutran1410  ( 2023-03-07 08:54:05 -0500 )edit
1

Hi @vutran1410, yes. The WaitSet enables a greater flexibility of execution management, like the example with three bool variables. I agree, that the functionality of such a hand-written Executor using WaitSets is equivalent to the rclc-Executor, regarding execution behavior. The difference is memory allocation at runtime (rclcpp: dynamic, rclc: no dynamic).

I would like to add the feature of the rclc-Executor to configure scheduling parameters for callbacks. (though published in 2021, but not in mainline yet). You could achieve this with the existing ROS 2 functionality e.g. by creating a thread with user-defined scheduling parameters and inside calling an Executor. However, this would require more knowledge about operating systems, that most robotics engineers probably do not want to get into. I my opinion, ROS 2 should provide a proper API instead.

JanStaschulat gravatar image JanStaschulat  ( 2023-03-07 09:44:06 -0500 )edit

Since the multi-thread rclc executor isn't in mainline yet, is it possible to create multiple single-thread rclc executor and then run each of the executor in a separate OS thread to achieve the effect of a multi-thread executor?

vutran1410 gravatar image vutran1410  ( 2023-03-08 03:35:34 -0500 )edit

Yes, you can do that. Also the micro-ROS client is thread-safe. So you can run multiple threads (with the rclc-Executor) on a micro-controller in parallel.

The difference is, that if you have multiple entities in an Executor (ROS 2 or rclc), then new data is always processed sequentially (this is similarly the case for the MultiThreadedExecutor (just one wait_set and a thread pool with n threads is processing n messages in parallel.) In the multi-threaded Executor, you could cherry-pick callbacks to threads with user-defined scheduling parameters.

So if you have a high-priority topic, you would have to create a thread with a high priority and have the rclc-Executor only with this high priority callback, to make sure that the operating system prioritizes over all other callbacks (in other Executors/threads).

JanStaschulat gravatar image JanStaschulat  ( 2023-03-08 03:42:02 -0500 )edit

Hi @JanStaschulat, sorry for the late question. When I run multiple executors with each executor in one thread, if the executor in the higher priority thread runs a blocking spin continuously (not the spin_period with sleep() function), does this mean that all other executors in lower threads cannot run at all? I think the same case happens with the rclcpp executor.

vutran1410 gravatar image vutran1410  ( 2023-03-28 08:00:21 -0500 )edit

Hi @vutran1410, no.

The micro-ROS library is thread-safe. That means, the middleware can be simultaneously accessed from different threads (with a different thread-priority). The spin() function blocks only the thread in which the executor is created. This has no impact on other spin-calls of other executors (in different threads) to the rclc-library / XRCE-DDS middleware.

What do you mean with "I think the same case happens with the rclcpp executor."? There are several examples with multiple threads, in which each an executor is created (e..g SingleThreadedExecutor or MultiThreadedExecutor) and they will access DDS middleware simultaneously.

For example see the callback-group level executor (rclcpp): https://github.com/ros2/examples/blob...

JanStaschulat gravatar image JanStaschulat  ( 2023-03-28 11:01:16 -0500 )edit
0

answered 2023-03-28 03:57:09 -0500

vutran1410 gravatar image

To answer my second question, I found a helpful comment from the WaitSet representation at the RTWG

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2023-03-05 06:04:59 -0500

Seen: 812 times

Last updated: Mar 28 '23