Understanding ROS Topics with Turtlesim
1. Objective β What You Are Building and Why
In this lesson, you will visually understand how Publisher and Subscriber work using one of the most famous ROS tools:
π Turtlesim
Turtlesim is a simple simulator included in ROS where you control a small turtle moving on the screen.
Why do we use it?
Because it allows you to:
- see ROS concepts in action
- understand topics visually
- experiment without needing a real robot
Instead of imagining data flowing between nodes, you will see it happening.
In this lesson you will:
- run a ROS simulation
- control a turtle using your keyboard
- inspect nodes and topics
- visualize the communication graph
- manually publish messages from the terminal
This is where everything starts to connect.
2. Code Explanation β What / How / Why
Step 1 β Start Turtlesim
First, run the simulator:
rosrun turtlesim turtlesim_node
What happens?
- a window opens
- you see a turtle in a 2D world
This is a ROS node called:
/turtlesim
This node is already running internally as a subscriber.
It is listening for velocity commands.
Step 2 β Control the Turtle
Open a new terminal and run:
rosrun turtlesim turtle_teleop_key
Now use your keyboard:
- arrow keys β move the turtle
qβ quit
What is happening here?
turtle_teleop_keyis a publisher- it sends velocity commands to a topic
The turtle node is a subscriber that receives those commands.
So you now have:
keyboard β publisher β topic β subscriber β turtle moves
This is exactly how real robots work.
Step 3 β Inspect Nodes
Now letβs see what is running.
rosnode list
You should see something like:
/turtlesim/teleop_turtle
These are your two nodes:
- one publishes (keyboard)
- one subscribes (turtlesim)
Step 4 β Inspect Topics
Now list all topics:
rostopic list
You will see topics like:
/turtle1/cmd_vel/turtle1/pose/turtle1/color_sensor
The most important one is:
/turtle1/cmd_vel
This is the topic used to control the turtle.
Step 5 β Understand the Topic
Now inspect it:
rostopic info /turtle1/cmd_vel
You will see:
- message type:
geometry_msgs/Twist - publisher:
/teleop_turtle - subscriber:
/turtlesim
This tells you exactly:
- who sends data
- who receives data
- what type of data is sent
This is extremely powerful.
You can debug any ROS system using this information.
Step 6 β Visualize Everything with rqt_graph
Now run:
rqt_graph
You will see a graph like:
/teleop_turtle β /turtle1/cmd_vel β /turtlesim
This is the exact architecture we discussed before.
- publisher node
- topic
- subscriber node
Now you can see it visually.
Step 7 β Publish a Message Manually
Now comes the most important experiment.
You will act as the publisher yourself.
Run:
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist
You will see a structure like:
linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
Modify values, for example:
linear: x: 2.0 angular: z: 1.0
Press enter.
π The turtle moves.
What Just Happened?
You manually published a message to the topic.
So now:
- YOU are the publisher
- turtlesim is the subscriber
This proves something very important:
ROS does not care who publishes the data.
As long as:
- topic name matches
- message type matches
communication works.
This is the decoupling principle of ROS.
3. Demo
In the video you will:
- Launch turtlesim
- Control the turtle with the keyboard
- Inspect nodes with
rosnode list - Inspect topics with
rostopic list - Analyze a topic with
rostopic info - Visualize everything with
rqt_graph - Manually publish a command
You will see the turtle moving in real time based on ROS messages.
This is your first visual proof of ROS communication.
4. Key Takeaways
After this lesson, you should clearly understand how ROS communication works in practice.
You learned that:
- a publisher sends commands
- a subscriber receives commands
- a topic connects them
You also learned how to inspect a running ROS system:
rosnode listβ see active nodesrostopic listβ see topicsrostopic infoβ understand connectionsrqt_graphβ visualize the architecture
And most importantly:
π you manually published a message and controlled the system
This is a big step.
Because now you understand that:
ROS is just data flowing between nodes.
And if you can control the data,
you can control the robot.
This is exactly the mindset you need moving forward.