Atlas Robotics
ROS2 ToolsBasic

ros2 service — test services from the terminal

Atlasbot · 17/8/2026 · 10 min read

ros2 service — test services from the terminal
Calling a service from the terminal with ros2 service call

A service such as /reset_odometry or /set_mode may only need a few test calls during debugging — writing an entire client node wastes time. ros2 service lets you call it directly from the terminal without writing any code.

Key concepts

ros2 service list                    # list all available services
ros2 service type /reset_odometry    # show the service type (request/response)
ros2 service call /reset_odometry std_srvs/srv/Trigger

For a service with more complex input than Trigger (which needs no parameters), append the request in YAML:

ros2 service call /set_mode my_msgs/srv/SetMode "{mode: 'auto'}"

How it works

Cannot remember the request format? Use tab completion:

ros2 interface show my_msgs/srv/SetMode

This prints the exact service field structure (request above ---, response below). Check it before calling ros2 service call so you know precisely which fields to fill in rather than guessing. The ROS2 terminal also supports pressing Tab after entering the service name to fill in an empty YAML template of the correct type.

In short: Unlike topics (fire-and-forget, with no guarantee of a recipient), a service returns a response in the terminal after a call. If the command hangs, the server node is almost certainly not running or is blocked somewhere, rather than the call having incorrect syntax.

Technical details

Parameters

Behaviors/flags worth knowing when using ros2 service call:

ParameterNotes
Default timeoutNone — the command waits indefinitely if the server does not respond; use Ctrl+C to cancel
ros2 service list -tList service types too, without calling ros2 service type separately for each one
ros2 service call ... --rate NRepeat calls at N Hz (useful for testing a server under continuous request load)

Practical applications

Using ros2 service call in a shell script is a simple way to build an automated self-test before a robot begins real operation. For example, a script calls the self_test service on each critical node (motor driver, LiDAR, IMU) in sequence and checks that all return success: true before allowing autonomous mode. This catches nodes that failed to start properly, preventing operation with an unnoticed faulty component.

#!/bin/bash
for srv in /motor_driver/self_test /lidar_driver/self_test /imu_driver/self_test; do
  result=$(ros2 service call "$srv" std_srvs/srv/Trigger | grep -o "success=True")
  if [ -z "$result" ]; then
    echo "LỖI: $srv không sẵn sàng — huỷ chuyển chế độ tự hành"
    exit 1
  fi
done
echo "Tất cả node đã sẵn sàng — cho phép chuyển chế độ tự hành"

The script calls each self_test service in turn and continues only if every node reports success=True. Failure at any node immediately stops the process with a clear error, rather than allowing the robot to run with an unchecked, unready component. This approach also integrates easily into CI or the robot's automatic startup script as a mandatory check before entering the operational state.

Practical example

$ ros2 service call /reset_odometry std_srvs/srv/Trigger
Output:
waiting for service to become available...
requester: making request: std_srvs.srv.Trigger_Request()

response:
std_srvs.srv.Trigger_Response(success=True, message='Odometry reset thành công')

This is the fastest way to reset odometry between SLAM test runs without restarting the entire node — provided the package already offers this service.

Common mistakes

  • The command hangs indefinitely when the server is absent/unresponsive — as noted under Parameters, there is no default timeout. If response: does not appear after a long wait, check ros2 service list to see whether the service is actually running instead of waiting indefinitely.
  • YAML syntax errors in requests with nested fields — as with ros2 topic pub, use ros2 interface show first to learn the exact structure rather than guessing and causing parse errors.
  • Calling the correct service name with the wrong type — ros2 service call reports a clear error if the type differs from what the server provides. Check with ros2 service type before calling if unsure.
  • Using ros2 service call for high-frequency automation loops — every CLI call incurs process startup overhead, making it unsuitable for continuous calls at tens of Hz in an automated workflow. Write a proper client node for this instead of relying on the CLI.

Conclusion

ros2 service call removes the need for a dedicated client node just for testing — call directly from the terminal and inspect the response immediately, especially for utility services such as reset/self-test. Always remember there is no default timeout when debugging a hanging command. The next article covers ros2 action — the equivalent tool for long-running tasks with progress and cancellation.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

ros2 service — test services from the terminal — Atlas Robotics