Unit 04 · lesson

Publish From the Command Line

You do not need to write a Python node to test every topic.

The ROS 2 CLI can publish a message directly.

Use the interface as your guide

You already inspected:

ros2 interface show geometry_msgs/msg/Twist

The official topic tutorial uses YAML-shaped data for CLI publication.

Try a bounded command such as:

ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist \
  "{linear: {x: 2.0}, angular: {z: 1.0}}"

The exact movement is less important than the evidence chain:

CLI publisher
  ↓ geometry_msgs/msg/Twist
/turtle1/cmd_vel

/turtlesim subscriber

visible movement

Continuous publication

The official tutorial also demonstrates repeated publishing with a rate. Turtlesim movement commands commonly need continuing updates rather than one command forever.

For this course, use continuous publication only long enough to observe the behavior, then stop it with Ctrl+C.

Observe your own CLI publisher

While publishing, inspect:

ros2 topic info /turtle1/cmd_vel --verbose

Your CLI command creates another publisher endpoint.

Checkpoint

Record:

Topic:
Type:
Message I published:
Visible/CLI evidence of effect:
Publisher count before:
Publisher count during CLI publication: