Welcome to RDK S600 Developer Kit repository
16.ROS2 common command tools
16. ROS2 Common Command Tools
Note: The accompanying reference video uses the ROS Humble version, for reference only
1. Package Management Tool - ros2 pkg
1.1. ros2 pkg create
Function: Create a package. When creating, you need to specify package name, build type, dependencies, etc.
Format:
ros2 pkg create <package_name> --build-type <build-type> --dependencies <dependencies>In ros2 command:
pkg: Package-related functionality;
create: Create a package;
package_name: Required: Name of the new package;
build-type: Required: Indicates whether the new package is C++ or Python. Use ament_cmake for C/C++, or ament_python for Python;
dependencies: Optional: Package dependencies. C++ packages need rclcpp, Python packages need rclpy, plus other needed dependencies;
1.2. ros2 pkg list
Function: List all packages in the system
Format:
xxxxxxxxxxros2 pkg list
1.3. ros2 pkg executables
Function: View all executable files in a package
Format:
xxxxxxxxxxros2 pkg executables pkg_name
2. Node Execution - ros2 run
Function: Run a package node program
Format:
xxxxxxxxxxros2 run pkg_name node_namepkg_name: Package name
node_name: Executable program name

3. Node-related Tools - ros2 node
3.1. ros2 node list
Function: List all node names in the current domain
Format:
xxxxxxxxxxros2 node list

3.2. ros2 node info
Function: View detailed node information, including subscriptions, published messages, services, and actions
Format:
xxxxxxxxxxros2 node info node_name
node_name: Name of the node to query

4. Topic-related Tools - ros2 topic
4.1. ros2 topic list
Function: List all topics in the current domain
Format:
xxxxxxxxxxros2 topic list
4.2. ros2 topic info
Function: Display topic message type, number of subscribers/publishers
Format:
xxxxxxxxxxros2 topic info topic_nametopic_name: Name of the topic to query

4.3. ros2 topic type
Function: Check the message type of a topic
Format:
xxxxxxxxxxros2 topic type topic_nametopic_name: Name of the topic to query type for

4.4. ros2 topic hz
Function: Display the average publishing frequency of a topic
Format:
xxxxxxxxxxros2 topic hz topic_name
topic_name: Name of the topic to query frequency for

4.5. ros2 topic echo
Function: Print topic messages in the terminal, similar to a subscriber
Format: ros2 topic echo topic_name
topic_name: Name of the topic to print messages from

4.5. ros2 topic pub
Function: Publish a specified topic message in the terminal
Format:
xxxxxxxxxxros2 topic pub topic_name message_type message_content
topic_name: Name of the topic to publish to
message_type: Data type of the topic
message_content: Message content
By default, it publishes at 1Hz continuously. You can set the following parameters:
Parameter -1: Publish only once. ros2 topic pub -1 topic_name message_type message_content
Parameter -t count: Publish count times then end. ros2 topic pub -t count topic_name message_type message_content
Parameter -r count: Publish continuously at count Hz. ros2 topic pub -r count topic_name message_type message_content
Example:
Publish velocity command via command line
Note: There is a space after each colon, otherwise a format error will be reported
xxxxxxxxxxros2 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}}"
5. Interface-related Tools - ros2 interface
5.1. ros2 interface list
Function: List all interfaces in the current system, including topics, services, and actions.
Format:
xxxxxxxxxxros2 interface list
5.2. ros2 interface show
Function: Display detailed content of a specified interface
Format:
xxxxxxxxxxros2 interface show interface_nameinterface_name: Name of the interface to display

6. Service-related Tools - ros2 service
6.1. ros2 service list
Function: List all services in the current domain
Format:
xxxxxxxxxxros2 interface show interface_name
6.2. ros2 service call
Function: Call a specified service
Format:
xxxxxxxxxxros2 interface call service_name service_Type arguments
service_name: Service to call
service_Type: Service data type
arguments: Parameters needed to provide the service
For example, call the spawn turtle service:
xxxxxxxxxxros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: 'turtle10'}"