ROS2安装教程指南

一、安装步骤

我的ubuntu版本是18.04,这里选择的是ROS2的Dashing版本,具体安装步骤如下:

1 设置UTF-8编码

sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-82 

2 更新软件源

sudo apt update && sudo apt install curl gnupg2 lsb-release
curl http://repo.ros2.org/repos.key | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

3 安装ros2

sudo apt update

-- 桌面版安装(包含ROS, RViz, demos, tutorials)
sudo apt install ros-dashing-desktop

-- 基础版安装(包含通讯库、消息包、命令行工具,没有GUI工具)
sudo apt install ros-dashing-ros-base

4 安装自动补全工具
ros2的命令行使用argcomplete工具进行补全,所以需要安装该工具:

sudo apt install python3-argcomplete

5 设置环境变量
和ROS 1一样,为了让系统找到ROS命令,安装完成后需要将以下语句添加到.bashrc中:

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

注意!!!
若是同时安装了ROS1和ROS2,可以在.bashrc中添加自己比较常用的ROS路径,另外的ROS版本,每次启动前都source一下路径即可。

6 安装相关的工具包和依赖

sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  python3-colcon-common-extensions \
  python3-lark-parser \
  python3-pip \
  python-rosdep \
  python3-vcstool \
  wget

#install some pip packages needed for testing
$ python3 -m pip install -U \
  argcomplete \
  flake8 \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures \
  pytest \
  pytest-cov \
  pytest-runner \
  setuptools
  
#install Fast-RTPS dependencies
$ sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev

注意!!!第6步安装的时候可能会报错
问题:Could not find a version that satisfies the requirement pytest (from versions: )
No matching distribution found for pytest
解决办法:主要是国内网络问题,所以使用豆瓣源安装

pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

示例

pip3 install pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

7 用rosdep安装依赖项

sudo rosdep init
rosdep update

注意!!!第7步可能会报错
打开网址:https://site.ip138.com
输入:raw.githubusercontent.com
随便挑选一个ip地址,我选的是美国的。
在桌面打开终端输入如下指令:

sudo gedit  /etc/hosts

在之中添加真实IP地址(根据自己的网址输入,会有变动):

199.232.68.133 raw.githubusercontent.com

然后再执行,即成功:

sudo rosdep init
rosdep update

8 ROS 2和ROS 1之间通过ros-bridge通信,需要安装

sudo apt update
sudo apt install ros-dashing-ros1-bridge

二、创建工作空间

1 创建工作空间并进行下载源码

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
wget https://raw.githubusercontent.com/ros2/ros2/dashing/ros2.repos
vcs import src < ros2.repos

2 编译所有包

cd ~/ros2_ws/
colcon build --symlink-install

3 新终端,执行以下命令

source  ~/ros2_ws/install/local_setup.bash
ros2 run demo_nodes_cpp talker

4 新终端,执行以下命令

source  ~/ros2_ws/install/local_setup.bash
ros2 run demo_nodes_cpp listener

大功告成!!!


版权声明:本文为weixin_37801425原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。