ROS2 Command Line Cheatsheet

Using TurtleSim Simulation and Teleop_Key

Setup & Launch Commands

Start TurtleSim

# Launch turtlesim node
ros2 run turtlesim turtlesim_node

# Launch teleop keyboard control (in separate terminal)
ros2 run turtlesim turtle_teleop_key

Launch Files

# Note: turtlesim has no built-in launch files
# For multiple turtles, use spawn service instead:
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2.0, y: 2.0, theta: 0.0, name: 'turtle2'}"

Node Commands

List and Info

# List all running nodes
ros2 node list
/turtlesim
/teleop_turtle
# Get detailed info about a node
ros2 node info /turtlesim
/turtlesim
  Subscribers:
    /turtle1/cmd_vel: geometry_msgs/msg/Twist
  Publishers:
    /turtle1/color_sensor: turtlesim/msg/Color
    /turtle1/pose: turtlesim/msg/Pose
  Service Servers:
    /clear: std_srvs/srv/Empty
    /kill: turtlesim/srv/Kill
    /reset: std_srvs/srv/Empty
    /spawn: turtlesim/srv/Spawn
    /turtle1/set_pen: turtlesim/srv/SetPen
    /turtle1/teleport_absolute: turtlesim/srv/TeleportAbsolute
    /turtle1/teleport_relative: turtlesim/srv/TeleportRelative
  Action Servers:
    /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

Topic Commands

Basic Topic Operations

# List all topics
ros2 topic list
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
# List topics with message types
ros2 topic list -t
/turtle1/cmd_vel [geometry_msgs/msg/Twist]
/turtle1/color_sensor [turtlesim/msg/Color]
/turtle1/pose [turtlesim/msg/Pose]

Monitor Topics

# Echo topic messages
ros2 topic echo /turtle1/pose
x: 5.544444561004639
y: 5.544444561004639
theta: 0.0
linear_velocity: 0.0
angular_velocity: 0.0
---

Publish to Topics

# Publish velocity commands (move turtle)
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}"
# Publish once
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist \
  "linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}"
# Publish at specific rate (10 Hz)
ros2 topic pub --rate 10 /turtle1/cmd_vel geometry_msgs/msg/Twist \
  "linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}"

Service Commands

List and Info

# List all services
ros2 service list
/clear
/kill
/reset
/spawn
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative

Call Services

# Spawn a new turtle
ros2 service call /spawn turtlesim/srv/Spawn \
  "{x: 5.0, y: 5.0, theta: 0.0, name: 'turtle2'}"
# Change pen color and width
ros2 service call /turtle1/set_pen turtlesim/srv/SetPen \
  "{r: 255, g: 0, b: 0, width: 5, 'off': 0}"
# Teleport turtle (absolute)
ros2 service call /turtle1/teleport_absolute turtlesim/srv/TeleportAbsolute \
  "{x: 1.0, y: 1.0, theta: 0.0}"
# Clear screen
ros2 service call /clear std_srvs/srv/Empty

Action Commands

List and Info

# List all actions
ros2 action list
/turtle1/rotate_absolute

Send Action Goals

# Rotate turtle to absolute angle
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute \
  "{theta: 1.57}"
# Rotate with feedback
ros2 action send_goal --feedback /turtle1/rotate_absolute \
  turtlesim/action/RotateAbsolute "{theta: 3.14}"

Parameter Commands

List and Get Parameters

# List all parameters
ros2 param list
/turtlesim:
  background_b
  background_g
  background_r
  qos_overrides./parameter_events.publisher.depth
  qos_overrides./parameter_events.publisher.durability
  qos_overrides./parameter_events.publisher.history
  qos_overrides./parameter_events.publisher.reliability
  use_sim_time

Set Parameters

# Set background color
ros2 param set /turtlesim background_r 255
Set parameter successful
# Apply background changes (call after setting colors)
ros2 service call /clear std_srvs/srv/Empty

Interface Commands

Message Interfaces

# Show message definition
ros2 interface show geometry_msgs/msg/Twist
geometry_msgs/Vector3 linear
        float64 x
        float64 y
        float64 z
geometry_msgs/Vector3 angular
        float64 x
        float64 y
        float64 z
# Show message prototype
ros2 interface proto geometry_msgs/msg/Twist
linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0

Debugging & Monitoring

RQt Tools

# Launch RQt (GUI tools)
rqt

# RQt graph (visualize nodes and topics)
rqt_graph

# RQt console (view log messages)
rqt_console

# RQt plot (plot topic data)
rqt_plot /turtle1/pose/x /turtle1/pose/y

System Info

# Check ROS2 environment
ros2 doctor

Recording & Playback

Bag Files

# Record topics
ros2 bag record /turtle1/cmd_vel /turtle1/pose
# Play back recorded data
ros2 bag play my_bag
# Get bag info
ros2 bag info my_bag
# Play with rate control
ros2 bag play my_bag --rate 0.5

Common Message Formats

Twist (cmd_vel)

linear:
  x: 2.0    # forward/backward
  y: 0.0    # left/right (usually 0 for differential drive)
  z: 0.0    # up/down (usually 0 for ground robots)
angular:
  x: 0.0    # roll (usually 0)
  y: 0.0    # pitch (usually 0)
  z: 1.8    # yaw (turning)

Pose (turtle position)

x: 5.544444561004639        # x position
y: 5.544444561004639        # y position
theta: 0.0                  # orientation (radians)
linear_velocity: 0.0        # current linear velocity
angular_velocity: 0.0       # current angular velocity

Quick Reference

Essential TurtleSim Commands

# Start simulation
ros2 run turtlesim turtlesim_node

# Start teleop
ros2 run turtlesim turtle_teleop_key

# Move turtle programmatically
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist \
  "linear: {x: 2.0}, angular: {z: 1.8}"

# Spawn new turtle
ros2 service call /spawn turtlesim/srv/Spawn \
  "{x: 2.0, y: 2.0, theta: 0.0, name: 'turtle2'}"

# Change pen color
ros2 service call /turtle1/set_pen turtlesim/srv/SetPen \
  "{r: 255, g: 0, b: 0, width: 3}"

# Watch turtle position
ros2 topic echo /turtle1/pose

Keyboard Controls (teleop_key)

Key Action
Arrow keys Move turtle
Space Stop turtle
q/w Increase/decrease linear speed
a/s Increase/decrease angular speed
Pro Tips
  • Use ros2 topic echo to debug message flow
  • Use rqt_graph to visualize system architecture
  • Use --help flag with any command for detailed options
  • Record important experiments with ros2 bag for later analysis
Back to RAISE 2025