一站式解决Ubuntu20.04安装ROS的问题

1.添加安装ROS的软件源

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'

2.添加密钥

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

 3.更新软件源,更新前面添加的ROS软件源,否则会找不到安装包(E: 无法定位软件包 ros-noetic-desktop-full),更新软件源即可

sudo apt update

4.安装ROS(根据Ubuntu的不同版本选择不同版本的ROS,20.04对应的是noetic版本)

sudo apt install ros-noetic-desktop-full

5.初始化rosdep(方法三直接无敌解决问题

sudo rosdep init

 运行: 

rosdep update

方法一:直接运行

运气好的网络多运行几次就可以成功,但大多数是很难成功的,或者可以通过魔法进行更新,概率比正常会大很多,成功之后如下所示: 方法二:

如果尝试多次不能成功可以通过将文件下载至本地,对本地文件进行链接

git clone https://github.com/ros/rosdistro.git

通过命令拉取迟迟没有反应,可以直接访问上面的github连接直接下载到本地,放在home目录下,将文件名重命名为 rosdistro,根据以下步骤分别替换五个文件中的内容

注意:此方法中的所有yourname都需要改为自己电脑的用户名

第一个文件:

cd /home/yourname/rosdistro/rosdep/sources.list.d/
sudo gedit 20-default.list 

 全选将所有的内容替换为:

# 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

第二个文件:(注:20.04的python版本为python3,低版本的python版本为python2.7,进行相应的更改即可)

cd /usr/lib/python3/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py

 替换为:

FUERTE_GBPDISTRO_URL = 'file:///home/yourname/rosdistro/' \
    'releases/fuerte.yaml'

第三个文件:

cd /usr/lib/python3/dist-packages/rosdep2/
sudo gedit rep3.py

替换为:

REP3_TARGETS_URL = 'file:///home/yourname/rosdistro/releases/targets.yaml'

第四个文件:

cd /usr/lib/python3/dist-packages/rosdistro/
sudo gedit __init__.py

替换为 :

DEFAULT_INDEX_URL = 'file:///home/yourname/rosdistro/index-v4.yaml'

第五个文件: 

cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

 替换为:

#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

 打开新终端运行:

rosdep update

 成功解决!!!

方法三:这部分完全参考这篇文章,超级好用,简单高效:https://zhuanlan.zhihu.com/p/398754989

rosdepc的安装及使用:

安装

sudo pip install rosdepc

如果显示没有pip可以试试pip3。

sudo pip3 install rosdepc

如果pip3还没有

sudo apt-get install python3-pip 
sudo pip install rosdepc

使用

sudo rosdepc init
rosdepc update

 6.设置环境变量

echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

7.安装rosinstall

sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool

8.测试roscore

roscore

成功运行 !!!!!!!!!!!!!!!!!

猜你喜欢

转载自blog.csdn.net/abc20150125/article/details/129996764