Skip to content

ROS 2 Command Reference

Roy Yao edited this page Apr 24, 2026 · 1 revision

ROS 2 Command Reference

Target: ROS 2 Jazzy / Humble · Ubuntu 22.04
Scope: Nodes, Topics, Services, Parameters, Launch


Table of Contents


Environment Setup

# Source ROS 2 installation (add to ~/.bashrc to persist)
source /opt/ros/jazzy/setup.bash

Source your local workspace overlay

source ~/ros2_ws/install/setup.bash

Check ROS 2 environment

printenv | grep ROS


Workspace & Build

# Create a workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws

Clone a package into src/

cd src && git clone <package_url>

Build the entire workspace

cd ~/ros2_ws colcon build

Build only specific packages

colcon build --packages-select my_package

Build with symlink install (faster dev iteration — no rebuild on Python changes)

colcon build --symlink-install

Source after building

source install/setup.bash

💡 Always source install/setup.bash after a build before running nodes.


Nodes

Nodes are individual processes. Each does one thing (a sensor driver, a planner, a controller).

# Run a node
ros2 run <package_name> <executable_name>

Example

ros2 run demo_nodes_cpp talker

List all running nodes

ros2 node list

Get info about a node (publishers, subscribers, services)

ros2 node info /talker

Kill a node

Use Ctrl+C in its terminal, or:

kill $(ros2 node list | grep my_node) # not official — use with care


Topics

Topics use a publish / subscribe pattern. Publishers don't know who is listening.

# List all active topics
ros2 topic list

List with message types

ros2 topic list -t

Show info about a topic (publishers, subscribers, type)

ros2 topic info /chatter

Print messages being published to a topic

ros2 topic echo /chatter

Echo with a message count limit

ros2 topic echo /chatter --once ros2 topic echo /chatter -n 5

Check publishing rate (Hz)

ros2 topic hz /chatter

Check message bandwidth

ros2 topic bw /chatter

Manually publish a message (one-shot)

ros2 topic pub /chatter std_msgs/msg/String "data: 'hello world'"

Publish at a specific rate (Hz)

ros2 topic pub --rate 10 /chatter std_msgs/msg/String "data: 'hello world'"

Show the definition of a message type

ros2 interface show std_msgs/msg/String

Common Message Types

Type Package Use Case
std_msgs/msg/String std_msgs Simple text
std_msgs/msg/Float64 std_msgs Single float
geometry_msgs/msg/Twist geometry_msgs Velocity commands
sensor_msgs/msg/LaserScan sensor_msgs LIDAR data
sensor_msgs/msg/Image sensor_msgs Camera frames
nav_msgs/msg/Odometry nav_msgs Robot pose + velocity

Last updated: April 2026 · ROS 2 Jazzy Jalisco

# ROS 2 Command Reference

Target: ROS 2 Jazzy / Humble · Ubuntu 22.04
Scope: Nodes, Topics, Services, Parameters, Launch


Table of Contents


Environment Setup

# Source ROS 2 installation (add to ~/.bashrc to persist)
source /opt/ros/jazzy/setup.bash

# Source your local workspace overlay
source ~/ros2_ws/install/setup.bash

# Check ROS 2 environment
printenv | grep ROS

Workspace & Build

# Create a workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws

# Clone a package into src/
cd src && git clone <package_url>

# Build the entire workspace
cd ~/ros2_ws
colcon build

# Build only specific packages
colcon build --packages-select my_package

# Build with symlink install (faster dev iteration — no rebuild on Python changes)
colcon build --symlink-install

# Source after building
source install/setup.bash

💡 Always source install/setup.bash after a build before running nodes.


Nodes

Nodes are individual processes. Each does one thing (a sensor driver, a planner, a controller).

# Run a node
ros2 run <package_name> <executable_name>

# Example
ros2 run demo_nodes_cpp talker

# List all running nodes
ros2 node list

# Get info about a node (publishers, subscribers, services)
ros2 node info /talker

# Kill a node
# Use Ctrl+C in its terminal, or:
kill $(ros2 node list | grep my_node)  # not official — use with care

Topics

Topics use a publish / subscribe pattern. Publishers don't know who is listening.

# List all active topics
ros2 topic list

# List with message types
ros2 topic list -t

# Show info about a topic (publishers, subscribers, type)
ros2 topic info /chatter

# Print messages being published to a topic
ros2 topic echo /chatter

# Echo with a message count limit
ros2 topic echo /chatter --once
ros2 topic echo /chatter -n 5

# Check publishing rate (Hz)
ros2 topic hz /chatter

# Check message bandwidth
ros2 topic bw /chatter

# Manually publish a message (one-shot)
ros2 topic pub /chatter std_msgs/msg/String "data: 'hello world'"

# Publish at a specific rate (Hz)
ros2 topic pub --rate 10 /chatter std_msgs/msg/String "data: 'hello world'"

