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_key is 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:

  1. Launch turtlesim
  2. Control the turtle with the keyboard
  3. Inspect nodes with rosnode list
  4. Inspect topics with rostopic list
  5. Analyze a topic with rostopic info
  6. Visualize everything with rqt_graph
  7. 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 nodes
  • rostopic list β†’ see topics
  • rostopic info β†’ understand connections
  • rqt_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.

Complete and Continue