当前位置:   article > 正文

Ubuntu20.04系统安装ROS与ROS2_ubuntu20.04 ros2

ubuntu20.04 ros2

Ubuntu20.04系统安装ROS与ROS2需要对应好版本,不能随意安装。ubuntu20.04对应:

        ROS1:noetic

        ROS2:foxy、galactic

我们此处安装ROS noeticROS2 galactic


一、更新源

        通常有两种方式:通过软件更新手动修改source.list

        简便起见,使用软件更新的方法。设置中,自行寻找最佳服务器。更新之后需要执行:sudo apt-get update

二、安装ROS noetic

  1. #(1)添加ROS软件源
  2. 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'
  3. #(2)添加秘钥
  4. sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  5. #(3)更新软件源
  6. sudo apt update
  7. # 若出现失败,则执行以下语句,否则到(4)
  8. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
  9. #(4)安装ROS noetic桌面版(如有科学方法先挂上)
  10. sudo apt install ros-noetic-desktop-full
  11. #(5)初始化rosdep
  12. sudo rosdep init
  13. # 如果找不到命令,执行
  14. sudo apt install python-rosdep2
  15. # 或者
  16. sudo apt install python3-rosdep2
  17. # (6)安装rosinstall
  18. sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool
  19. # (7)配置环境
  20. sudo gedit ~/.bashrc
  21. # 末尾添加
  22. source /opt/ros/noetic/setup.bash
  23. # 保存退出
  24. source ~/.bashrc
  25. # (8)验证
  26. roscore
  27. # 小乌龟测试
  28. rosrun turtlesim turtlesim_node
  29. 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:或者再次尝试以下方法。

  1. # 下载以下文件
  2. https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
  3. # 备份后替换到
  4. /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. #(1)设置编码UTF-8,检查是否支持 UTF-8
  2. locale
  3. # 若不支持
  4. sudo locale-gen en_US en_US.UTF-8
  5. sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
  6. export LANG=en_US.UTF-8
  7. #(2)检查是否启用ubuntu Universe存储库
  8. apt-cache policy | grep universe
  9. ## 输出应如下:
  10. # 500 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages
  11. # release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=i386
  12. # 500 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
  13. # release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64
  14. # 注意换源已经默认启用,但是界面上并没有勾选,不用管,若没有启用不会有输出,则
  15. sudo apt install software-properties-common
  16. sudo add-apt-repository universe
  17. #(3)设置密钥
  18. sudo apt update && sudo apt install curl
  19. sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
  20. 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
  21. #(4)安装
  22. sudo apt update
  23. sudo apt install ros-galactic-desktop
  24. sudo apt install ros-galactic-ros-base
  25. sudo apt install ros-dev-tools
  26. #(5)配置环境
  27. echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc
  28. source ~/.bashrc
  29. #(6)demo测试
  30. ros2 run demo_nodes_cpp talker
  31. ros2 run demo_nodes_cpp listener
  32. # 小乌龟测试
  33. ros2 run turtlesim turtlesim_node
  34. 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)。

  1. echo "ros noetic(1) or ros2 galactic(2)?"
  2. read edition
  3. if [ "$edition" -eq "1" ];then
  4. source /opt/ros/noetic/setup.bash
  5. echo "source /opt/ros/noetic/setup.bash"
  6. else
  7. source /opt/ros/galactic/setup.bash
  8. echo "source /opt/ros/galactic/setup.bash"
  9. 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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/1011343
推荐阅读
相关标签
  

闽ICP备14008679号