Follow+Star Public Account Number, don’t miss wonderful content
Author | strongerHuang
WeChat Public Account | Embedded Column
Embedded Column
1
Unlike ordinary OS (RTOS, TSOS), ROS is primarily aimed at robots, providing a series of libraries and tools on top of the operating system to help software developers create robotic applications. It offers hardware abstraction, device drivers, library functions, visualization, messaging, and software package management, among many other functionalities. ROS adheres to the BSD open-source license.
ROS designers describe ROS as “ROS = Plumbing + Tools + Capabilities + Ecosystem”, meaning that ROS is a collection of communication mechanisms, tool packages, high-level skills for robots, and the robot ecosystem.
Embedded Column
2
Traditionally, even with many ROSs, ROS still stays at the boundary of microcontrollers. They are usually integrated through serial protocols with tools like ROS-serial in the old ROS.
Wouldn’t it be great to have all the functionalities of ROS 2 and the same API in a microcontroller? That’s exactly what micro-ROS provides – an embedded part of the ROS development ecosystem within the robotic system. micro-ROS allows developers to run ROS 2 nodes close to the hardware level. This makes all hardware peripherals available to the application, enabling direct interaction with low-level buses like SPI or I²C to interface with sensors and actuators.
Micro-ROS is a set of layered libraries that can directly reuse ROS 2 libraries or adapt them to the functionalities and needs of resource-constrained devices. Specifically, if we turn to the ROS 2 architecture, the layers maintained by micro-ROS are the ROS Client Library (RCL) and the ROS Middleware Interface (RMW). Similarly, RCLCPP is the C++ abstraction layer on top of RCL, which can be used by micro-ROS application components even though most interface directly with RCL. This layer provides additional functionalities relative to ROS 2 in RCLC, which is a library written in C99 designed and developed with functionalities similar to those provided by RCLCPP, such as convenience functions or executors suitable for microcontrollers.
Typically, ROS is a set of systems running on top of Linux, while this micro-ROS system runs on FreeRTOS.
This makes micro-ROS compatible with most embedded platforms at both hardware and software levels.
However, the final component of the micro-ROS architecture is the RMW implementation, which is based on a middleware library called Micro XRCE-DDS. Micro XRCE-DDS is a C/C++ implementation of the DDS-XRCE (DDS for Extreme Resource Constrained Environments) protocol defined and maintained by the Object Management Group (OMG).
As the name suggests, DDS-XRCE is a wired protocol that allows the introduction of a data-centric publisher-subscriber DDS model into the embedded world. DDS-XRCE relies on a client-server architecture, where the client is a lightweight entity written in C99 that can run on low-resource devices, while the proxy (a C++11 application) acts as a bridge between the client and the DDS world. The DDS-XRCE protocol is responsible for passing requests and messages between these two entities. Accordingly, the proxy is able to communicate with the global DDS data space through standard DDS wired protocols. In the DDS world, the proxy represents the client by communicating with other DDS participants. This communication is coordinated by the client proxy, which can interact with DDS through a simulated DDS application capable of communicating with all standard DDS entities. The proxy keeps the client’s state in its memory, so even if the proxy disconnects, it can survive. Communication between the proxy and the client follows a request-response pattern, which is bidirectional and based on operations and responses.
Embedded Column
3
Specifically, FreeRTOS has become one of the first RTOS supported by the micro-ROS project, and has been integrated into its software stack. This allows reuse of all tools and implementations provided by the FreeRTOS community and partners. Since the micro-ROS software stack is modular, swapping software entities is expected and anticipated.
FreeRTOS is an ideal choice for developing micro ROS and Micro XRCE-DDS applications. First, it provides an independent solution for many different architectures and development tools, is written in a very clear and transparent manner, and has a very large user base, ensuring that a large number of FreeRTOS users will be able to integrate their applications with micro-ROS applications. Moreover, it is well-known for being a highly reliable RTOS. Crucially, FreeRTOS has minimal ROM, RAM, and processing overhead. Typically, the size of the RTOS kernel binary image ranges from 6K to 12K bytes. Since competition for resources with RTOS is required, this memory is ideal when minimizing the memory footprint of micro-ROS applications on MCUs.
In the following sections, we will discuss several functionalities provided by FreeRTOS, and how micro-ROS leverages them to optimize the required functionalities of the different libraries that make up its stack.
Embedded Column
4
There are two types of tasks provided by FreeRTOS: standard tasks and idle tasks. The former are created by the user and can be seen as applications on the RTOS. Crucially, integrating micro-ROS applications into the RTOS as one of these tasks with a given priority is essential. The idle task, on the other hand, is a lower-priority task that only enters the running mode when no other tasks are running. Since micro-ROS is primarily aimed at low-power and IoT devices, these idle tasks and associated idle hooks are very suitable for enabling deep sleep states in MCUs. Since the stateless XRCE-DDS client is implemented as micro-ROS middleware, these deep sleep states can be memory volatile, meaning that due to the connection-oriented middleware wired protocol, deep sleep modes can be used without RAM persistence.
Using the FreeRTOS scheduler, micro-ROS is able to manage the priority of its main tasks as well as those responsible for the transport layer. Typically, the tasks responsible for the network stack or serial interfaces must take precedence over the micro-ROS applications.
Embedded Column
5
In this regard, it is worth mentioning that these memory management tools provide an ideal framework for benchmarking the memory footprint of micro-ROS and XRCE-DDS. Specifically, a thorough stack consumption analysis has been conducted to assess the memory consumption of XRCE-DDS clients. The stack is a block of memory unknown to the programmer before the application runs. To measure it, the FreeRTOS uxTaskGetStackHighWaterMark() function can be used, which returns the amount of unused stack when the XRCE-DDS task stack reaches its maximum during execution. By subtracting this value from the total stack, the peak stack usage of the XRCE-DDS application can be obtained. The results obtained using this method are summarized in a report published here.
We also note that due to the use of a pluggable dynamic memory management approach in FreeRTOS, micro-ROS is able to fulfill the required interfaces for managing memory. In this way, functions such as calloc() or realloc() have been implemented using heap_4 as a reference. These functions have been wrapped before being fed into the micro-ROS memory management API for analysis of dynamic memory consumption.
Similar to static memory scenarios, FreeRTOS’s interchangeable dynamic memory management approach makes it particularly easy to perform dynamic memory profiling analysis in embedded systems. Indeed, while in other RTOSs, dynamic (de)allocation functionalities are hidden deep within the RTOS or standard libraries, in FreeRTOS, they are exposed to users and easy to customize, thus simplifying the process of handling and controlling dynamic memory usage.
Embedded Column
6
In addition to the TCP/IP stack, lwIP has several other important components, such as network interfaces, operating system emulation layers, buffers, and memory management sections. The operating system emulation layer and network interface allow the network stack to be ported to the operating system, providing a common interface between the lwIP code and the operating system kernel.
The integration of FreeRTOS with lwIP is designed from the ground up with standard and familiar interfaces (Berkeley sockets), and with thread safety, aimed at making it as easy to use as possible. Moreover, it can retain buffer management in a portable layer.
It is worth noting that the XRCE-DDS client also supports the FreeRTOS + TCP network stack. FreeRTOS + TCP is the official FreeRTOS extension library for TCP/IP stack protocol support.
Efforts are also being made to ensure compatibility between FreeRTOS + TCP and micro-ROS. This includes support for TCP and UDP connections, relying on the FreeRTOS + TCP API to provide the abstraction layer required by the micro XRCE-DDS Client API to communicate with the proxy using these protocols.
Additionally, there is the possibility of using FreeRTOS’s timing measurement functionalities, allowing the XRCE-DDS library to perform time-based tasks without users noticing the implementation.
Embedded Column
7
Indeed, although the micro-ROS middleware has a lower POSIX dependency (just the clock_gettime() function), the entire micro-ROS stack has a higher dependency related to functionality and type definitions. Additionally, since one of the fundamental principles of the micro-ROS project is to port or reuse code from ROS 2 natively coded in Linux (mainly POSIX compatible operating systems), an RTOS that is somewhat compatible with Linux is used. POSIX is obviously beneficial as it requires minimal effort to port the code.
For this purpose, functions like sleep() and usleep() are used. The POSIX type definition dependencies of micro-ROS rely on certain structures that are not defined in the FreeRTOS kernel, such as struct timeval or struct timespec. Some standard type definitions and structures also require files like type.h, signal.h, or unistd.h to be defined.
Regarding errno.h, although it is not implemented in the FreeRTOS + POSIX layer, micro-ROS must include some unavailable definitions for compilation purposes.
By using the FreeRTOS + FAT library, these definitions should be reconstructed in the micro-ROS stack to ensure full compatibility with FreeRTOS + POSIX. This way, advanced micro-ROS functionalities that depend on file system support, such as logging mechanisms, can be fully supported.
Embedded Column
8
The tutorial address:
(The public account does not support external links, please copy the link to open in the browser)
Embedded Column
9
As the user base of micro-ROS and FreeRTOS rapidly expands and compelling use cases surge, further integration of micro-ROS with FreeRTOS and the libraries provided by FreeRTOS + is expected in the near future.
Among these, leveraging the FreeRTOS + FAT library appears particularly desirable to add a virtual file system component, allowing logging operations to be visualized and managed just like in a fully deployed ROS 2 ecosystem.
Further utilization of the memory management tools described in the dedicated section is also envisioned to extend the memory profiling of the XRCE-DDS client, thereby providing similar analysis for the micro-ROS client.
Another future action planned for the micro-ROS project is to adopt the certified version of FreeRTOS, SafeRTOS.
Last but not least, it is worth mentioning two very successful cases of hardware integration related to the typical target applications of FreeRTOS and micro-ROS, namely the powerful Crazyflie 2.1 drone and the ESP32 MCU hardware. In fact, Crazyflie software can leverage several tools and functionalities of FreeRTOS. Examples of demonstrations of micro-ROS applications with FreeRTOS related to this MAV work can be understood here. As for the second hardware that integrates natively with FreeRTOS and provides ready-made Wi-Fi antenna and Bluetooth functionality, the latest micro ROS port has been conducted on this system.
For more content, please refer to:
Reply with『RTOS』『FreeRTOS』『Microcontroller』 to read more related articles.
Click “Read Original” for more shares, welcome to share, collect, like, and view.