rosdep命令出现的问题
linux环境:Ubuntu20.04
ros2版本:foxy
foxy安装方式:Debian软件包安装
处理日期:2021/5/5
一、sudo rosdep init
当执行初始化rosdep命令时:
sudo rosdep init
出现下面错误:
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
解决方案一(成功):
多尝试几次。(参考github)
解决方案二(成功):
复制上面的代码,使用浏览器打开:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
复制浏览器界面的代码,保存为20-default.list,存储位置:
/etc/ros/rosdep/sources.list.d/20-default.list
浏览器中的代码如下:
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
如果rosdep已经初始化了,再次执行此条指令,会出现下面错误:
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
二、rosdep update
当执行初始化rosdep命令时:
rosdep update
出现下面错误(20-default.list中的网站都无法连接):
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
<urlopen error timed out> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
<urlopen error timed out> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
...
解决方案1(失败):
这次尝试了无数次,都无法更新成功。
解决方案2(失败):
解决方案3(成功):
通过浏览器打开上面的网站,如:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
可以看到浏览器界面的代码,于是参照sudo rosdep init的方案二,自己手动本地添加需要的代码。比较简单的方式是,选择一个目录,如:
cd /etc/ros/
使用命令如下:
sudo git clone https://github.com/ros/rosdistro.git
更改下面的文件:
sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
更改后的内容如下:
# os-specific listings first
# yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
yaml file:///etc/ros/rosdistro-master/rosdep/osx-homebrew.yaml osx
# generic
# yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
# yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
# yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
# gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte
# after
yaml file:///etc/ros/rosdistro-master/rosdep/base.yaml
yaml file:///etc/ros/rosdistro-master/rosdep/python.yaml
yaml file:///etc/ros/rosdistro-master/rosdep/ruby.yaml
gbpdistro file:///etc/ros/rosdistro-master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
保存退出后
打开/usr/lib/python3/dist-packages/rosdistro/__init__.py
这个文件,修改如下:
#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'file:///etc/ros/rosdistro-master/index-v4.yaml'
保存后,再次运行:
rosdep update
可能还会有报错:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///etc/ros/rosdistro-master/rosdep/osx-homebrew.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/base.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/python.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/ruby.yaml
ERROR: unable to process source [file:///etc/ros/rosdistro-master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
The read operation timed out
Query rosdistro index file:///etc/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/wkai/.ros/rosdep/sources.cache
ERROR: Not all sources were able to be updated.
[[[
ERROR: unable to process source [file:///etc/ros/rosdistro-master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
The read operation timed out
]]]
再尝试几次就成功了:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///etc/ros/rosdistro-master/rosdep/osx-homebrew.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/base.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/python.yaml
Hit file:///etc/ros/rosdistro-master/rosdep/ruby.yaml
Hit file:///etc/ros/rosdistro-master/releases/fuerte.yaml
Query rosdistro index file:///etc/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/wkai/.ros/rosdep/sources.cache
补充1:如果执行rosdep update
并没有出现上面的错误,而是下面的内容:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///etc/ros/rosdistro-master/rosdep/osx-homebrew.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/base.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/python.yaml
Hit file:///etc/ros/rosdistro/master/rosdep/ruby.yaml
ERROR: unable to process source [file:///etc/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
<urlopen error [Errno 111] Connection refused>
Query rosdistro index file:///etc/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/wkai/.ros/rosdep/sources.cache
ERROR: Not all sources were able to be updated.
[[[
ERROR: unable to process source [file:///etc/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
<urlopen error [Errno 111] Connection refused>
]]]
你需要执行下面指令,打开hosts文件:
sudo gedit /etc/hosts
添加raw.githubusercontent.com解析后的ip地址:
185.199.108.133 raw.githubusercontent.com
ip地址可以到https://www.ipaddress.com/
上查询
参考:https://zhuanlan.zhihu.com/p/77483614
三、rosdep install -i --from-path src --rosdistro foxy -y
当我新建一个工作空间,并在src目录下克隆ros2官网示例作准备作为练习:
git clone https://github.com/ros2/examples.git
当我在工作空间根目录下执行检查依赖包的指令:
rosdep install -i --from-path src --rosdistro foxy -y
出现下面的错误:
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
examples_rclpy_pointcloud_publisher: Cannot locate rosdep definition for [sensor_msgs_py]
这说明有类似依赖包的东西缺失,通过关键字查询,找到了下面的目录:
cd ./src/examples-master/relpy/pointcloud_publisher/package.xml
在文件中,我找到了这样两行依赖说明代码:
<exec_depend>sensor_msgs_py</exec_depend>
...
<exec_depend>sensor_msgs</exec_depend>
我以为是我当初安装ros时有些东西没装,于是又卸载重装,重装后,这个sensor_msgs_py依赖包还是缺失。要么去手动下载这个依赖包,要么直接删除对应的文件,我不想折腾了直接选择了第二种。毕竟这个功能我也暂时用不着:
cd ./src/examples-master/relpy/
rm -rf ./pointcloud_publisher/
在工作区根目录再次执行:
rosdep install -i --from-path src --rosdistro foxy -y
没有缺少任何依赖包:
#All required rosdeps installed successfully
其实缺少依赖是可以原谅的,因为当我查看https://github.com/ros2/examples
我发现最新的一次修改在9天前(9 days ago)
但是在工作空间根目录执行colcon build
,还是出现很多错误:
Summary: 8 packages finished [6.37s]
1 package failed: examples_rclcpp_cbg_executor
6 packages aborted: examples_rclcpp_minimal_action_client examples_rclcpp_minimal_publisher examples_rclcpp_minimal_subscriber examples_rclpy_minimal_action_client examples_rclpy_minimal_action_server examples_rclpy_minimal_client
4 packages had stderr output: examples_rclcpp_cbg_executor examples_rclcpp_minimal_action_client examples_rclcpp_minimal_publisher examples_rclcpp_minimal_subscriber
3 packages not processed
后来我才发现这些示例在安装ros2-foxy的时候都已经安装过了,source /opt/ros/foxy/setup.bash
后直接可以执行示例,如ros2 run examples_rclcpp_minimal_publisher publisher_lambda
,其他示例在/opt/ros/foxy目录下搜索examples关键字就出来了。
我的理解是,https://github.com/ros2/examples
上的示例可能是留给开发人员做测试的,并不适合我这种新人。