ROS2学习(一).Ubuntu 20.04安装ROS2 Galactic
ROS 2 Galactic安裝手冊和踩過的坑
- 官方流程
- 準備工作
- 魔術工具
- 更換國內源
- 安裝前提
- 系統要求
- 安裝選擇
- 安裝流程
- 設置語言區域
- 設置源
- 安裝ROS2包
- 環境配置
- 驗證樣例
- 參考
之前寫過一篇18.04下安裝ROS2E的手冊,最近要用Moveit2了,發現還是要升級到Foxy Fitzroy,看了看,最新已經到了Galactic Geochelone,所以再記錄一下在Ubuntu 20.04下安裝ROS 2 Galactic Geochelone的過程,由于ROS 2在國內的安裝過程里面確實很多坑,記錄下來幫助大家避坑。
官方流程
ROS 2 Documentation: Galactic1
準備工作
魔術工具
眾所周知,在國內各種下載不流暢,所以首要的是準備魔術工具。這里推薦Trojan-Qt5,可以簡單搞定GUI以及終端的上網問題。
更換國內源
Ubuntu 20.04支持圖形界面直接更換源了,操作上簡便了不少。基本參考鏈接: Ubuntu 20.04 apt 更換國內源的實現方法。2
設置完軟件源,可以大大地加速我們的apt更新安裝速度。
安裝前提
系統要求
按照官方,要求是
Ubuntu Linux - Focal Fossa (20.04)
安裝選擇
ROS2F在Ubuntu上有三種安裝方法
- 二進制包
- Debian packages
- “fat” archive
- 源碼編譯
由于我目前不需要修改ROS2源碼,還只是處于用的階段,因此采用最簡單的Debian packages來安裝。
安裝流程
設置語言區域
官方要求是需要確認支持UTF-8,雖然說起來似乎不一定需要,不過確認一下即可。
特別是在docker容器內使用時,由于locale經常會被最小化地設置為POSIX。
運行結果如下
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... doneen_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的。
由于更換了清華的國內源,我們可以在運行結果中看到
500 http://mirrors.ustc.edu.cn/ubuntu focal/universe amd64 Packagesrelease 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倉庫
執行以下命令:
結果如下:
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軟件倉庫
首先要驗證我們的GPG key
注意:
這里如果直接執行的話,有可能會遇到raw.githubusercontent.com的DNS污染問題。
解決方法:
通過IPAddress.com,可以查到raw.githubusercontent.com的真實IP地址為 .*..
通過sudo vi /etc/hosts
在hosts文件最后加入IP和域名的綁定即可解決。
安裝ROS2包
設置倉庫后,更新apt倉庫的緩存
sudo apt update桌面版安裝(推薦):包括ROS, RViz, demos, tutorials.
sudo apt install ros-galactic-desktopROS-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 installedDepends: ros-galactic-action-tutorials-interfaces but it is not going to be installedDepends: ros-galactic-action-tutorials-py but it is not going to be installedDepends: ros-galactic-composition but it is not going to be installedDepends: ros-galactic-demo-nodes-cpp but it is not going to be installedDepends: ros-galactic-demo-nodes-cpp-native but it is not going to be installedDepends: ros-galactic-demo-nodes-py but it is not going to be installedDepends: ros-galactic-depthimage-to-laserscan but it is not going to be installedDepends: ros-galactic-dummy-map-server but it is not going to be installedDepends: ros-galactic-dummy-robot-bringup but it is not going to be installedDepends: ros-galactic-dummy-sensors but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-action-client but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-action-server but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-client but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-composition but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-publisher but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-service but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-subscriber but it is not going to be installedDepends: ros-galactic-examples-rclcpp-minimal-timer but it is not going to be installedDepends: ros-galactic-examples-rclcpp-multithreaded-executor but it is not going to be installedDepends: ros-galactic-examples-rclpy-executors but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-action-client but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-action-server but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-client but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-publisher but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-service but it is not going to be installedDepends: ros-galactic-examples-rclpy-minimal-subscriber but it is not going to be installedDepends: ros-galactic-image-tools but it is not going to be installedDepends: ros-galactic-intra-process-demo but it is not going to be installedDepends: ros-galactic-joy but it is not going to be installedDepends: ros-galactic-lifecycle but it is not going to be installedDepends: ros-galactic-logging-demo but it is not going to be installedDepends: ros-galactic-pcl-conversions but it is not going to be installedDepends: ros-galactic-pendulum-control but it is not going to be installedDepends: ros-galactic-pendulum-msgs but it is not going to be installedDepends: ros-galactic-quality-of-service-demo-cpp but it is not going to be installedDepends: ros-galactic-quality-of-service-demo-py but it is not going to be installedDepends: ros-galactic-ros-base but it is not going to be installedDepends: ros-galactic-rqt-common-plugins but it is not going to be installedDepends: ros-galactic-rviz-default-plugins but it is not going to be installedDepends: ros-galactic-rviz2 but it is not going to be installedDepends: ros-galactic-teleop-twist-joy but it is not going to be installedDepends: ros-galactic-teleop-twist-keyboard but it is not going to be installedDepends: ros-galactic-tlsf-cpp but it is not going to be installedDepends: ros-galactic-topic-monitor but it is not going to be installedDepends: 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 installedDepends: ros-galactic-robot-state-publisher but it is not going to be installedDepends: ros-galactic-ros-core but it is not going to be installedDepends: 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-ros-base如果系統中沒有aptitude命令,先執行以下命令安裝aptitude:
sudo apt-get install aptitudeaptitude命令與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 ??
總結
以上是生活随笔為你收集整理的ROS2学习(一).Ubuntu 20.04安装ROS2 Galactic的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫实践 —— 一、入门篇
- 下一篇: ROS2学习(三).ROS2环境配置