Welcome to Jetson Orin NANO Developer Kit repository
16.ROS2 common command tools
16. ROS 2 Common Command Tools
1. Package Management Tool ros2 pkg
1.1. ros2 pkg create
Purpose: Create a package. When creating it, you need to specify the package name, compilation method, dependencies, and so on.
Format:
ros2 pkg create <package_name> --build-type <build-type> --dependencies <dependencies>In the ros2 command:
pkg: Indicates the functions related to packages;
create: Indicates creating a package;
package_name: Required item: the name of the new package;
build-type: Required item: indicates whether the newly created package is C++ or Python. If C++ or C is used, then ament_cmake is used here; if Python is used, then ament_python is used;
dependencies: Optional item: indicates the dependencies of the package. A C++ package needs to include rclcpp, a Python package needs to include rclpy, as well as other required dependencies;
1.2. ros2 pkg list
Purpose: View the list of packages in the system
Format:
xxxxxxxxxxros2 pkg list
1.3. ros2 pkg executables
Purpose: View all executable files in a package
Format:
xxxxxxxxxxros2 pkg executables pkg_name
2. Node Running ros2 run
Purpose: Run the node program of a package
Format:
xxxxxxxxxxros2 run pkg_name node_namepkg_name: Package name
node_name: The name of the executable program

3. Node-Related Tools ros2 node
3.1. ros2 node list
Purpose: List the names of all nodes in the current domain
Format:
xxxxxxxxxxros2 node list
3.2. ros2 node info
Purpose: View detailed node information, including subscribed and published messages, enabled services and actions, and so on
Format:
xxxxxxxxxxros2 node info node_name
node_name: The name of the node to be viewed
4. Topic-Related Tools ros2 topic
4.1. ros2 topic list
Purpose: List all topics in the current domain
Format:
xxxxxxxxxxros2 topic list
4.2. ros2 topic info
Purpose: Display the topic message type and the number of subscribers/publishers
Format:
xxxxxxxxxxros2 topic info topic_nametopic_name: The name of the topic to be queried
4.3. ros2 topic type
Purpose: View the message type of a topic
Format:
xxxxxxxxxxros2 topic type topic_nametopic_name: The name of the topic whose type is to be queried
4.4. ros2 topic hz
Purpose: Display the average publishing frequency of a topic
Format:
xxxxxxxxxxros2 topic hz topic_name
topic_name: The name of the topic whose frequency is to be queried

4.5. ros2 topic echo
Purpose: Print topic messages in the terminal, similar to a subscriber
Format: ros2 topic echo topic_name
topic_name: The name of the topic whose messages are to be printed
4.5. ros2 topic pub
Purpose: Publish specified topic messages in the terminal
Format:
xxxxxxxxxxros2 topic pub topic_name message_type message_content
topic_name: The name of the topic whose messages are to be published
message_type: The data type of the topic
message_content: Message content
By default, it publishes in a loop at a frequency of 1 Hz. The following parameters can be set,
Parameter -1 publishes only once, ros2 topic pub -1 topic_name message_type message_content
Parameter -t count publishes in a loop count times and then ends, ros2 topic pub -t count topic_name message_type message_content
Parameter -r count publishes in a loop at a frequency of count Hz, ros2 topic pub -r count topic_name message_type message_content
Example:
Publish a velocity command through the command line
Note here that there is a space after each colon, otherwise a format error will be prompted
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
Purpose: List all interfaces of the current system, including topics, services, and actions.
Format:
xxxxxxxxxxros2 interface list
5.2. ros2 interface show
Purpose: Display the detailed content of a specified interface
Format:
xxxxxxxxxxros2 interface show interface_nameinterface_name: The name of the interface content to be displayed
6. Service-Related Tools ros2 service
6.1. ros2 service list
Purpose: List all services in the current domain
Format:
xxxxxxxxxxros2 interface show interface_name
6.2. ros2 service call
Purpose: Call a specified service
Format:
xxxxxxxxxxros2 interface call service_name service_Type arguments
service_name: The service to be called
service_Type: The service data type
arguments: The parameters required 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'}"