Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >ROS2编程基础课程--colcon

ROS2编程基础课程--colcon

作者头像
zhangrelay
发布于 2019-09-19 06:14:21
发布于 2019-09-19 06:14:21
2.8K0
举报

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

本文链接:https://blog.csdn.net/ZhangRelay/article/details/100773358

Using colcon to build packages

使用colcon编译包

This is a brief tutorial of how to create and build a ROS 2 workspace with colcon. It is a practical tutorial and not designed to replace the core documentation.

这是一个使用colcon如何创建和编译ROS 2工作区的简要教程。这是一个实用的教程,并非旨在取代核心文档。

ROS 2 releases before Bouncy used ament_tools described in the ament tutorial.

如果使用Bouncy或之前发行版本的ROS 2参考ament教程中ament_tools使用说明。

在Crystal和Dashing中均使用colcon进行编译。

Background 背景

colcon is an iteration on the ROS build tools catkin_make, catkin_make_isolated, catkin_tools and ament_tools. For more information on the design of colcon see this document.

colcon是对ROS编译(编译)工具catkin_make,catkin_make_isolated,catkin_tools和ament_tools迭代。有关colcon设计的更多信息,请参考此文档

The source code can be found in the colcon GitHub organization.

源代码可以在colcon GitHub组织中找到

Prerequisites 预备基础

Install colcon 安装colcon 

Linux

sudo apt install python3-colcon-common-extensions

python3-colcon-common-extensions is already the newest version (0.2.0-2).

OS X

python3 -m pip install colcon-common-extensions

Windows

pip install -U colcon-common-extensions

Install ROS 2 安装ROS2

To build the samples, you will need to install ROS 2.

编译示例前,需要先安装ROS 2。

Follow the installation instructions.

请参考安装说明

Attention 注意

If installing from Debian packages, this tutorial requires the desktop installation.

如果从Debian软件包安装,本教程需要桌面安装

Basics 基础知识

A ROS workspace is a directory with a particular structure. Commonly there is a src subdirectory. Inside that subdirectory is where the source code of ROS packages will be located. Typically the directory starts otherwise empty.

ROS工作空间是具有特定结构的目录。通常有一个src子目录。这个src子目录中是ROS包的源代码所在的位置。通常,通常都从这个目录开始,否则为空。

colcon does out of source builds. By default it will create the following directories as peers of the src directory:

colcon完成源代码编译。默认情况下,它将创建以下目录作为src目录的对等项:

The build directory will be where intermediate files are stored. For each package a subfolder will be created in which e.g. CMake is being invoked.

其中build目录将是存储中间文件的位置。对于每个包,将创建一个子文件夹,例如调用CMake。

The install directory is where each package will be installed to. By default each package will be installed into a separate subdirectory.

其中install目录是每个软件包将安装到的目录。默认情况下,每个包都将安装到单独的子目录中。

The log directory contains various logging information about each colcon invocation.

其中log目录包含有关每个colcon调用的各种日志记录信息。

Note 注意

Compared to catkin there is no devel directory. 与catkin相比,没有devel目录。

Create a workspace 创建工作区

First, create a directory (ros2_example_ws) to contain our workspace:

首先,创建一个目录(ros2_example_ws)来包含自定义的工作区:

Linux/OS X

mkdir -p ~/ros2_example_ws/src

cd ~/ros2_example_ws

Windows

md \dev\ros2_example_ws\src

cd \dev\ros2_example_ws

At this point the workspace contains a single empty directory src:

此时工作空间包含一个空目录文件夹src:

.

└── src

1 directory, 0 files

Add some sources 添加一些来源

Let’s clone the examples repository into the src directory of the workspace:

示例库克隆到工作区的src目录中:

git clone https://github.com/ros2/examples src/examples

Attention 注意

It is recommended to checkout a branch that is compatible with the version of ROS that was installed (e.g. crystal、dashing).

建议检查与已安装的ROS版本兼容的分支(例如crystal、dashing)。

cd ~/ros2_example_ws/src/examples/

git checkout $ROS_DISTRO

cd ~/ros2_example_ws

