ROS 2 Humble Container For Incus
No more Ubuntu Re installs and VMs for new ROS Distros
ROS 2 is a sequel to the master-slave approach of ROS 1, and just like its prequel its mostly Ubuntu Distro specific but with a few know - hows from the previous Tutorials its possible to have various OS level containers that are just as fast as installing on the host system but are portable enough to not brick your system packages. The previous tutorials are listed below:
Creating a New Container:
ROS2 Humble is recommended to be installed in Ubuntu 22.04 LTS.
Assuming that the name of the Container is ros-humble
incus launch images:ubuntu/22.04 ros-humbleLaunching the container
incus exec ros-humble -- sudo --login --user ubuntuLaunch Shortcut (Optional)
I get it, sometimes that login command looks way too tedious to type (I'm Lazy), so we can create an alias (a.k.a short-cut) to login easily using:
incus alias add ubuntu 'exec @ARGS@ -- su -l ubuntu'Use this command only once, Its not required for subsequent newly created containers
This will now condense the login method to:
incus ubuntu ros-humbleInstall ROS2 Humble
This is identical to the instructions available from the Official Documentation:
Update and Upgrade existing system packages:
sudo apt update && sudo apt upgrade -ySet Locale
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 settingsVerify Locale
localeOutput:
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=Setup Sources
Ensure that the Ubuntu Universe repository is enabled
sudo apt install software-properties-common -y
sudo add-apt-repository universeAdd ROS2 GPG key with apt
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpgAdd repository to sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/nullInstall ROS2 Packages
sudo apt update && sudo apt upgrade -y
sudo apt install ros-humble-desktop ros-dev-tools -yAdd Environmental script to .bashrc
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrcInitialize Rosdep
sudo rosdep init
rosdep updateOptional Workflows:
GUI Support:
If you have not created the incus prior to this step, follow the instructions here, once the gui profile has been created, it can be added to our container.
incus profile add ros-humble guiReboot the container using incus reboot ros-humbleValidation:
Login to the container:
incus ubuntu ros-humbleInstall x11-apps and check for a gui:
sudo apt install x11-apps -y
xeyesNvidia Drivers with CUDA support:
incus config device add ros-humble gpu gpu gputype=physical
incus config set ros-humble nvidia.runtime=true
incus config set ros-humble nvidia.driver.capabilities=allReboot the container using incus reboot ros-humbleValidation:
Login to the container:
incus ubuntu ros-humbleRun nvidia-smi:
nvidia-smiOutput:
Sat Jul 22 05:51:20 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.116.04 Driver Version: 525.116.04 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:07:00.0 On | N/A |
| 30% 42C P8 12W / 170W | 347MiB / 12288MiB | 4% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
Install Conda / Mamba:
This has been covered in the tutorial here:
Follow this part whilst being in the container
Install VS-Code:
This has been covered in the tutorial here:
Follow this part whilst being in the container