Main Content

Call Service

Call service in ROS 2 network

Since R2021b

  • Call Service Block ROS 2

Libraries:
ROS Toolbox / ROS 2

Description

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.

Ports

Input

expand all

Request message, specified as a nonvirtual bus. The request message type corresponds to your service type. To generate an empty request message bus to populate with data, use the Blank Message block.

Data Types: bus

Output

expand all

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.

Data Types: bus

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.

Error CodeCondition
0The service response was successfully retrieved and is available in the Resp output.
1The connection was not established within the specified Connection timeout.
2The response from the server was not received.

Dependencies

This output is enabled when the Show ErrorCode output port check box is on.

Data Types: uint8

Parameters

expand all

Main

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.

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 network, see ros2.

Service type, specified as a character vector. Each service name has a corresponding type.

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 1.

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.

Quality of Service (QoS)

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 Keep all, the queue stores all requests up to the MATLAB resource limits.

Number of requests stored in the request queue when History is set to Keep last.

Affects the guarantee of request delivery. If Reliable, then delivery is guaranteed, but may retry multiple times. If Best effort, then attempt delivery and do not retry. Reliable setting is recommended for services.

Affects persistence of requests, which allows late-starting servers to receive the number of old requests specified by Depth. If Volatile, then requests do not persist. If Transient local, then the block will persist most recent requests.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2021b