Service (ROS)
服务CommonROS's request-response communication pattern: a client sends a request and the server sends back a result.
A service is one of ROS's three basic communication patterns, alongside topics and actions. One node acts as the server, offering a service; other nodes act as clients, sending a request and waiting for a response, with the request and response formats declared in a .srv file. The difference from a topic is that a topic is a continuous, one-way stream of data suited to sensor readings, while a service is a single call-and-response suited to quick operations like “reset,” “open the gripper,” or “query status.” A task that takes a long time, or needs feedback partway through or the ability to be cancelled, should use an action instead.
ExampleRunning ros2 service call /reset_world std_srvs/srv/Empty from the command line resets a simulation; or a /gripper/open service can be written so that calling it once opens the gripper.
- Also called
- ROS service
- Related
- Topic (ROS) · Action (ROS Action) · Node (ROS) · Message (msg / srv / action interface) · Publish-Subscribe · Robot Operating System 2
- Sources
- ROS 2 Docs: About services
ROS 2 Tutorial: Understanding services