2021年2月20日 星期六

在Ubuntu 20.04中安装ROS2 Foxy Fitzroy

在Ubuntu 20.04中安装ROS2最新版本Foxy Fitzroy_大橙员-CSDN博客 

ROS2 是新一代機器人操作系統。 2020年6月5日,ROS2 的最新版本 正式發佈了, 支援到2023年的3月!Foxy Fitzroy

在这里插入图片描述

ROS2 支持的平台

  • Linux (Ubuntu Focal(20.04))
  • macOS
  • Windows

ROS2 真正是跨平臺了,ROS1 只支援 Linux。

有大神說,不要搞 ROS1 了,直接上 ROS2 ~~

安裝ROS2

我們按照官方的文檔在 Ubuntu 20.04 中安裝 ROS2 Foxy Fitzroy:

設置本地設置

確保系統要支援 :UTF-8

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
  • 1
  • 2
  • 3

設置源

新增ROS2的來源:

sudo apt update
sudo apt install curl gnupg2 lsb-release

# 下面这条语句,我的输出错误: gpg: no valid OpenPGP data found
# curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# 解决上面的问题,可以换成下面这条语句:
$ curl http://repo.ros2.org/repos.key | sudo apt-key add - 

# 之后再添加源:
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

安裝 ROS 2 包

(1)更新源

# 执行更新后,出现问题了
sudo apt update
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'http://packages.ros.org/ros2/ubuntu focal InRelease' doesn't support architecture 'i386'
  • 1
  • 2
  • 3

參照ROS 2 安裝後BUG,解決方法是:

$ cd /etc/apt/sources.list.d
$ sudo gedit ros2-latest.list

# 打开文本后出现:
deb http://packages.ros.org/ros2/ubuntu bionic main

# 在deb后插入[arch=amd64]变成:
deb [arch=amd64] http://packages.ros.org/ros2/ubuntu bionic main

# 保存并关闭

# 再次更新即可
sudo apt update
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

注: 如果更新出现问题了,试试更新多几次

(2)推荐安装ROS2桌面版本(包括ROS, RViz, demos, tutorials)

sudo apt install ros-foxy-desktop
  • 1

注:如果出现问题,试试多重复几次

Environment setup

(1)使用脚本来设置
如果你的SHELL是用bash,就是:

source /opt/ros/foxy/setup.bash
  • 1

如果你的SHELL是用zsh的,就是:

source /opt/ros/foxy/setup.zsh
  • 1

以后每次打开终端都需要输入一次上面的语句,比较麻烦。我们以zsh为例,解决方法:

$ echo "source /opt/ros/foxy/setup.zsh" >> ~/.zshrc 
$ source ~/.zshrc
  • 1
  • 2

这样,以后每次新打开终端,就不需要输入这条烦人的语句了, 终端会自动帮你加载这条语句,设置好ROS2的环境变量。source /opt/ros/foxy/setup.zsh

(2)安装argcomplete(可选)

sudo apt install python3-argcomplete

(3)安装RMW implementation
```bash
sudo apt update
sudo apt install ros-foxy-rmw-connext-cpp
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

(4)安装ROS1 packages(可选)

sudo apt update
sudo apt install ros-foxy-ros1-bridge
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-foxy-ros1-bridge : Depends: ros-noetic-actionlib-msgs but it is not installable
                        Depends: ros-noetic-catkin but it is not installable
                        Depends: ros-noetic-common-msgs but it is not installable
                        Depends: ros-noetic-gazebo-msgs but it is not installable
                        Depends: ros-noetic-geometry-msgs but it is not installable
                        Depends: ros-noetic-nav-msgs but it is not installable
                        Depends: ros-noetic-rosbash but it is not installable
                        Depends: ros-noetic-roscpp but it is not installable
                        Depends: ros-noetic-roscpp-tutorials but it is not installable
                        Depends: ros-noetic-roslaunch but it is not installable
                        Depends: ros-noetic-rosmsg but it is not installable
                        Depends: ros-noetic-rospy-tutorials but it is not installable
                        Depends: ros-noetic-sensor-msgs but it is not installable
                        Depends: ros-noetic-std-msgs but it is not installable
                        Depends: ros-noetic-std-srvs but it is not installable
                        Depends: ros-noetic-stereo-msgs but it is not installable
                        Depends: ros-noetic-tf but it is not installable
                        Depends: ros-noetic-tf2-msgs but it is not installable
                        Depends: ros-noetic-trajectory-msgs but it is not installable
                        Depends: ros-noetic-visualization-msgs but it is not installable
E: Unable to correct problems, you have held broken packages.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

这些问题应该是我没有事先安装好 ROS1, 我也暂时不用ROS1,所以暂时也不用理会了。

试试例子

我们通过一个例子来看看ROS2有无安装成功:

(1)打开第一个终端,运行C++ talker:
(2)打开第两个终端,运行Python listener:

在这里插入图片描述

我們看到,終端1不斷地發送[Hello World: xx], 終端2則不斷地接收終端1發送的資訊。

卸載ROS2

sudo apt remove ros-foxy-*
sudo apt autoremove
  • 1
  • 2

OVER~~