ROS 2 Documentation: Galactic1
众所周知,在国内各种下载不流畅,所以首要的是准备魔术工具。这里推荐Trojan-Qt5,可以简单搞定GUI以及终端的上网问题。
Ubuntu 20.04支持图形界面直接更换源了,操作上简便了不少。基本参考链接: Ubuntu 20.04 apt 更换国内源的实现方法。2
设置完软件源,可以大大地加速我们的apt更新安装速度。
按照官方,要求是
Ubuntu Linux - Focal Fossa (20.04)
ROS2F在Ubuntu上有三种安装方法
由于我目前不需要修改ROS2源码,还只是处于用的阶段,因此采用最简单的Debian packages来安装。
官方要求是需要确认支持UTF-8,虽然说起来似乎不一定需要,不过确认一下即可。
特别是在docker容器内使用时,由于locale经常会被最小化地设置为POSIX。
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
运行结果如下
TWR:~$ locale # check for UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=
TWR:~$ sudo apt update && sudo apt install locales
Get:1 http://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:2 http://mirrors.ustc.edu.cn/ubuntu focal InRelease
Get:3 http://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease [114 kB]
Get:4 http://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease [101 kB]
Get:5 http://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,101 B]
Get:6 http://mirrors.ustc.edu.cn/ubuntu focal-security InRelease [114 kB]
Get:7 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 Packages [1,031 kB]
Get:8 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main i386 Packages [490 kB]
Get:9 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main Translation-en [229 kB]
Get:10 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 DEP-11 Metadata [283 kB]
Get:11 http://mirrors.ustc.edu.cn/ubuntu focal-updates/main amd64 c-n-f Metadata[13.5 kB]
Get:12 http://mirrors.ustc.edu.cn/ubuntu focal-updates/restricted amd64 Packages[272 kB]
Get:13 http://mirrors.ustc.edu.cn/ubuntu focal-updates/restricted Translation-en[39.5 kB]
Get:14 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe i386 Packages [576 kB]
Get:15 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 Packages [781 kB]
Hit:16 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Get:17 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe Translation-en [170 kB]
Get:18 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 DEP-11 Metadata [330 kB]
Get:19 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe DEP-11 48x48 Icons [203 kB]
Get:20 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 c-n-f Metadata [17.7 kB]
Get:21 http://mirrors.ustc.edu.cn/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:22 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe amd64 DEP-11 Metadata [1,768 B]
Get:23 http://mirrors.ustc.edu.cn/ubuntu focal-security/main amd64 DEP-11 Metadata [24.4 kB]
Get:24 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe i386 Packages [462 kB]
Get:25 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 Packages [588 kB]
Get:26 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe Translation-en [95.2 kB]
Get:27 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 DEP-11 Metadata [58.3 kB]
Get:28 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 c-n-f Metadata [11.5 kB]
Get:29 http://mirrors.ustc.edu.cn/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,468 B]
Fetched 6,014 kB in 2s (3,864 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
locales is already the newest version (2.31-0ubuntu9.3).
locales set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo locale-gen en_US en_US.UTF-8
Generating locales (this might take a while)...
en_US.ISO-8859-1... done
en_US.UTF-8... done
Generation complete.
TWR:~$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
TWR:~$ export LANG=en_US.UTF-8
TWR:~$ locale # verify settings
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=
1. 确认Ubuntu Universe仓库
我们需要将我们的ROS2 apt软件仓库加入系统,并运行以下命令确认Ubuntu Universe仓库是被enabled的。
TWR:~$ apt-cache policy | grep universe
500 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=i386
500 http://mirrors.ustc.edu.cn/ubuntu focal-security/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64
100 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=i386
100 http://mirrors.ustc.edu.cn/ubuntu focal-backports/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=amd64
500 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=i386
500 http://mirrors.ustc.edu.cn/ubuntu focal-updates/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=amd64
500 http://mirrors.ustc.edu.cn/ubuntu focal/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=i386
500 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64
由于更换了清华的国内源,我们可以在运行结果中看到
500 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64
这边关于源的地址
http://mirrors.ustc.edu.cn/ubuntu
根据设置的不同可能不一致,只要确认有focal/universe amd64 Packages这一条就说明已经设置成功了,如果没看到,则执行第2步 设置Universe仓库。
2. 设置Ubuntu Universe仓库
执行以下命令:
sudo apt install software-properties-common
sudo add-apt-repository universe
结果如下:
TWR:~$ sudo apt install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.98.9.5).
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo add-apt-repository universe
'universe' distribution component is already enabled for all sources.
3. 增加ROS 2 apt软件仓库
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
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
TWR:~$ sudo apt update && sudo apt install curl gnupg lsb-release
Hit:1 http://mirrors.ustc.edu.cn/ubuntu focal InRelease
Hit:2 http://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease
Hit:3 http://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease
Hit:4 http://mirrors.ustc.edu.cn/ubuntu focal-security InRelease
Hit:5 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:6 http://packages.ros.org/ros2/ubuntu focal InRelease
Hit:7 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
curl is already the newest version (7.68.0-1ubuntu2.5).
gnupg is already the newest version (2.2.19-3ubuntu2.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
TWR:~$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
TWR:~$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
注意:
这里如果直接执行的话,有可能会遇到raw.githubusercontent.com的DNS污染问题。
解决方法:
通过IPAddress.com,可以查到raw.githubusercontent.com的真实IP地址为 .*..
通过sudo vi /etc/hosts
在hosts文件最后加入IP和域名的绑定即可解决。
***.***.**.*** raw.githubusercontent.com
设置仓库后,更新apt仓库的缓存
sudo apt update
桌面版安装(推荐):包括ROS, RViz, demos, tutorials.
sudo apt install ros-galactic-desktop
ROS-Base版安装 (裸骨架): 通信库, 消息包, 命令行工具. 没有GUI工具.
sudo apt install ros-galactic-ros-base
在执行过程中,出现了broken packages错误
TWR:~$ sudo apt install ros-galactic-desktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
ros-galactic-desktop : Depends: ros-galactic-action-tutorials-cpp but it is not going to be installed
Depends: ros-galactic-action-tutorials-interfaces but it is not going to be installed
Depends: ros-galactic-action-tutorials-py but it is not going to be installed
Depends: ros-galactic-composition but it is not going to be installed
Depends: ros-galactic-demo-nodes-cpp but it is not going to be installed
Depends: ros-galactic-demo-nodes-cpp-native but it is not going to be installed
Depends: ros-galactic-demo-nodes-py but it is not going to be installed
Depends: ros-galactic-depthimage-to-laserscan but it is not going to be installed
Depends: ros-galactic-dummy-map-server but it is not going to be installed
Depends: ros-galactic-dummy-robot-bringup but it is not going to be installed
Depends: ros-galactic-dummy-sensors but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-action-client but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-action-server but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-client but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-composition but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-publisher but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-service but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-subscriber but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-minimal-timer but it is not going to be installed
Depends: ros-galactic-examples-rclcpp-multithreaded-executor but it is not going to be installed
Depends: ros-galactic-examples-rclpy-executors but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-action-client but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-action-server but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-client but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-publisher but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-service but it is not going to be installed
Depends: ros-galactic-examples-rclpy-minimal-subscriber but it is not going to be installed
Depends: ros-galactic-image-tools but it is not going to be installed
Depends: ros-galactic-intra-process-demo but it is not going to be installed
Depends: ros-galactic-joy but it is not going to be installed
Depends: ros-galactic-lifecycle but it is not going to be installed
Depends: ros-galactic-logging-demo but it is not going to be installed
Depends: ros-galactic-pcl-conversions but it is not going to be installed
Depends: ros-galactic-pendulum-control but it is not going to be installed
Depends: ros-galactic-pendulum-msgs but it is not going to be installed
Depends: ros-galactic-quality-of-service-demo-cpp but it is not going to be installed
Depends: ros-galactic-quality-of-service-demo-py but it is not going to be installed
Depends: ros-galactic-ros-base but it is not going to be installed
Depends: ros-galactic-rqt-common-plugins but it is not going to be installed
Depends: ros-galactic-rviz-default-plugins but it is not going to be installed
Depends: ros-galactic-rviz2 but it is not going to be installed
Depends: ros-galactic-teleop-twist-joy but it is not going to be installed
Depends: ros-galactic-teleop-twist-keyboard but it is not going to be installed
Depends: ros-galactic-tlsf-cpp but it is not going to be installed
Depends: ros-galactic-topic-monitor but it is not going to be installed
Depends: ros-galactic-turtlesim but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
TWR:~$ sudo apt install ros-galactic-ros-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
ros-galactic-ros-base : Depends: ros-galactic-geometry2 but it is not going to be installed
Depends: ros-galactic-robot-state-publisher but it is not going to be installed
Depends: ros-galactic-ros-core but it is not going to be installed
Depends: ros-galactic-rosbag2 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
注意:
试着根据依赖一个个修复,发现底下都有继续依赖的项目,这样也不是办法。
查了一圈,发现了 解决apt install包损坏问题方法3。
解决方法:
主要说来就是采用aptitude install命令替代apt install命令,在执行了
sudo aptitude install ros-galactic-desktop
或
sudo aptitude install ros-galactic-ros-base
如果系统中没有aptitude命令,先执行以下命令安装aptitude:
sudo apt-get install aptitude
aptitude命令与apt-get命令一样,都是Linux中的包管理工具。
但aptitude在处理依赖问题上比apt要更优秀一些。
举例来说,aptitude在删除一个包时,会同时删除本身所依赖的包。这样,系统中不会残留无用的包,整个系统更为干净。它通过文本操作菜单和命令两种方式管理软件包。
感兴趣的同学可以参考aptitude命令4。
当然在解决依赖的过程中,存在一些降级的需求,可以看我的另一篇博文Ubuntu20下用aptitude替代apt安装ROS包5。
source /opt/ros/galactic/setup.bash
在一个终端(A)里,运行配置,启动C++的talker
source /opt/ros/galactic/setup.bash
ros2 run demo_nodes_cpp talker
在另一个终端(B)里,运行配置,启动Python的listener
source /opt/ros/galactic/setup.bash
ros2 run demo_nodes_py listener
终端A中显示
TWR:~$ ros2 run demo_nodes_cpp talker
[INFO] [1623401499.188649472] [talker]: Publishing: 'Hello World: 1'
[INFO] [1623401500.188617681] [talker]: Publishing: 'Hello World: 2'
[INFO] [1623401501.188593316] [talker]: Publishing: 'Hello World: 3'
[INFO] [1623401502.188556101] [talker]: Publishing: 'Hello World: 4'
[INFO] [1623401503.188479541] [talker]: Publishing: 'Hello World: 5'
[INFO] [1623401504.188489280] [talker]: Publishing: 'Hello World: 6'
[INFO] [1623401505.188454974] [talker]: Publishing: 'Hello World: 7'
[INFO] [1623401506.188441022] [talker]: Publishing: 'Hello World: 8'
[INFO] [1623401507.188367939] [talker]: Publishing: 'Hello World: 9'
[INFO] [1623401508.188375095] [talker]: Publishing: 'Hello World: 10'
[INFO] [1623401509.188330276] [talker]: Publishing: 'Hello World: 11'
[INFO] [1623401510.188318712] [talker]: Publishing: 'Hello World: 12'
[INFO] [1623401511.188298142] [talker]: Publishing: 'Hello World: 13'
[INFO] [1623401512.188284017] [talker]: Publishing: 'Hello World: 14'
[INFO] [1623401513.188240477] [talker]: Publishing: 'Hello World: 15'
[INFO] [1623401514.188066415] [talker]: Publishing: 'Hello World: 16'
[INFO] [1623401515.188242309] [talker]: Publishing: 'Hello World: 17'
[INFO] [1623401516.188110920] [talker]: Publishing: 'Hello World: 18'
[INFO] [1623401517.188080784] [talker]: Publishing: 'Hello World: 19'
[INFO] [1623401518.188069913] [talker]: Publishing: 'Hello World: 20'
[INFO] [1623401519.187919954] [talker]: Publishing: 'Hello World: 21'
[INFO] [1623401520.188002262] [talker]: Publishing: 'Hello World: 22'
[INFO] [1623401521.187967031] [talker]: Publishing: 'Hello World: 23'
[INFO] [1623401522.187975595] [talker]: Publishing: 'Hello World: 24'
[INFO] [1623401523.188033320] [talker]: Publishing: 'Hello World: 25'
[INFO] [1623401524.187846522] [talker]: Publishing: 'Hello World: 26'
[INFO] [1623401525.187901371] [talker]: Publishing: 'Hello World: 27'
[INFO] [1623401526.187828211] [talker]: Publishing: 'Hello World: 28'
[INFO] [1623401527.187834611] [talker]: Publishing: 'Hello World: 29'
[INFO] [1623401528.187805688] [talker]: Publishing: 'Hello World: 30'
[INFO] [1623401529.187782235] [talker]: Publishing: 'Hello World: 31'
[INFO] [1623401530.187745137] [talker]: Publishing: 'Hello World: 32'
^C[INFO] [1623401530.710697371] [rclcpp]: signal_handler(signal_value=2)
直到收到Ctrl^C的中断
终端B中显示
TWR:~$ ros2 run demo_nodes_py listener
[INFO] [1623401519.208580911] [listener]: I heard: [Hello World: 21]
[INFO] [1623401520.188769293] [listener]: I heard: [Hello World: 22]
[INFO] [1623401521.190202256] [listener]: I heard: [Hello World: 23]
[INFO] [1623401522.190453180] [listener]: I heard: [Hello World: 24]
[INFO] [1623401523.190435333] [listener]: I heard: [Hello World: 25]
[INFO] [1623401524.188595768] [listener]: I heard: [Hello World: 26]
[INFO] [1623401525.190340553] [listener]: I heard: [Hello World: 27]
[INFO] [1623401526.190241530] [listener]: I heard: [Hello World: 28]
[INFO] [1623401527.190022097] [listener]: I heard: [Hello World: 29]
[INFO] [1623401528.190283940] [listener]: I heard: [Hello World: 30]
[INFO] [1623401529.190121333] [listener]: I heard: [Hello World: 31]
[INFO] [1623401530.190186865] [listener]: I heard: [Hello World: 32]
大功告成~~~
https://docs.ros.org/en/galactic/Installation.html ↩︎
https://www.jb51.net/article/187442.htm ↩︎
https://askubuntu.com/questions/363200/e-unable-to-correct-problems-you-have-held-broken-packages ↩︎
https://man.linuxde.net/aptitude ↩︎
https://blog.csdn.net/amuro_ray027/article/details/117820800 ↩︎