Unit 05 · lesson

Read and Call Service Interfaces

Before calling a service with data, inspect the request/response contract.

Empty service

Run:

ros2 interface show std_srvs/srv/Empty

The official tutorial shows a separator with no request or response fields because this type carries no data.

Call the clear service:

ros2 service call /clear std_srvs/srv/Empty

If the Turtlesim window had drawn lines, they should clear.

Service with request and response data

Inspect:

ros2 interface show turtlesim/srv/Spawn

The source tutorial shows request fields above --- and the response below it:

float32 x
float32 y
float32 theta
string name
---
string name

Now call it:

ros2 service call /spawn turtlesim/srv/Spawn \
  "{x: 2, y: 2, theta: 0.2, name: 'turtle2'}"

Evidence chain

service name
  ↓ has type
service interface
  ↓ defines request/response
CLI client
  ↓ sends request
service server
  ↓ returns response

Checkpoint

Record the exact request you sent and the exact response you received. Explain which fields belonged to each side of the interface.