Installing ROS2 humble on RISC-V Ubuntu

Hi all!

I’m new to ROS 2, and I’m trying to install it on a RISC-V Ubuntu 22.04.3 using QEMU. I’m following these isntructions:

https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html

The main issue is that ROS repository does not support riscv targets, and I wonder how difficult it is to add support to this architecture or how to build it from source without using ROS repo. Can anyone send me a few pointers to achieve this?

1 Like

Moderator note: we usually don’t allow questions of the type, “How do I install X version of ROS on Y host OS.” Questions like those usually need to go to Robotics Stack Exchange. In this case I don’t really know about the status of ROS installation on RISC-V (but I would like to!). Feel free to use this thread to share pointers on compiling ROS for RISC-V.

I’ll use this topic to record all the steps I’m taking in case someone finds them useful.

I’m using an Ubuntu Server 22.04.3 preinstalled image that can be download from here. I also use QEMU 8.2.1 to emulate a RISC-V machine. For QEMU, we need additional boot files, which can be downloaded from here.

I’m working on an isolated ros2-riscv directory, and I have the Ubuntu image, the bios and the kernel files in ros2-riscv/boot. So, to start QEMU, just type the following command:

qemu-system-riscv64 \
    -machine virt -nographic -m 4096 -smp 4 \
    -bios boot/fw_jump.elf \
    -kernel boot/uboot.elf \
    -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
    -drive file=boot/ubuntu-22.04.3.img,format=raw,if=virtio

Now that we “are” on a RISC-V Ubuntu machine, let’s get some inspiration from the ROS 2 installation from source guide.
The main issue is that we cannot use the ROS 2 repository, because it does not provide binaries for RISC-V. So we are going to be alternatively working with apt and pip to get the dependencies.

System setup

Set locale

This is exactly the same as in the official instructions:

locale  # check for UTF-8

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

locale  # verify settings

Enable required repositories

Here things differ a bit. I think we can only do the following:

sudo apt install software-properties-common
sudo add-apt-repository universe

Install dependencies

Okay, let’s try to install all the stuff required but without using ros-dev-tools. We will use apt and pip:

sudo apt update && sudo apt upgrade && sudo apt install -y \
    build-essential \
    cmake \
    git \
    apt-utils \
    ca-certificates \
    conntrack \
    curl \
    dh-python \
    dhcpcd5 \
    ebtables \
    ethtool \
    git-lfs \
    gnupg2 \
    ifupdown \
    iptables \
    iproute2 \
    iputils-ping \
    libasio-dev \
    libbullet-dev \
    libconsole-bridge-dev \
    libtinyxml2-dev \
    libeigen3-dev \
    lsb-release \
    net-tools \
    openssh-client \
    python3-dev \
    python3-distlib \
    python3-empy \
    python3-lark \
    python3-notify2 \
    python3-numpy \
    python3-pip \
    python3-pytest-cov \
    python3-setuptools \
    python3-yaml \
    samba \
    socat \
    systemd \
    vim \
    wget 

DISCLAIMER: Probably we don’t need ALL those dependencies. Feel free to opt out some of them (and share with us :smiley: )

There are still some dependencies missing that are not available without ROS 2 repo. Let’s use pip for them:

sudo pip install vcstool \
    rosdep \
    catkin-pkg-modules \
    rosdistro-modules \
    colcon-common-extensions

So far so good. Let’s move to building ROS 2.

Build ROS 2

Get ROS 2 code

The same as in the official docs:

mkdir -p ~/ros2_iron/src
cd ~/ros2_iron
vcs import --input https://raw.githubusercontent.com/ros2/ros2/iron/ros2.repos src

Install dependencies using rosdep

Here things start being a bit tricky:

sudo rosdep init
rosdep update
rosdep install -r --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

Take a closer look: I added the -r option to ignore failures. rosdep assumes we have access to the ROS repo and uses apt to install some dependencies. apt will fail finding some dependencies. Thankfully, we could download them using pip previously. In any case, rosdep will print which packages failed, so you can double-check that we installed them using pip previously and that we are good to go.

Build the code in the workspace

I’m currently stuck here. If you run the following command:

colcon build --symlink-install

It starts building some dependencies… but it will eventually fail with mimick_vendor. In essence, mimick_vendor just tries to compile the Mimick package which does not support RISC-V architectures. However, the original fork of this package has an open PR that DOES provide support for RISC-V. Sadly, it seems that the author is not very active. However, I already opened a few issues asking the maintainers of ROS 2 Mimick to add this functionality.

From now, I’ll tweak the ROS dependency list to point to this fork that provides support for RISC-V and see if I can advance in the installation. I’ll keep you updated.

1 Like

It worked!

FIRST OF ALL: you need AT LEAST 25 GB of hard drive space in your VM to install ROS 2 from source. Make sure that you have the space before continuing.

Before “Build the code in the workspace”

As I previously mentionend, the Mimick library does not provide support for RISC-V 64. However, GitHub user @ziyao233 helped me and opened a PR to fix this (thank you so much!). So, before building the code, we must tweak the mimick_vendor dependency:

vi ~/ros2_iron/src/ros2/mimick_vendor/CMakeLists.txt
   # Go to line 61 and modify the commit hash to https://github.com/ziyao233/Mimick/tree/ros2-fixed:
  set(mimick_version "90d02296025f38da2e33c67b02b7fa0c7c7d460c")
    # Go to line 63 and modify git repo to https://github.com/ziyao233/Mimick:
    GIT_REPOSITORY https://github.com/ziyao233/Mimick.git

We are now ready to go.

Build the code in the workspace

You can now run the build command:

cd ~/ros2_iron/
colcon build --symlink-install

On out-of-memory errors

Sometimes, the build process gets out of memory. If that is your case, just re-enter the colcon build command as follows:

colcon build --packages-skip-build-finished --symlink-install

It will skip already built packages and save you time. The build process is very long, so be patient :slight_smile:

We can now proceed with the official guide:

Setup environment

. ~/ros2_iron/install/local_setup.bash

Try some examples

Check the C++ API:

ros2 run demo_nodes_cpp talker

And the Python API:

ros2 run demo_nodes_py listener

I hope I did not forget any step. Anyway, I plan to go through all the steps to verify that it works. Cheers!

2 Likes

Hi !

Have you considered cross compiling? Should be able to do so with yocto and meta-ros or forked meta-ros. Should be more reproducible and you can use the probably not that much limited hardware on the host.

Regrads,
Matthias

1 Like

Didn’t think about it! I’ll explore this option and let you know

I’d like to add in some tips:
I also needed to install lark using pip install lark.
For minimal, headless machines, adding

--packages-ignore rqt_gui_cpp qt_gui_cpp

will skip some QT dependencies which would fail otherwise and might add some avoidable build time.

1 Like

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