The ros2 command-line interface is the practical control surface for ROS 2 development and operation: it creates packages, runs executables, inspects interfaces and graphs, and communicates through topics. section 4.3 section 4.1
Use ros2 alongside workspace and build commands to:
- Create Python packages with ros2 pkg create, then build them with colcon and source the install setup file. section 4.3
- Run package executables with ros2 run and verify discoverability with ros2 pkg list or ros2 pkg prefix. section 4.3 section 4.7
- Publish, echo, and inspect typed topic data, including custom message types and interface definitions. section 4.7 section 4.4
- Diagnose disconnected communication by comparing topic names, message types, node information, and the ROS graph. section 4.7
Run a publisher and subscriber
After building and sourcing the workspace, run `ros2 run my_ros_py_pkg my_ros_pub` in one terminal and `ros2 run my_ros_py_pkg my_ros_sub` in another. The publisher sends String messages on `my_topic`; the subscriber logs each received message. section 4.4
cd ~/rfp_ws/src ros2 pkg create --build-type ament_python my_ros_py_pkg
Create a ROS Python package directly from the CLI, then build it with the workspace workflow shown by b10. section 4.3
