之前就简单学习了一下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.