Ubuntu20.04安装ROS2 Foxy

Ubuntu20.04安装ROS2 Foxy

实操安装

安装ROS2的教程在网上很多,但是我操作之后都有问题,大部分的问题是在 sudo apt update 时访问packages.ros.org无法成功,主要的原因是没有外网,而自己整一个外网代理又非常麻烦,所以一般是通过设置国内源来实现

设置sources.list为国内源

修改 /etc/apt/sources.list里面的源为国内的

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list

如清华大学的源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu-ports/ 注意:一定要选择跟自己ubuntu版本匹配的源,我的是ubuntu20.04,对应的源是:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse

deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse

Ubuntu20.04安装ROS2 Foxy_第1张图片

设置编码为UTF-8

locale
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

添加ROS2的apt仓库到自己的系统

sudo apt install software-properties-common
sudo add-apt-repository universe

apt-cache policy | grep universe

Ubuntu20.04安装ROS2 Foxy_第2张图片

更新并安装curl 、gnupg2 、lsb-release等软件

sudo apt update && sudo apt install curl gnupg2 lsb-release

与apt授权GPG密钥

sudo curl -verbose -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg

如果这一步有问题,参考:https://blog.searchinfogo.com/2021/01/27/github-connection-refused/

添加ROS2仓库到自己的source.list

如果设置了科学上网可以执行如下命令

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

如果无法科学上网,需要将域名packages.ros.org替换为国内的镜像源的域名,这里我替换为清华大学源域名mirrors.tuna.tsinghua.edu.cn,建议最好替换一下

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

更新

sudo apt update
sudo apt upgrade

安装ROS2-Foxy(带ROS, RViz, demos, tutorials等)

sudo apt install ros-foxy-desktop

如果指向安装基础包,执行以下指令

sudo apt install ros-foxy-ros-base

默认情况下,每次打开新shell终端时都必source安装文件,执行

source /opt/ros/foxy/setup.bash

可以将命令添加到shell启动脚本中,后面就不需要再输入source /opt/ros/foxy/setup.bash

echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc

测试安装结果

1、测试talker和listener

启动talker

ros2 run demo_nodes_cpp talker

启动listener

ros2 run demo_nodes_py listener

2、测试小海龟

打开终端,创建海龟

ros2 run turtlesim turtlesim_node

打开新终端,创建鼠标控制

ros2 run turtlesim turtle_teleop_key
参考

https://github.com/ya77ya/Installation-ROS-2-on-Jetson-Nano

你可能感兴趣的:(机器人,ROS2,Foxy,Ubuntu20.04)