Micro-ros C++ application

Dear all,

I’m a newbie on the ROS2/microROS. I’d like to know how to compile and/or execute a C++ application using Micro-Ros instead of ROS2.

Our current setup includes a micro-ROS bare-metal C application, running on the Xilinx ZCU102 board, and various ROS2 C++ applications, running on the Ubuntu 20.04 host with the micro-ROS agent. As for the next part, we need to move one C++ application to the Xilinx board and consequently from ROS2 to micro-ROS.
Do I have to rewrite the application in C? So far I’ve found only micro-ROS C-based examples.

Thanks in advance.

Generally we ask that questions go to answers.ros.org. I am going to let this one slide as it is a good discussion question about porting micro-ROS applications and dove tails with the new HW Acceleration WG. It is also a good chance to talk about how people structure more complex ROS 2 applications

@vmayoral @FraFin @Jaime_Martin_Losa – would love your two cents, or two euros cents.


So how do we deal with the older cross-post on ROS Answers?

Welcome @evi001 to the community,

You have two avenues forward in here:

  1. If your objective is to run stuff in the ZCU102, why don’t you simply run your micro-ROS Agent and ROS 2 logic natively in the ZU+ APUs (or just run everything natively in ROS 2)? This can be easily done if your ZCU102 FS is Ubuntu/Debian-based, just install ROS 2 from deb files. This is well documented. If instead you’ve got a PetaLinux-based fs, use meta-ros. Add the layers into your PetaLinux project and build them altogether to get a new FS with ROS 2 support. You can ask new questions at https://answers.ros.org/. If you’re struggling, I’d encourage you to stay tuned to the Hardware Acceleration Working Group activities. The ZCU102 is one of the community boards we’re supporting and we’re hoping to release tools soon to automate embedded flows.

  2. You could run everything with micro-ROS as a client. I had a quick look and found rclcpp micro-ROS examples (GitHub - micro-ROS/micro-ROS-demos: Sample code using rclc and rclcpp implementations.), however, this doesn’t seem to be advertised in the architecture. The underlying default RTOS (at least last time I checked) is NuttX, which has some degree of C++ support. However layers between the RTOS and rcl need also to expose such capability. I don’t see rclcpp in the last diagram so I’ll defer to @FraFin @Jaime_Martin_Losa , @Ingo_Lutkebohle and @ralph-lange (amongst many others) who know more about this than me.

Actually, you have a few more. I should have said, two “simple” ones.

Thank you for explaining the two avenues and for pointing to the C++ examples for micro-ROS, @vmayoral. That’s very well summarized.

Rclcpp makes intensive use of dynamic memory allocations, which is generally considered harmful when developing software for tiny microcontrollers. That’s why rclcpp is not shown in the current version of the micro-ROS architecture diagram, but you can use it directly with the micro-ROS stack. In the micro-ROS organization on GitHub, you’ll also find an example for the use of uClibc++. (Note that uClibc++ is licensed under LGPL.)

There is also a decision paper from 2019 that analyzes the different options in more depth and explains the choice of rcl+rclc. You can find the paper at Introduction to Client Library | micro-ROS.

Recently, in the Embedded Working Group, a discussion was triggered about providing a C++ API that uses C++ compile-time features only. Technically, such API could even be integrated in rclc. We plan a dedicated slot to discuss this topic (and to seek for contributors) in the next Embedded Working Group on July 27th. It would be great if you, @evi001, could attend the meeting.


thanks for the welcome to the ROS community and your replies.
I’ll answer to the avenues pointed out by @vmayoral.

The first option is not feasible due to some constraints on the system.
In fact, the system has to be distributed with one application component running on the Xilinx board, whereas other application components and micro-ROS agent have to run on a separate host machine with Ubuntu 20.04.
The application component on the Xilinx board will be executed on top of our RTOS and communicate with other ROS2 components through the micro-ROS agent. The source code of the application has been already implemented for C++.

As for the micro-ROS examples (GitHub - micro-ROS/micro-ROS-demos: Sample code using rclc and rclcpp implementations.), I’ve already tested some examples. As for the C examples, I’ve been able to run the same example as ROS2 node and micro-ROS node (using RMW_IMPLEMENTATION macro), whereas as for the C++ examples, I’ve been able to run the examples only as ROS2 nodes. Given my little experience on the subject, I don’t know how to execute one of the C++ examples for micro-ROS. From what I’ve recalled from @ralph-lange, it is still an open topic. Is it right?

Thanks in advance.

A dedicated C++ API for micro-ROS is an open topic and will be discussed in the next Embedded WG on July 27th, but we have examples for use of C++ with micro-ROS and the rcl+rclc client library. An older example from Dashing is the Kobuki demo, which uses classes and exceptions. The sources for the microcontroller can be found at nuttx_apps/examples/kobuki at demo/safe_kobuki · micro-ROS/nuttx_apps · GitHub.