Skip to content

Commit 090f435

Browse files
committed
Update parameters
1 parent 3121c77 commit 090f435

3 files changed

Lines changed: 138 additions & 58 deletions

File tree

_docs/tutorials/programming_rcl_rclc/parameters/parameters.md

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,79 @@
11
---
2-
title: Parameters
2+
title: Parameter server
33
permalink: /docs/tutorials/programming_rcl_rclc/parameters/
44
---
55

6-
## <a name="parameters"/>Parameters
7-
// TODO: add link to example
6+
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)
87

9-
## <a name="parameters_server"/>Creating a parameter server
10-
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.
119

12-
```C
13-
// Parameter server object
14-
rclc_parameter_server_t param_server;
10+
Note: micro-ROS parameter server is only supported on ROS2 galactic distribution
1511

16-
// Initialize parameter server with default configuration
17-
rcl_ret_t rc = rclc_parameter_server_init_default(&param_server, &node);
12+
## <a name="parameters_init"/>Initialization
1813

19-
if (RCL_RET_OK != rc) {
20-
printf("Error creating parameter server\n");
21-
return -1;
22-
}
14+
- Default initialization:
15+
```C
16+
// Parameter server object
17+
rclc_parameter_server_t param_server;
2318

24-
// Configure executor with atleast RCLC_PARAMETER_EXECUTOR_HANDLES_NUMBER handles
25-
rclc_executor_t executor;
26-
rclc_executor_init(&executor, &support.context, RCLC_PARAMETER_EXECUTOR_HANDLES_NUMBER, &allocator);
19+
// Initialize parameter server with default configuration
20+
rcl_ret_t rc = rclc_parameter_server_init_default(&param_server, &node);
2721

28-
// Add parameter server to executor
29-
rc = rclc_executor_add_parameter_server(&executor, &param_server, NULL);
30-
```
22+
if (RCL_RET_OK != rc) {
23+
... // Handle error
24+
return -1;
25+
}
26+
```
3127

32-
- Parameter changed callback
28+
// TODO: explain options
29+
- Custom options:
30+
```C
31+
// Parameter server object
32+
rclc_parameter_server_t param_server;
3333

34-
When adding the paramater server to the executor, a callback for parameter changes can be passed.
35-
This callback will be called after a parameter value is modified.
34+
// Define parameter server options
35+
const rclc_parameter_options_t options = { .notify_changed_over_dds = true, .max_params = 4 };
36+
37+
// Initialize parameter server with configured options
38+
rcl_ret_t rc = rclc_parameter_server_init_with_option(&param_server, &node, &options);
39+
40+
if (RCL_RET_OK != rc) {
41+
... // Handle error
42+
return -1;
43+
}
44+
```
45+
46+
- Memory and executor requirements:
47+
The variable `RCLC_PARAMETER_EXECUTOR_HANDLES_NUMBER` defines the RCLC executor handles required for a parameter server.
48+
This needs to be taken into account when initializing the executor and on the colcon memory configuration of the `rmw-microxredds` package, which will need atleast 4 services and 1 publisher:
49+
50+
```C
51+
# colcon.meta example with minimum memory requirements to use parameter server
52+
{
53+
"names": {
54+
"rmw_microxrcedds": {
55+
"cmake-args": [
56+
"-DRMW_UXRCE_MAX_NODES=1",
57+
"-DRMW_UXRCE_MAX_PUBLISHERS=1",
58+
"-DRMW_UXRCE_MAX_SUBSCRIPTIONS=0",
59+
"-DRMW_UXRCE_MAX_SERVICES=4",
60+
"-DRMW_UXRCE_MAX_CLIENTS=0"
61+
]
62+
}
63+
}
64+
}
65+
```
66+
67+
```C
68+
// Executor init example with the minimum RCLC executor handles required
69+
rclc_executor_t executor = rclc_executor_get_zero_initialized_executor();
70+
rc = rclc_executor_init(&executor, &support.context, RCLC_PARAMETER_EXECUTOR_HANDLES_NUMBER, &allocator);
71+
```
72+
73+
## <a name="parameters_callback"/>Callback
74+
75+
When adding the paramater server to the executor, a callback can be configured.
76+
This callback will be executed after a parameter value is modified.
3677

3778
A pointer to the changed parameter is passed as first and only argument. Example:
3879
```C
@@ -60,14 +101,19 @@ void on_parameter_changed(Parameter * param)
60101

61102
printf("\n");
62103
}
63-
104+
```
105+
Once the parameter server and the executor are initialized, the parameter server must be added to the executor in order to accept parameters commands from ROS2:
106+
```C
64107
// Add parameter server to executor including defined callback
65108
rc = rclc_executor_add_parameter_server(&executor, &param_server, on_parameter_changed);
66109
```
67110

