@@ -39,21 +39,21 @@ Install colcon
39
39
40
40
.. group-tab :: Linux
41
41
42
- .. code-block :: bash
42
+ .. code-block :: console
43
43
44
- sudo apt install python3-colcon-common-extensions
44
+ $ sudo apt install python3-colcon-common-extensions
45
45
46
46
.. group-tab :: macOS
47
47
48
- .. code-block :: bash
48
+ .. code-block :: console
49
49
50
- python3 -m pip install colcon-common-extensions
50
+ $ python3 -m pip install colcon-common-extensions
51
51
52
52
.. group-tab :: Windows
53
53
54
- .. code-block :: bash
54
+ .. code-block :: console
55
55
56
- pip install -U colcon-common-extensions
56
+ $ pip install -U colcon-common-extensions
57
57
58
58
59
59
Install ROS 2
@@ -73,7 +73,7 @@ Commonly there is a ``src`` subdirectory.
73
73
Inside that subdirectory is where the source code of ROS packages will be located.
74
74
Typically the directory starts otherwise empty.
75
75
76
- colcon does out of source builds.
76
+ colcon performs out-of- source builds.
77
77
By default it will create the following directories as peers of the ``src `` directory:
78
78
79
79
* The ``build `` directory will be where intermediate files are stored.
@@ -93,24 +93,24 @@ First, create a directory (``ros2_ws``) to contain our workspace:
93
93
94
94
.. group-tab :: Linux
95
95
96
- .. code-block :: bash
96
+ .. code-block :: console
97
97
98
- mkdir -p ~ /ros2_ws/src
99
- cd ~ /ros2_ws
98
+ $ mkdir -p ~/ros2_ws/src
99
+ $ cd ~/ros2_ws
100
100
101
101
.. group-tab :: macOS
102
102
103
- .. code-block :: bash
103
+ .. code-block :: console
104
104
105
- mkdir -p ~ /ros2_ws/src
106
- cd ~ /ros2_ws
105
+ $ mkdir -p ~/ros2_ws/src
106
+ $ cd ~/ros2_ws
107
107
108
108
.. group-tab :: Windows
109
109
110
- .. code-block :: bash
110
+ .. code-block :: console
111
111
112
- md \d ev\r os2_ws\s rc
113
- cd \d ev\r os2_ws
112
+ $ md \dev\ros2_ws\src
113
+ $ cd \dev\ros2_ws
114
114
115
115
At this point the workspace contains a single empty directory ``src ``:
116
116
@@ -126,9 +126,9 @@ Add some sources
126
126
127
127
Let's clone the `examples <https://github.com/ros2/examples >`__ repository into the ``src `` directory of the workspace:
128
128
129
- .. code-block :: bash
129
+ .. code-block :: console
130
130
131
- git clone https://github.com/ros2/examples src/examples -b {REPOS_FILE_BRANCH}
131
+ $ git clone https://github.com/ros2/examples src/examples -b {REPOS_FILE_BRANCH}
132
132
133
133
Now the workspace should have the source code to the ROS 2 examples:
134
134
@@ -172,19 +172,19 @@ This allows the installed files to be changed by changing the files in the ``sou
172
172
173
173
.. code-block :: console
174
174
175
- colcon build --symlink-install
175
+ $ colcon build --symlink-install
176
176
177
177
.. group-tab :: macOS
178
178
179
179
.. code-block :: console
180
180
181
- colcon build --symlink-install
181
+ $ colcon build --symlink-install
182
182
183
183
.. group-tab :: Windows
184
184
185
185
.. code-block :: console
186
186
187
- colcon build --symlink-install --merge-install
187
+ $ colcon build --symlink-install --merge-install
188
188
189
189
Windows doesn't allow long paths, so ``merge-install `` will combine all the paths into the ``install `` directory.
190
190
@@ -213,21 +213,21 @@ To run tests for the packages we just built, run the following:
213
213
214
214
.. code-block :: console
215
215
216
- colcon test
216
+ $ colcon test
217
217
218
218
.. group-tab :: macOS
219
219
220
220
.. code-block :: console
221
221
222
- colcon test
222
+ $ colcon test
223
223
224
224
.. group-tab :: Windows
225
225
226
226
Remember to use a ``x64 Native Tools Command Prompt for VS 2019 `` for executing the following command, as we are going to build a workspace.
227
227
228
228
.. code-block :: console
229
229
230
- colcon test --merge-install
230
+ $ colcon test --merge-install
231
231
232
232
You also need to specify ``--merge-install `` here since we used it for building above.
233
233
@@ -245,43 +245,43 @@ These files will add all of the required elements to your path and library paths
245
245
246
246
.. group-tab :: Linux
247
247
248
- .. code-block :: bash
248
+ .. code-block :: console
249
249
250
- source install/setup.bash
250
+ $ source install/setup.bash
251
251
252
252
.. group-tab :: macOS
253
253
254
- .. code-block :: bash
254
+ .. code-block :: console
255
255
256
- . install/setup.bash
256
+ $ . install/setup.bash
257
257
258
258
.. group-tab :: Windows
259
259
260
- .. code-block :: bash
260
+ .. code-block :: console
261
261
262
- call install\s etup.bat
262
+ $ call install\setup.bat
263
263
264
264
Or with Powershell:
265
265
266
- .. code-block :: bash
266
+ .. code-block :: console
267
267
268
- install\s etup.ps1
268
+ $ install\setup.ps1
269
269
270
270
Try a demo
271
271
^^^^^^^^^^
272
272
273
273
With the environment sourced, we can run executables built by colcon.
274
274
Let's run a subscriber node from the examples:
275
275
276
- .. code-block :: bash
276
+ .. code-block :: console
277
277
278
- ros2 run examples_rclcpp_minimal_subscriber subscriber_member_function
278
+ $ ros2 run examples_rclcpp_minimal_subscriber subscriber_member_function
279
279
280
280
In another terminal, let's run a publisher node (don't forget to source the setup script):
281
281
282
- .. code-block :: bash
282
+ .. code-block :: console
283
283
284
- ros2 run examples_rclcpp_minimal_publisher publisher_member_function
284
+ $ ros2 run examples_rclcpp_minimal_publisher publisher_member_function
285
285
286
286
You should see messages from the publisher and subscriber with numbers incrementing.
287
287
@@ -307,22 +307,23 @@ Setup ``colcon_cd``
307
307
308
308
The command ``colcon_cd `` allows you to quickly change the current working directory of your shell to the directory of a package.
309
309
As an example ``colcon_cd some_ros_package `` would quickly bring you to the directory ``~/ros2_ws/src/some_ros_package ``.
310
+ To set up ``colcon_cd `` you need to run the following commands to modify your shell startup script:
310
311
311
312
.. tabs ::
312
313
313
314
.. group-tab :: Linux
314
315
315
316
.. code-block :: console
316
317
317
- echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
318
- echo "export _colcon_cd_root=/opt/ros/{DISTRO}/" >> ~/.bashrc
318
+ $ echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
319
+ $ echo "export _colcon_cd_root=/opt/ros/{DISTRO}/" >> ~/.bashrc
319
320
320
321
.. group-tab :: macOS
321
322
322
323
.. code-block :: console
323
324
324
- echo "source /usr/local/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
325
- echo "export _colcon_cd_root=~/ros2_install" >> ~/.bashrc
325
+ $ echo "source /usr/local/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
326
+ $ echo "export _colcon_cd_root=~/ros2_install" >> ~/.bashrc
326
327
327
328
.. group-tab :: Windows
328
329
346
347
347
348
* If you want to run a single particular test from a package:
348
349
349
- .. code-block :: bash
350
+ .. code-block :: console
350
351
351
- colcon test --packages-select YOUR_PKG_NAME --ctest-args -R YOUR_TEST_IN_PKG
352
+ $ colcon test --packages-select YOUR_PKG_NAME --ctest-args -R YOUR_TEST_IN_PKG
352
353
353
354
Setup ``colcon `` mixins
354
355
-----------------------
@@ -359,21 +360,21 @@ For example, to change the CMake build type to debug, you normally use:
359
360
360
361
.. code-block :: console
361
362
362
- colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
363
+ $ colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
363
364
364
365
To make common command line options easier to invoke this repository makes these "shortcuts" available.
365
366
366
367
To install the default colcon mixins, run the following:
367
368
368
369
.. code-block :: console
369
370
370
- colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
371
- colcon mixin update default
371
+ $ colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
372
+ $ colcon mixin update default
372
373
373
374
Then, try out using the ``debug `` mixin:
374
375
375
376
.. code-block :: console
376
377
377
- colcon build --mixin debug
378
+ $ colcon build --mixin debug
378
379
379
380
For more details, see the `colcon mixin repository <https://github.com/colcon/colcon-mixin-repository >`__.
0 commit comments