Skip to content

Commit 3768630

Browse files
committed
Minor fix on parameters guide
1 parent bac44c5 commit 3768630

1 file changed

Lines changed: 98 additions & 88 deletions

File tree

_docs/tutorials/programming_rcl_rclc/parameters/parameters.md

Lines changed: 98 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@ permalink: /docs/tutorials/programming_rcl_rclc/parameters/
55

66
<img src="https://img.shields.io/badge/Written_for-Galactic-green" style="display:inline"/> <img src="https://img.shields.io/badge/Tested_on-Rolling-green" style="display:inline"/>
77

8-
ROS 2 parameters 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)
8+
ROS 2 parameters 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).
99

1010
Ready to use code related to this tutorial can be found in [`rclc/rclc_examples/src/example_parameter_server.c`](https://github.com/ros2/rclc/blob/master/rclc_examples/src/example_parameter_server.c). Fragments of code from this example is used on this tutorial.
1111

1212
micro-ROS parameters implementation has been upgraded in the latest micro-ROS Rolling distribution, two approaches are presented in this tutorial: micro-ROS Foxy/Galactic and micro-ROS Rolling and beyond:
1313

14-
- [Initialization](#initialization)
15-
- [Memory requirements](#memory-requirements)
16-
- [Add a parameter](#add-a-parameter)
17-
- [Cleaning up](#cleaning-up)
14+
- [General implementation](#general-implementation)
15+
- [Initialization](#initialization)
16+
- [Memory requirements](#memory-requirements)
17+
- [Add a parameter](#add-a-parameter)
18+
- [Cleaning up](#cleaning-up)
1819
- [micro-ROS Foxy/Galactic](#micro-ros-foxygalactic)
1920
- [Initialization options](#initialization-options)
2021
- [Callback](#callback)
2122
- [micro-ROS Rolling](#micro-ros-rolling)
2223
- [Initialization options](#initialization-options-1)
2324
- [Callback](#callback-1)
25+
- [Add a parameter](#add-a-parameter-1)
2426
- [Delete a parameter](#delete-a-parameter)
2527
- [Parameters description](#parameters-description)
2628

27-
## Initialization
29+
## General implementation
30+
### Initialization
2831

2932
- Default initialization:
3033
```c
@@ -35,16 +38,16 @@ micro-ROS parameters implementation has been upgraded in the latest micro-ROS Ro
3538
rcl_ret_t rc = rclc_parameter_server_init_default(&param_server, &node);
3639

3740
if (RCL_RET_OK != rc) {
38-
... // Handle error
39-
return -1;
41+
... // Handle error
42+
return -1;
4043
}
4144
```
4245

43-
## Memory requirements
46+
### Memory requirements
4447

4548
The parameter server uses 5 services and an optional publisher, this needs to be taken into account on the `rmw-microxredds` package memory configuration:
4649

47-
```json
50+
```yaml
4851
# colcon.meta example with memory requirements to use a parameter server
4952
{
5053
"names": {
@@ -71,7 +74,7 @@ rc = rclc_executor_init(
7174
RCLC_PARAMETER_EXECUTOR_HANDLES_NUMBER, &allocator);
7275
```
7376

74-
## Add a parameter
77+
### Add a parameter
7578

7679
micro-ROS parameter server supports the following parameter types:
7780

@@ -90,8 +93,8 @@ micro-ROS parameter server supports the following parameter types:
9093
rc = rclc_parameter_get_bool(&param_server, "param1", &param_value);
9194

9295
if (RCL_RET_OK != rc) {
93-
... // Handle error
94-
return -1;
96+
... // Handle error
97+
return -1;
9598
}
9699
```
97100

@@ -127,7 +130,7 @@ micro-ROS parameter server supports the following parameter types:
127130

128131
*Max name size is controlled by the compilation time option `RCLC_PARAMETER_MAX_STRING_LENGTH`, default value is 50.*
129132

130-
## Cleaning up
133+
### Cleaning up
131134

132135
To destroy an initialized parameter server:
133136

@@ -161,8 +164,8 @@ This will delete any automatically created infrastructure on the agent (if possi
161164
rcl_ret_t rc = rclc_parameter_server_init_with_option(&param_server, &node, &options);
162165
163166
if (RCL_RET_OK != rc) {
164-
... // Handle error
165-
return -1;
167+
... // Handle error
168+
return -1;
166169
}
167170
```
168171
@@ -220,29 +223,30 @@ rc = rclc_executor_add_parameter_server(&executor, &param_server, NULL);
220223
- notify_changed_over_dds: Publish parameters events to the rest of nodes.
221224
- max_params: Maximum number of parameters allowed on the `rclc_parameter_server_t` object.
222225
- allow_undeclared_parameters: Allows creation of parameters from external parameters clients. A new parameter will be created if a `set` operation is requested on a non-existing parameter.
223-
- low_mem_mode: Reduces the memory used by the parameter server, functionality constrains are applied.
226+
- low_mem_mode: Reduces the memory used by the parameter server, functionality constrains are applied.
224227

225-
```c
226-
// Parameter server object
227-
rclc_parameter_server_t param_server;
228+
```c
229+
// Parameter server object
230+
rclc_parameter_server_t param_server;
228231

229-
// Initialize parameter server options
230-
const rclc_parameter_options_t options = {
231-
.notify_changed_over_dds = true,
232-
.max_params = 4,
233-
.allow_undeclared_parameters = true,
234-
.low_mem_mode = false; };
232+
// Initialize parameter server options
233+
const rclc_parameter_options_t options = {
234+
.notify_changed_over_dds = true,
235+
.max_params = 4,
236+
.allow_undeclared_parameters = true,
237+
.low_mem_mode = false; };
235238

236-
// Initialize parameter server with configured options
237-
rcl_ret_t rc = rclc_parameter_server_init_with_option(&param_server, &node, &options);
239+
// Initialize parameter server with configured options
240+
rcl_ret_t rc = rclc_parameter_server_init_with_option(&param_server, &node, &options);
238241

239-
if (RCL_RET_OK != rc) {
240-
... // Handle error
241-
return -1;
242-
}
243-
```
242+
if (RCL_RET_OK != rc) {
243+
... // Handle error
244+
return -1;
245+
}
246+
```
244247

245248
- Low memory mode:
249+
246250
This mode ports the parameters functionality to memory constrained devices. The following constrains are applied:
247251
- Request size limited to 1 parameter on Set, Get, Get types and Describe services.
248252
- List parameters request has no prefixes enabled nor depth.
@@ -268,37 +272,44 @@ Callback parameters:
268272
```c
269273
bool on_parameter_changed(const Parameter * old_param, const Parameter * new_param, void * context)
270274
{
271-
(void) context;
272-
273-
if (old_param == NULL) {
274-
printf("Creating new parameter %s\n", new_param->name.data);
275-
} else if (new_param == NULL) {
276-
printf("Deleting parameter %s\n", old_param->name.data);
277-
} else {
278-
printf("Parameter %s modified.", old_param->name.data);
279-
switch (old_param->value.type) {
280-
case RCLC_PARAMETER_BOOL:
281-
printf(
282-
" Old value: %d, New value: %d (bool)", old_param->value.bool_value,
283-
new_param->value.bool_value);
284-
break;
285-
case RCLC_PARAMETER_INT:
286-
printf(
287-
" Old value: %ld, New value: %ld (int)", old_param->value.integer_value,
288-
new_param->value.integer_value);
289-
break;
290-
case RCLC_PARAMETER_DOUBLE:
291-
printf(
292-
" Old value: %f, New value: %f (double)", old_param->value.double_value,
293-
new_param->value.double_value);
294-
break;
295-
default:
296-
break;
275+
(void) context;
276+
277+
if (old_param == NULL)
278+
{
279+
printf("Creating new parameter %s\n", new_param->name.data);
297280
}
298-
printf("\n");
299-
}
281+
else if (new_param == NULL)
282+
{
283+
printf("Deleting parameter %s\n", old_param->name.data);
284+
}
285+
else
286+
{
287+
printf("Parameter %s modified.", old_param->name.data);
288+
switch (old_param->value.type)
289+
{
290+
case RCLC_PARAMETER_BOOL:
291+
printf(
292+
" Old value: %d, New value: %d (bool)", old_param->value.bool_value,
293+
new_param->value.bool_value);
294+
break;
295+
case RCLC_PARAMETER_INT:
296+
printf(
297+
" Old value: %ld, New value: %ld (int)", old_param->value.integer_value,
298+
new_param->value.integer_value);
299+
break;
300+
case RCLC_PARAMETER_DOUBLE:
301+
printf(
302+
" Old value: %f, New value: %f (double)", old_param->value.double_value,
303+
new_param->value.double_value);
304+
break;
305+
default:
306+
break;
307+
}
300308

301-
return true;
309+
printf("\n");
310+
}
311+
312+
return true;
302313
}
303314
```
304315
@@ -312,7 +323,6 @@ Parameters modifications are disabled while this callback is executed, causing t
312323
- rclc_add_parameter_constraints_double
313324
- rclc_add_parameter_constraints_integer
314325
315-
316326
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:
317327
```c
318328
// Add parameter server to executor including defined callback
@@ -331,51 +341,51 @@ To configure the callback context:
331341
rc = rclc_executor_add_parameter_server_with_context(&executor, &param_server, on_parameter_changed, &context);
332342
```
333343

344+
### Add a parameter
345+
Parameters can also be created by external clients if `allow_undeclared_parameters` flag is set.
346+
They client just needs to set a value on a unexisting parameter, the parameter will be created if the server is not full and the callback allows the operation.
347+
334348
### Delete a parameter
335349
Parameters can be deleted both by the parameter server and external clients:
336-
Example usage:
337350
```c
338351
rclc_delete_parameter(&param_server, "param2");
339352
```
340353
341-
Note that for external delete requests the server callback will be executed, allowing the user to reject the operation.
354+
*For external delete requests the server callback will be executed, allowing the user to reject the operation.*
342355
343356
### Parameters description
344357
345-
- Parameter description
346-
Adds a description of a parameter and its constrains. This descriptors will be returned to describe parameters requests.
347-
Example usage:
358+
- Parameter description
359+
Adds a description of a parameter and its constrains, which will be returned on a describe parameters requests:
348360
```c
349361
rclc_add_parameter_description(&param_server, "param2", "Second parameter", "Only even numbers");
350362
```
351363
352364
*The maximum string size is controlled by the compilation time option `RCLC_PARAMETER_MAX_STRING_LENGTH`, default value is 50.*
353365
354-
- Parameter constrains
355-
Informative numeric constrains can be added to int and double parameters, returning this values on describe parameters requests.
356-
Note that this constrains will not be applied by the parameter server, leaving values filtering to the user callback.
357-
358-
The following values can be configured:
366+
- Parameter constrains
367+
Informative numeric constrains can be added to int and double parameters, returning this values on describe parameters requests:
359368
- from_value: Start value for valid values, inclusive.
360369
- to_value: End value for valid values, inclusive.
361370
- step: Size of valid steps between the from and to bound.
362371
363-
Example usage:
364-
```c
365-
int64_t int_from = 0;
366-
int64_t int_to = 20;
367-
uint64_t int_step = 2;
368-
rclc_add_parameter_constraints_integer(&param_server, "param2", int_from, int_to, int_step);
369-
370-
double double_from = -0.5;
371-
double double_to = 0.5;
372-
double double_step = 0.01;
373-
rclc_add_parameter_constraints_double(&param_server, "param3", double_from, double_to, double_step);
374-
```
372+
```c
373+
int64_t int_from = 0;
374+
int64_t int_to = 20;
375+
uint64_t int_step = 2;
376+
rclc_add_parameter_constraints_integer(&param_server, "param2", int_from, int_to, int_step);
377+
378+
double double_from = -0.5;
379+
double double_to = 0.5;
380+
double double_step = 0.01;
381+
rclc_add_parameter_constraints_double(&param_server, "param3", double_from, double_to, double_step);
382+
```
375383
376-
- Read only parameters:
377-
The new API offers a read only flag. This flag blocks parameter changes from external clients, but allows changes on the server side. Example usage:
384+
*This constrains will not be applied by the parameter server, leaving values filtering to the user callback.*
385+
386+
- Read only parameters:
387+
The new API offers a read only flag. This flag blocks parameter changes from external clients, but allows changes on the server side:
378388
```c
379389
bool read_only = true;
380390
rclc_set_parameter_read_only(&param_server, "param3", read_only);
381-
```
391+
```

0 commit comments

Comments
 (0)