Call Service
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.
Examples
Call ROS 2 Service in Simulink
Call a service on the ROS 2 network in Simulink® using the Call Service block and receive a response.
Call and Provide ROS 2 Services
Set up service servers to advertise a service to the ROS network. In addition, you will learn how to use service clients to call the server and receive a response.
Ports
Input
Req — Request message
nonvirtual bus
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
Resp — Response message
nonvirtual bus
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
ErrorCode — Error conditions for service call
integer
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 Code | Condition |
---|---|
0 | The service response was successfully retrieved and is available in the
Resp output. |
1 | The connection was not established within the specified
Connection timeout . |
2 | The 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
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
character vector
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
.
Type — Service type
character vector
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 1
.
Show ErrorCode output port — Enable error code output port
on
(default) | off
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) | Keep all
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.
Depth — Size of the request queue
1
(default) | positive scalar
Number of requests stored in the request queue when History
is
set to Keep last
.
Reliability — Delivery guarantee of requests
Reliable
(default) | Best effort
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.
Durability — Persistence of requests
Volatile
(default) | Transient local
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.
Deadline — Maximum amount of time allowed between sending service request and receiving response
Inf
(default) | positive scalar
Maximum amount of time allowed between sending a service request and receiving a
response, specified as a positive scalar. The Deadline
QoS
parameter of service servers receiving request from the block must be less than or equal
to the value of this parameter.
The default value is Inf
which implies that after the service
client sends a request, it can wait for an infinite period of time before receiving
response to that request.
Note
The quality of service settings must be compatible between service servers and clients for a connection to be made.
Lifespan — Length of time a service request is considered valid
Inf
(default) | positive scalar
Length of time a service request is considered valid, specified as a positive scalar. This value determines the time for which the service requests sent are stored in the queue.
The default value is Inf
which implies that a service request
sent by service client is considered valid for infinite period of time.
Note
The quality of service settings must be compatible between service servers and clients for a connection to be made.
Liveliness — Level of liveliness reporting provided by the block and expected from service server
automatic
(default)
Level of liveliness reporting provided by the block and expected from the connected
service server, specified as automatic
.
Liveliness set to automatic
implies that after the block
receives a service response from the connected server, the block considers that server
to be alive for another Lease Duration
.
Note
The quality of service settings must be compatible between service servers and clients for a connection to be made.
Lease Duration — Maximum amount of time before which connected service server has to assert liveliness
Inf
(default) | positive scalar
Maximum amount of time before which the connected service server has to assert liveliness, specified as a positive scalar.
The default value is Inf
which implies that the service server
connected to the client can assert liveliness for infinite period of time.
Note
The quality of service settings must be compatible between service servers and clients for a connection to be made.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2021b
See Also
Blocks
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)