Skip to content

Commit 43df4b9

Browse files
committed
Update
1 parent 7dba179 commit 43df4b9

6 files changed

Lines changed: 132 additions & 88 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Executor and timers
3+
permalink: /docs/tutorials/programming_rcl_rclc/micro-ROS/
4+
---
5+
6+
// TODO: Use existing tutorial if possible

_docs/tutorials/programming_rcl_rclc/node/node.md

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,112 @@ title: Nodes
33
permalink: /docs/tutorials/programming_rcl_rclc/node/
44
---
55

6-
## <a name="node"/>Nodes
6+
ROS 2 nodes are the ground element on ROS2 ecosystem. They will contain communicate between each other using publishers, subscriptions, services, ... .Further information about ROS 2 nodes can be found [here](https://docs.ros.org/en/galactic/Tutorials/Understanding-ROS2-Nodes.html)
77

8-
## <a name="init_node"/>Creating a node
8+
// TODO: explain general micro-ROS initialization (allocator and support)
9+
## <a name="init_node"/>Initialization
910

10-
// TODO: explain reliable vs best_effort
11+
- Create a node with default configuration:
12+
```C
13+
// Initialize micro-ROS allocator
14+
rcl_allocator_t allocator = rcl_get_default_allocator();
1115

12-
- Create a node:
13-
```C
14-
// TODO: explain allocator and support
15-
rcl_allocator_t allocator = rcl_get_default_allocator();
16-
rclc_support_t support;
17-
18-
rcl_ret_trc = rclc_support_init(&support, argc, argv, &allocator);
19-
if (rc != RCL_RET_OK) {
20-
printf("Error creating support object\n");
21-
return -1;
22-
}
23-
24-
// Node object
25-
rcl_node_t node;
26-
const char * node_name = "test_node";
27-
const char * namespace = "test_namespace";
28-
rc = rclc_node_init_default(&node, node_name, namespace, &support);
29-
if (rc != RCL_RET_OK) {
30-
// Handle error
31-
printf("Error creating node\n");
32-
return -1;
33-
}
16+
// Initialize support object
17+
rclc_support_t support;
18+
rcl_ret_t rc = rclc_support_init(&support, argc, argv, &allocator);
3419

35-
```
20+
// Create node object
21+
rcl_node_t node;
22+
const char * node_name = "test_node";
3623

37-
## <a name="end_node"/>Destroy a node
24+
// Node namespace (Can remain empty "")
25+
const char * namespace = "test_namespace";
3826

39-
```C
40-
// Destroy a node
41-
rc = rcl_node_fini(&node);
27+
// Init default node
28+
rc = rclc_node_init_default(&node, node_name, namespace, &support);
29+
if (rc != RCL_RET_OK) {
30+
... // Handle error
31+
return -1;
32+
}
33+
```
4234
43-
if (rc == RCL_RET_OK) {
44-
printf("Error destroying node\n");
45-
}
46-
```
35+
- Create a node with custom options:
4736
48-
## <a name="node_opt"/>Node options
37+
Node configuration will also be applied to its future elements (Publishers, subscribers, services, ...).
4938
39+
// TODO: explain possible options and their meaning
5040
51-
```C
52-
// TODO: explain allocator and support
53-
rcl_allocator_t allocator = rcl_get_default_allocator();
54-
rclc_support_t support;
41+
The API used to customize the node options differs between ROS2 distributions:
42+
43+
Foxy: The `rcl_node_options_t` is used to configure the node
44+
45+
```C
46+
// Initialize allocator and support objects
47+
...
48+
49+
// Create node object
50+
rcl_node_t node;
51+
const char * node_name = "test_node";
52+
53+
// Node namespace (Can remain empty "")
54+
const char * namespace = "test_namespace";
55+
56+
// Get default node options and modify them
57+
rcl_node_options_t node_ops = rcl_node_get_default_options();
58+
59+
// Set node ROS domain ID to 10
60+
node_ops.domain_id = (size_t)(10);
61+
62+
// Init node with custom options
63+
rc = rclc_node_init_with_options(&node, node_name, namespace, &support, &node_ops);
5564
56-
// Node object
57-
rcl_node_t node;
58-
const char * node_name = "test_node";
59-
const char * namespace = "test_namespace";
65+
if (rc != RCL_RET_OK) {
66+
... // Handle error
67+
return -1;
68+
}
69+
```
6070

61-
// TODO: explain options
62-
rcl_node_options_t node_options = rcl_node_get_default_options();
71+
Galactic: In this case, the node options are configured on the `rclc_support_t` object with a custom API
6372

64-
rc = rclc_node_init_default(&node, node_name, namespace, &support, &node_options);
65-
if (rc != RCL_RET_OK) {
66-
printf("Error creating node\n");
67-
return -1;
68-
}
73+
```C
74+
// Initialize micro-ROS allocator
75+
rcl_allocator_t allocator = rcl_get_default_allocator();
76+
77+
// Initialize and modify options (Set DOMAIN ID to 10)
78+
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
79+
rcl_init_options_init(&init_options, allocator);
80+
rcl_init_options_set_domain_id(&init_options, 10);
81+
82+
// Initialize rclc support object with custom options
83+
rclc_support_t support;
84+
rclc_support_init_with_options(&support, 0, NULL, &init_options, &allocator);
85+
86+
// Create node object
87+
rcl_node_t node;
88+
const char * node_name = "test_node";
89+
90+
// Node namespace (Can remain empty "")
91+
const char * namespace = "test_namespace";
92+
93+
// Init node with configured support object
94+
rclc_node_init_default(&node, node_name, namespace, &support);
95+
96+
if (rc != RCL_RET_OK) {
97+
... // Handle error
98+
return -1;
99+
}
100+
```
101+
102+
### <a name="node_end"/>Cleaning Up
103+
104+
To destroy a initialized node all entities owned by the node (Publishers, subscribers, services, ...) needs to be destroyed before the node itself:
105+
106+
```C
107+
// Destroy created entities
108+
...
109+
110+
// Destroy a node
111+
rcl_node_fini(&node);
112+
```
69113

70-
```
114+
This will delete any automatically created infrastructure on the agent (if possible) and deallocate used memory on the client side.

_docs/tutorials/programming_rcl_rclc/overview/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ In this tutorial, you'll learn the basics of the micro-ROS C API. The major conc
1111
* [**Publishers and Subscriptions**](../pub_sub/)
1212
* [**Services**](../service/)
1313
* [**Parameters**](../parameters/)
14+
* [**Executor and timers**](../executor/)
1415
* [**QoS**](../qos/)
1516
* [**micro-ROS Utils**](../micro-ROS/)

_docs/tutorials/programming_rcl_rclc/parameters/parameters.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ permalink: /docs/tutorials/programming_rcl_rclc/parameters/
55

66
ROS 2 parameter allow the user to create variables on a node and manipulate/read them with different ROS2 commands. Further information about ROS 2 parameters can be found [here](https://docs.ros.org/en/galactic/Tutorials/Parameters/Understanding-ROS2-Parameters.html)
77

8-
Ready to use code related to this tutorial can be found in [`micro-ROS-demos/rclc/parameter_server`](https://github.com/micro-ROS/micro-ROS-demos/blob/galactic/rclc/parameter_server/main.c) folder. Fragments of code from this example is used on this tutorial.
8+
Ready to use code related to this tutorial can be found in [`rclc/rclc_examples/src/`](https://github.com/ros2/rclc/blob/master/rclc_examples/src/example_parameter_server.c) folder. Fragments of code from this example is used on this tutorial.
99

1010
Note: micro-ROS parameter server is only supported on ROS2 galactic distribution
1111

@@ -169,14 +169,13 @@ rc = rclc_parameter_set_double(&param_server, parameter_name, param_value);
169169
rc = rclc_parameter_get_double(&param_server, parameter_name, &param_value);
170170
```
171171

172-
## <a name="parameters_end"/>Destroy the parameter server
172+
## <a name="parameters_end"/>Cleaning up
173+
174+
To destroy an initialized parameter server:
173175

174176
```C
175177
// Delete parameter server
176-
rcl_ret_t rc = rclc_parameter_server_fini(&param_server, &node);
178+
rclc_parameter_server_fini(&param_server, &node);
179+
```
177180
178-
if (rc == RCL_RET_OK) {
179-
... // Handle error
180-
return -1;
181-
}
182-
```
181+
This will delete any automatically created infrastructure on the agent (if possible) and deallocate used memory on the client side.

_docs/tutorials/programming_rcl_rclc/pub_sub/pub_sub.md

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Publishers and Subscriptions
33
permalink: /docs/tutorials/programming_rcl_rclc/pub_sub/
44
---
55

6-
ROS 2 publishers and subscribers are the basic communication mechanism between nodes using topics. Further information about ROS 2 publish–subscribe pattern can be found [here](https://docs.ros.org/en/foxy/Tutorials/Topics/Understanding-ROS2-Topics.html)
6+
ROS 2 publishers and subscribers are the basic communication mechanism between nodes using topics. Further information about ROS 2 publish–subscribe pattern can be found [here](https://docs.ros.org/en/foxy/Tutorials/Topics/Understanding-ROS2-Topics.html).
77

88
Ready to use code related to this tutorial can be found in [`micro-ROS-demos/rclc/int32_publisher`](https://github.com/micro-ROS/micro-ROS-demos/blob/foxy/rclc/int32_publisher/main.c) and [`micro-ROS-demos/rclc/int32_subscriber`](https://github.com/micro-ROS/micro-ROS-demos/blob/foxy/rclc/int32_subscriber/main.c) folders. Fragments of code from this examples are used on this tutorial.
99

@@ -110,24 +110,6 @@ if (rc != RCL_RET_OK) {
110110

111111
Note: `rcl_publish` is thread safe and can be called from multiple threads.
112112

113-
## <a name="pub_end"/>Destroy a publisher
114-
115-
Deallocates memory
116-
After finishing the publisher, the node will no longer be advertising that it is publishing
117-
on this topic (assuming this is the only publisher on this topic).
118-
119-
```C
120-
// Destroy publisher
121-
rcl_ret_t rc = rcl_publisher_fini(&publisher, &node);
122-
123-
if (rc == RCL_RET_OK) {
124-
... // Handle error
125-
return -1;
126-
}
127-
```
128-
129-
Note: Publishers needs to be destroyed before its containing node
130-
131113
## <a name="sub"/>Subscription
132114

133115
### <a name="sub_init"/>Initialization
@@ -221,16 +203,16 @@ if (RCL_RET_OK != rc) {
221203
}
222204
```
223205

224-
### <a name="sub_end"/>Destroy a subscriber
225-
Destroy subscriber (Publisher needs to be destroyed manually before the node)
226-
Destroys any automatically created infrastructure and deallocates memory.
206+
### <a name="pubsub_end"/>Cleaning Up
227207

228-
```C
229-
// Destroy
230-
rcl_ret_t rc = rcl_publisher_fini(&subscriber, &node);
208+
To destroy an initialized publisher or subscriber:
231209

232-
if (RCL_RET_OK != rc) {
233-
... // Handle error
234-
return -1;
235-
}
210+
```C
211+
// Destroy publisher and subscriber
212+
rcl_publisher_fini(&publisher, &node);
213+
rcl_subscription_fini(&subscriber, &node);
236214
```
215+
216+
After finishing the publisher/subscriber, the node will no longer be advertising that it is publishing/listening on the topic.
217+
218+
This will delete any automatically created infrastructure on the agent (if possible) and deallocate used memory on the client side.

_docs/tutorials/programming_rcl_rclc/service/services.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,15 @@ rcl_send_request(&client, &request_msg, &sequence_number);
278278
// Spin the executor to get the response
279279
rclc_executor_spin(&executor);
280280
```
281+
282+
### <a name="services_end"/>Cleaning Up
283+
284+
To destroy an initialized service or client:
285+
286+
```C
287+
// Destroy service server and client
288+
rcl_service_fini(&service, &node);
289+
rcl_client_fini(&client, &node);
290+
```
291+
292+
This will delete any automatically created infrastructure on the agent (if possible) and deallocate used memory on the client side.

0 commit comments

Comments
 (0)