首页 > 其他分享 >ROS2进阶:colcon的初步使用--‘colcon‘ is not recognized

ROS2进阶:colcon的初步使用--‘colcon‘ is not recognized

时间:2022-11-05 23:00:30浏览次数:72  
标签:cmake 进阶 package -- build colcon packages


系统安装路径:C:\opt\ros\galactic

系统安装参考:​​ROS2在windows上的安装​​。

如果你是按ROS官网的办法安装的,路径可能会有所不同,比如按

​Installing ROS 2 on Windows — ROS 2 Documentation: Galactic documentation​

此时的路径会是,

C:\dev\ros2_galactic

不管你按哪个办法安装,使用起来都差不多。

首先检查一下你是否安装了必要的工具,例如,你可能会碰到这样的报错,

ERROR: 'colcon' is not recognized as an internal or external command,

colcon是依赖python的,那说明你没有安装colcon脚本,或者,你没有在系统路径中添加这个:C:\Python38\Scripts。下面的把一些常用的脚本例在下面,

pip install -U colcon-common-extensions
pip install -U vcstool

貌似各个版本的ROS2文档都有些区别,比如eloquent就单独列出了这些命令,但foxy和galactic就没有,

​Building ROS 2 on Windows — ROS 2 Documentation: Eloquent documentation​

安装好了之后,你就可以正常使用colcon了,检查一下,

C:>colcon
usage: C:\Python38\Scripts\colcon [-h] [--log-base LOG_BASE] [--log-level LOG_LEVEL]
{build,extension-points,extensions,graph,info,list,metadata,test,test-result,version-check} ...

Error: No verb provided

另外,如果你碰到找不到vc之类的问题,通常是因为没有启动VS2019或VS2017的环境,

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64

 为了避免这个麻烦,我通常都是直接在VS2019命令窗口"x64 Native Tools Command Prompt for VS 2019" 中进行操作。

什么是colcon?

在ROS2中的构建工具是colcon,这非常类似我们在ROS中使用的catkin_make。

下面我们打开一个命令窗口,

call C:\opt\ros\galactic\x64\setup.bat

然后,新建一个路径

~> mkdir  examples_ws\src
~> cd examples_ws\src
~examples_ws\src> git clone -b galactic-devel https://github.com/ros2/examples.git
~examples_ws\src> cd ..
~examples_ws> colcon build

另外,我们也可以试一下那个demos

~> mkdir  demos_ws\src
~> cd demos_ws\src
~demos_ws\src> git clone -b galactic-devel https://github.com/ros2/demos.git
~demos_ws\src> cd ..
~demos_ws> colcon build

比如我第一次构建的结果是这样的,

D:\ros2prj\demo_ws>colcon build
[0.755s] root DEBUG Using proactor: IocpProactor
Starting >>> action_tutorials_interfaces
Starting >>> dummy_map_server
Starting >>> dummy_sensors
Starting >>> pendulum_msgs
Starting >>> composition
Starting >>> demo_nodes_cpp
Starting >>> demo_nodes_cpp_native
Starting >>> demo_nodes_py
Starting >>> image_tools
Starting >>> intra_process_demo
Starting >>> lifecycle
Starting >>> logging_demo
Finished <<< demo_nodes_py [1.61s]
Starting >>> quality_of_service_demo_cpp
Finished <<< dummy_map_server [4.20s]
Starting >>> quality_of_service_demo_py
Finished <<< dummy_sensors [4.80s]
Starting >>> topic_monitor
Finished <<< lifecycle [5.20s]
Starting >>> topic_statistics_demo
Finished <<< quality_of_service_demo_py [1.34s]
Starting >>> dummy_robot_bringup
Finished <<< topic_monitor [1.34s]
Finished <<< pendulum_msgs [7.11s]
Starting >>> pendulum_control
Finished <<< action_tutorials_interfaces [7.36s]
Starting >>> action_tutorials_cpp
Starting >>> action_tutorials_py
Finished <<< dummy_robot_bringup [1.99s]
Finished <<< action_tutorials_py [2.16s]
Failed <<< demo_nodes_cpp_native [10.1s, exited with code 1]
Aborted <<< image_tools [11.6s]
Aborted <<< demo_nodes_cpp [12.0s]
Aborted <<< composition [12.7s]
Aborted <<< intra_process_demo [13.9s]
Aborted <<< quality_of_service_demo_cpp [13.3s]
Aborted <<< topic_statistics_demo [10.8s]
Aborted <<< logging_demo [16.0s]
Aborted <<< pendulum_control [9.20s]
Aborted <<< action_tutorials_cpp [11.2s]