68-
// TODO: explain options on creation
69-
// TODO: explain destruction
70-
// TODO: explain memory requirements
111+
Note that this callback is optional as its just an event information for the user. To use the parameter server without a callback:
112+
```C
113+
// Add parameter server to executor without callback
114+
rc = rclc_executor_add_parameter_server(&executor, &param_server, NULL);
115+
```
116+
71117

72118
## <a name="parameters_add"/>Add a parameter
73119

@@ -88,7 +134,7 @@ rc = rclc_parameter_set_bool(&param_server, parameter_name, param_value);
88134
rc = rclc_parameter_get_bool(&param_server, "param1", &param_value);
89135

90136
if (RCL_RET_OK != rc) {
91-
// Handle error
137+
... // Handle error
92138
return -1;
93139
}
94140
```
@@ -122,3 +168,15 @@ rc = rclc_parameter_set_double(&param_server, parameter_name, param_value);
122168
// Get parameter value on param_value
123169
rc = rclc_parameter_get_double(&param_server, parameter_name, &param_value);
124170
```
171+
172+
## <a name="parameters_end"/>Destroy the parameter server
173+
174+
```C
175+
// Delete parameter server
176+
rcl_ret_t rc = rclc_parameter_server_fini(&param_server, &node);
177+
178+
if (rc == RCL_RET_OK) {
179+
... // Handle error
180+
return -1;
181+
}
182+
```

_docs/tutorials/programming_rcl_rclc/pub_sub/pub_sub.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@ 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)
7+
8+
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.
9+
610
## <a name="pub"/>Publisher
711

812
### <a name="pub_init"/>Initialization
913

10-
Starting from a code where RCL is initialized and a micro-ROS node is created, there are tree ways to initialize a publisher:
14+
Starting from a code where RCL is initialized and a micro-ROS node is created, there are tree ways to initialize a publisher depending on the desired quality-of-service configuration:
1115

1216
// TODO: explain and link diferences between each approach on QoS section
1317

14-
- Reliable publisher:
18+
- Reliable:
1519
```C
1620
// Publisher object
1721
rcl_publisher_t publisher;
1822
const char * topic_name = "test_topic";
1923

20-
// TODO: explain type_support?
2124
// Get message type support
2225
const rosidl_message_type_support_t * type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32);
2326

24-
// Create a reliable rcl publisher.
27+
// Creates a reliable rcl publisher
2528
rcl_ret_t rc = rclc_publisher_init_default(&publisher, &node, &type_support, &topic_name);
2629

2730
if (RCL_RET_OK != rc) {
2831
... // Handle error
2932
return -1;
3033
}
3134
```
32-
33-
Reliable publishers will wait for confirmation for each published message, which leads to blocking `rcl_publish` calls. The `rmw-microxrcedds` offer an API to configure the acknowledgement timeout for each publisher:
35+
36+
// TODO: move to micro-ROS features section?
37+
Reliable publishers will wait for confirmation for each published message, which leads to blocking `rcl_publish` calls, `rmw-microxrcedds` offers an API to configure the acknowledgement timeout for each publisher:
3438
3539
```C
3640
// Set confirmation timeout in milliseconds
37-
int publish_timeout = 1000;
38-
rc = rmw_uros_set_publisher_session_timeout(&publisher, publish_timeout);
41+
int ack_timeout = 1000;
42+
rc = rmw_uros_set_publisher_session_timeout(&publisher, ack_timeout);
3943
4044
if (RCL_RET_OK != rc) {
4145
... // Handle error
@@ -45,11 +49,7 @@ Starting from a code where RCL is initialized and a micro-ROS node is created, t
4549

4650
The default value for all publishers is configured at compilation time by the cmake variable `RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT`.
4751

48-
- Best effort publisher:
49-
50-
// TODO: explain in QoS section?
51-
Publish the message without reception confirmation, allowing a faster publish rate.
52-
52+
- Best effort:
5353
```C
5454
// Publisher object
5555
rcl_publisher_t publisher;
@@ -58,7 +58,7 @@ Starting from a code where RCL is initialized and a micro-ROS node is created, t
5858
// Get message type support
5959
const rosidl_message_type_support_t * type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32);
6060

61-
// Creates an rcl publisher with quality-of-service option best effort
61+
// Creates a best effort rcl publisher
6262
rcl_ret_t rc = rclc_publisher_init_best_effort(&publisher, &node, &type_support, &topic_name);
6363

