Intro

Learn the basics of ROS2 by running the Turtlesim simulator, controlling it with the keyboard, and exploring ROS 2 tools like rqt_graph and ros2 topic.

Robot Operating System (ROS) - Part II by OC Robotics (Slides by JSON)

📎TODO

  • * Run and control Turtlesim in ROS 2
  • * Inspect active topics with ros2 topic
  • * Visualize node connections with rqt_graph
  • * Publish messages from the terminal

Launch Turtlesim

Turtlesim is a lightweight simulator for learning ROS 2. It illustrates what ROS 2 does at the most basic level to give you an idea of what you will do with a real robot or a robot simulation later on.

This tutorial touches upon core ROS 2 concepts, like nodes, topics, and services. All of these concepts will be elaborated on in later tutorials; for now, you will simply set up the tools and get a feel for them

  • Source the ROS2 installation
source /opt/ros/humble/setup.bash
  • Start the turtlesim node
ros2 run turtlesim turtlesim_node
[INFO] [1729587409.041614825] [turtlesim]: Starting turtlesim with node name /turtlesim
[INFO] [1729587409.072164425] [turtlesim]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]

Control the Turtle

  • Open another terminal and use the teleop node to send velocity commands:
ros2 run turtlesim turtle_teleop_key
  • Use arrow keys to move the turtle and try drawing a square or circle

Inspect ROS 2 Topics

Nodes in ROS 2 communicate through topics

description
  • Open a 3rd terminal and list all active topics
ros2 topic list
  • You should see topics like:
    • /turtle1/cmd_vel (velocity commands)
    • /turtle1/pose (current turtle position)
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
  • Show list of active topics with topic type
ros2 topic list -t
/parameter_events [rcl_interfaces/msg/ParameterEvent]
/rosout [rcl_interfaces/msg/Log]
/turtle1/cmd_vel [geometry_msgs/msg/Twist]
/turtle1/color_sensor [turtlesim/msg/Color]
/turtle1/pose [turtlesim/msg/Pose]
  • Check messages being published:
ros2 topic echo /turtle1/pose
  • You will see live updates of the turtle’s position and heading
x: 2.1204445362091064
y: 5.544444561004639
theta: -0.01600000075995922
linear_velocity: 0.0
angular_velocity: 0.0
---
x: 2.1204445362091064
y: 5.544444561004639
theta: -0.01600000075995922
linear_velocity: 0.0
angular_velocity: 0.0

Using rqt_graph

rqt_graph

The rqt_graph visually represents the connections between nodes and the topics they communicate over description

The /teleop_turtle node publishes velocity commands to /turtle1/cmd_vel, which is consumed by /turtlesim to move the turtle. Additionally, action-related topics handle feedback and status for rotating the turtle to specific angles.

  • Use rqt_graph to visualize how nodes and topics are connected
ros2 run rqt_graph rqt_graph
  • You’ll see a graph showing:
    • turtle_teleop_key → publishes to /turtle1/cmd_vel
    • turtlesim_node → subscribes to /turtle1/cmd_vel and publishes /turtle1/pose

Challenges

  • Drive the turtle in a perfect circle with the keyboard.
  • Publish commands directly from the terminal:
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0}, angular: {z: 1.8}}"

(press Ctrl+C to stop publishing)


Conclusion

This foundation will set you up to work with more advanced robots and sensors in ROS 2

📎TODO

  • * Run and control Turtlesim in ROS 2
  • * Inspect active topics with ros2 topic
  • * Visualize node connections with rqt_graph
  • * Publish messages from the terminal

Learn on your own

How to Learn ROS2

Next

ros2_control architecture