This repo builds a Raspberry Pi 4 image with ROS 2 and the real-time kernel pre-installed. This image can be downloaded directly from the releases page, flashed to a SD card, and booted on a Raspberry Pi 4.
Before you start, you need an SD card that is at least 8GB in size.
xz
compression format. You will need to
decompress it. On Windows, try using 7-zip to do
this if your file archiver doesn't decompress this format already. Once
decompressed, you should have a file that ends with the extension .img
.
xz --decompress file.img.xz
in the command line.CHOOSE OS
.Use custom
.Write
to flash the image.ubuntu
and the password is ubuntu
. The default
hostname is ubuntu
. You can login either directly on the Raspberry Pi or
via SSH (enabled by default). You'll need to change your password the first
time you login.sudo apt update && sudo apt upgrade
sudo apt install ubuntu-desktop
sudo apt install ros-humble-desktop
ros2
into the terminal. You should
see:usage: ros2 [-h] [--use-python-default-buffering] Call `ros2 <command> -h` for more detailed usage. ...
ros2 is an extensible command-line tool for ROS 2.
options:
-h, --help show this help message and exit
[...omitted for brevity]
arm_freq=2000
and over_voltage=6
when using power
supplies that can consistently output 5V/3A (like the official power supply).The rest of this README is meant for developers who want to know more about the image builder.
This is a custom image builder for the Raspberry Pi 4. Some features:
PREEMPT_RT
applied.pv
to display progress when applicable.focal-rt-ros2/ros2/rootfs/setup/phase1.sh
for the setup script that runs against the Ubuntu image and focal-rt-ros2/rootfs
for files that gets overlaid on top of the Ubuntu image. That said, some basics are:
PREEMPT_RT
kernel.vcgencmd
).Why not docker? Unfortunately, the current setup doesn't work in Docker, as
I used systemd-nspawn
to make setting up and executing commands in a chroot easier
(mainly so I can save some time figuring out the various bind mounts I need, to
shutdown the container correctly if a command fails, and to force quit a
container if something goes really wrong by pressing ^] 3 times). This tool
also rely on loop devices, which are not namespaced and thus not readily usable
in Docker without privileged access. It may be possible to use Docker later by
changing this code, but for now it's not possible (the code will also likely be
uglier as nspawn can't be easily used in docker?).
Thus, you'll need a Linux machine with root and the following tools installed:
cut
, grep
, parted
, pv
, rsync
, truncate
, wget
, systemd-nspawn
,
and qemu-aarch64-static
.
You will also need python3
.
To build the focal-rt-ros2
image, you'll also need: zip
.
For Ubuntu, you can simply run:
$ sudo apt install parted pv rsync wget systemd-container qemu-user-static make zip
make jammy-rt-ros2
.make focal-rt-ros2
.out
folder and dd
it into an SD card (or flash it
in another way).There are two ways to use cross-compilation with this system:
To cross-compile, you'll need to install this builder on the host machine via setuptools:
[host]$ sudo python3 setup.py install
Make sure the built image is mounted by running the following command in the
same directory where you built the image. This will also create a file called
cache/loop-device.txt
that records which loop device is used to mount the
image.
[host]$ sudo ros-rt-img mount out/ubuntu-22.04.1-rt-ros2-arm64+raspi.img
This will mount the image at /tmp/rpi4-image-build
. At this point, you might
need to install dependencies into this image before you can build and link your
application. To do this, first enter the container:
[host]$ sudo ros-rt-img chroot
Then install any dependencies you want:
[rpi4image]# sudo apt install libboost-dev # An example
Note, this changes the built img file. So either you want to create a backup if you want the pristine copy (or alternatively, use the phase2 cross-compile instead).
This project provides a cmake toolchain
file and
its absolute is printed when you run the command ros-rt-img toolchain
. To use
this file with cmake, make sure you have the cross-compiler installed on your
host machine, then configure your project and build via the following commands:
[host]$ sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
[host]$ cd <project path>
[host]$ cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=$(ros-rt-img toolchain)
[host]$ cmake --build build -j $(nproc)
The targets built can then be copied to the Raspberry Pi (via SSH, or other means), where it can then run.
To unmount the img, run the following command in the same directory where you
mounted it originally (where it originally created the cache/loop-device.txt
file):
$ sudo ros-rt-img umount