# Simplifying ROS 2 embedded flows with colcon extensions

**URL:** <https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761>\
**Category:** ROS General\
**Tags:** ros2, embedded, hardware, wg-acceleration\
**Created:** [October 20, 2021, 11:56am UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761 "2021-10-20T11:56:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmayoral](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/vmayoral/32/3665_2.png) [@vmayoral](https://discourse.openrobotics.org/u/vmayoral)\
**Post date:** [October 20, 2021, 11:56am UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761/1 "2021-10-20T11:56:24Z")

</div>

For those of you dealing with embedded hardware in robots on a usual/daily basis, you’ll probably know how cumbersome and time consuming it sometimes becomes. Specially if you have more than one embedded targets.

In an attempt to simplify some of these embedded flows while aligning with ROS 2, we’ve contributed at [colcon-acceleration](https://github.com/ros-acceleration/colcon-acceleration) various extensions for colcon-core to include capabilities to navigate across firmware options in a workspace, customize the Linux kernel, create Xen hypervisor configurations and associated partitions, extracting ramdisks, and more. This can save you minutes, hours (or even days) depending on your familiarity with some of these embedded aspects.

Though these contributions have been made with hardware acceleration purposes in mind, the extensions themselves could be reused by other groups within the community. Pinging the Real-Time WG guys (@carlossv, @LanderU) or the Embedded WG (@mamerlan), among others. Here’re some of the current capabilities:

| verb | quick peek | description |
| --- | --- | --- |
| `select` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/6/6d899764e7ae581da12f4f2773ec13ee83fb77fa.svg)](https://asciinema.org/a/434781) | The `select` verb allows to easily select and configure a specific target firmware for hardware acceleration, and default to it while producing binaries and accelerators. |
| `list` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/6/6d899764e7ae581da12f4f2773ec13ee83fb77fa.svg)](https://asciinema.org/a/434781) | The `list` verb allows to inspect the acceleration firmware available in the ROS workspace, marking with a `*` the currently selected option. |
| `linux` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/6/6b15b5ca58c2c6ddbd359314a940b960b0368d11.svg)](https://asciinema.org/a/scOognokU4wt0PW3E1N4F0jCe) | The `linux` verb helps configure the Linux kernel in the raw SD card image produced by the firmware. E.g. `colcon acceleration linux vanilla` will produce a Linux vanilla kernel, whereas `colcon acceleration linux preempt_rt` will instead use a pre-built kernel and kernel modules for improved determinism (fully preemptible kernel). |
| `hypervisor` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/3/3681717f63edb0744b221f325596cbb68b0b7991.svg)](https://asciinema.org/a/443406) | The `hypervisor` verb helps configure the [Xen](https://xenproject.org/) hypervisor in the raw SD card image produced by the firmware. E.g. `colcon acceleration hypervisor --dom0 vanilla --domU vanilla --dom0less preempt_rt` will produce a raw image leveraging Xen with 3 VMs. The first, `dom0`, uses a vanilla kernel. The second, `domU`, uses a vanilla kernel. The third is a `dom0less` VM and uses a fully preemtible kernel (_preemt\_rt_). Unless otherwise specified, all VMs use the default ROS 2 configuration, PetaLinux-based rootfs, the LNS and an Ethernet link layer. |
| `emulation` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/5/5a55334abe7f61ddae1e1107ce4fde52419b3890.svg)](https://asciinema.org/a/443408) | The `emulation` verb helps manage the emulation capabilities with [QEMU](https://www.qemu.org/) open source machine emulator and virtualizer. This way, developers can test their setups and algorithms without the hardware, which facilitates testing and speeds up the development process allowing for CI/CD pipelines. Emulation boots the same SD card image produced by previous commands and including the ROS 2 development workspace, providing a unified development approach. |
| `platform` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/9/9ce3f7bd5e258f24169c9a358b94ce4e836ee93a.svg)](https://asciinema.org/a/443410) | The `platform` verb helps reports Vitis platform enabled in the firmware deployed in the ROS 2 workspace. |
| `mkinitramfs` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/d/d014b5e671be5cd57c3a28931bea7b3e9a994dda.svg)](https://asciinema.org/a/443412) | The `mkinitramfs` verb creates compressed cpio initramfs (ramdisks). These can then be used to back up the current rootfs or to create dom0less VMs in Xen easily. |
| `mount` / `umount` | [![asciicast](https://us1.discourse-cdn.com/flex022/uploads/ros/original/2X/c/cc8ba405cff5ba2251fd75315b4cd9d8f54de526.svg)](https://asciinema.org/a/443414) | The `mount` and `umount` verbs help mount/umount the raw SD card image produced by previous steps. This way, developers can easily access the embedded rootfs directly, across the various partitions of the raw image (e.g. as in the case of multi-VMs in Xen). |

We’re also looking for feedback on what other (embedded) things the community is missing when developing with their boards. Some of the aspects being considered include _network booting of multiple embedded targets_ (which is cool if you have a multi-board/SOM robot) and _simplified security additions and configurations for embedded_. Are there any asks out there that we should consider?

---

<div class="post-metadata">

**Author:** ![Osilva](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/osilva/32/11321_2.png) [@Osilva](https://discourse.openrobotics.org/u/Osilva)\
**Post date:** [October 20, 2021, 11:35pm UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761/2 "2021-10-20T23:35:38Z")

</div>

With respect to Qemu emulation what is the best source to find examples tutorials using ROS2?

---

<div class="post-metadata">

**Author:** ![vmayoral](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/vmayoral/32/3665_2.png) [@vmayoral](https://discourse.openrobotics.org/u/vmayoral)\
**Post date:** [October 21, 2021, 7:39am UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761/3 "2021-10-21T07:39:02Z")

</div>

The best example I know to get started is [this one](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/1_hello_xilinx.html#launch-hello-xilinx-example-in-an-emulated-kv260). I would recommend, nevertheless, to look at all those examples in order, as they were built so that people could dive into this incrementally:

1. [ROS 2 publisher](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/0_ros2_publisher.html)
2. [Hello Xilinx](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/1_hello_xilinx.html) (here’s the first intro to the use of emulation for hardware)
3. [HLS in ROS 2](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/2_hls_ros2.html)
4. [Offloading a ROS 2 publisher](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/3_offloading_ros2_publisher.html)
5. [Accelerated ROS 2 publisher](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/4_accelerated_ros2_publisher.html)
6. [Faster ROS 2 publisher](https://xilinx.github.io/KRS/sphinx/build/html/docs/examples/5_faster_ros2_publisher.html)

You can run all the examples in emulation, instead of with the real hardware. Note that Xilinx offers three build targets for its Vitis compiler (`v++`), the first two leverage emulation (QEMU):

- **Software Emulation** ( `sw_emu` ): The kernel code is compiled to run on the host processor. This allows iterative algorithm refinement through fast build-and-run loops. This target is useful for identifying syntax errors, performing source-level debugging of the kernel code running together with application, and verifying the behavior of the system. _Simply put, a transformation which runs all the code in an emulated processor matching the K26 SOM, as if there wasn’t any accelerator_ .
- **Hardware Emulation** ( `hw_emu` ) - The kernel code is compiled into a hardware model (RTL), which is run in a dedicated simulator. This build-and-run loop takes longer but provides a detailed, cycle-accurate view of kernel activity. This target is useful for testing the functionality of the logic that will go in the FPGA and getting initial performance estimates. _In other words, a simulation within an emulation. The FPGA is simulated and runs inside of an emulation (QEMU), sitting together to emulated processors and allowing to get performance estimations faster_ .
- **Hardware** ( `hw` ) - The kernel code is compiled into a hardware model (RTL) and then implemented on the FPGA, resulting in a binary that will run on the actual FPGA.

Note the `emulation` verb above allows you to do this directly from the colcon extensions contributed:

```bash
colcon acceleration emulation -h
usage: colcon acceleration emulation [-h] [--no-install] [--mixin-files [FILE [FILE ...]]]
                                     [--mixin [mixin1 [mixin2 ...]]]
                                     [emulation_type] [install_dir]

Manage emulation capabilities.
Vitis offers two emulation targets for development, debugging and validation purposes.

positional arguments:
  emulation_type Emulation of board with either PL software simulation ("sw_emu" key) or
                        PL software emulation ("hw_emu" key).
  install_dir relative path to the workspace directory to deploy in emulation
                        (typically 'install-*').

optional arguments:
  -h, --help show this help message and exit
  --no-install Do not copy install_dir (or default) to second partition

Mixin predefined sets of command line parameters:
  --mixin-files [FILE [FILE ...]]
                        Additional files providing mixins
  --mixin [mixin1 [mixin2 ...]]
                        No mixins are available for this verb

```

In other words, you can do something like:

```bash
colcon acceleration emulation sw_emu # for sw_emu
# or
colcon acceleration emulation hw_emu # for hw_emu

```

Of course, for kernels to be run in this emulated environments, you need to build them with the right flags. This is simplified and integrated into the `ament` extensions proposed. You can configure this directly in the kernel definition within the CMakeLists.txt of each ROS 2 package. See [this example](https://github.com/ros-acceleration/acceleration_examples/blob/main/accelerated_doublevadd_publisher/CMakeLists.txt#L55-L68).

If after all of this, you still want to dive deeper, then the following resources will be helpful:

- [KRS’ _HowTo and Troubleshooting_](https://xilinx.github.io/KRS/sphinx/build/html/docs/howto.html#) (includes lots of tips about manually emulating things, as opposed to use [colcon-acceleration](https://github.com/ros-acceleration/colcon-acceleration) tooling)
- [Xilinx Vitis _“Running Emulation”_ documentation page (`v2020.2`)](https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/runemulation1.html)
- [Xilinx Vitis _“Debugging Applications and Kernels”_ documentation page (`v2020.2`)](https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/debuggingapplicationskernels.html)
- [Xilinx Vitis _“Build Targets”_ documentation page (`v2020.2`)](https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/buildtargets1.html)

---

<div class="post-metadata">

**Author:** ![Osilva](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/osilva/32/11321_2.png) [@Osilva](https://discourse.openrobotics.org/u/Osilva)\
**Post date:** [October 21, 2021, 2:16pm UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761/4 "2021-10-21T14:16:06Z")

</div>

Thank you for the detailed response! I’ll work my way through the tutorials.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/ros/original/3X/b/6/b607ee3cc8e908b1b613bd74a683d749fea635a1.svg) [@system](https://discourse.openrobotics.org/u/system)\
**Post date:** [November 20, 2021, 2:16pm UTC](https://discourse.openrobotics.org/t/simplifying-ros-2-embedded-flows-with-colcon-extensions/22761/5 "2021-11-20T14:16:48Z")

</div>

Closed on November 20, 2021, 2:16pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