Now the workspace should have the source code to the ROS 2 examples:

现在工作区应该有ROS 2示例的源代码:

.

└── src

└── examples

├── CONTRIBUTING.md

├── LICENSE

├── rclcpp

├── rclpy

└── README.md

4 directories, 3 files

Source an underlay 导入底层

It is important that we have sourced the environment for an existing ROS 2 installation that will provide our workspace with the necessary build dependencies for the example packages. This is achieved by sourcing the setup script provided by a binary installation or a source installation, ie. another colcon workspace (see Installation). We call this environment an underlay.

重要的是,为现有的ROS 2安装提供环境,这将为编译工作区示例包提供必要的依赖性。通过获取二进制安装或源安装提供的安装脚本来实现的,即:另一个colcon工作区(请参考安装)。通常将此环境称为底层

Our workspace, ros2_examples_ws, will be an overlay on top of the existing ROS 2 installation. In general, it is recommended to use an overlay when you plan to iterate on a small number of packages, rather than putting all of your packages into the same workspace.

工作空间ros2_examples_ws将叠加在现有的ROS 2安装之上。通常,建议在计划迭代少量软件包时使用覆盖,而不是将所有软件包放在同一个工作区中。

Build the workspace 编译工作区

Attention 注意

To build packages on Windows you need to be in a Visual Studio environment, see Building the ROS 2 Code for more details.

要在Windows上编译软件包,需要在Visual Studio环境中,请参考编译ROS 2代码以获取更多详细信息。

In the root of the workspace, run colcon build. Since build types such as ament_cmake do not support the concept of the devel space and require the package to be installed, colcon supports the option --symlink-install. This allows the installed files to be changed by changing the files in the source space (e.g. Python files or other not compiled resourced) for faster iteration.

在工作区的根目录中,运行colcon build。由于编译类型ament_cmake(例如不支持devel的概念并且需要安装包),因此colcon支持选项--symlink-install。这允许通过更改source空间中的文件(例如Python文件或其他未编译的资源)来更改已安装的文件,以便更快地进行迭代。

colcon build --symlink-install

After the build is finished, we should see the build, install, and log directories:

编译完成后,可以看到build,install和log文件夹目录:

.

├── build

├── install

├── log

└── src

4 directories, 0 files

Run tests 运行测试

To run tests for the packages we just built, run the following:

为刚刚编译的包运行测试,请运行以下命令:

colcon test

Source the environment 导入环境

When colcon has completed building successfully, the output will be in the install directory. Before you can use any of the installed executables or libraries, you will need to add them to your path and library paths. colcon will have generated bash/bat files in the install directory to help setup the environment. These files will add all of the required elements to your path and library paths as well as provide any bash or shell commands exported by packages.

当colcon成功完成编译后,输出将在install目录中。在使用任何已安装的可执行文件或库之前,需要将它们添加到路径和库路径中。colcon将在install目录中生成bash / bat文件以帮助设置环境。这些文件将向路径和库路径添加所有必需元素,并提供由包导出的任何bash或shell命令。

Linux/OS X

. install/setup.bash

Or 或者

source install/setup.bash

Windows

call install\setup.bat

Try a demo 试试示例

With the environment sourced we can run executables built by colcon. Let’s run a subscriber node from the examples:

在环境导入后,可以运行colcon编译的可执行文件。从示例中运行订阅器节点如下:

ros2 run examples_rclcpp_minimal_subscriber subscriber_member_function

In another terminal, let’s run a publisher node (don’t forget to source the setup script):

在另一个终端中,运行一个发布器节点(不要忘记导入安装脚本):

ros2 run examples_rclcpp_minimal_publisher publisher_member_function

You should see messages from the publisher and subscriber with numbers incrementing.

应该看到来自发布器和订阅器的消息,并且数字会递增。

Create your own package 创建自定义的包

colcon uses the package.xml specification defined in REP 149 (format 2 is also supported).

colcon使用REP 149中的规范定义package.xml(也支持格式2)。

colcon supports multiple build types. The recommended build types are ament_cmake and ament_python. Also supported are pure cmake packages.

