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 -ySteps¶
Terminal 1 — Launch the simulator
ros2 run turtlesim turtlesim_nodeA blue window with a turtle will appear.
Terminal 2 — Keyboard control
ros2 run turtlesim turtle_teleop_keyWarning
Keep Terminal 2 focused (clicked) when pressing arrow keys — keyboard input only works when that terminal is active.
Controls:
| Key | Action |
|---|---|
| Arrow Up | Move forward |
| Arrow Down | Move backward |
| Arrow Left | Rotate left |
| Arrow Right | Rotate right |
Terminal 3 — Monitor velocity commands
ros2 topic echo /turtle1/cmd_velBonus — See all active topics
ros2 topic listExpected 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¶
| Topic | Type | Description |
|---|---|---|
/turtle1/cmd_vel | geometry_msgs/Twist | Velocity commands sent to turtle |
/turtle1/pose | turtlesim/Pose | Current position and heading |
/turtle1/color_sensor | turtlesim/Color | RGB color under the turtle |