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
Copy file name to clipboardExpand all lines: _docs/tutorials/advanced/handling_type_memory/index.md
+131-3Lines changed: 131 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,16 @@ This page aims to explain how to handle messages and types memory in micro-ROS.
7
7
8
8
First of all, since the micro-ROS user is in an embedded C99 environment, it is important to be aware of what messages and ROS 2 types are being used in order to handle memory correctly.
9
9
10
+
The micro-ROS type memory handling has changed in the latest micro-ROS Galactic distribution, two approaches are presented in this tutorial: micro-ROS Foxy and micro-ROS Galactic and beyond:
11
+
12
+
-[micro-ROS Foxy](#micro-ros-foxy)
13
+
-[Sequence types in micro-ROS](#sequence-types-in-micro-ros)
14
+
-[Compound types in micro-ROS](#compound-types-in-micro-ros)
15
+
-[Sequences of compound types](#sequences-of-compound-types)
16
+
-[micro-ROS Galactic](#micro-ros-galactic)
17
+
18
+
# micro-ROS Foxy
19
+
10
20
By watching the `.msg` or `.srv` of the types used in a micro-ROS application, you can determine the type of each member. Currently, the following types are supported:
11
21
- Basic type
12
22
- Array type
@@ -58,7 +68,7 @@ In the case of `MyType.msg`, the `values` sequence member is represented in C99
58
68
59
69
```c
60
70
typedefstruct rosidl_runtime_c__int32__Sequence
61
-
{
71
+
{
62
72
int32_t* data; /* The pointer to an array of int32 */
63
73
size_t size; /* The number of valid items in data */
64
74
size_t capacity; /* The number of allocated items in data */
@@ -94,7 +104,7 @@ for(int32_t i = 0; i < 3; i++){
94
104
95
105
## Compound types in micro-ROS
96
106
97
-
When dealing with a compound type, the user should recursively inspect the types in order to determine how to handle each internal member.
107
+
When dealing with a compound type, the user should recursively inspect the types in order to determine how to handle each internal member.
98
108
99
109
For example in the `MyType.msg` example, the `header` member has the following structure:
100
110
@@ -148,7 +158,7 @@ int8[10] coefficients
148
158
string name
149
159
```
150
160
151
-
In this case, the generated typesupport will be:
161
+
In this case, the generated typesupport will be:
152
162
153
163
```c
154
164
typedef struct mypackage__msg__MyComplexType
@@ -191,3 +201,121 @@ for(int32_t i = 0; i < 3; i++){
191
201
mymsg.multiheaders.size++;
192
202
}
193
203
```
204
+
205
+
# micro-ROS Galactic
206
+
207
+
Due to the inclusion of [`rosidl_typesupport_introspection_c`](https://github.com/ros2/rosidl/tree/master/rosidl_typesupport_introspection_c) in micro-ROS Galactic distribution, an automated memory handling for micro-ROS types is available. The tools related to this feature are available in the package [`micro_ros_utilities`](https://github.com/micro-ROS/micro_ros_utilities).
208
+
209
+
The documentation of the package [`micro_ros_utilities`](https://github.com/micro-ROS/micro_ros_utilities) is available [here](https://micro.ros.org/docs/api/utils/).
210
+
211
+
This package is able to auto-assign memory to a certain message struct using default dynamic memory allocators, for example, using the previouly declated type:
This code will init all the string and sequences recursively in `MyType` type. The size of this memory slots will be by default the ones in [`micro_ros_utilities_memory_conf_default`](https://github.com/micro-ROS/micro_ros_utilities/blob/c829971bd33ac1f14a94aa722476110b4b59eaf9/include/micro_ros_utilities/type_utilities.h#L51), that is:
The library provides utilies for calculating the size that both approaches will use with a certain configuration. Notice that this amount of memory is only the dynamic usage or the usage in the user provided buffer, `sizeof(mypackage__msg__MyComplexType)` is not taken into account.
0 commit comments