几年没手工安装ros了,一般拉个安装好了cuda和ros等工具软件的docker image直接使用,以前安装过程中很顺利不会有什么报错,最近按照melodic/Installation/Ubuntu - ROS Wiki这里的步骤
sudo apt install lsb-core
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt install curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo rosdep init
rosdep update
执行到curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -时
死掉,rosdep init和rosdep update时总是下面的报错:
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
ERROR: unable to process source [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]:
...
根本原因是执行这些步骤时需要连到raw.githubusercontent.com这个已经被墙掉的网站下载一些文件,网上推荐的解决办法一般是去修改/etc/resolve.conf或者/etc/hosts增加谷歌的服务器ip地址或githubusercontent.com的ip地址,这样做现在根本没用!被逼着去翻看了一下ros源码和网上信息,其实解决比较简单,对于ros.asc下载不了,可以从国内镜像网站上下载这个文件到本地,然后执行:
sudo apt-key add ros.asc
对于rosdep init和rosdep update报错思路就是把从githubusercontent.com上下载文件改成从国内的镜像网站下载即可,
执行下面的命令即完成了rosdep init 和rosdep update:
sudo apt-get install wget
sudo mkdir -p /etc/ros/rosdep/sources.list.d
wget https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list -O /etc/ros/rosdep/sources.list.d/20-default.list
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml && rosdep update
后来看到网上有人单独做了个工具rosdepc来替代rosdep,可以执行下面的命令安装:
sudo apt-get install python3-pip
sudo pip install rosdepc
然后执行rosdepc init和rosdepc update
但是因为OS环境支持的字符集的不同,执行过程中可能会报下面的错误:
Traceback (most recent call last):
File "/usr/local/bin/rosdepc", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py", line 52, in main
print(hints['welcome'])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-7: ordinal not in range(128)
Traceback (most recent call last):
File "/usr/local/bin/rosdepc", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py", line 52, in main
print(hints['welcome'])
UnicodeEncodeError: 'ascii' codec can't encode character '\u201c' in position 145: ordinal not in range(128)
原因是这个rosdepc工具的/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py这个文件里写了大量的用于提示的中文字符以及@等ascii码字符集不支持的字符,把里面的包含的中文和特殊格式符都删掉即可,这些信息其实没啥用,删干净了再执行rosdepc init即可,可以看到rosdepc.py这个文件里的核心语句其实就是我上面写的那几句命令,所以完全不用安装这个工具包,直接执行这两句命令更简捷:
wget https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list -O /etc/ros/rosdep/sources.list.d/20-default.list
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml && rosdep update