ros2svcclient
Description
Use ros2svcclient
to create a ROS 2 service client object. This
service client uses a connection to send requests to, and receive responses from, a ROS 2
service server. For more information, see Call and Provide ROS 2 Services.
Creation
Syntax
Description
creates a service client of the specified client
= ros2svcclient(node
,servicename
,servicetype
)servicetype
regardless of
whether a service server offering servicename
is available. It
attaches the client to the ROS 2 node specified by the ros2node
object, node
.
sets the rest of the properties based
on the additional options specified by one or more client
= ros2svcclient(___,Name=Value)Name=Value
pair
arguments, using the arguments from the previous syntax.
[
returns a new service request message in client
,reqmsg
]
= ros2svcclient(___)reqmsg
, using any of the
arguments from previous syntaxes. The message type of reqmsg
is
determined by the input service type. The message is initialized with default values.
You can also create the request message using ros2message
.
Properties
Object Functions
ros2message | Create ROS 2 message structures |
call | Call ROS or ROS 2 service server and receive a response |
isServerAvailable | Determine if ROS or ROS 2 service server is available |
waitForServer | Wait for ROS or ROS 2 service server to start |
Examples
Tips
ROS 2 service servers cannot communicate errors in callback execution directly to clients. In such situations, the servers only return the default response without any indication of failure. Hence, it is recommended to use try-catch blocks within the callback function, and set specific fields in the response message to communicate the success/failure of the callback execution on the server side.
Extended Capabilities
Version History
Introduced in R2021b