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
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).
9
9
10
10
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.
11
11
12
12
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:
The parameter server uses 5 services and an optional publisher, this needs to be taken into account on the `rmw-microxredds` package memory configuration:
46
49
47
-
```json
50
+
```yaml
48
51
# colcon.meta example with memory requirements to use a parameter server
- notify_changed_over_dds: Publish parameters events to the rest of nodes.
221
224
- max_params: Maximum number of parameters allowed on the `rclc_parameter_server_t` object.
222
225
- 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.
224
227
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;
228
231
229
-
// Initialize parameter server options
230
-
constrclc_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
+
constrclc_parameter_options_t options = {
234
+
.notify_changed_over_dds = true,
235
+
.max_params = 4,
236
+
.allow_undeclared_parameters = true,
237
+
.low_mem_mode = false; };
235
238
236
-
// Initialize parameter server with configured options
" 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
+
}
300
308
301
-
return true;
309
+
printf("\n");
310
+
}
311
+
312
+
return true;
302
313
}
303
314
```
304
315
@@ -312,7 +323,6 @@ Parameters modifications are disabled while this callback is executed, causing t
312
323
- rclc_add_parameter_constraints_double
313
324
- rclc_add_parameter_constraints_integer
314
325
315
-
316
326
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:
317
327
```c
318
328
// Add parameter server to executor including defined callback
@@ -331,51 +341,51 @@ To configure the callback context:
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
+
334
348
### Delete a parameter
335
349
Parameters can be deleted both by the parameter server and external clients:
336
-
Example usage:
337
350
```c
338
351
rclc_delete_parameter(¶m_server, "param2");
339
352
```
340
353
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.*
342
355
343
356
### Parameters description
344
357
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:
348
360
```c
349
361
rclc_add_parameter_description(¶m_server, "param2", "Second parameter", "Only even numbers");
350
362
```
351
363
352
364
*The maximum string size is controlled by the compilation time option `RCLC_PARAMETER_MAX_STRING_LENGTH`, default value is 50.*
353
365
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:
359
368
- from_value: Start value for valid values, inclusive.
360
369
- to_value: End value for valid values, inclusive.
361
370
- step: Size of valid steps between the from and to bound.
0 commit comments