Call service in ROS 2 network
ROS Toolbox / ROS 2
The Call Service block takes a ROS 2 service request message, sends it to
the ROS 2 service server, and waits for a response. A ROS 2 service server should be set up
somewhere on the network before using this block. Check the available services on a ROS 2
network by executing
ros2 service list command, which uses
ros2 function. Use
ros2svcserver to set
up a service server in MATLAB®.
Specify the name for your ROS 2 service and the service type in the block mask. If connected to a ROS 2 network, you can select from a list of available services. You can create a blank service request or response message to populate with data using the Blank Message block.
Always specify the quality of service (QoS) parameters in the block mask. QoS parameters for this block must be compatible with the service server to send requests and receive responses.
Resp — Response message
Response message, returned as a nonvirtual bus. The response is based on the input Req message. The response message type corresponds to your service type. To generate an empty response message bus to populate with data, use the Blank Message block.
ErrorCode — Error conditions for service call
Error conditions for service call, specified as an integer. Each integer corresponds to a different error condition for the service connection or the status of the service call. If an error condition occurs, Resp outputs the last response message or a blank message if a response was not previously received.
|The service response was successfully retrieved and is available in the
|The connection was not established within the specified
|The response from the server was not received.|
This output is enabled when the Show ErrorCode output port
check box is
Source — Source for specifying service name
Select from ROS network |
Specify your own
Source for specifying the service name:
Select from ROS network— Use Select to select a service name. The Name and Type parameters are set automatically. You must be connected to a ROS 2 network.
Specify your own— Enter a service name in Name and specify its service type in Type. You must match a service name exactly.
Name — Service name
Service name, specified as a character vector. The service name must match a service
name available on the ROS service server. To see a list of valid services in a ROS 2
Type — Service type
Service type, specified as a character vector. Each service name has a corresponding type.
Connection timeout — Timeout for service server connection
5 (default) | positive numeric scalar
Timeout for service server connection, specified as a positive numeric scalar in
seconds. If a connection cannot be established with the ROS service server in this time,
then ErrorCode outputs
Show ErrorCode output port — Enable error code output port
on (default) |
Check this box to output the ErrorCode output. If an error condition occurs, Resp outputs the last response message or a blank message if response was not previously received.
History — Mode of storing requests in the queue
Keep last (default) |
Determines the mode of storing requests in the queue. If the queue fills with
requests waiting to be processed, then old requests will be dropped to make room for
new. If set to
Keep last, the queue stores the number of
requests set by the
Depth parameter. If set to
all, the queue stores all requests up to the MATLAB resource limits.
Depth — Size of the request queue
1 (default) | positive scalar
Number of requests stored in the request queue when
Reliability — Delivery guarantee of requests
Reliable (default) |
Affects the guarantee of request delivery. If
delivery is guaranteed, but may retry multiple times. If
effort, then attempt delivery and do not retry.
Reliable setting is recommended for services.
Durability — Persistence of requests
Volatile (default) |
Affects persistence of requests, which allows late-starting servers to receive the
number of old requests specified by
Volatile, then requests do not persist. If
Transient local, then the block will persist most recent