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
Function: View the list of function packages in the system
Command format: ros2 pkg list
Command function: View the list of executable files in the package
Command format: ros2 pkg executables pkg_name
Command function: Run function package node program
Command format: ros2 run pkg_name node_name
Command function: List all node names in the current domain
Command format: ros2 node list
Command function: View node details, including subscriptions, published messages, enabled services and actions, etc.
Command format: ros2 node info node_name
Command function: List all topics in the current domain
Command format: ros2 topic list
Command function: Display topic message type, number of subscribers/publishers
Command format: ros2 topic info topic_name
Command function: View the message type of the topic
Command format: ros2 topic type topic_name
Command function: Display the average publishing frequency of the topic
Command format: ros2 topic hz topic_name
Command function: print topic messages in the terminal, similar to a subscriber
Command format: ros2 topic echo topic_name
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,
ros2 topic pub turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.2}}"
What needs to be noted here is that there is a space after the colon.
Command function: List all interfaces of the current system, including topics, services, and actions.
Command format: ros2 interface list
Command function: display the details of the specified interface
Command format: ros2 interface show interface_name
Command function: List all services in the current domain
Command format:ros2 interface show interface_name
Command function: Call specified service
Command format: ros2 interface call service_name service_Type arguments
For example, calling the spawn turtle service
xxxxxxxxxx
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
requester: making request: turtlesim.srv.Spawn_Request(x=2.0, y=2.0, theta=0.2, name='turtle2')