ROS系统的介绍和安装

之前就简单学习了一下ROS,但只是照猫画虎地进行仿真,不能熟练的运用。
这么久没有继续学习了,连之前学的都忘记了。这次再次捡起来,并将学习的知识总结在博客里。

一、ROS的介绍

请添加图片描述
请添加图片描述

ROS的行业分析2019年
ROS的官网
ROS的年度盛会,每年一次。每年会聚集全世界各类的应用开放者,展示各种前沿的ROS应用。2018的链接为:ROS的年度会-2018链接
ROS的wiki百科
ROS的社区
ROS开发社区

二、ROS的安装

我的ubuntu版本是18.04.4,因此选择安装Melodic版本的ROS。
安装后的路径:其他位置-计算机-opt-ros
在这里插入图片描述
安装参考链接

2.1 设置软件源

搜索software,设置软件源
在这里插入图片描述
在这里插入图片描述
在弹出的如下页面,勾选如图并选择软件源是http://mirrors.tuna.tsinghua.edu.cn/ubuntu
在这里插入图片描述
然后设置软件源:
在这里插入图片描述

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'
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

2.2 安装

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

2.3 初始化rosdep

第一步:
全程sudo,建立一个文件夹/etc/ros/rosdep/sources.list.d

sudo mkdir -p /etc/ros/rosdep/sources.list.d

第二步:写入文件

sudo gedit 20-default.list

复制如下内容到打开的空白文件中,并保存。

# os-specific listings first
yaml https://raw.github.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.github.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.github.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

在这里插入图片描述
第三步:写入IP地址

cd /etc
sudo gedit hosts

在文件末尾添加:151.101.84.133 raw.githubusercontent.com
在这里插入图片描述

2.4 rosdep更新

由于近期国内Github Raw的可用IP越来越少,通过修改hosts文件解决rosdep update超时问题的方法已经不太好用,本文通过修改rosdep源码中下载资源的函数来解决这一问题。
网站https://ghproxy.com/支持github的资源代理,非常好用,我们将用此代理加速rosdep对Github Raw的访问,进而解决rosdep update超时问题。
首先定位rosdep资源下载函数。从报错信息中得知,该函数名为download_rosdep_data,位于/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py。我们修改这一函数,添加:

url="https://ghproxy.com/"+url

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
用同样的方法修改/usr/lib/python2.7/dist-packages/rosdistro/init.py里面的DEFAULT_INDEX_URL。
即将DEFAULT_INDEX_URL 进行如下替换:

DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'

在这里插入图片描述
在这里插入图片描述
除此处外,下述文件中也含有github地址,分别是:

/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 36行
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py 72行
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py 39行
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py 68行 119行

均可通过在地址前添加https://ghproxy.com/前缀来应用代理服务。

gbpdistro_url ="https://ghproxy.com/" + gbpdistro_url

在这里插入图片描述
运行rosdep更新

rosdep update

在这里插入图片描述

2.5 安装rosinstall

sudo apt-get install python-rosinstall

2.6 加载环境设置文件

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

2.7 创建并初始化工作目录

mkdir -p ~/catkin_ws/src 
cd ~/catkin_ws/src 
source /opt/ros/melodic/setup.bash
catkin_init_workspace

目前,只有src目录和CMakeLists.txt文件在catkin工作目录中,使用catkin_make命令来构建

cd ~/catkin_ws/
catkin_make

2.8 设置环境变量

sudo apt install net-tools
gedit ~/.bashrc

在打开的文件里设置环境变量。

# Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
 
# Set ROS Network
#ifconfig查看你的电脑ip地址
export ROS_HOSTNAME=192.168.89.135
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
 
# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'

环境变量要写在文件里,这里的IP地址要按照你的来设置。
在这里插入图片描述
ubuntu系统查看IP地址:IP是IPV4的192.168.202.130这个
在这里插入图片描述

三 测试

小海龟测试,打开三个终端:

roscore
sudo apt install rosbash
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

在这里插入图片描述

四、遇到问题

4.1 sudo apt-get install * 遇到问题

在这里插入图片描述

sudo rm /var/lib/dpkg/lock-frontend    
sudo rm /var/lib/dpkg/lock

4.2 E: Unable to locate package 问题的参考链接

4.3 sudo rosdep:找不到命令问题的参考链接

遇到这个报错:

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.

参考这篇文章
还有这篇文章
参考链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kissgoodbye2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值