ROS环境搭建步骤总结

ROS环境搭建踩坑总结

Ubuntu 16.04安装ROS Kinetic

ROS安装

  1. 进入到 ROS官网选择安装的版本和系统
  2. 配置Ubuntu的repositories,以允许“restricted”,“ universe”和“ multiverse”。 可以按照Ubuntu指南中的说明进行操作。
  3. 设置接受来自package.ros.org的软件。
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/ `lsb_release -cs` 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/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
  1. 设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  1. apt升级一下到最新版本
sudo apt-get update
  1. 安装完整版本
sudo apt-get install ros-kinetic-desktop-full

可以通过下面这条命令来寻找可供下载的package

apt-cache search ros-kinetic

ROS环境搭建

  1. 每次启动新的shell时,将ROS环境变量自动添加到bash session中,很方便:
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
  1. 安装一些其他依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
  1. 安装rosdep
    rosdep使我们能轻松地为要编译的源安装系统依赖,并且是运行ROS中某些核心组件所必需的。 如果在上一步中没有安装,一定要装。
sudo apt install python-rosdep
  1. 初始化rosdep
sudo rosdep init

这一步可能会报下面的错误:

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.

大概有下面几种可能:

  • ca-certificates问题,证书不对,重新安装
sudo apt-get install ca-certificates
  • 系统时间同步问题,同步系统时间
sudo apt-get install ntpdate
sudo ntpdate cn.pool.ntp.org
sudo hwclock --systohc
  • ssl certs问题
sudo c_rehash /etc/ssl/certs 
sudo -E rosdep init
  • python-rosdep问题
sudo apt-get install python-rosdep

但是发现并没有用,之后在
在/etc目录下,新建了/ros/rosdep/sources.list.d/20-default.list这么个文件(注意sudo rosdep init失败时,/etc下并没有/ros目录,需要依次逐级新建),然后将https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list内容粘贴进去,如下:

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

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.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

根据网上的总结,到这一步应该就没有问题了,或者是会报错但不影响继续往下走的步骤,但实际上,往下走到5依旧会出错。
最终发现:这一步需要科学上网
5. 初始化rosdep

rosdep update

如果没有科学上网,这一步是会报错的,并且按照所谓的步骤:

#打开hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133  raw.githubusercontent.com
#保存后退出再尝试
rosdep update

是无效的。

ROS环境设置

  1. 如果完成了上面的步骤,就可以来确认一下是否安装正确了
printenv | grep ROS
  1. 打开的每个新Shell上都要先运行下面的命令,以访问ROS命令,除非我们将此行添加到.bashrc中。 这一步使我们可以在同一台计算机上安装多个ROS版本并在它们之间进行切换。
source /opt/ros/kinetic/setup.bash
  1. 创建ROS工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make

catkin_make命令是用于使用catkin workspace的便捷工具。 第一次在workspace运行它,它将在src文件夹中创建一个CMakeLists.txt链接。
当前目录中应该有一个build和devel文件夹。 在devel文件夹中,可以看到有多个setup. sh文件。运行任何一个都会覆盖整个环境。

要确保安装脚本正确覆盖了您的工作区,请确保ROS_PACKAGE_PATH环境变量包含你所在的目录。

echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/kinetic/share

这样,ROS环境就搭建好了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YuhsiHu

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

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

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

打赏作者

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

抵扣说明:

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

余额充值