ROS学习笔记-----ROS环境安装(Ubuntu18.04)

N首先根据自己的系统,选择对应的版本

一、更新镜像源

切记第一步一定要执行,否则后面会遇上错误

1,设置中的镜像源的更改

ubuntu18.04 软件与更新(software & update)的位置没有在设置(setting)里面,而是在这个地方:

打开后进行勾选及更换:

2.更改Ubuntu软件源

如果忽略这步,Ros相关软件包安装下载时需要很长时间,更换为国内软件源后会大大加快软件下载以及update的速度。

首先,修改源文件,输入命令:

sudo gedit /etc/apt/sources.list

 打开后把配置文件内容修改如下:

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic main universe restricted multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main universe restricted multiverse #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main universe restricted multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main universe restricted multiverse #Added by software-properties
deb http://security.ubuntu.com/ubuntu/ bionic-security main universe restricted multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main universe restricted multiverse #Added by software-properties

3,更新并升级

 sudo apt-get update && sudo apt-get upgrade

二、正式安装步骤

1.添加ROS软件源

输入以下命令:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

注意:上述命令如果下载速度过慢,可以使用以下命令重新添加软件源(经测试均可正常安装):

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软件包

首先,更新系统软件:

sudo apt update

然后正式安装,为了避免之后出现缺少软件包的问题,在这里直接下载完整版Ros-Melodic软件包

sudo apt install ros-melodic-desktop-full

此步会耗时较长,需要耐心等待,如果一边结束后显示有某些软件包漏掉未下载或下载失败,再次运行该命令即可,可能是因为下载某些软件包时网络问题。

执行中出现错误,解决方法参考连接:

 解决方法参考:

解决ros-melodic-desktop-full安装过程中未满足的依赖关系问题_杰哥亡命天涯的博客-CSDN博客_ros-melodic-desktop-full

我是执行了4次n后成功的。 

4.初始化rosdep

运行命令:

sudo apt-get install python-rosdep
sudo rosdep init

安装上面的显示运行:

rosdep update

出现错误: 

 解决方法:

造成该问题的原因是:

raw.githubusercontent.com实际上就是github的用户数据服务器
rosdep程序下载的就是从github.com/ros/rosdistro这个repo里的yaml文件
虽然raw.githubusercontent.com服务器无法访问,但是yaml文件可以直接从git clone的repo中获得

第一步
将rosdistro clone到本地

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

如果卡住了,可以百度云下载
链接: https://pan.baidu.com/s/1BwAskFFs_Qd7Fp_gZX-GdQ
提取码: as59
解压到home下,我的用户名是kxn,那么这个文件夹的地址就是

/home/kxn/rosdistro

第二步,更改4个文件

终端打开刚刚下载(clone)下来的rosdistro文件夹
以下的所有yourname 都改成你们自己的用户名!!!!

文件1:

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

文件2

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

替换为以下内容

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

文件3

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

替换为以下内容

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

文件四:

cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py
(我的电脑里是 __init__.py,但是原作者的是init.py,大家可以自己查看)

同样的替换,如下

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

最后一步,将su权限下的文件更改

执行

sudo su //输入你的密码切换至root
sudo mkdir -p /etc/ros/rosdep/sources.list.d   
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

参考博文:

 rosdep init/update 解决方法_CCsherlock的博客-CSDN博客_rosdep updaterosdep init/update 解决方法最近在国内上github越来越难,我自己的校园网曾经还是很好使的,但是最近也上不去了,加上不想花钱在ubuntu上买代理,所以在很多需要上git的场景很头疼。包括今天写的这个ros 安装过程中出现的问题。我使用的是ubuntu 18.04系统 ros melodic当我们在sudo rosdep init报错ERROR: cannot download default sources list from:https://raw.githubuse.https://blog.csdn.net/weixin_43311920/article/details/114796748

问题成功解决的显示为: 

 5.设置环境变量:

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

source ~/.bashrc

6,安装依赖包

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

三、测试安装是否成功

1.启动RosMaster(管理Ros中各个节点的“大管家”,每次启动Ros时需要首先启动RosMaster)

roscore

 安装成功的话显示的内容为: 

