ROS2 Brief IntroductionFeaturesAPILanguageCPPNodeLaunchCommunicationDifferences in specific useROS2 foxy installationInstall ROS 2 packageEnvironment configurationConfiguration EnvironmentInstall GazeboCompileSoftware package configuration

ROS2 Brief Introduction

ROS2 is a huge update of ROS1.

ROS1 was born in 2007. With the support of an active open source community, its functions are constantly enriched and the number of codes continues to grow. However, its overall design is not very scientific, lacks security, real-time, and robustness, and is not very suitable for industry. and specific industry applications.

The ROS leadership team is aware of this problem, but ROS1 has been hard to come back from. Some important underlying modifications will make ROS1 more unstable, and will inevitably encounter a large number of ROS1 package code compatibility issues. Rather than patching things up, it’s better to recreate a more scientific and stable ROS2.

Currently, Noetic of ROS1 will stop supporting it in 2025. For the large existing code base of ROS1, it is feasible for existing projects to remain in ROS1, but migrating to ROS2 in the future is undoubtedly inevitable, so it is necessary to learn to migrate and use ROS2 now.

Like ROS1, ROS2 is released once a year. Since humility and Ubuntu 22.04 are not stable enough after testing, Galactic will stop supporting it, so the foxy version + ubuntu20.04 is selected. At present, the core functions of ROS2 have been improved, and some third-party packages are still being adapted.

image-20220811121548836

Features

The update of ROS2 is comprehensive, so here I will only briefly describe the situation that the author currently understands.

API

The bottom layer of ROS2 is written in C language, and its name is rcl library. The rclcpp and rclpy called when writing the upper-layer program are packaged on the rcl library. The advantage of this is that the calling API of cpp and python programs is more convenient. They are unified and similar. When updating the functions of ros2 at the same time, directly update the rcl library and add support for cpp and python.

Language

CPP

The cpp 11, cpp1A4, and cpp17 standards are used by default, which are more modern than the cpp98 standard used by ROS1 by default. Support more security and efficiency features.

###python

Completely abandon python2 and fully embrace python3.

Node

For a more standardized Node writing standard, you must create a class that inherits from the Node object (for example: rclcpp::Node in cpp, rclpy.node.Node in Python). Convenient for team development.

Launch

Different from ROS1's extensive xml format launch file, ROS2 recommends using python files to write launch files, providing more flexibility in startup.

Communication

ROS2 no longer has the master node in ROS1. The child nodes in ROS1 need to register and communicate with the master node before they can communicate with each other. It is a centralized architecture. ROS2 uses a distributed node method, and nodes can discover each other without any master node. This avoids the collapse of the entire system due to the crash of the master node, and at the same time makes ROS2 more flexible in multi-machine distributed deployment.

At the same time, service requests in ROS1 are blocked by Block, and the client will be in stop the world (stuck) state before getting a response.

The service design of ROS2 is Asyn asynchronous, and the client will not be stuck in receiving the server response. But you can also use blocking mode if you want.

Differences in specific use

Only common parts are listed

ROS1ROS2introduction
catkin_makecolcon buildcompile
roslaunch ros2 launch launch
rostopic listros2 topic list 
rostopic echo ros2 topic echo  
rosrun ros2 run  
rosrun rqt_graph rqt_graphrqt_graph 
rosrun rqt_tf_tree rqt_tf_treeros2 run tf2_tools view_frames.pyros2 will save a pdf file in the terminal path and cannot be viewed directly
rvizrviz2 

ROS2 foxy installation

Note: To download the humble version, you need to change foxy to humble

The installation process can be found on the official website: https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html

Install ROS 2 package

Update software libraries

ROS 2 packages are built on frequently updated Ubuntu systems. Before installing new packages, it is always recommended to ensure that your system is up to date.

It is recommended to install the full version of ROS including ROS base rviz tutorial and other software.

Packages that may be needed for subsequent development:

Environment configuration

Configuration Environment

Execute the following command to configure the terminal environment. This command must be executed every time you open the terminal.

Or use once and for all, configure automatically every time you open the terminal

Install Gazebo

gazebo is a powerful simulation platform provided by ROS

Just install Gazebo 11 and related ROS support packages:

For navigation, the following packages can be installed

Compile

Enter the source package

colcon provides many parameter options Commonly used parameters:

  1. --symlink-install: Use symbolic links instead of copying files, such as Taking the dynamic link library as an example, a symbolic link will be used in the install directory to point to the library file (such as *.so) generated in the build directory. Without this option, both directories will have the library file.

  2. --packages-select: Only compile specified packages, such as colcon build --packages-select autoware_map_msgs vector_map_msgs

  3. --packages-ignore: Ignore the specified package, same as above

  4. --continue-on-error: Continue to compile other modules after a compilation error

  5. --cmake-args, --ament-cmake-args, --catkin-cmake-args: pass parameters to the corresponding package

     

Different from ROS1, after modifying any files in ROS2, please recompile colcon build

Software package configuration

Visible in the created software package

image-20220811150149772

Modify the package name in project() of CMakeLists.txt and the name of package.xml to modify the name of the software package.

At the same time, in order to use the files in the folder in the software package, you need to install it in cmakelist.

image-20220811150829750

image-20220811150802102