You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/tutorials/core/programming_rcl_rclc/index.md
+131-6Lines changed: 131 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,17 +35,61 @@ if (rc != RCL_RET_OK) {
35
35
}
36
36
```
37
37
38
-
39
38
## <aname="pub_sub"/>Publishers and Subscriptions
39
+
Publisher and subscribers are created with the rclc-package with the following functions
40
+
`rclc_publisher_init_default(..)` and `rclc_subscription_init_default(..)` in [rclc/publisher.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/publisher.h) and [rclc/node.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/subscription.h), respectively:
printf("Failed to create subscriber %s.\n", topic_name);
76
+
return -1;
77
+
} else {
78
+
printf("Created subscriber %s:\n", topic_name);
79
+
}
80
+
81
+
// initialize string message for subscriber
82
+
std_msgs__msg__String__init(&sub_msg);
83
+
```
42
84
43
85
## <a name="services"/>Services
44
86
45
87
ROS 2 services is another communication mechanism between nodes. Services implement a client-server paradigm based on ROS 2 messages and types. Further information about ROS 2 services can be found [here](https://index.ros.org/doc/ros2/Tutorials/Services/Understanding-ROS2-Services/)
46
88
47
89
Ready to use code related to this tutorial can be found in [`micro-ROS-demos/rcl/addtwoints_server`](https://github.com/micro-ROS/micro-ROS-demos/blob/dashing/rcl/addtwoints_server/main.c) and [`micro-ROS-demos/rcl/addtwoints_client`](https://github.com/micro-ROS/micro-ROS-demos/blob/dashing/rcl/addtwoints_client/main.c) folders.
48
90
91
+
Note: Services are not supported in rclc package yet. Therefore the configuration is described using RCL layer.
92
+
49
93
Starting from a code where RCL is initialized and a micro-ROS node is created, these steps are required in order to generate a service server:
50
94
51
95
```c
@@ -90,7 +134,7 @@ Once service client and server are configured, service client can perform a requ
printf("Created timer with timeout %d ms.\n", timer_timeout);
224
+
}
225
+
```
165
226
166
227
## <a name="rclc_executor"/>Rclc Executor
228
+
The Executor is configured and setup with the functions
229
+
`rclc_executor_get_zero_initialized_executor(..)`, `rclc_executor_set_timeout(..)`, `rclc_executor_add_subscription(...)`, `rclc_executor_add_timer(...)`, `rclc_executor_spin_some(...)` and `rclc_executor_fini(...)` in [rclc/executor.h](https://github.com/micro-ROS/rclc/blob/master/rclc/include/rclc/executor.h).
230
+
231
+
Assuming that you have created a subscription and a timer, as described above, the following code snippet shows the configuration of the RCLC-executor.
232
+
233
+
The executor is configured with 2 handles, aka one subscription and one timer. The `support.context` is the ROS 2 context, as shown above with `rclc_support_init(...)`.
234
+
235
+
The timeout is the waiting time for new handles to get ready, for example new messages arrive or timers are ready. The unit of the timeout is milliseconds.
167
236
237
+
A subscription `my_sub`, a place-holder for it's message `sub_msg` and it's corresponding callback `my_subscriber_callback` is added to the executor with the function `rclc_executor_add_subscription(...)`
238
+
239
+
A timers is added to the executor with the function `rclc_executor_add_timer(...)`
240
+
241
+
A key feature of the rclc-Executor is, that the order of these functions to add handles matters. It defines the processing order when multiple messages have arrived or timers are ready. This provides full control over the execution order to the user.
242
+
243
+
There are are several functions, how to start the executor, one is `rclc_executor_spin_some(...)`, which allows the user to specify a timeout in nanoseconds.
244
+
245
+
Finally the code snippet shows how to destroy the objects for the node, publisher, subscriber and the executor with the respective fini-methods.
246
+
247
+
```c
248
+
rclc_executor_t executor;
249
+
250
+
// compute total number of subsribers and timers
251
+
unsigned int num_handles = 1 + 1;
252
+
printf("Debug: number of DDS handles: %u\n", num_handles);
0 commit comments