系统安装路径: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.

未完待续
 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