Skip to content

Commit fb113ce

Browse files
pablogs9FranFin
andauthored
Ref #8731. Update RMW configuration user API (#173)
* Update * Minor adjustments. Co-authored-by: francesca <francescafinocchiaro@eprosima.com>
1 parent c6ba5b7 commit fb113ce

1 file changed

Lines changed: 54 additions & 17 deletions

File tree

  • _docs/tutorials/core/microxrcedds_rmw_configuration
Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
---
2-
title: Optimizing the Middleware Configuration
2+
title: Middleware Configuration
33
permalink: /docs/tutorials/core/microxrcedds_rmw_configuration/
44
---
55

66
micro-ROS targets microcontroller, devices with low memory resources.
7-
With that in mind, micro-ROS try to address the memory management issue prioritizing the use of static memory instead of dynamic memory and optimizing the memory footprint of the applications. This, of course, has a cost that the users must agree to pay, a precompile tunning.
7+
With that in mind, micro-ROS try to address the memory management issue prioritizing the use of static memory instead of dynamic memory and optimizing the memory footprint of the applications.
8+
This, of course, has a cost that the users must agree to pay, a precompile tunning.
89

910
This tutorial explains which are the memory resources managed by micro-ROS and how to tune them for a particular application.
11+
It also addresses the RMW run-time configuration API where the user can configure the micro-ROS Agent endpoints or the Micro XRCE-DDS session `client_key`.
1012

11-
## Memory resources
13+
## Memory resources optimization
1214

13-
micro-ROS deal with two different memory resources related with Micro XRCE-DDS library and its RMW implementation named rmw-microxrcedds.
15+
micro-ROS deals with two different memory resources related with the Micro XRCE-DDS library and its RMW implementation named rmw-microxrcedds.
1416

1517
### Micro XRCE-DDS
1618

17-
Micro XRCE-DDS messages flows between Client and Agent throw **streams**.
18-
A stream represents an independent ordered flow of information, that is, it is a sort of messaging queue.
19+
Micro XRCE-DDS messages flow between Client and Agent throw **streams**.
20+
A stream represents an independent ordered flow of information, so it is a sort of messaging queue.
1921
There are two kinds of streams, **best-effort** and **reliable**.
20-
Both, best-effort and reliable streams, have a raw buffer (`uint8_t` array) associated with them, but the layout is different.
22+
Both best-effort and reliable streams, have a raw buffer (`uint8_t` array) associated with them, but the layout is different.
2123

2224
On the one hand, best-effort streams could be interpreted as a single message queue.
23-
Therefore, the raw buffer a single data buffer where only one message is popped/pushed.
25+
Therefore, the raw buffer is a single data buffer where only one message is popped/pushed.
2426

2527
![](./imgs/best_effort_stream.svg)
2628

27-
On the other hand, reliable streams contains multiple messages which are popped/pushed according to the reliable communication protocol described in the DDS-XRCE specification.
28-
It is achieved splitting the raw buffer into chucks, each one of those could contain a single message.
29+
On the other hand, reliable streams contain multiple messages which are popped/pushed according to the reliable communication protocol described in the DDS-XRCE specification.
30+
It is achieved splitting the raw buffer into chucks, each of which each contains a single message.
2931

3032
![](./imgs/reliable_strea.svg)
3133

32-
The size of the best-effort and reliable stream can be set by two sets of CMake flags.
34+
The size of the best-effort and reliable stream can be configured by two sets of CMake flags.
3335

34-
* `UCLIENT_UDP_TRANSPORT_MTU`, `UCLIENT_TCP_TRANSPORT_MTU` and `UCLIENT_SERIAL_TRANSPORT_MTU` (depending of the transport selected): control the size of the best-effort stream buffer which matches with the size of each chunk of the reliable stream.
36+
* `UCLIENT_UDP_TRANSPORT_MTU`, `UCLIENT_TCP_TRANSPORT_MTU` and `UCLIENT_SERIAL_TRANSPORT_MTU` (depending on the transport selected): these flags control the size of the best-effort stream buffer which matches with the size of each chunk of the reliable stream.
3537
* `RMW_UXRCE_MAX_HISTORY`: sets the number of slots for the reliable streams.
3638

3739
The size of the stream sets indirectly the maximum message size (MMS) of the micro-ROS application.
3840
This MMS is (`UCLIENT_<XXX>_TRANSPORT_MTU` - 12 B) for best-effort messages and (`UCLIENT_<XXX>_TRANSPORT_MTU` * (`RMW_UXRCE_MAX_HISTORY` - 12 B)) in the case of reliable messages.
3941