colcon支持多种编译类型。推荐的编译类型是ament_cmake和ament_python。也支持纯cmake包。

An example of an ament_python build is the ament_index_python package , where the setup.py is the primary entry point for building.

ament_python编译的一个示例是ament_index_python包,其中setup.py是编译的主要入口点。

A package such as demo_nodes_cpp uses the ament_cmake build type, and uses CMake as the build tool.

诸如demo_nodes_cpp包使用ament_cmake编译类型,并使用CMake作为编译工具。

For convenience, you can use the tool ros2 pkg create to create a new package based on a template.

为方便起见,可以使用该工具ros2 pkg create基于模板创建新包。

Note 注意

For catkin users, this is the equivalent of catkin_create_package.

对于catkin用户来说,这相当于catkin_create_package。

注意区别,ROS1和ROS2,创建自定义包的区别。

Tips 注意事项

If you do not want to build a specific package place an empty file named COLCON_IGNORE in the directory and it will not be indexed.

如果不想构建特定的包,请在目录中指定一个COLCON_IGNORE空文件,将不会编入索引。

If you want to avoid configuring and building tests in CMake packages you can pass: --cmake-args -DBUILD_TESTING=0.

如果想避免在CMake软件包中配置和构建测试,可以通过:--cmake-args -DBUILD_TESTING=0。

If you want to run a single particular test from a package:

如果要从包中运行单个特定测试:

colcon test --packages-select YOUR_PKG_NAME --ctest-args -R YOUR_TEST_IN_PKG

Using Ament 使用Ament

Warning 警告

As of ROS 2 Bouncy the recommended build tool is ``colcon`` described in the colcon tutorial. The current default branch as well as releases after Bouncy do not include ament_tools anymore.

从ROS 2 Bouncy开始,推荐的编译工具是 colcon教程中提及的``colcon``。当前的默认发行版以及Bouncy之后的版本不再将ament_tools包括在内。

