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
+126-3Lines changed: 126 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,10 @@ 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
13
+
10
14
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
15
- Basic type
12
16
- Array type
@@ -58,7 +62,7 @@ In the case of `MyType.msg`, the `values` sequence member is represented in C99
58
62
59
63
```c
60
64
typedefstruct rosidl_runtime_c__int32__Sequence
61
-
{
65
+
{
62
66
int32_t* data; /* The pointer to an array of int32 */
63
67
size_t size; /* The number of valid items in data */
64
68
size_t capacity; /* The number of allocated items in data */
@@ -94,7 +98,7 @@ for(int32_t i = 0; i < 3; i++){
94
98
95
99
## Compound types in micro-ROS
96
100
97
-
When dealing with a compound type, the user should recursively inspect the types in order to determine how to handle each internal member.
101
+
When dealing with a compound type, the user should recursively inspect the types in order to determine how to handle each internal member.
98
102
99
103
For example in the `MyType.msg` example, the `header` member has the following structure:
100
104
@@ -148,7 +152,7 @@ int8[10] coefficients
148
152
string name
149
153
```
150
154
151
-
In this case, the generated typesupport will be:
155
+
In this case, the generated typesupport will be:
152
156
153
157
```c
154
158
typedef struct mypackage__msg__MyComplexType
@@ -191,3 +195,122 @@ for(int32_t i = 0; i < 3; i++){
191
195
mymsg.multiheaders.size++;
192
196
}
193
197
```
198
+
199
+
# micro-ROS Galactic
200
+
201
+
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).
202
+
203
+
The documentation of the package [`micro_ros_utilities`](https://github.com/micro-ROS/micro_ros_utilities) are available [here](https://micro.ros.org/docs/api/utils/).
204
+
205
+
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