2、Common commands and tools for ROS2

1、Package management tool ros2 pkg

1.1、ros2 pkg create

Function: To create a function package, you need to specify the package name, compilation mode, dependencies, etc. when creating it.

Command format:ros2 pkg create --build-type ament_python pkg_name rclpy std_msgs sensor_msgs

ros2 pkg create:Instructions for creating packages

--build-type:If the newly created feature pack uses C++ or C, then write ament_cmake here, and if you use Python, write ament_python

pkg_name:Create a name for the feature pack

rclpy std_msgs sensor_msgs:These are some compilation dependencies

1.2、ros2 pkg list

Features: View the list of feature packs in your system

Command format:ros2 pkg list

image-20230427154146879

1.3、ros2 pkg executeables

Command function: View the list of executable files in the package

Command format: ros2 pkg executables pkg_name

image-20230427154419005

2、The node runs ROS2 run

Command function: Run the feature pack node program

Command format:ros2 run pkg_name node_name

image-20230427155359745

3.1、ros2 node list

Command function: Lists all node names in the current domain

Command format: ros2 node list

image-20230427155655753

3.2、ros2 node info

Command function: View node details, including subscriptions, published messages, enabled services, and actions

Command format: ros2 node info node_name

image-20230427160001101

4.1、ros2 topic list

Command function: Lists all topics in the current domain

Command format: ros2 topic list

image-20230427160351051

4.2、ros2 topic info

Command function: Displays the topic message type, number of subscribers/publishers

Command format: ros2 topic info topic_name

image-20230427160625594

4.3、ros2 topic type

Command function: View the message type of the thread

Command format: ros2 topic type topic_name

image-20230427161056536

4.4、ros2 topic hz

Command function: Displays the average publishing frequency of the topic

Command format: ros2 topic hz topic_name

image-20230427161721650

4.5、ros2 topic echo

Command function: Print topic messages in the terminal, similar to a subscriber

Command format: ros2 topic echo topic_name

image-20230427162312888

4.5、ros2 topic pub

Command function: Publish a specified topic message in the terminal

Command format: ros2 topic pub topic_name message_type message_content

The default is to cycle the release at a frequency of 1Hz, and the following parameters can be set:

It should be noted here that there is a space after the colon.

5.1、ros2 interface list

Command function: lists all interfaces of the current system, including topics, services, and actions.

Command format: ros2 interface list

image-20230427164755075

5.2、ros2 interface show

Command function: Displays the details of the specified interface

Command format: ros2 interface show interface_name

image-20230427165057647

6.1、ros2 service list

Command function: lists all services in the current domain

Command format: ros2 interface show interface_name

image-20230427172236875

6.2、ros2 service call

Command function: Invoke the specified service

Command format: ros2 interface call service_name service_Type arguments

For example: call the Build Turtle service

image-20230427173625631

7、rqt_image_view

rosrun rqt_image_view rqt_image_view

rqt_image_view can be used to view images, if there is published image topic data in the current domain, you can use this tool to view images.

image-20230427192305253

Image data is displayed by the image topic selected in the upper-left corner.

8、rqt_graph

rqt_graph can be used to view which nodes are running in the current domain and the topic communication between nodes, use the following command to open:

image-20230427192536559

9、rviz2

The core framework of Rviz is an open platform based on Qt visualization tools, and you can see the graphical effect according to the corresponding topic of news release in ROS. In ROS2, launch the rviz tool using rviz2.

image-20230427191933170

Through the above steps, you can add visual data through plugins or through topics, generally choosing to add through topics.

10、tf2_tools

tf2_tools You can view the current TF tree, and a frame.pdf file will be generated under the terminal where the command is entered.