Summary: 10 packages finished [18.9s]
1 package failed: demo_nodes_cpp_native
9 packages aborted: action_tutorials_cpp composition demo_nodes_cpp image_tools intra_process_demo logging_demo pendulum_control quality_of_service_demo_cpp topic_statistics_demo

官方介绍

官方资料可以去这里,

​colcon - collective construction — colcon documentation​

或者

​GitHub - colcon/colcon.readthedocs.org​

一些常用的colcon参数

参考:

​build - Build Packages — colcon documentation​

colcon提供了很多的参数选项,大家可以去官网查看,这里我不再逐一翻译 ,只是简单枚举一下官网的内容,

目前遇到常用参数:

1.--symlink-install     :使用符号链接而不是复制文件,如

 以动态链接库为例,会在install目录中使用符号链接,指向build目录下生成的库文件(如 *.so). 没有该选项,则两个目录都会有该库文件

2.--packages-select :只编译指定包,如

colcon build --packages-select  autoware_map_msgs  vector_map_msgs
3.--packages-ignore  : 忽略指定包,同上

4. --continue-on-error :在编译出错之后继续编译其他模块

5. --cmake-args ,--ament-cmake-args, --catkin-cmake-args :传递参数给对应的package

针对cmake参数,常用的有

 -DCMAKE_BUILD_TYPE=Release
 
 -DCMAKE_CXX_FLAGS="-O2 -g -Wall " 
  “-D” --宏定义, 每定义一个就在前边加上"-D",给gcc传递参数

   -g  debug选项, gdb模式,符号表会保存

  -s    link选项,删除符号表,这一步会极大减少文件体积

下面为colcon官网上的原英文解释。

build - Build Packages

The ​​build​​​ verb is building a set of packages. It is provided by the ​​colcon-core​​ package.

Command line arguments

These common arguments can be used:

Additionally, the following specific command line arguments can be used:

--build-base BUILD_BASE

The base path for all build directories. The default value is ​​./build​​. Each package uses a subdirectory in that base path as its package specific build directory.

--install-base INSTALL_BASE

The base path for all install prefixes. The default value is ​​./install​​.

--merge-install

Use the ​​--install-base​​ as the install prefix for all packages instead of a package specific subdirectory in the install base.

Without this option each package will contribute its own paths to environment variables which leads to very long environment variable values.

With this option most of the paths added to environment variables will be the same, resulting in shorter environment variable values.

The disadvantage of using this option is that it doesn’t provide proper isolation between packages. For example declaring a dependency on one package also allows access to resources from other packages installed in the same install prefix (without requiring a declared dependency).

Note: on Windows using ​​cmd​​ this argument should be used for workspaces with many packages otherwise the environment variables might exceed the supported maximum length.

--symlink-install

Use symlinks instead of copying files from the source and build directories where possible.

--test-result-base TEST_RESULT_BASE

The base path for all test results. The default value is the ​​--build-base​​ argument. Each package uses a subdirectory in that base path as its package specific test result directory.

--continue-on-error

Continue building other packages when a package fails to build. Packages recursively depending on the failed package are skipped.

CMake specific arguments

The following arguments are provided by the ​​colcon-cmake​​ package:

--cmake-args [* [* …]]

Pass arbitrary arguments to CMake projects. Arguments matching other options must be prefixed by a space, e.g. ​​--cmake-args " --help"​​.

--cmake-target CMAKE_TARGET

