Ubuntu20.04系统安装ROS与ROS2
火山大兄 2024-08-12 10:37:01 阅读 90
Ubuntu20.04系统安装ROS与ROS2需要对应好版本,不能随意安装。ubuntu20.04对应:
ROS1:noetic
ROS2:foxy、galactic
我们此处安装ROS noetic和ROS2 galactic。
一、更新源
通常有两种方式:通过软件更新和手动修改source.list。
简便起见,使用软件更新的方法。设置中,自行寻找最佳服务器。更新之后需要执行:sudo apt-get update
二、安装ROS noetic
<code>#(1)添加ROS软件源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
#(2)添加秘钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
#(3)更新软件源
sudo apt update
# 若出现失败,则执行以下语句,否则到(4)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
#(4)安装ROS noetic桌面版(如有科学方法先挂上)
sudo apt install ros-noetic-desktop-full
#(5)初始化rosdep
sudo rosdep init
# 如果找不到命令,执行
sudo apt install python-rosdep2
# 或者
sudo apt install python3-rosdep2
# (6)安装rosinstall
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool
# (7)配置环境
sudo gedit ~/.bashrc
# 末尾添加
source /opt/ros/noetic/setup.bash
# 保存退出
source ~/.bashrc
# (8)验证
roscore
# 小乌龟测试
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
1、当出现ERROR: cannot download default sources list from:https : //raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.listWebsite may be down.错误时,是外网无法链接
法1:需要科学上网。
法2:如果还出现“ERROR: cannot download default sources list from”错误,则需要访问 https://www.ipaddress.com/ 该网站,查询 raw.githubusercontent.com 的ip地址。并将这句话 185.199.108.133 raw.githubusercontent.com 加入到 /etc/hosts 文件中。
法3:或者再次尝试以下方法。
<code># 下载以下文件
https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
# 备份后替换到
/etc/ros/rosdep/sources.list.d/20-default.list
2、当出现 Command ‘roscore’ not found, but can be installed with:sudo apt install python3-roslaunch,安装
sudo apt install python3-roslaunch
3、当出现 Resorce not found: roslaunch
说明之前的安装没有安装全,继续安装
sudo apt install ros-noetic-desktop-full
三、安装ROS2 galactic
#(1)设置编码UTF-8,检查是否支持 UTF-8
locale
# 若不支持
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
#(2)检查是否启用ubuntu Universe存储库
apt-cache policy | grep universe
## 输出应如下:
# 500 http://security.ubuntu.com/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://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
# release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64
# 注意换源已经默认启用,但是界面上并没有勾选,不用管,若没有启用不会有输出,则
sudo apt install software-properties-common
sudo add-apt-repository universe
#(3)设置密钥
sudo apt update && sudo apt install curl
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
#(4)安装
sudo apt update
sudo apt install ros-galactic-desktop
sudo apt install ros-galactic-ros-base
sudo apt install ros-dev-tools
#(5)配置环境
echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc
source ~/.bashrc
#(6)demo测试
ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener
# 小乌龟测试
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
1、如果报错 Failed to connect to raw.githubusercontent.com port 443 after 13 ms: 拒绝连接,参考上一节的方法在 /etc/hosts 文件中添加 raw.githubusercontent.com 的IP。
四、ROS与ROS2的混合环境处理
在~/.bashrc文件中添加如下语句,则可在终端开启时,选择使用ROS环境(选择1)还是ROS2环境(选择2)。
<code>echo "ros noetic(1) or ros2 galactic(2)?"
read edition
if [ "$edition" -eq "1" ];then
source /opt/ros/noetic/setup.bash
echo "source /opt/ros/noetic/setup.bash"
else
source /opt/ros/galactic/setup.bash
echo "source /opt/ros/galactic/setup.bash"
fi
参考链接:
(1)Ubuntu20.04同时安装ROS1和ROS2共存_ros版本与ubuntu对应版本-CSDN博客
(2)Ubuntu20.04 ROS1和ROS2同时安装及使用 - 古月居
(3)ubuntu20.04安装ros2,并与ros1共存_ros2和ros1兼容吗-CSDN博客
(4)详细介绍如何在ubuntu20.04中安装ROS系统,超快完成安装(最新版教程)_ubuntu安装ros-CSDN博客
(5)noetic/Installation/Ubuntu - ROS Wiki
(6)Ubuntu (Debian) — ROS 2 Documentation: Galactic documentation
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。