Hi, I’m Xiaozhi. Yesterday the weather, today the storm.

Try to tell you something new every day in order to keep the content fresh.

Today’s article is excerpted from the first draft of hands-on learning ROS2. Let’s focus on the build tools used by ros2.

If you use ROS and catkin_make every time, please accept the look of contempt from Satochi.

Here recommend you a new tool ha! ROS will do it. The installation method is as follows.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list'wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get updatesudo apt-get install python-catkin-toolscatkin 
Copy the code

1. What is Colcon?

Colcon is actually a package builder. What does this tool do?

The last few videos showed you how to create a ROS2 workspace, but not how to compile it. It’s just colcon.

ROS2 does not have colcon installed by default, so Xiaozhi started from how to install Colcon to explain how to use colcon.

Colcon is equivalent to the CATkin tool in ROs1. Students who have learned ROs1 can help understand it. Never learned it doesn’t matter, use more nature will understand.

2. Install colcon

Install a word, very simple, quickly open the terminal copy paste into it

sudo apt-get install python3-colcon-common-extensions
Copy the code

3. Make something to test

1. Create a workspace folder colcon_test

mkdir colcon_tet && cd colcon_test
Copy the code

1. Download a ROS2 sample source code to test

git clone https://github.com/ros2/examples src/examples -b foxy
Copy the code

1. Compilation project

 colcon build
Copy the code

1. Directory structure

From one SRC to four, one in gives you three

4. Run a node created by yourself

1. Open a terminal to source resources

source install/setup.bash
Copy the code

2. Run a magazine subscription node

ros2 run examples_rclcpp_minimal_subscriber subscriber_member_function
Copy the code

3. Open a new terminal, start source, and then run a magazine node

source install/setup.bashros2 run examples_rclcpp_minimal_publisher publisher_member_function
Copy the code

5. Common commands

Only one package is compiled

colcon test --packages-select YOUR_PKG_NAME
Copy the code

The test unit is not compiled

colcon test --packages-select YOUR_PKG_NAME  --cmake-args -DBUILD_TESTING=0
Copy the code

Run tests for the compiled package

colcon test
Copy the code

Allows you to change Install by changing parts of files under SRC (important)

colcon build --symlink-install
Copy the code

This is especially important because ros2 builds do not have the concept of ros devel. If you want to achieve the same effect as a devel directory, you need to add this parameter. If you haven’t learned ROS, please ignore the above.

References:

• colcon official documentation colcon. Readthedocs. IO/en/released… Docs.ros.org/en/foxy/Tut…

If you have any questions, you can tell Xiaozhi immediately. If you meet more people, Xiaozhi will write an article to talk about it separately.

Write in the last

I am Xiaozhi, a senior player in the field of robotics, and an algorithm engineer of a one-legged robot in Shenzhen

At present, we are exporting robot learning guide, paper notes, work experience, welcome everyone to pay attention to Xiaozhi, exchange technology together, learn robot