ROS2入门教程-linux下安装ROS2(源码安装)

说明:

介绍如何Linux系统上源码安装ROS2

系统要求

建议使用Ubuntu 16.04 LTS (64位)

确保有一个支持UTF-8的locale设置。locale设置例子如下:

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

创建开发环境

添加仓库:

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

sudo apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 421C365BD9FF1F717815A3895523BAEEB01FA116

安装相关的工具包

sudo apt update && sudo apt install -y

build-essential

git

python3-colcon-common-extensions

python3-pip

python-rosdep

python3-vcstool

wget

# install some pip packages needed for testing

sudo -H 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

# [Ubuntu 16.04] install extra packages not available or recent enough on Xenial

python3 -m pip install -U

pytest

pytest-cov

pytest-runner

setuptools

# install Fast-RTPS dependencies

sudo apt install --no-install-recommends -y

libasio-dev

libtinyxml2-dev

下载源码

创建工作空间并进行下载

mkdir -p ~/ros2_ws/src

cd ~/ros2_ws

wget https://raw.githubusercontent.com/ros2/ros2/release-latest/ros2.repos

vcs-import src < ros2.repos

Note: if you want to get all of the latest bug fixes then you can try the "tip" of development by replacing release-latest in the URL above with master. The release-latest is preferred by default because it goes through more rigorous testing on release than changes to master do. See also Maintaining a Source Checkout.

用rosdep安装依赖项

sudo rosdep init

rosdep update

rosdep install --from-paths src --ignore-src --rosdistro bouncy -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 rti-connext-dds-5.3.1 urdfdom_headers"

使用ament工具进行编译

编译所有包

src/ament/ament_tools/scripts/ament.py build --build-tests --symlink-install

测试

运行talker-listener例子测试是否成功安装

打开.bashrc文件在末尾添加ROS2的环境变量

source ~//setup.bash

新终端,执行以下命令:

ros2 run demo_nodes_cpp talker

新终端,执行以下命令:

ros2 run demo_nodes_cpp listener

测试成功截图

ros2-talkerdemo.png

参考资料

https://github.com/ros2/ros2/wiki/Linux-Install-Debians#setup-sources

https://github.com/ros2/ros2/wiki/Ament-Tutorial

https://github.com/ros2/ros2/wiki/Linux-Development-Setup

http://blog.csdn.net/xmy306538517/article/details/78770646

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