Multiple distributions of ROS 2 are supported at a time. We recommend using the most recent release available when possible.
一次同时支持多个ROS 2发行版,但是建议尽可能使用最新版本(Dashing)。
ROS 2 Bouncy Bolson |
ROS 2 Crystal Clemmys |
ROS 2 Dashing Diademata |
Released July 2018 |
Released December 2018 |
Released May 2019 |
Supported until July 2019 |
Supported until December 2019 |
Supported until May 2021 |
For more detailed descriptions of each release see REP-2000 有关每个版本的更详细说明,请参考REP-2000
You may want to install an older distribution if you need ROS 2 to:
考虑到如下一些需求可能需要安装较旧的ROS 2发行版:
在较旧的平台上运行
尚未支持针对最新版本进行优化的旧软件包
得到更长时间的支持(最新版本不一定支持时间最长)
General users with no special considerations should use the most recent release available.
没有特殊注意事项的一般用户应使用最新版本。
If you plan to contribute directly to ROS 2 core packages, you can install the latest development from source.
如果计划直接为ROS 2核心软件包做出贡献,可以从源代码安装最新的开发版。
We provide ROS 2 binary packages for the following platforms:
以下平台可直接使用ROS 2二进制包进行安装:
Debian packages
"fat" archive
We support building ROS 2 from source on the following platforms:
支持在以下平台上从源代码编译ROS 2:
Installing from binary packages or from source will both result in a fully-functional and usable ROS 2 install. Differences between the options depend on what you plan to do with ROS 2. Binary packages are for general use and provide an already-built install of ROS 2. This is great for people who want to dive in and start using ROS 2 as-is, right away.
从二进制包或源代码安装完全功能和可用的ROS 2安装。选项之间的差异取决于将如何使用ROS 2。二进制包是普遍用途,并提供已经编译好的ROS 2安装包。这对于想要进入并立即开始使用ROS 2的人来说非常棒的选择。推荐使用二进制包进行安装!
Linux users have two options for installing binary packages: Linux用户有两种安装二进制包的选项:
Installing from Debian packages is the recommended method. It’s more convenient because it installs its necessary dependencies automatically. It also updates alongside regular system updates. However, you need root access in order to install Debian packages. If you don’t have root access, the “fat” archive is the next best choice.
建议使用Debian软件包进行安装。因为它更方便,并会自动安装必要的依赖项,还会与常规系统更新一起更新。但是,需要root访问权限才能安装Debian软件包。如果没有root访问权限,那么“fat”档案包是另一个最佳选择。
OS X and Windows users who choose to install from binary packages only have the “fat” archive option (Debian packages are exclusive to Ubuntu/Debian).
选择从二进制包安装的OS X和Windows用户只有“fat”档案包选项(Debian软件包是Ubuntu/Debian独有的)。
Building from source is meant for developers looking to alter or explicitly omit parts of ROS 2’s base. It is also recommended for platforms that don’t support binaries. Building from source also gives you the option to install the absolute latest version of ROS 2.
从源代码编译适用于希望改变或明确省略部ROS 2基础的开发人员。对于不支持二进制文件安装的平台,也建议使用源码编译安装。从源代码编译还可以选择安装最新版本的ROS 2。
Debian packages for ROS 2 Dashing Diademata are available for Ubuntu Bionic.
用于ROS 2 Dashing Diademata的Debian软件包可用于Ubuntu Bionic。
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. It should be fine if you’re using a different UTF-8 supported locale.
确保语言环境支持UTF-8。如果处于最小的环境中,例如docker容器,则语言环境可能与POSIX一样极小。使用以下设置进行测试。如果使用不同的支持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-8
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:
需要将ROS 2 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 -
And then add the repository to your sources list:
然后将库添加到源列表:
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'
Update your apt repository caches after setting up the repositories. 设置库后更新apt库缓存。
sudo apt update
Desktop Install (Recommended): ROS, RViz, demos, tutorials. 桌面安装(推荐):ROS、RViz、示例、教程。
sudo apt install ros-dashing-desktop
ROS-Base Install (Bare Bones): Communication libraries, message packages, command line tools. No GUI tools. ROS-Base安装(精简):通信库、消息包、命令行工具。没有GUI工具。
sudo apt install ros-dashing-ros-base
See specific sections below for how to also install the ros1_bridge, TurtleBot packages, or alternative RMW packages.
有关如何安装ros1_bridge、TurtleBot软件包或其他RMW软件包的信息,请参考下面的特定部分。
ROS 2 command line tools use argcomplete to autocompletion. So if you want autocompletion, installing argcomplete is necessary.
ROS 2命令行工具使用argcomplete完成自动补全功能(Tab补全命令的功能)。因此,如果想要自动完成,则需要安装argcomplete。
sudo apt install python3-argcomplete
Set up your environment by sourcing the following file. 通过导入以下文件设置环境。
source /opt/ros/dashing/setup.bash
You may want to add this to your .bashrc. 想将此添加到.bashrc。
echo "source /opt/ros/dashing/setup.bash" >> ~/.bashrc
By default the RMW implementation FastRTPS is used. If using Ardent OpenSplice is also installed.
默认情况下,使用RMW实现FastRTPS。如果还使用了Ardent OpenSplice。
To install support for OpenSplice or RTI Connext on Bouncy:
在Bouncy上安装对OpenSplice或RTI Connext的支持:
sudo apt update
sudo apt install ros-dashing-rmw-opensplice-cpp # for OpenSplice
sudo apt install ros-dashing-rmw-connext-cpp # for RTI Connext (requires license agreement)
By setting the environment variable RMW_IMPLEMENTATION=rmw_opensplice_cpp you can switch to use OpenSplice instead. For ROS 2 releases Bouncy and newer, RMW_IMPLEMENTATION=rmw_connext_cpp can also be selected to use RTI Connext.
通过设置环境变量RMW_IMPLEMENTATION=rmw_opensplice_cpp,可以切换为使用OpenSplice。对于ROS 2 Bouncy或更新版本,如Dashing,RMW_IMPLEMENTATION=rmw_connext_cpp也可以选择使用RTI Connext。
If you want to install the Connext DDS-Security plugins please refer to this page.
如果要安装Connext DDS-Security插件,请参考此网页。
University, purchase or evaluation options are also available for RTI Connext.
RTI Connext也提供大学,购买或试用选项。
The ros1_bridge as well as the TurtleBot demos are using ROS 1 packages. To be able to install them please start by adding the ROS 1 sources as documented here.
在ros1_bridge还有TurtleBot示例等使用ROS 1包。为了能够安装它们,请首先添加ROS 1源,如此处所述。
If you’re using Docker for isolation you can start with the image ros:melodic or osrf/ros:melodic-desktop (or Kinetic if using Ardent). This will also avoid the need to setup the ROS sources as they will already be integrated. 如果使用Docker进行隔离,则可以从镜像ros:melodic或者osrf/ros:melodic-desktop开始,(如果使用Ardent则使用Kinetic)。这也将避免设置ROS源的需要,因为它们已经被集成。
Now you can install the remaining packages: 现在可以安装剩余的包:
sudo apt update
sudo apt install ros-dashing-ros1-bridge
The turtlebot2 packages are not currently available in Dashing. 目前,Dashing中不提供turtlebot2软件包。
However, Dashing supports the turtlebot3 package. 但是,Dashing支持turtlebot3软件包。
If you would like to build your own packages, refer to the tutorial "Using Colcon to build packages".
如果您想编译自定义的包,请参考教程“使用Colcon编译包”。
测试一下,ROS Dashing是否安装配置正常吧,分别在不同终端输入如下命令:
ros2 run examples_rclcpp_minimal_subscriber subscriber_lambda
ros2 run examples_rclcpp_minimal_publisher publisher_lambda
命令分别打开一个订阅器和一个发布器,用于收发hello world消息。
使用rqt图形化工具可以看到:
简要看一下如下代码,和常见C++或ROS 1代码相比,有何相同和不同之处?
发布器:
#include
#include
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
using namespace std::chrono_literals;
/* This example creates a subclass of Node and uses a fancy C++11 lambda
* function to shorten the callback syntax, at the expense of making the
* code somewhat more difficult to understand at first glance. */
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{
publisher_ = this->create_publisher
auto timer_callback =
[this]() -> void {
auto message = std_msgs::msg::String();
message.data = "Hello, world! " + std::to_string(this->count_++);
RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
this->publisher_->publish(message);
};
timer_ = this->create_wall_timer(500ms, timer_callback);
}
private:
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher
size_t count_;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared
rclcpp::shutdown();
return 0;
}
接收器:
#include
#include
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
class MinimalSubscriber : public rclcpp::Node
{
public:
MinimalSubscriber()
: Node("minimal_subscriber")
{
subscription_ = this->create_subscription
"topic",
10,
[this](std_msgs::msg::String::UniquePtr msg) {
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
});
}
private:
rclcpp::Subscription
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared
rclcpp::shutdown();
return 0;
}
试一试ROS 2的小乌龟案例吧:
Turtlesim(https://blog.csdn.net/ZhangRelay/article/details/99932959)