Intro

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

  • start turtlesim
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]
  • Use rqt_graph to see the running node and topics it’s subscribed to
    • Click refresh if window is blank
rqt_graph

picture 0

  • use turtlesim
    • Open another terminal to run a new node to control the turtle
ros2 run turtlesim turtle_teleop_key

Refresh rqt_graph to see how teleop node is interacting w/ the turtlesim node

picture 1
In this setup, 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. The rqt_graph visually represents the connections between nodes and the topics they communicate over.

  • Show list of active topics
ros2 topic list
/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]
  • Show these topics in rqt_graph by unchecking the boxes under Hide: picture 2

  • See data being published on a topic

    • /teleop_turtle will publish data over /turtle1/cmd_vel topic when you use the keys to move the turtle
ros2 topic echo /turtle1/cmd_vel
linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: -2.0
---
linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 2.0
  • View the publisher publishing data over cmd_vel topic with 2 subscribers subscribed to it
    • Uncheck debug box
    • /_ros2cli5009 is the node created by the echo command picture 3

Show info on topics including number of publishers and subscribers

  • Show Twist messages on /turtle1/cmd_vel
 ros2 topic info /turtle1/cmd_vel
Type: geometry_msgs/msg/Twist
Publisher count: 0
Subscription count: 2

Twist messages

  • Twist messages have x,y,z components for angular and linear velocity picture 4
  • Show the details of a message- the structure of data it expects
ros2 interface show geometry_msgs/msg/Twist
  • This same structure was shown with the echo command earlier
# This expresses velocity in free space broken into its linear and angular parts.

Vector3  linear
        float64 x
        float64 y
        float64 z
Vector3  angular
        float64 x
        float64 y
        float64 z
  • Pubish data direclty to a topic from the command line
ros2 topic pub <topic_name> <msg_type> '<args>'
  • Example using YAML syntax
    • With no command-line options, ros2 topic pub publishes the command in a steady stream at 1 Hz.
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"

Try the spawn service

  • Use rqt to call the /spawn service and create another turtle