Ubuntu18.04安装ros(最新,亲测有效)

设置软件源

点击Show Applications在software updater中设置Ubuntu Software如下图:
Ubuntu18.04安装ros(最新,亲测有效)_第1张图片
选中Source code,然后选择服务器镜像,这也很重要,国内清华和阿里云速度快一些,我推荐清华,比较稳定。
Ubuntu18.04安装ros(最新,亲测有效)_第2张图片

设置软件源

清华源:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

设置密钥

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

安装依赖项

sudo apt install libvtk6-jni libvtk6-java libvtk6-dev libvtk6-qt-dev libpcl-dev
sudo apt install ros-melodic-pcl-conversions ros-melodic-pcl-ros ros-melodic-perception-pcl ros-melodic-perception

安装Ros-melodic

sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*

初始化rosdep

sudo rosdep init
rosdep update

这两部执行一般都会有问题
一般出现的问题如下:
在运行sudo rosdep init后出现下所示错误:

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.

方法:
1.新建文件夹,并进入文件夹

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

2.下载git
通过运行以下命令确保您的系统和apt包列表完全更新:

sudo apt-get update -y
sudo apt-get upgrade -y

开始安装Git
使用命令:sudo apt install git 来安装Git,使用命令:git --version 来查看git版本号

sudo apt install git

配置Git
在Git 中配置自己的名称和电子邮件地址,使用命令:

git config --global user.name "xxx"
git config --global user.email "xxx"

3.下载项目

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

需要确保Ubuntu有网络,网络越快越好

4.另打开一个终端,备份原文件

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

5.替换原文件网址到本地下载

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

并全部做替换,将 https://raw.githubusercontent.com/ros/rosdistro/master/xxxx/xx中的https://raw.githubusercontent.com/ros/rosdistro/master全部替换为 file:///home/one/git/rosdistro

6.运行

sudo rosdep init

终端显示 rosdep update 即可进入下一步。

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/xxxx/xx中 https://raw.githubusercontent.com/ros/rosdistro/master全部替换为 file:///home/one/git/rosdistro

8.运行

rosdep update

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

安装rosinstall

sudo apt-get install python-rosinstall

安装catkin编译器

sudo apt-get install ros-melodic-catkin python-catkin-tools

配置环境变量

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

测试小海龟

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

小海龟测试成功!

你可能感兴趣的:(Ubuntu18.04,ROS,ubuntu)