liminfo

ROS2 Reference

Free reference guide: ROS2 Reference

35 results

About ROS2 Reference

This ROS2 Reference is a comprehensive cheat sheet for Robot Operating System 2 CLI commands and workflows, organized across five practical categories. The Node and Run section covers ros2 run with node name remapping and namespace assignment, ros2 node list/info for discovering running nodes and their publishers, subscribers, services, and actions. It also includes ros2 daemon management for fixing discovery issues, ros2 lifecycle for managed node state transitions (unconfigured, inactive, active, finalized), and ros2 doctor for system-wide diagnostic checks.

Topic, message, service, and action communication patterns are documented with full command syntax and practical examples. Topic commands include ros2 topic list with type display, echo with field filtering and CSV output, pub for direct terminal publishing, info with verbose QoS details, hz for frequency measurement, and delay for latency analysis. The interface show command reveals message, service, and action type structures. Common message types from std_msgs, geometry_msgs (Twist, Pose, Transform), sensor_msgs (Image, LaserScan, PointCloud2, Imu, JointState), and nav_msgs (Odometry, Path, OccupancyGrid) are cataloged. Service and action commands cover list, call, find, send_goal with feedback, and info.

Package management, build systems, parameters, launch files, rosbag, QoS, and TF2 tools round out the reference. Package commands include ros2 pkg create for ament_cmake and ament_python, with colcon build options for selective builds, symlink install, and Release optimization. Parameter commands cover list, get/set at runtime, and YAML dump/load. Launch file syntax documents Python-based LaunchDescription with Node declarations, remappings, and argument handling. Rosbag commands include record with compression and play with rate control and looping. QoS profile documentation explains RELIABLE vs BEST_EFFORT compatibility. TF2 tools cover frame tree visualization, tf2_echo for transform queries, and static transform publishing.

Key Features

  • Node and run commands: ros2 run (remapping, namespaces, parameters), node list/info, daemon, lifecycle, and doctor
  • Topic commands: list, echo (field filtering, CSV, once), pub (rate control), info (verbose QoS), hz, delay, and bw
  • Complete message type catalog: std_msgs, geometry_msgs, sensor_msgs, and nav_msgs with field structures
  • Service and action commands: list, call, find, send_goal with feedback, and interface show for type inspection
  • Package and build: ros2 pkg create, colcon build (selective, symlink, Release), rosdep, and ament_cmake vs ament_python
  • Parameter management: list, get/set at runtime, YAML dump/load, and params-file at launch
  • Launch files and rosbag: Python LaunchDescription syntax, ros2 bag record (compression) and play (rate, loop, topics)
  • QoS profiles (RELIABLE/BEST_EFFORT compatibility) and TF2 tools (view_frames, tf2_echo, static_transform_publisher)

Frequently Asked Questions

How do I run a ROS2 node with custom name and namespace?

Use ros2 run with --ros-args for remapping. To rename a node: ros2 run turtlesim turtlesim_node --ros-args -r __node:=my_turtle. To set a namespace: add -r __ns:=/sim1. You can also pass parameters at launch: --ros-args -p frequency:=2.0. These remappings allow running multiple instances of the same node with different configurations.

How do I inspect topics and their messages?

Use ros2 topic list -t to see all active topics with their message types. Use ros2 topic echo to print real-time messages (add --once for single output, --field for specific fields, --csv for CSV format). Check publish frequency with ros2 topic hz, bandwidth with ros2 topic bw, and latency with ros2 topic delay. Use ros2 interface show to view the complete field structure of any message type.

What is the difference between services and actions?

Services are synchronous request-response calls suitable for quick operations (e.g., spawning a turtle, clearing the screen). Actions are for long-running tasks that need progress feedback and cancellation support (e.g., navigation to a goal pose). Actions have three components: Goal (sent by client), Result (final outcome), and Feedback (progress updates). Use --feedback with ros2 action send_goal to see real-time progress.

How do I create and build a ROS2 package?

For C++: ros2 pkg create --build-type ament_cmake my_pkg --dependencies rclcpp std_msgs. For Python: ros2 pkg create --build-type ament_python my_pkg --dependencies rclpy std_msgs. Build with colcon build (use --packages-select for specific packages, --symlink-install so Python changes do not require rebuild, --cmake-args -DCMAKE_BUILD_TYPE=Release for optimization). Always run source install/setup.bash after building.

How do I write a Python launch file?

Create a file in your package launch directory importing LaunchDescription, DeclareLaunchArgument, and Node from launch and launch_ros. Define generate_launch_description() returning a LaunchDescription with Node entries specifying package, executable, name, parameters, remappings, and output. Use DeclareLaunchArgument for configurable options and LaunchConfiguration to reference them. Run with ros2 launch my_pkg my_launch.py.

How do I record and play back rosbag data?

Record with ros2 bag record: use -a for all topics, or specify topics like /scan /odom /cmd_vel. Add -o my_bag for a custom name and --compression-format zstd for compression. Play back with ros2 bag play my_bag/: use --rate 2.0 for 2x speed, --loop for continuous replay, --topics to filter specific topics, and --start-paused to begin in pause mode (spacebar to play). Check bag contents with ros2 bag info.

What are QoS profiles and why do they matter?

QoS (Quality of Service) controls communication reliability. RELIABLE guarantees message delivery (TCP-like, used for commands), while BEST_EFFORT prioritizes speed (UDP-like, used for sensor data like laser scans and images). A RELIABLE publisher can serve BEST_EFFORT subscribers, but a BEST_EFFORT publisher cannot serve RELIABLE subscribers. Use ros2 topic info --verbose to check QoS settings, and --qos-reliability best_effort with ros2 topic echo for sensor topics.

How do I debug TF2 coordinate transforms?

Visualize the full TF tree with ros2 run tf2_tools view_frames (generates frames.pdf). Query the transform between two frames with ros2 run tf2_ros tf2_echo map base_link to see translation and rotation (quaternion). Publish a static transform with static_transform_publisher using --x, --y, --z, --roll, --pitch, --yaw, --frame-id, and --child-frame-id arguments. Monitor all transforms in real time with ros2 run tf2_ros tf2_monitor.