以ROS 2 Dashing Diademata版本的安装为例,来说明如何搭建ros2环境:
安装方式
有如下几种安装方式:
1.二进制包安装
2.通过编译源码安装
Binary packages-二进制包安装
We provide ROS 2 binary packages for the following platforms:
Building from source-通过源码安装
支持的平台:
安装方式如何选择?
ROS 2从二进制软件包或从源代码安装功能都是完备的。选项之间的差异取决于我们打算对ROS 2做些什么。
二进制程序包供一般使用,并提供已构建的ROS 2安装。这对于希望立即开始使用ROS 2的人们来说非常有用。
Linux用户有两个安装二进制软件包的选项:
-
Debian软件包
-
"fat" archive :无root权限时选择此种方式
从Debian软件包安装是推荐的方法。这更加方便,因为它会自动安装其必需的依赖项。它还会与常规系统更新一起更新。
但是,需要root用户访问权限才能安装Debian软件包。
如果使用者没有超级用户访问权限,那么“fat” archive将是下一个最佳选择。
选择从二进制软件包安装的macOS和Windows用户仅具有“fat”存档选项(Debian软件包是Ubuntu / Debian独有的)。
从源代码构建是为寻求更改或明确省略ROS 2基础部分的开发人员而设计的。对于不支持二进制文件安装的平台,也建议使用源码编译安装。从源代码编译还可以选择安装最新版本的ROS 2
源码构建方式
系统要求
Target platforms for Dashing Diademata are (see REP 2000):
-
Tier 1: Ubuntu Linux - Bionic Beaver (18.04) 64-bit
Tier 3 platforms (not actively tested or supported) include:
-
Debian Linux - Stretch (9)
-
Fedora 30, see alternate instructions
-
Arch Linux, see alternate instructions
-
OpenEmbedded / webOS OSE, see alternate instructions
系统安装
设置语言环境
Make sure you have a locale which supports UTF-8
. If you are in a minimal environment (such as a docker container), the locale may be something minimal like POSIX
. We test with the following settings. However, it should be fine if you’re using a different UTF-8 supported locale.
确保语言环境支持UTF-8
。如果是处于最小环境中(例如docker容器),则语言环境可能像POSIX
一样最小。我们使用以下设置进行测试。
locale # check for UTF-8 sudo apt update && sudo apt install locales 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 locale # verify settings
You will need to add the ROS 2 apt repositories to your system. To do so, first authorize our GPG key with apt like this:
添加ROS2 apt仓库
请首先使用如下命令授权我们的GPG密钥
sudo apt update && sudo apt install curl gnupg2 lsb-release curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
然后将仓库添加到我们的源列表中:
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
安装开发工具和ROS工具
sudo apt update && sudo apt install -y \ build-essential \ cmake \ git \ python3-colcon-common-extensions \ 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 # install Cyclone DDS dependencies sudo apt install --no-install-recommends -y \ libcunit1-dev
获取ROS2源码
创建一个工作目录,然后下载代码:
mkdir -p ~/ros2_dashing/src cd ~/ros2_dashing wget https://raw.githubusercontent.com/ros2/ros2/dashing/ros2.repos vcs import src < ros2.repos
使用rosdep安装依赖库
sudo rosdep init rosdep update rosdep install --from-paths src --ignore-src --rosdistro dashing -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 libopensplice69 rti-connext-dds-5.3.1 urdfdom_headers"
安装其他的DDSInstall additional DDS implementations (optional)¶
If you would like to use another DDS or RTPS vendor besides the default, eProsima’s Fast RTPS, you can find instructions here.
在工作区编译源码
More info on working with a ROS workspace can be found in this tutorial.
cd ~/ros2_dashing/ colcon build --symlink-install
Note: if you are having trouble compiling all examples and this is preventing you from completing a successful build, you can use AMENT_IGNORE
in the same manner as CATKIN_IGNORE to ignore the subtree or remove the folder from the workspace. Take for instance: you would like to avoid installing the large OpenCV library. Well then simply $ touch AMENT_IGNORE
in the cam2image
demo directory to leave it out of the build process.
Optionally install all packages into a combined directory (rather than each package in a separate subdirectory). On Windows due to limitations of the length of environment variables you should use this option when building workspaces with many (~ >> 100 packages).
Also, if you have already installed ROS 2 from Debian make sure that you run the build
command in a fresh environment. You may want to make sure that you do not have source /opt/ros/${ROS_DISTRO}/setup.bash
in your .bashrc
.
colcon build --symlink-install --merge-install
Afterwards source the local_setup.*
from the install
folder.
建立开发环境
Source 安装脚本
Set up your environment by sourcing the following file.
. ~/ros2_dashing/install/setup.bash
尝试一些实例
在一个终端运行C++ talker
:
. ~/ros2_dashing/install/local_setup.bash ros2 run demo_nodes_cpp talker
在另一个终端运行一个python的listener:
. ~/ros2_dashing/install/local_setup.bash ros2 run demo_nodes_py listener
You should see the talker
saying that it’s Publishing
messages and the listener
saying I heard
those messages. This verifies both the C++ and Python APIs are working properly. Hooray!
参考:
https://index.ros.org/doc/ros2/Installation/Dashing/