|
1 | 1 | --- |
2 | | -title: Decision Paper |
3 | | -permalink: /docs/concepts/client_library/decision_paper/ |
| 2 | +title: Design Analysis and Decisions |
| 3 | +permalink: /docs/concepts/client_library/design_analysis_and_decisions/ |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | This document served as decision template for the design and implementation of the micro-ROS client library in March 2019. We discuss different options and existing starting points for this undertaking, decision criteria and analysis results regarding the existing assets. |
@@ -211,3 +211,146 @@ Diagnostics (Bosch) |
211 | 211 | Power management (Acutronic Robotics) |
212 | 212 |
|
213 | 213 | * Highly dependent on RTOS, it would require implementation for each one |
| 214 | + |
| 215 | + |
| 216 | +# Embedded rcutils Analysis |
| 217 | + |
| 218 | +## Proposed changes |
| 219 | + |
| 220 | +The main issues found when porting rcutils package to embedded systems with RTOS during micro*ROS development were: |
| 221 | + * the lack of filesystem |
| 222 | + * dynamic memory allocations out of the RTOS control (usually with standard library implementations of `malloc` and `free`) |
| 223 | + * the POSIX API dependency |
| 224 | + |
| 225 | +This document addresses the first two items. |
| 226 | + |
| 227 | +To avoid the **filesystem** dependency without modifying high*level layers (such as `rcl` or `rmw`), it is proposed to use a combination between the available `rcl_logging_noop` package and a modified version of the filesystem dependencies in `rcutils`. This approach is enabled using the `RCUTILS_NO_FILESYSTEM` flag in compilation time. |
| 228 | + |
| 229 | +**Dynamic memory allocation** must be bounded to ROS2 custom allocators. `rcl` and `rmw` layers usually rely on `rcutils_get_default_allocator` function to obtain allocators, so a setter function is proposed. |
| 230 | +This way, using `rcutils_set_default_allocator` function is possible to modify the defaults easing the use of custom memory management in embedded systems. |
| 231 | + |
| 232 | +Dynamic memory allocation is also found when dealing with error handling in `rcutils`. By using `RCUTILS_AVOID_DYNAMIC_ALLOCATION` some string related `memmove` functions along the error handling are avoided. |
| 233 | + |
| 234 | +## Dependencies in `rcl`, `rcutils` and `rmw` |
| 235 | + |
| 236 | +*Test folders are excluded.* |
| 237 | + |
| 238 | +### error_handling.h |
| 239 | + |
| 240 | +* Macro **RCUTILS_SAFE_FWRITE_TO_STDERR** in `rcutils` error_handling.h: |
| 241 | +[Check here](https://github.com/micro-ROS/rcutils/commit/bcaa00a6ed12fc62d05dc5e44521a1648fd2d07f#diff-1b06d4a1ccca0f0dff66d961923143a1L42) |
| 242 | + * Problem: use `fwrite` to print to stderr and relies on a filesytem |
| 243 | + * Appears in: |
| 244 | + * rcl/rcl/src/rcl/expand_topic_name.c |
| 245 | + * rcl/rcl/src/rcl/logging_rosout.c |
| 246 | + * rcl/rcl/src/rcl/logging.c |
| 247 | + * rcl/rcl/src/rcl/context.c |
| 248 | + * rcl/rcl_yaml_param_parser/src/parser.c |
| 249 | + * rcutils/src/split.c |
| 250 | + * rcutils/src/error_handling.c |
| 251 | + * rcutils/src/allocator.c |
| 252 | + * rcutils/src/logging.c |
| 253 | + * rcutils/src/error_handling_helpers.h |
| 254 | + * rcutils/include/rcutils/logging.h |
| 255 | + * rcutils/include/rcutils/error_handling.h |
| 256 | + * rcl/rcl/src/rcl/expand_topic_name.c |
| 257 | + * rcl/rcl/src/rcl/logging_rosout.c |
| 258 | + * rcl/rcl/src/rcl/logging.c |
| 259 | + * rcl/rcl/src/rcl/context.c |
| 260 | + * rcl/rcl_yaml_param_parser/src/parser.c |
| 261 | + * rmw/rmw/include/rmw/error_handling.h |
| 262 | + |
| 263 | +* Macro **RCUTILS_SET_ERROR_MSG** in `rcutils` error_handling.h: [Check here](https://github.com/micro-ROS/rcutils/commit/bcaa00a6ed12fc62d05dc5e44521a1648fd2d07f#diff-1b06d4a1ccca0f0dff66d961923143a1R202) |
| 264 | + * Problem: use inconditionally `memmove` inside `__rcutils_copy_string()` inside `rcutils_set_error_state`. It implies dynamic memory allocation. |
| 265 | + * Dependecies: |
| 266 | + * rcl/rcl/include/rcl/error_handling.h |
| 267 | + * rcutils/src/security_directory.c |
| 268 | + * rcutils/src/time_unix.c |
| 269 | + * rcutils/src/split.c |
| 270 | + * rcutils/src/error_handling.c |
| 271 | + * rcutils/src/time.c |
| 272 | + * rcutils/src/string_map.c |
| 273 | + * rcutils/src/uint8_array.c |
| 274 | + * rcutils/src/hash_map.c |
| 275 | + * rcutils/src/char_array.c |
| 276 | + * rcutils/src/logging.c |
| 277 | + * rcutils/src/string_array.c |
| 278 | + * rcutils/src/array_list.c |
| 279 | + * rcutils/include/rcutils/types/array_list.h |
| 280 | + * rcutils/include/rcutils/types/hash_map.h |
| 281 | + * rcutils/include/rcutils/allocator.h |
| 282 | + * rcutils/include/rcutils/error_handling.h |
| 283 | + * rcl/rcl/include/rcl/error_handling.h |
| 284 | + * rmw/rmw/include/rmw/error_handling.h |
| 285 | + |
| 286 | +* Macro **RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING** in `rcutils` error_handling.h:. [Check here](https://github.com/micro-ROS/rcutils/commit/bcaa00a6ed12fc62d05dc5e44521a1648fd2d07f#diff-1b06d4a1ccca0f0dff66d961923143a1R218) |
| 287 | + * Problem: use `RCUTILS_SET_ERROR_MSG`, see above. |
| 288 | + * Dependecies: |
| 289 | + * rcl/rcl/include/rcl/error_handling.h |
| 290 | + * rcutils/src/security_directory.c |
| 291 | + * rcutils/src/string_map.c |
| 292 | + * rcutils/src/logging.c |
| 293 | + * rcutils/include/rcutils/error_handling.h |
| 294 | + * rcl/rcl/include/rcl/error_handling.h |
| 295 | + * rmw/rmw/include/rmw/error_handling.h |
| 296 | + |
| 297 | +### security_directory.c (moved from `rcl` to `rcutils`) |
| 298 | + |
| 299 | +* Function **get_best_matching_directory** in `rcutils` security_directory.c [Check here](https://github.com/micro-ROS/rcutils/commit/9804287c3489ce9c88b714832abf54f9a7b7198d#diff-1ca0173d6a68ba1bdcd9ff908b769911R91) |
| 300 | + * Problem: use **tinydir** library which relies on filesytem |
| 301 | + * Dependecies: |
| 302 | + * rcutils/src/security_directory.c |
| 303 | + * rcl/rcl/src/rcl/security_directory.c |
| 304 | + |
| 305 | +* Function **prefix_match_lookup**. [Check here](https://github.com/micro-ROS/rcutils/commit/9804287c3489ce9c88b714832abf54f9a7b7198d#diff-1ca0173d6a68ba1bdcd9ff908b769911L151) |
| 306 | + * Problem: use **tinydir** library which relies on filesytem |
| 307 | + * Dependencies: |
| 308 | + * rcutils/src/security_directory.c |
| 309 | + * rcl/rcl/src/rcl/security_directory.c |
| 310 | + |
| 311 | +### allocator.c |
| 312 | + |
| 313 | +* Function **rcutils_get_default_allocator**. [Check here](https://github.com/micro-ROS/rcutils/commit/3abb1eb2c9b206054101293997c0d4e541b1c657) |
| 314 | +* Problem: use static allocated **default_allocator** which uses malloc/free. **rcutils_set_default_allocator** is proposed. |
| 315 | +* Dependecies: |
| 316 | + * rcl/rcl/include/rcl/allocator.h |
| 317 | + * rcl/rcl/include/rcl/expand_topic_name.h |
| 318 | + * rcutils/src/allocator.c |
| 319 | + * rcutils/src/logging.c |
| 320 | + * rcutils/include/rcutils/types/string_map.h |
| 321 | + * rcutils/include/rcutils/types/array_list.h |
| 322 | + * rcutils/include/rcutils/types/string_array.h |
| 323 | + * rcutils/include/rcutils/types/hash_map.h |
| 324 | + * rcutils/include/rcutils/allocator.h |
| 325 | + * rmw_implementation/rmw_implementation/src/functions.cpp |
| 326 | + * rcl/rcl/include/rcl/allocator.h |
| 327 | + * rcl/rcl/include/rcl/expand_topic_name.h |
| 328 | + * rmw/rmw/src/allocators.c |
| 329 | + |
| 330 | +### filesystem.c |
| 331 | + |
| 332 | +* Functions **rcutils_get_cwd**, **rcutils_is_directory**, **rcutils_is_file**, **rcutils_exists**, **rcutils_is_readable**, **rcutils_is_writable** and **rcutils_is_readable_and_writable**. [Check here](https://github.com/micro-ROS/rcutils/commit/9804287c3489ce9c88b714832abf54f9a7b7198d) |
| 333 | + * Problem: rely on filesystem |
| 334 | + * Dependecies **rcutils_get_cwd()**: |
| 335 | + * rcutils/src/filesystem.c |
| 336 | + * rcutils/include/rcutils/filesystem.h |
| 337 | + * Dependecies **rcutils_is_directory()**: |
| 338 | + * rcutils/src/security_directory.c |
| 339 | + * rcutils/src/filesystem.c |
| 340 | + * rcutils/include/rcutils/filesystem.h |
| 341 | + * rcl/rcl/src/rcl/security_directory.c |
| 342 | + * Dependecies **rcutils_is_file()**: |
| 343 | + * rcutils/src/filesystem.c |
| 344 | + * rcutils/include/rcutils/filesystem.h |
| 345 | + * Dependencies **rcutils_exists()**: |
| 346 | + * rcutils/src/filesystem.c |
| 347 | + * rcutils/include/rcutils/filesystem.h |
| 348 | + * Dependencies **rcutils_is_readable()**: |
| 349 | + * rcutils/src/filesystem.c |
| 350 | + * rcutils/include/rcutils/filesystem.h |
| 351 | + * Dependencies **rcutils_is_writable()**: |
| 352 | + * rcutils/src/filesystem.c |
| 353 | + * rcutils/include/rcutils/filesystem.h |
| 354 | + * Dependencies **rcutils_is_readable_and_writable()**: |
| 355 | + * rcutils/src/filesystem.c |
| 356 | + * rcutils/include/rcutils/filesystem.h |
0 commit comments