桌面点击Ubuntu软件,接着左上角点击Ubuntu软件,点击软件和更新。
将可从互联网下载的所有选项选中,并且将下载自 选为 中国 的服务器
ros官网安装教程: ROS Instal
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'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt update
python-rosdep
,避免出现sudo rosdep:找不到命令提示
sudo apt install python-rosdep
sudo apt-get install ros-melodic-desktop-full
W: GPG 错误:http://mirrors.ustc.edu.cn/ros/ubuntu bionic InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY F42ED6FBAB17C654
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
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.
ERROR: error loading sources list:
('The read operation timed out',)
sudo rosdep init
与rosdep update
报错终极解决方案如下:
1 将rosdistro clone到本地
这里,可以选择github
方式
git clone https://github.com/ros/rosdistro.git
建议选择gitee
的方式(此方法下载更快,库是我自己导入的,可以使用!)
git clone https://gitee.com/huang_hongzhi/rosdistro.git
注意这里克隆的地址选择根目录,我的用户名是hhz,那么这个文件夹的地址就是~/rosdistro,即/home/hhz/rosdistro
2 创建20-default.list,对应sudo rosdep init 这一步
打开一个新终端,输入以下内容,用途是创建20-default.list
sudo su //输入你的密码切换至root
sudo mkdir -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list
将以下内容复制进20-default.list
注意:以下的yourname全部改为你们自己的用户名
#os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte
#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
3 替换下载网址为本地的文件
cd /home/yourname/rosdistro/rosdep/sources.list.d/
sudo gedit 20-default.list
将里面所有的 raw.githubusercontent.com
替换成file:///home/yourname/rosdistro
的地址,如下:
# os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py
替换对应的内容(注意两行都要换)
FUERTE_GBPDISTRO_URL = 'file:///home/yourname/rosdistro/' \
'releases/fuerte.yaml'
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit rep3.py
替换对应的内容
REP3_TARGETS_URL = 'file:///home/yourname/rosdistro/releases/targets.yaml'
__init__.py
,但是作者的是init.py
cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py
替换对应的内容
DEFAULT_INDEX_URL = 'file:///home/yourname/rosdistro/index-v4.yaml'
4 执行rosdep update
新建一个终端执行rosdep update
,出现如下代码则成功:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/hhz/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/hhz/rosdistro/rosdep/base.yaml
Hit file:///home/hhz/rosdistro/rosdep/python.yaml
Hit file:///home/hhz/rosdistro/rosdep/ruby.yaml
Hit file:///home/hhz/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/hhz/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Add distro "bouncy"
Add distro "crystal"
Add distro "dashing"
Add distro "eloquent"
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"
updated cache in /home/hhz/.ros/rosdep/sources.cache
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
初始化工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
编译工作空间
cd ~/catkin_ws/
catkin_make
使得工作空间的环境变量生效
source devel/setup.bash
使得环境变量在所有的终端中都有效
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
检查环境变量已经生效,创建一个新终端,输入:
echo $ROS_PACKAGE_PATH
如果打印的路径中包含当前工作空间的路径,则环境变量设置成功
如果以上内容对你有帮助的话,麻烦点个关注谢谢啦~