Ubuntu ROS2.0安装使用教程

来源:互联网 发布:仿凡科 源码 编辑:程序博客网 时间:2024/06/03 22:38

一、二进制安装

安装依赖

  1. Install runtime dependencies and wget:
sudo apt-get update && sudo apt-get install -q -y \     libopencv-core2.4v5 \     libhighgui2.4 \     libopencv-imgproc2.4v5 \     libasio-dev \     libeigen3-dev \     libtinyxml-dev \     libtinyxml2-dev \     libcurl4-openssl-dev \     libqt5core5a \     libqt5gui5 \     libqt5opengl5 \     libqt5widgets5 \     libxaw7-dev \     libgles2-mesa-dev \     libglu1-mesa-dev \     python3-pip \     python3-setuptools \     python3-yaml \     wget
  1. Install argcomplete from pip for argument completion. Note that the version available through apt-get in Ubuntu 16.04 (Xenial) will not work due to a bug in argcomplete:

    sudo pip3 install argcomplete

    下载ROS 2

  2. Go the releases page: https://github.com/ros2/ros2/releases

  3. Unpack it:
mkdir -p ~/ros2_installcd ~/ros2_installtar xf ~/Downloads/ros2-package-linux-x86_64.tar.bz2

运行实例

source ~/ros2_install/ros2-linux/setup.bash#In one terminalros2 run demo_nodes_cpp talker#In another terminalros2 run demo_nodes_cpp listener

你将看到发布并收听到了hello word,说明安装成功

ROS 1 bridge

如果你已经安装了ROS1,先source ros1的安装文件,假设它在/opt/ros/kinetic/setup.bash.然后开启roscore

source /opt/ros/kinetic/setup.bashroscore

在另一个终端开启桥接

source /opt/ros/kinetic/setup.bashsource ~/ros2_install/ros2-linux/setup.bashros2 run ros1_bridge dynamic_bridge

二、源码安装

系统要求

sudo locale-gen en_US en_US.UTF-8sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8export 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

安装GCC,G ++ CMake,Python 3 EmPy包(custom packages which don’t collide)和setuptools:

sudo apt-get updatesudo apt-get install git wgetsudo apt-get install build-essential cppcheck cmake libopencv-dev python-empy python3-dev python3-empy python3-nose python3-pip python3-pyparsing python3-setuptools python3-vcstool python3-yaml libtinyxml-dev libeigen3-dev# dependencies for testingsudo apt-get install clang-format pydocstyle pyflakes python3-coverage python3-mock python3-pep8 uncrustify# Install argcomplete for command-line tab completion from the ROS2 tools.# Install from pip rather than from apt-get because of a bug in the Ubuntu 16.04 version of argcomplete:sudo pip3 install argcomplete# additional testing dependencies from pip (because not available on ubuntu 16.04)sudo pip3 install flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes pytest pytest-cov pytest-runner# dependencies for FastRTPSsudo apt-get install libasio-dev libtinyxml2-dev

创建工作区并克隆all repos

mkdir -p ~/ros2_ws/srccd ~/ros2_wswget https://raw.githubusercontent.com/ros2/ros2/release-latest/ros2.reposvcs-import src < ros2.repos

安装一个或多个DDS实现
PrismTech OpenSplice Debian Packages built by OSRF

sudo apt update && sudo apt install curlcurl http://repo.ros2.org/repos.key | sudo apt-key add -sudo sh -c 'echo "deb http://repo.ros2.org/ubuntu/main xenial main" > /etc/apt/sources.list.d/ros2-latest.list'sudo apt-get updatesudo apt-get install libopensplice67  # from repo.ros2.org

使用ament_tools的引导脚本构建原型

build the ROS 1 bridge

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

然后设置ros1的环境变量ros2的环境变量

source /opt/ros/kinetic/setup.bashsource ~/ros2_ws/install/local_setup.bash

然后建立一个 ROS 1 桥:

src/ament/ament_tools/scripts/ament.py build --build-tests --symlink-install --only ros1_bridge --force-cmake-configure

Example 1: run the bridge and the example talker and listener

# Shell A:source /opt/ros/kinetic/setup.bashroscore# Shell B:source /opt/ros/kinetic/setup.bashsource ~/ros2_ws/install/setup.bashexport ROS_MASTER_URI=http://localhost:11311ros2 run ros1_bridge dynamic_bridge# Shell C:source /opt/ros/kinetic/setup.bashrosrun rospy_tutorials talker# Shell D:source ~/ros2_ws/install/setup.bashros2 run demo_nodes_cpp listener

当查看shell B中的输出时,将会有一行指出已经创建了该主题的桥梁:

该屏幕截图显示了所有的shell窗口及其预期内容:
这里写图片描述

原创粉丝点击