Ubuntu22.04对应的ROS2的版本为Humble Hawksbill(ros-humble)
如果不是在Ubuntu22.04中安装ROS,请参考下面Ubuntu和ROS的版本对应关系
$ sudo apt update
将ubuntu环境语言编码设置为en_US en_US.UTF-8(疑问:不设置会咋样?)
安装locales用来配置ubuntu语言环境
locale-gen:配置语言环境并生效
update-locale:将更新语言环境配置
$ 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
首先设置DNS,否则报错
curl: Failed to connect to raw.githubusercontent.com port 443 after 1000 ms: Connection refused
1)登录网站:https://www.ipaddress.com
2)在打开的网站中将“raw.githubusercontent.com”复制到查询栏中进行搜索,可以看到域名对应的IP地址信息
3)修改i/etc/hosts
~$ cat /etc/hosts
127.0.0.1 localhost
185.199.108.133 raw.githubusercontent.com
4)重启电脑,使DNS生效
$ 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
$ 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
大约需要2G空间
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install ros-humble-desktop
执行ros的环境脚本
$ source /opt/ros/humble/setup.bash
将上述命令写入~/.bashrc,这样每次打开终端就会自动执行配置ROS2环境的脚本,不需要手动执行了
$ echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc
测试目的:测试ROS2最为重要的底层通信系统DDS是否正常
终端1中执行如下命令:
$ ros2 run demo_nodes_cpp talker
打印信息如下:
[INFO] [1684480670.409470994] [talker]: Publishing: 'Hello World: 1'
[INFO] [1684480671.409418842] [talker]: Publishing: 'Hello World: 2'
[INFO] [1684480672.409424762] [talker]: Publishing: 'Hello World: 3'
……
终端2中输入:
$ ros2 run demo_nodes_py listener
打印信息如下:
[INFO] [1684480681.849102662] [listener]: I heard: [Hello World: 12]
[INFO] [1684480682.410752673] [listener]: I heard: [Hello World: 13]
[INFO] [1684480683.410712416] [listener]: I heard: [Hello World: 14]
……
如果系统正常,将会在终端2中看到“I heard: [Hello World: xx]”
终端1中输入:
$ ros2 run turtlesim turtlesim_node
令将启动一个蓝色背景的海龟仿真器
终端2中输入:
$ ros2 run turtlesim turtle_teleop_key