四、ROS turtlesim小乌龟的使用与分析

4.1 控制一只小乌龟

首先打开一个终端,先输入roscore启用ros master,不要关闭该终端

 之后再开一个terminal输入rosrun turtlesim turtlesim_node启用小乌龟,

 再开一个terminal输入rosrun turtlesim turtle_teleop_key启用键盘控制。

这样就可以控制小乌龟 

 

 所以其命令的格式为:

格式
rosrun 功能包 节点

4.2 分析ros命令使用的基本原理

4.2.1 关于roscore


    通过上面的代码,可以启用turtlesim(功能包)里面的两个节点。首先先看下roscore 的terminal,之前仅是启用ros master但是没有去分析terminal里面的信息的含义。打印的信息基本上是版本信息。其中有比较重要的信息,如图,有个http,由于ROS是分布式的,因此ros master可能存在于任一主机中,因此需要标记下。ROS分布式的优点就是可以使得不同的功能模块在不同的主机上面运行,可以节省计算资源,提高效率等。


在这里插入图片描述

关于计算图和节点

用rqt_graph查看一下计算图,可以看到有两个节点。图中两种输入方式皆可。

在这里插入图片描述

 如果不想使用界面的方式看结点,可以输入以下的命令:

前提是将上面rqt_graph查看计算图得我终端关闭

rosnode list
rostopic list

 在这里插入图片描述

对该部分的详细的分析可以看下面博文的链接: 

ROS turtlesim小乌龟的使用与分析_1、、的博客-CSDN博客_ros turtlesim入门ROS时基本上都会去操作turtlesim小海龟,有的人只是在安装完之后开个小海龟测试一下能不能用(我以前就是这样的),但是个人觉得还是可以研究下小海龟的,小海龟这个例子涉及很多ROS的知识。https://blog.csdn.net/sf9898/article/details/105306685

使用小乌龟绘制一个正方形的方法

重新打开一个终端输入:

rosrun turtlesim draw_square

五、关于ros资料一些好的博文链接和示例

 关于ros坐标变换,下面这个链接里面收录了许多资料和博客。ROS之tf空间坐标变换完全详解_zhanghm1995的博客-CSDN博客_tf坐标变换本博文主要汇总了自己在使用ROS中tf坐标变换包时查找的一些参考资料和博客,包括了tf和部分tf2的使用,在此感谢所有博客中出现的博客链接!参考资源:ROS官网详细介绍:http://wiki.ros.org/tf/Tutorialshttp://wiki.ros.org/tfintroduction to tf: http://wiki.ros.org/tf/Tutorials/Int...https://blog.csdn.net/zhanghm1995/article/details/84644984

5.1 显示两只乌龟并实现一只乌龟追另一只乌龟的方法

开两个终端

首先打开一个终端,先输入roscore启用ros master,不要关闭该终端

再开一个终端,输入:

roslaunch turtle_tf turtle_tf_demo.launch 

显示下面图中的结果:

在这里插入图片描述  

开始时会有两只turtle,一只在图中心,一只在别的位置但是会向着另一只移动,一会儿就在图中心重合了。

重新开启一个终端,输入如下的命令。启用键盘控制,可以看到图中蓝色的turtle追着绿色的turtle。

rosrun turtlesim turtle_teleop_key 

在这里插入图片描述

 在这里插入图片描述

重新开启一个终端, 用rosrun tf view_frames生成一份PDF,文件里描述了两只turtle的关系。文件在home目录下。

在这里插入图片描述

5.2 可视化 

在terminal中输入rviz可以可视化查看二者的坐标关系。

打开后的RVIZ是这样的,需要加点东西才能看到效果。

在这里插入图片描述

可以看到有红色报错的地方,通过下图的改正,将fixed frame更改为world就可以将错误修复。 

 

在修改第一个fixed frame为world之后可以看到红色的报错部分也没了。之后点击add按键,添加三个坐标系,如图设置,再加上一个tf。 

     之后可以打开键盘控制小海龟移动,看看RVIZ里面的坐标系变化情况和小海龟的移动情况,将小海龟移到中间栅格的世界坐标系,不难发现世界坐标系对应的是海龟界面的左下角。

 在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值