# Show the definition of a message type
ros2 interface show std_msgs/msg/String

Common Message Types

Type Package Use Case
std_msgs/msg/String std_msgs Simple text
std_msgs/msg/Float64 std_msgs Single float
geometry_msgs/msg/Twist geometry_msgs Velocity commands
sensor_msgs/msg/LaserScan sensor_msgs LIDAR data
sensor_msgs/msg/Image sensor_msgs Camera frames
nav_msgs/msg/Odometry nav_msgs Robot pose + velocity

Services

Services use a request / response pattern — synchronous, like a function call.

# List all active services
ros2 service list

# List with types
ros2 service list -t

# Show the type of a service
ros2 service type /add_two_ints

# Show the definition of a service interface
ros2 interface show example_interfaces/srv/AddTwoInts

# Call a service manually
ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 3, b: 5}"

# Find services by type
ros2 service find example_interfaces/srv/AddTwoInts

Service vs Topic — When to Use Which

Topic Service
Pattern Publish / Subscribe Request / Response
Direction One-to-many One-to-one
Synchronous? No Yes
Use case Sensor streams, commands Queries, one-time actions

Parameters

Parameters are node-level configuration values (not inter-node communication).

# List all parameters across all nodes
ros2 param list

# List parameters for a specific node
ros2 param list /my_node

# Get a parameter value
ros2 param get /my_node my_param

# Set a parameter at runtime
ros2 param set /my_node my_param 42

# Dump all parameters of a node to YAML
ros2 param dump /my_node

# Load parameters from a YAML file at launch
ros2 run my_package my_node --ros-args --params-file config/params.yaml

Parameter YAML Format

# config/params.yaml
my_node:
  ros__parameters:
    speed: 1.5
    frame_id: "base_link"
    debug: false

Launch Files

Launch files start multiple nodes with shared configuration. Written in Python (ROS 2).

Basic Launch File

# my_package/launch/my_launch.py
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='demo_nodes_cpp',
            executable='talker',
            name='my_talker',
            output='screen',
        ),
        Node(
            package='demo_nodes_cpp',
            executable='listener',
            name='my_listener',
            output='screen',
        ),
    ])

Launch with Parameters

Node(
    package='my_package',
    executable='my_node',
    parameters=[
        {'speed': 1.5, 'frame_id': 'base_link'},
        '/path/to/params.yaml',          # can also load a file
    ]
)

Launch with Remapping

Node(
    package='my_package',
    executable='my_node',
    remappings=[
        ('/input/topic', '/actual/topic'),
    ]
)

Run a Launch File

# Basic usage
ros2 launch my_package my_launch.py

# Pass arguments
ros2 launch my_package my_launch.py speed:=2.0

# List available launch arguments
ros2 launch my_package my_launch.py --show-args

Bag Files (rosbag2)

Record and replay topic data for testing and debugging.

# Record all topics
ros2 bag record -a

# Record specific topics
ros2 bag record /chatter /scan

# Record to a named directory
ros2 bag record -o my_recording /chatter

# Play back a bag
ros2 bag play my_recording

# Play at half speed
ros2 bag play my_recording --rate 0.5

# Loop playback
ros2 bag play my_recording --loop

# Show bag info (duration, topics, message counts)
ros2 bag info my_recording

Useful Utilities

rqt — GUI Tools

# Launch the rqt GUI hub
rqt

# Topic monitor with graphs
rqt_graph          # visualize node/topic connections
rqt_plot           # plot numeric topic data over time
rqt_console        # view log messages

tf2 — Coordinate Frames

# List all active transforms
ros2 run tf2_ros tf2_monitor

# Print the transform between two frames
ros2 run tf2_ros tf2_echo base_link odom

# Generate a PDF of the TF tree
ros2 run tf2_tools view_frames

Logging

# Set log level for a node at launch
ros2 run my_package my_node --ros-args --log-level DEBUG

# Available levels: DEBUG, INFO, WARN, ERROR, FATAL

Interface Introspection

# List all available message types
ros2 interface list

# Show definition of any interface (msg / srv / action)
ros2 interface show geometry_msgs/msg/Twist
ros2 interface show nav_msgs/srv/GetPlan

Quick Reference Cheat Sheet

Goal Command
Run a node ros2 run <pkg> <exe>
List nodes ros2 node list
Inspect a node ros2 node info /<node>
List topics ros2 topic list -t
Monitor a topic ros2 topic echo /<topic>
Publish once ros2 topic pub --once /<topic> <type> "<data>"
List services ros2 service list -t
Call a service ros2 service call /<srv> <type> "<args>"
Get a parameter ros2 param get /<node> <param>
Set a parameter ros2 param set /<node> <param> <value>
Run a launch file ros2 launch <pkg> <file>.py
Record topics ros2 bag record -a
Replay recording ros2 bag play <dir>
Visualize graph rqt_graph

Last updated: April 2026 · ROS 2 Jazzy Jalisco

Clone this wiki locally