ubuntu20.04安装ROS【详细】

Ubuntu20.04安装ROS与Ubuntu18.04大差不差,安装过程基本没出现问题,按以下教程操作即可。

一、更换源:

1、备份源文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、编辑源文件

该命令打开源文件可能会比较慢

sudo gedit /etc/apt/sources.list

将文件里的替换为

deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

## Pre-released source, not recommended.
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

然后执行

sudo apt-get update

再执行

sudo apt-get upgrade

二、设置软件源:

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

ubuntu20.04安装ROS【详细】_第1张图片

三、安装Ros-noetic:

1、更新一下

sudo apt-get update

2、安装

sudo apt-get install ros-noetic-desktop-full
sudo apt-get install ros-noetic-rqt*

四、初始化rosdep:

这一步执行一般都会出错!!!!!!!按以下方法是可以成功的!

1.新建文件夹,并进入文件夹

sudo mkdir -p  /home/one/git/
cd /home/one/git/

2、下载项目

sudo git clone https://gitee.com/one_DS/rosdistro.git

若找不到命令,安装git即可

sudo apt-get install git

3、另打开一个终端,备份原文件

sudo cp /usr/lib/python3/dist-packages/rosdep2/main.py /usr/lib/python3/dist-packages/rosdep2/main.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdep2/rep3.py /usr/lib/python3/dist-packages/rosdep2/rep3.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdistro/__init__.py /usr/lib/python3/dist-packages/rosdistro/__init__.py.bak
sudo cp /usr/lib/python3/dist-packages/rosdep2/sources_list.py /usr/lib/python3/dist-packages/rosdep2/sources_list.py.bak

4、安装rosdep

sudo apt install python3-rosdep2

5、替换原文件网址到本地文件

sudo gedit /usr/lib/python3/dist-packages/rosdep2/main.py
sudo gedit /usr/lib/python3/dist-packages/rosdep2/rep3.py
sudo gedit /usr/lib/python3/dist-packages/rosdistro/__init__.py
sudo gedit /usr/lib/python3/dist-packages/rosdep2/sources_list.py

将文件中的https://raw.githubusercontent.com/ros/rosdistro/master 全部替换为 file:///home/one/git/rosdistro(若哪个文件找不到该句,就不做替换)

6、运行

sudo rosdep init

ubuntu20.04安装ROS【详细】_第2张图片
这样就是成功的!

若出现错误:

(1)错误1

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.

这一步按正常来说应该是成功的,出现这个错误说明没替换成功!!!重新返回 5、替换原文件网址到本地下载 重新替换,要记得保存!!

(2)错误2

在运行sudo rosdep init后出现下所示错误:
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize

执行

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

再执行

sudo rosdep init

7、备份并替换

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

将文件中的https://raw.githubusercontent.com/ros/rosdistro/master 全部替换为 file:///home/one/git/rosdistro

8、运行

rosdep update


这样就是成功了!!

注:/home/one/git/rosdistro这个文件不能删除,保留着。因为我们是直接指向本地的。

五、设置环境变量

1、添加

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

2、生效

source ~/.bashrc

六、安装rosinstall

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

七、验证ROS是否安装成功

roscore

若出现:
在这里插入图片描述
执行:

sudo apt install python3-roslaunch

然后再执行roscore时出现:
ubuntu20.04安装ROS【详细】_第3张图片
执行:

sudo apt install ros-noetic-desktop-full

重新再启动roscore就可以正常启动了。

八、测试小海龟

打开三个终端分别输入以下:

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

你可能感兴趣的:(ubuntu,linux,开源软件,git)