Install ROS2 (ros-humble-desktop) on Ubuntu 22.04 LTS

This article records the process of installing ROS2 on the Ubuntu 22.04 virtual machine and the problems encountered.

1. Determine the Ubuntu and ROS versions

There is a version correspondence between Ubuntu and ROS2. For details, you can see this page on the official website:
REP 2000 – ROS 2 Releases and Target Platforms (ROS.org)
where the humble version of ROS2 (that is, the latest version as of early October 2022) requires As follows:
insert image description here
So the ROS2 version that should be installed on Ubuntu 22.04 is ros-humble-desktop.
In addition, if the version number of Ubuntu has the word LTS (Long Term Support), it is a long-term support version, and you should give priority to this version when installing Ubuntu.

2. Configuration and installation

Official installation documentation link: Ubuntu (Debian) — ROS 2 Documentation: Humble documentation

2.1 Set the locale

The official case naturally uses the English locale, but according to the documentation, any locale that supports UTF-8 is fine.

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

2.2 Set Ubuntu software source

2.2.1 First confirm whether the Universe source has been enabled

Check with the following command:

apt-cache policy | grep universe

The return may have several lines, but should contain the following:

500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
    release v=22.04,o=Ubuntu,a=jammy,n=jammy,l=Ubuntu,c=universe,b=amd64

If the above content is not included, enter the following command:

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

2.2.2 Add ROS 2 apt repository

a) Add certificate

sudo apt update && sudo apt install curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

If you encounter this step Failed to connect to raw.githubusercontent.com, please visit https://www.ipaddress.com website, enter: in the query box raw.githubusercontent.comand press Enter, and find the corresponding ipv4 address in it:
insert image description here
choose any one of these four IP addresses, use sudo vi /etc/hoststhe IP and the domain name are added to /etc/hoststhe file, as shown below:
insert image description here

b) Add ros repository

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

2.3 Install the ros2 package

sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop

You may encounter the following errors:
insert image description here
Solution: Replace all: in "/etc/apt/sources.list" http://cn.archive.ubuntu.com/ubuntu
with available mirrors, such as Alibaba Cloud's: http://mirrors.aliyun.com/ubuntu/. Then use sudo apt --fix-broken installthe command to repair the incomplete installation. For other mirror lists, please refer to the China section in Mirrors: Ubuntu .

The Desktop version (recommended) includes: ROS, RViz, demos, tutorials.
Veterans can install the base version. sudo apt install ros-humble-ros-baseThe base version only includes Communication libraries, message packages, command line tools. GUI tools are not included.

2.4 Configure environment variables

source /opt/ros/humble/setup.bash
echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc 

3 tests

Open the first terminal and start a data publisher node:

ros2 run demo_nodes_cpp talker

You should see
insert image description here
Open a second terminal and start a data subscriber node:

ros2 run demo_nodes_py listener

You should see:
insert image description here

Guess you like

Origin blog.csdn.net/toopoo/article/details/127178416
Recommended