由于介绍的教程针对Crystal和Dashing发行版本的ROS 2,所以设计ament的章节就省略了,如果需要了解更多细节,请查阅官方文档。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年09月12日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
使用机器人操作系统ROS 2和仿真软件Gazebo 9搭建机器人教程(一)
参考链接:https://github.com/bunchofcoders/basic_bocbot
zhangrelay
2020/02/19
3.9K0
使用机器人操作系统ROS 2和仿真软件Gazebo 9搭建机器人教程(一)
ROS2 框架下运行 Python
ROS2是怎么搭建这个房子的呢?它是要先创建一个统一的固定名字的文件夹“src”,然后在这个文件夹下面再去具体定义各个房间。
为为为什么
2024/07/12
7190
ROS2编程基础课程--中间件
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
zhangrelay
2019/09/19
1.2K0
小米机器狗铁蛋资料整理 cyberdog ros2
基本信息 铁蛋默认用户是mi, 密码为123 使用USB线连接Download接口, 可通过ssh mi@192.168.55.1连接铁蛋进行内部操作 软件架构 我们基于ROS 2实现了大部分的机器人应用, 如架构图所示, 包括多设备链接、多模态感知、多模态人机交互、自主决策、空间定位、导航和目标追踪等功能. 目前使用的DDS中间件是Cyclone DDS, ROS 2的版本为Galactic.
zhangrelay
2022/05/01
3.7K0
小米机器狗铁蛋资料整理 cyberdog ros2
webots和ros2笔记02-启程
看完01-资料篇https://zhangrelay.blog.csdn.net/article/details/112670542。
zhangrelay
2021/03/03
8750
ROS2编程基础课程--安装
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
zhangrelay
2019/09/18
1.2K0
ROS2机器人应用简明教程4工区
工区/工作区/工作空间(workspace简写为ws)是机器人操作系统核心概念之一。
zhangrelay
2020/07/03
9350
ROS2机器人应用简明教程4工区
ROS2之OpenCV的windows和linux差异在哪里
使用 rosdep install 看到 wnen 的错误只是 rosdep 告诉它不知道给定操作系统的“opencv2”是什么,因此它无法安装满足 cv_basics pacakge 的 package.xml 中列出的要求的东西.至于解决方案,建议参考问题#232795,该问题很好地解释了 rosdep 的工作原理以及您接下来可以做什么。
zhangrelay
2022/06/15
7590
ROS2极简总结-文件系统
$ sudo apt install ros-<distro>-package-name
zhangrelay
2021/12/02
3.3K0
ROS2极简总结-文件系统
【C++】ROS:ROS2环境配置与基础示例
ROS 2 (Robot Operating System 2)是一个开源的机器人操作系统,它是ROS(Robot Operating System)的下一代版本。它提供了一系列工具、库和约定,用于构建机器人应用程序。与ROS 1相比,ROS 2具有更强大的功能,更好的性能和更好的可靠性。
DevFrank
2024/07/24
2.2K0
【C++】ROS:ROS2环境配置与基础示例
Webots和ROS2使用说明(部分翻译)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
zhangrelay
2019/09/18
1.7K0
Webots和ROS2使用说明(部分翻译)
ROS2机器人编程简述humble-第二章-DEVELOPING THE FIRST NODE .2
0.1ROS2机器人编程简述新书推荐-A Concise Introduction to Robot Programming with ROS2
zhangrelay
2023/02/03
6290
ROS学习——第1讲 ROS概述及环境搭建
好事文章地址:https://cloud.tencent.com/developer/article/2469534
Arya
2024/11/22
6920
ROS学习——第1讲 ROS概述及环境搭建
ROS2编程基础课程--Actions
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
zhangrelay
2019/09/19
1.4K0
Tello和ROS的一些资料
之前,一些博文给出了Cozmo和Vector等地面小型机器人的资料,这篇博文,针对空中机器人---Tello。
zhangrelay
2019/01/31
2.6K0
Tello和ROS的一些资料
详细分析一个ROS2 CMakeLists.txt文件
ROS2的构建系统ament_cmake是基于CMake改进而来的。本篇文章我们详细介绍一下ament_cmake常用的语句。
首飞
2022/07/17
2.9K0
详细分析一个ROS2 CMakeLists.txt文件
Webots2021b和ROS2调试笔记21-07-27
先上结论: 凉 凉凉 透心凉 webots2021b刚发布时间不长,其ROS2接口包也不全。 2021b(win10)安装包小,很多库需要启动时联网下载。 很多节点不支持windows哦!如下: [WARNING] [webots_robotic_arm_node.EXE-2]: 'SIGINT' sent to process[webots_robotic_arm_node.EXE-2] not supported on Windows, escalating to 'SIGTERM' 还调试个毛线
zhangrelay
2021/12/02
7750
Webots2021b和ROS2调试笔记21-07-27
ROS1/2机器人操作系统发行版本(Distributions)和编译系统(Build Systems)
所有书都不可能是一本完备的 ROS 参考手册。几乎可以肯定,要真正动手使用 ROS 将要了解更多的细节。幸运的是,网上有关 ROS1 和 ROS2 的信息十分丰富。
zhangrelay
2022/05/01
1.3K0
ROS1/2机器人操作系统发行版本(Distributions)和编译系统(Build Systems)
ROS2与Rviz2的贪吃蛇代码学习
目前,这仅rclcpp针对 ROS2 Galactic/Humble 进行了测试,尽管它很可能在任何稍旧的设备上都可以正常工作。此外,您需要安装 rviz2 和 ncurses(用于用户输入),通过sudo apt-get install libncurses-dev.
zhangrelay
2022/06/05
5670
ROS2与Rviz2的贪吃蛇代码学习
ROS 2 Humble Hawksbill 之 f1tenth gym
# F1TENTH gym environment ROS2 communication bridge This is a containerized ROS communication bridge for the F1TENTH gym environment that turns it into a simulation in ROS2.
zhangrelay
2022/06/30
1.5K0
ROS 2 Humble Hawksbill 之 f1tenth gym
推荐阅读
相关推荐
使用机器人操作系统ROS 2和仿真软件Gazebo 9搭建机器人教程(一)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档