Build a specific target instead of the default target. To avoid packages which don’t have that target causing the build to fail, also pass ​​–cmake-target-skip-unavailable​​.

--cmake-target-skip-unavailable

Skip building packages which don’t have the target passed to ​​–cmake-target​​.

--cmake-clean-cache

Remove the CMake cache file ​​CMakeCache.txt​​ from the build directory before proceeding with the build. This implicitly forces a CMake configure step.

--cmake-clean-first

Build the target ​​clean​​​ first, then proceed with a regular build. To only invoke the clean target use ​​–cmake-target clean​​.

--cmake-force-configure

Force CMake configure step.

ROS ​​ament_cmake​​ specific arguments

The following arguments are provided by the ​​colcon-ros​​ package:

--ament-cmake-args [* [* …]]

Pass arbitrary arguments to ROS packages with the build type ​​ament_cmake​​​. Arguments matching other options must be prefixed by a space, e.g. ​​--ament-cmake-args " --help"​​.

ROS ​​catkin​​ specific arguments

The following arguments are provided by the ​​colcon-ros​​ package:

--catkin-cmake-args [* [* …]]

Pass arbitrary arguments to ROS packages with the build type ​​catkin​​​. Arguments matching other options must be prefixed by a space, e.g. ​​--catkin-cmake-args " --help"​​.

--catkin-skip-building-tests

By default the ​​tests​​​ target building the tests in ​​catkin​​​ packages is invoked. If running ​​colcon test​​ later isn’t intended this can be skipped.

未完待续
 

标签:cmake,进阶,package,--,build,colcon,packages
From: https://blog.51cto.com/SpaceVision/5826361

相关文章

  • Nginx配置安全选项
    默认网站配置(未更改前)server{listen80;server_namelocalhost;location/{roothtml;indexindex.htmlindex.htm;......
  • 关机程序
    附上代码:#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){ charinput[20]={0}; system("shutdown-s-t60"); again: printf("请注意,你的......
  • 【重识云原生】第三章云存储3.3节——Ceph统一存储方案
     《重识云原生系列》专题索引:第一章——不谋全局不足以谋一域第二章计算第1节——计算虚拟化技术总述第二章计算第2节——主流虚拟化技术之VMareESXi第二章计算第3节......
  • 开始使用AspectJ-@AfterThrowing ,@After ,@Pointcut 定义切入点(比较重要)
    开始使用AspectJ(接下来的作为了解就行)1.[了解]@AfterThrowing异常通知-注解中有throwing属性在目标方法抛出异常后执行。该注解的throwing属性用于指定所发生的异......
  • python之进程
    一、进程进程是计算机资源分配和调度的基本单位,线程是计算机能够进行运算调度的最小单位。二、python中的进程模块multiprocessing#文件名为test_Process_11im......
  • git的基本操作
    git的基本操作可以去看git的菜鸟教程:https://www.runoob.com/git/git-basic-operations.html初始化仓库建好后需要先进入要上传的文件夹进入命令行模式进入后先gi......
  • SAP Java Connector 的配置指南
    SAPJava连接器(JCo)3.1需要Java运行时环境(JRE)版本8或11。有关受支持平台和Java运行时环境的最新详细列表,请参阅SAP说明2786882。最新版本的SAPJava......
  • MySQL read_ only Read Only Attribute Description
    一、MySQLread_onlyReadOnlyAttributeDescription在MySQL数据库中,在进行数据迁移和从库只读状态设置时,都会涉及到只读状态和Master-Slave主从关系设置,以下针对rea......
  • SAP Java Connector 组件介绍
    SAPJavaConnector3.1运行时环境由两部分组成:sapjco3.jar-包含JCo的Java运行时类的存档{libraryprefix}sapjco3{sharedlibraryextension}-包含JCo原生......
  • C#动态编译2
    思路:通过C#的编译对象CSharpCodeProvider对一段C#代码进行编译C#代码包含命名空间、类、方法。以及需要引用的命名空间可以在编译前增加DLL引用,这样动态的C#代码就可以......