本文主要参考https://blog.csdn.net/dally2/article/details/118028380,根据自己配置过程中遇到的问题做了一些修补。
一、OS环境Ubuntu 18.04
二、配置系统软件源打开“软件和更新”,进入到“Ubuntu软件”界面,
其它博客提供的是ubuntu的源,在我的电脑下载速度过慢,因此推荐使用中科大源
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'四、开始安装
#1. 设置密钥 sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 #2. 更新包索引 sudo apt update #3. 下载桌面完整版 sudo apt install ros-melodic-desktop-full #5 初始化 rosdep sudo rosdep init (如果报错转向步骤6.1) rosdep update (如果报错转向步骤6.2) #6 设置环境 echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc source ~/.bashrc #7 安装rosinstall这个工具和其他构建ROS包的依赖项,轻松地从一个命令下载许多 ROS 包的源树 sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential五、测试是否安装成功
roscore
打开一个新的终端
rosrun turtlesim turtlesim_node
打开一个新的终端
rosrun turtlesim turtle_teleop_key
如果能够用键盘的上下左右控制小乌龟的运动,那么ros应该就安装成功了
六、可能的报错 6.1 sudo rosdep init第一种报错: rosdep commond not found
解决
sudo apt install python-rosdep
第二种报错: raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The ‘rosdep==0.21.0’ distribution was not found and is required by the application
解决: 将默认的python3版本改成python2
$ update-alternatives --list python 可能的报错:update-alternatives: 错误: 无 python 的候选项 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2 $ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/local/bin/python3 150 auto mode 1 /usr/bin/python2 150 manual mode 2 /usr/local/bin/python3 150 manual mode Press6.2 rosdep updateto keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode
思路就是再某些网址前面加上https://ghproxy.com/前缀, 以解决网络问题
#1 进入rosdep2目录 cd /usr/lib/python2.7/dist-packages/rosdep2/ #2 打开sources_list.py sudo gedit sources_list.py (1)将DEFAULT_SOURCES_LIST_URL 改为'https://ghproxy.com/https://raw.githubusercontent.com/ ros/rosdistro/master/rosdep/sources.list.d/20-default.list' # 在72行 (2)在download_rosdep_data(url)函数中加入: url="https://ghproxy.com/"+url #在310行,try之后,if之前 #3 打开 gbpdistro_support.py sudo gedit gbpdistro_support.py #第36行,加入“https://ghproxy.com/”代理前缀 #4 打开 rep3.py sudo gedit rep3.py #第39行,加入“https://ghproxy.com/”代理前缀 #5 切换至rosdistro目录 cd ../rosdistro #6 打开__init__.py,改DEFAULT_INDEX_URL sudo gedit __init__.py #第68行,加入“https://ghproxy.com/”代理前缀 #7 进入manifest_provider目录,为github.py添加前缀 cd manifest_provider sudo gedit github.py #68行 119行 #8 然后就可以 rosdep update



