Turtlesim + Keyboard Teleoperation

Concept

turtlesim is a simple 2D simulator included with ROS 2. It is the standard tool for learning how nodes, topics, and messages work. The teleop node reads keyboard input and publishes geometry_msgs/Twist messages to /turtle1/cmd_vel.

Install turtlesim

sudo apt install ros-humble-turtlesim -y

Steps

Terminal 1 — Launch the simulator

ros2 run turtlesim turtlesim_node

A blue window with a turtle will appear.

Terminal 2 — Keyboard control

ros2 run turtlesim turtle_teleop_key

Warning

Keep Terminal 2 focused (clicked) when pressing arrow keys — keyboard input only works when that terminal is active.

Controls:

KeyAction
Arrow UpMove forward
Arrow DownMove backward
Arrow LeftRotate left
Arrow RightRotate right

Terminal 3 — Monitor velocity commands

ros2 topic echo /turtle1/cmd_vel

Bonus — See all active topics

ros2 topic list

Expected Output

When you press an arrow key, Terminal 3 will show:

linear:
  x: 2.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0
---

Rotating will show a non-zero value in angular.z.

Key Topics

TopicTypeDescription
/turtle1/cmd_velgeometry_msgs/TwistVelocity commands sent to turtle
/turtle1/poseturtlesim/PoseCurrent position and heading
/turtle1/color_sensorturtlesim/ColorRGB color under the turtle