Skip to main content

16. ROS 2 Common Command Tools

1. Package Management Tool: ros2 pkg

1.1 ros2 pkg create

Function: Creates a new package. When creating a package, you must specify the package name, build type, and dependencies.

Format:

ros2 pkg create <package_name> --build-type <build-type> --dependencies <dependencies>

Parameters:

  • pkg: Package-related operations\
  • create: Create a new package\
  • package_name: Name of the new package\
  • build-type: ament_cmake for C++, ament_python for Python\
  • dependencies: Optional dependencies (C++ requires rclcpp, Python requires rclpy)

1.2 ros2 pkg list

Function: View all packages in the system.

Format:

ros2 pkg list

ROS2 Package List


1.3 ros2 pkg executables

Function: View all executable files in a package.

Format:

ros2 pkg executables pkg_name

ROS2 Package Executables


2. Node Execution Tool: ros2 run

Function: Run a node program in a specified package.

Format:

ros2 run pkg_name node_name
  • pkg_name: Package name\
  • node_name: Executable name

ROS2 Run Node


3.1 ros2 node list

Function: List all nodes in the current domain.

Format:

ros2 node list

ROS2 Node List


3.2 ros2 node info

Function: View detailed node information (publishers, subscribers, services, actions).

Format:

ros2 node info node_name

ROS2 Node Info


4.1 ros2 topic list

Function: List all topics.

ros2 topic list

ROS2 Topic List


4.2 ros2 topic info

Function: Show topic type and publisher/subscriber count.

ros2 topic info topic_name

ROS2 Topic Info


4.3 ros2 topic type

Function: Display message type for a topic.

ros2 topic type topic_name

ROS2 Topic Type


4.4 ros2 topic hz

Function: Display publishing frequency of a topic.

ros2 topic hz topic_name

ROS2 Topic Frequency


4.5 ros2 topic echo

Function: Print topic messages in the terminal.

ros2 topic echo topic_name

ROS2 Topic Echo


4.6 ros2 topic pub

Function: Publish a message to a topic from the terminal.

ros2 topic pub topic_name message_type message_content

Advanced Options:

  • -1: Publish only once\
  • -t <count>: Publish <count> times\
  • -r <hz>: Publish at <hz> frequency

Example:

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}}"

ROS2 Topic Publish


5.1 ros2 interface list

Function: List all available interfaces (topics, services, actions).

ros2 interface list

ROS2 Interface List


5.2 ros2 interface show

Function: Display details of a specific interface.

ros2 interface show interface_name

This documentation is maintained by HemiHex for educational and development purposes.