Ubuntu 20.04 安裝 ROS

举报
whitby 发表于 2022/03/12 11:21:54 2022/03/12
【摘要】 Ubuntu 20.04 安裝 ros-noetic-desktop-full,並解決國內訪問外網超時問題
1. 添加 source.list
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
2. 设置 Key
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3. 安裝
sudo apt update
sudo apt install ros-noetic-desktop-full
4. 在使用ROS的每个bash终端中获取此脚本的源代码
source /opt/ros/noetic/setup.bash
5. 环境配置
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
6. 测试

第一步,打开一个终端测试roscore是否能正常启动,使用ROS必须保证roscore运行:

 roscore

第二步,新开启一个终端,执行以下命令:

rosrun turtlesim turtlesim_node

第三步,再开启一个终端,执行以下命令:(鼠标必须聚焦在这个终端,乌龟才会移动)

rosrun turtlesim turtle_teleop_key
7. 安裝依赖包
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
8. rosdep 初始化

国内运行以下命令会出现超时、无法连接等现象

sudo rosdep init
rosdep update

可以采取如下方式解決:

​ 首先 git 將 rosdistro 下载到本地目录,作者下载的目录为:/home/whitby/Documents/ThirdParty

git clone https://github.com/ros/rosdistro.git

​ 将 /usr/lib/python3/dist-packages/rosdep2/rep3.py (作者系统版本 Ubuntu 20.04 默认 python3 环境)中的 targets.yaml URL 请求地址,换成本地刚下载的 rosdistro 文件中对应 targets.yaml 地址,作者修改后的内容为:

# location of targets file for processing gbpdistro files
REP3_TARGETS_URL = 'file:///home/whitby/Documents/ThirdParty/rosdistro/releases/targets.yaml'

​ 同样,将 /usr/lib/python3/dist-packages/rosdistro/__init__.py 中的 index-v4.yaml 换成本地地址,如下:

# index information
DEFAULT_INDEX_URL = 'file:///home/whitby/Documents/ThirdParty/rosdistro/index-v4.yaml'

sudo rosdep init 生成 /etc/ros/rosdep/sources.list.d/20-default.list,将此文件中的对应 yaml 文件地址换成本地文件地址,如下所示:

# os-specific listings first
yaml file:///home/whitby/Documents/ThirdParty/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/whitby/Documents/ThirdParty/rosdistro/rosdep/base.yaml
yaml file:///home/whitby/Documents/ThirdParty/rosdistro/rosdep/python.yaml
yaml file:///home/whitby/Documents/ThirdParty/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/whitby/Documents/ThirdParty/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

​ 最后,执行 rosdep update 即可

參照:官方文檔 珞珈小怪博客 小貝比導航博客

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。