4042
The use of best-effort or reliable stream is handled by the `rmw_qos_reliability_policy_t` set in the `rmw_qos_profile_t` for a particular publisher or subscription.
41-
In the case of `RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT` best-effort streams are used and for `RMW_QOS_POLICY_RELIABILITY_RELIABLE` reliable streams.
43+
In the case of `RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT` best-effort streams are used and for `RMW_QOS_POLICY_RELIABILITY_RELIABLE` reliable streams are used instead.
4244

4345
### rmw-microxrcedds
4446

@@ -48,16 +50,16 @@ The size of these memory pools could be set through CMake flags,
4850
for example, the `RMW_UXRCE_MAX_PUBLISHERS` sets the size of the `rcl_publisher_t`'s pool memory.
4951
It should be noted that the size of these memory pools restricts the maximum number of entities that a micro-ROS application could use.
5052

51-
The figure below summarizes the relation between the `rcl` entities and the CMake flags, which the size of the memory pool associated with such entity.
53+
The figure below summarizes the relation between the `rcl` entities and the CMake flags, which set the size of the memory pool associated with such entities.
5254

5355
![](./imgs/micro_ros_memory.svg)
5456

5557
Another important memory resource managed by the rmw-microxrcedds is the message history.
56-
The rmw-microxrcedds uses static-memory message queue in order to keep the subscription messages before the user read these.
58+
The rmw-microxrcedds uses a static-memory message queue where to to keep the subscription messages before the user reads them.
5759
The size of this message queue could be set by the `RMW_UXRCE_MAX_HISTORY`.
5860

59-
It is worth noting that all the afore mentioned CMake flags shall be set in a `.meta` for each platform supported in [micro-ros-build](https://github.com/micro-ROS/micro-ros-build).
60-
For example, the [ping-pong](https://micro-ros.github.io//docs/tutorials/core/first_application_linux/) the host [configuration file](https://github.com/micro-ROS/micro-ros-build/blob/dashing/micro_ros_setup/config/host/generic/client-host-colcon.meta) which can be optimized with the following modifications:
61+
It is worth noting that all the aforementioned CMake flags shall be set in a `.meta` for each platform supported in [micro-ros-build](https://github.com/micro-ROS/micro-ros-build).
62+
For example, in the [ping-pong application](https://micro-ros.github.io//docs/tutorials/core/first_application_linux/) the host [configuration file](https://github.com/micro-ROS/micro-ros-build/blob/dashing/micro_ros_setup/config/host/generic/client-host-colcon.meta) can be optimized with the following modifications:
6163

6264
```
6365
{
@@ -78,3 +80,38 @@ For example, the [ping-pong](https://micro-ros.github.io//docs/tutorials/core/fi
7880
}
7981
}
8082
```
83+
84+
## Run-time configuration
85+
86+
There are some build time parameters related to Client-to-Agent connection (such as **CONFIG_RMW_DEFAULT_UDP_PORT**, **CONFIG_RMW_DEFAULT_UDP_IP** and **CONFIG_RMW_DEFAULT_SERIAL_DEVICE**) that can be configured either at build time or at run-time.
87+
This means that you can set them in the [configuration file](https://github.com/micro-ROS/micro-ros-build/blob/dashing/micro_ros_setup/config/host/generic/client-host-colcon.meta) mentioned above and that micro-ROS provides a user configuration API for setting some RMW and middleware parameters at run-time.
88+
89+
The following example code shows the [API](https://github.com/micro-ROS/rmw-microxrcedds/blob/dashing/rmw_microxrcedds_c/include/rmw_uros/options.h) calls needed to set the agent's IP address, port or serial device:
90+
91+
```c
92+
#include <rmw_uros/options.h>
93+
94+
// Init RCL options and context
95+
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
96+
rcl_context_t context = rcl_get_zero_initialized_context();
97+
rcl_init_options_init(&init_options, rcl_get_default_allocator());
98+
99+
// Take RMW options from RCL options
100+
rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options);
101+
102+
// TCP/UDP case: Set RMW IP parameters
103+
rmw_uros_options_set_udp_address("127.0.0.1", "8888", rmw_options);
104+
105+
// Serial case: Set RMW serial device parameters
106+
mw_uros_options_set_serial_device("/dev/ttyAMA0", rmw_options)
107+
108+
// Set RMW client key
109+
rmw_uros_options_set_client_key(0xBA5EBA11, rmw_options);
110+
111+
// Init RCL
112+
rcl_init(0, NULL, &init_options, &context);
113+
114+
// ... micro-ROS code ...
115+
```
116+
117+
Notice that it is also possible to set the Micro XRCE-DDS `client_key`, which would otherwise be set randomly. This feature is useful for reusing DDS entities already created on the agent side. Further information can be found [here](https://micro-xrce-dds.readthedocs.io/en/latest/deployment.html#configurate-the-publisher).

0 commit comments

Comments
 (0)