19.ROS2 common command tools

 

1. Package management tool ros2 pkg

1.1.ros2 pkg create

Function: Create a function package. When creating, you need to specify the package name, compilation method, dependencies, etc.

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 function package uses C++ or C, then write ament_cmake here. If it uses Python, write ament_python.

pkg_name: the name of the created function package

rclpy std_msgs sensor_msgs: These are some compilation dependencies

1.2.ros2 pkg list

Function: View the list of function packages in the 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.Node runs ros2 run

Command function: Run function package node program

Command format: ros2 run pkg_name node_name

image-20230427155359745

3.1.ros2 node list

Command function: List 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, etc.

Command format: ros2 node info node_name

image-20230427160001101

4.1.ros2 topic list

Command function: List all topics in the current domain

Command format: ros2 topic list

image-20230427160351051

4.2. ros2 topic info

Command function: Display 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 topic

Command format: ros2 topic type topic_name

image-20230427161056536

4.4.ros2 topic hz

Command function: Display 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 specified topic messages in the terminal

Command format:ros2 topic pub topic_name message_type message_content

The default is to publish at a frequency of 1Hz. The following parameters can be set,

What needs to be noted here is that there is a space after the colon.

 

5.1. ros2 interface list

Command function: List 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: display the details of the specified interface

Command format: ros2 interface show interface_name

image-20230427165057647

6.1. ros2 service list

Command function: List all services in the current domain

Command format:ros2 interface show interface_name

image-20230427172236875

6.2. ros2 service call

Command function: Call specified service

Command format: ros2 interface call service_name service_Type arguments

For example, calling the spawn turtle service

image-20230427173625631