Ubuntu 20.04LTS安装ROS及rosdep初始化问题

Ubuntu 20.04LTS安装ROS及rosdep初始化问题,第1张

Ubuntu 20.04LTS安装ROS及rosdep初始化问题

文章目录
  • 一、Ubuntu 20.04LTS安装
    • 1. 设置源
    • 2.设置密钥
    • 3.安装ROS
    • 4.测试ROS
    • 5. 环境变量设置
    • 6. 安装依赖包
  • 二、ROS及rosdep初始化问题
    • 1. 修改 sources_list.py 文件
    • 2. 修改 init.py 文件
    • 3.rosdep 初始化
  • 参考文献:

一、Ubuntu 20.04LTS安装 1. 设置源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2.设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3.安装ROS
sudo apt update
sudo apt install ros-noetic-desktop-full
4.测试ROS

开启终端,运行roscore指令,打开Ros Master

roscore

另开启一个终端,运行海龟仿真节点

rosrun turtlesim turtlesim_node

再开启一个终端,键盘控制海龟运动

rosrun turtlesim turtle_teleop_key

再开启一个终端,查看海龟仿真节点

rosrun rqt_graph rqt_graph

5. 环境变量设置
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
6. 安装依赖包
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
二、ROS及rosdep初始化问题
sudo rosdep init
rosdep update

在默认的安装ROS时,初始化rosdep时,常常因为网络传输时间溢出而失败。尝试很多文献的方式都不行。后来参考完《美解决 ROS 安装 rosdep update(timed out)报错超时问题》完美解决初始化失败问题。具体说就是使用代理服务器,使GitHub Proxy 代理加速。

1. 修改 sources_list.py 文件
sudo nano /usr/lib/python3/dist-packages/rosdep2/sources_list.py

打开上述文件后,download_rosdep_data函数中增加一行代理服务器语句:

url="https://ghproxy.com/"+url # 新添加
def download_rosdep_data(url):
    """
    :raises: :exc:`DownloadFailure` If data cannot be
        retrieved (e.g. 404, bad YAML format, server down).
    """
    try:
        # http/https URLs need custom requests to specify the user-agent, since some repositories reject
        # requests from the default user-agent.

   
**url="https://ghproxy.com/"+url # 新添加**


        if url.startswith("http://") or url.startswith("https://"):
            url_request = request.Request(url, headers={'User-Agent': 'rosdep/{version}'.format(version=__version__)})
        else:
            url_request = url
        f = urlopen(url_request, timeout=DOWNLOAD_TIMEOUT)
        text = f.read()
        f.close()
        data = yaml.safe_load(text)
        if type(data) != dict:
            raise DownloadFailure('rosdep data from [%s] is not a YAML dictionary' % (url))
        return data
    except (URLError, httplib.HTTPException) as e:
        raise DownloadFailure(str(e) + ' (%s)' % url)
    except yaml.YAMLError as e:
        raise DownloadFailure(str(e))

2. 修改 init.py 文件
sudo nano /usr/lib/python3/dist-packages/rosdistro/__init__.py 

添加如下内容,并注释被替换的内容:

#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'

DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'

3.rosdep 初始化
sudo rosdep init
rosdep update

参考文献:

[1]: 如何在Ubuntu20.04中安装ROS Noetic
[2]: 完美解决 ROS 安装 rosdep update(timed out)报错超时问题
[3]: ROS Tutorials
[4]: Ubuntu20.04及18.04的ROS安装教程及各种失败解决方法(终极方法) (sudo rosdep init找不到命令或失败与rosdep update一直timeout,roscore找不到命令)

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5693739.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存