6464
if (RCL_RET_OK != rc) {
@@ -67,7 +67,7 @@ Starting from a code where RCL is initialized and a micro-ROS node is created, t
6767
}
6868
```
6969
70-
- Add QoS API
70+
- Custom QoS:
7171
7272
```C
7373
// Publisher object
@@ -80,7 +80,7 @@ Starting from a code where RCL is initialized and a micro-ROS node is created, t
8080
// Set publisher QoS
8181
const rmw_qos_profile_t * qos_profile = &rmw_qos_profile_default;
8282
83-
// Creates an rcl publisher with customized quality-of-service options
83+
// Creates a rcl publisher with customized quality-of-service options
8484
rcl_ret_t rc = rclc_publisher_init(&publisher, &node, &type_support, &topic_name, qos_profile);
8585
8686
if (RCL_RET_OK != rc) {
@@ -108,12 +108,12 @@ if (rc != RCL_RET_OK) {
108108
}
109109
```
110110

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

113113
## <a name="pub_end"/>Destroy a publisher
114114

115115
Deallocates memory
116-
After calling, the node will no longer be advertising that it is publishing
116+
After finishing the publisher, the node will no longer be advertising that it is publishing
117117
on this topic (assuming this is the only publisher on this topic).
118118

119119
```C
@@ -143,10 +143,7 @@ The suscriptor initialization is almost identical to the publisher one:
143143
// Get message type support
144144
const rosidl_message_type_support_t * type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32);
145145

146-
// Set client QoS
147-
const rmw_qos_profile_t * qos_profile = &rmw_qos_profile_default;
148-
149-
// Initialize subscriber with default configuration
146+
// Initialize a realiable subscriber
150147
rcl_ret_t rc = rclc_subscription_init_default(&subscriber, &node, &type_support, &topic_name);
151148

152149
if (RCL_RET_OK != rc) {
@@ -187,7 +184,7 @@ The suscriptor initialization is almost identical to the publisher one:
187184
// Set client QoS
188185
const rmw_qos_profile_t * qos_profile = &rmw_qos_profile_default;
189186

190-
// Initialize server with customized quality-of-service options
187+
// Initialize a subscriber with customized quality-of-service options
191188
rcl_ret_t rc = rclc_subscription_init(&subscriber, &node, &type_support, &topic_name, qos_profile);
192189

193190
if (RCL_RET_OK != rc) {
@@ -198,8 +195,6 @@ The suscriptor initialization is almost identical to the publisher one:
198195
199196
### <a name="sub_callback"/>Callbacks
200197
201-
// TODO: explain message memory allocation and link to tutorial
202-
203198
```C
204199
void subscription_callback(const void * msgin)
205200
{
@@ -214,7 +209,7 @@ void subscription_callback(const void * msgin)
214209
Once the subscriber and the executor are initialized, the subscriber callback must be added to the executor to receive incoming publications once the executor is spinning:
215210

216211
```C
217-
// Message object
212+
// Message object to save publication data
218213
std_msgs__msg__Int32 msg;
219214

220215
// Add subscription to the executor
@@ -234,7 +229,8 @@ Destroys any automatically created infrastructure and deallocates memory.
234229
// Destroy
235230
rcl_ret_t rc = rcl_publisher_fini(&subscriber, &node);
236231

237-
if (rc == RCL_RET_OK) {
238-
printf("Published message with value: %d\n", msg.data);
232+
if (RCL_RET_OK != rc) {
233+
... // Handle error
234+
return -1;
239235
}
240236
```

_docs/tutorials/programming_rcl_rclc/service/services.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@ Starting from a code where RCL is initialized and a micro-ROS node is created, t
3333
}
3434
```
3535
36-
// TODO: Add timeout API for reliable service
36+
A reliable service server will wait for confirmation for each response sended, which can increase the blocking time of the executor spins, `rmw-microxrcedds` offers an API to configure the acknowledgement timeout for each service:
3737
38+
```C
39+
// Set confirmation timeout in milliseconds
40+
int ack_timeout = 1000;
41+
rc = rmw_uros_set_service_session_timeout(&service, ack_timeout);
42+
43+
if (RCL_RET_OK != rc) {
44+
... // Handle error
45+
return -1;
46+
}
47+
```
48+
49+
The default value for all clients is configured at compilation time by the cmake variable `RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT`.
50+
3851
- Best effort:
3952

4053
```C
@@ -154,8 +167,21 @@ The service client initialization is almost identical to the server one:
154167
}
155168
```
156169
157-
// TODO: Add timeout API for reliable service
170+
A reliable service client will wait for confirmation for each request sended, which can increase the blocking time of the executor spins, `rmw-microxrcedds` offers an API to configure the acknowledgement timeout for each client:
171+
172+
```C
173+
// Set confirmation timeout in milliseconds
174+
int ack_timeout = 1000;
175+
rc = rmw_uros_set_client_session_timeout(&client, ack_timeout);
176+
177+
if (RCL_RET_OK != rc) {
178+
... // Handle error
179+
return -1;
180+
}
181+
```
158182

183+
The default value for all clients is configured at compilation time by the cmake variable `RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT`.
184+
159185
- Best effort:
160186

161187
```C

0 commit comments

Comments
 (0)