ROS1主要构建于Linux系统之上,但是跨平台性太弱。而ROS2对其架构进行了全新的升级,底层基于DDS通讯机制,规避了ROS的不足,实现了真正意义的跨平台。
使用阿里云的源:
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
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
apt-cache policy | grep universe
如果没有看到类似下面的输出,则需要启用 Universe 存储库。
500 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64
启用 Universe 存储库
sudo apt install software-properties-common
sudo add-apt-repository universe
将 ROS 2 apt 存储库添加到您的系统中。首先用apt授权GPG密钥:
sudo apt update && sudo apt install curl gnupg lsb-release
#使用下面的可能会出现如下错误: gpg: no valid OpenPGP data found
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
#推荐使用:
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.
更新 apt 存储库。
sudo apt update
桌面安装:
sudo apt install ros-rolling-desktop
ROS-Base Install (Bare Bones):通信库、消息包、命令行工具。没有 GUI 工具
sudo apt install ros-rolling-ros-base
运行如下指令,出来的结果如图结果,则说明安装成功。
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener
ros2 run demo_nodes_cpp talker:
ros2 run demo_nodes_py listener:
这是由于源设置错误造成的。此处是因为我把18.04的源放到了20.04中,所以会报错。更改源就好了。
参考链接:https://blog.csdn.net/sad490/article/details/81460395