rclpy.client module
- class rclpy.client.Client(context: Context, client_impl: rpyutils.import_c_library.Client, srv_type: Type[Srv[SrvRequestT, SrvResponseT, SrvEventT]], srv_name: str, qos_profile: rclpy.qos.QoSProfile, callback_group: CallbackGroup)
Bases:
Generic
[SrvRequestT
,SrvResponseT
,SrvEventT
]Create a container for a ROS service client.
Warning
Users should not create a service client with this constructor, instead they should call
Node.create_client()
.- Parameters:
context – The context associated with the service client.
client_impl –
_rclpy.Client
wrapping the underlyingrcl_client_t
object.srv_type – The service type.
srv_name – The name of the service.
qos_profile – The quality of service profile to apply the service client.
callback_group – The callback group for the service client. If
None
, then the nodes default callback group is used.
- call(request: SrvRequestT, timeout_sec: float | None = None) SrvResponseT | None
Make a service request and wait for the result.
Warning
Do not call this method in a callback, or a deadlock or timeout may occur.
- Parameters:
request – The service request.
timeout_sec – Seconds to wait. If
None
, then wait forever.
- Returns:
The service response, or None if timed out.
- Raises:
TypeError if the type of the passed request isn’t an instance of the Request type of the provided service when the client was constructed.
- call_async(request: SrvRequestT) Future[SrvResponseT]
Make a service request and asynchronously get the result.
- Parameters:
request – The service request.
- Returns:
A future that completes when the request does.
- Raises:
TypeError if the type of the passed request isn’t an instance of the Request type of the provided service when the client was constructed.
- configure_introspection(clock: rclpy.clock.Clock, service_event_qos_profile: rclpy.qos.QoSProfile, introspection_state: rpyutils.import_c_library.service_introspection.ServiceIntrospectionState) None
Configure client introspection.
- Parameters:
clock – Clock to use for generating timestamps.
service_event_qos_profile – QoSProfile to use when creating service event publisher.
introspection_state – ServiceIntrospectionState to set introspection.
- destroy() None
Destroy a container for a ROS service client.
Warning
Users should not destroy a service client with this destructor, instead they should call
Node.destroy_client()
.
- get_pending_request(sequence_number: int) Future[SrvResponseT]
Get a future from the list of pending requests.
- Parameters:
sequence_number – Number identifying the pending request.
- Returns:
The future corresponding to the sequence_number.
- Raises:
KeyError if the sequence_number is not in the pending requests.
- property handle
- remove_pending_request(future: Future[SrvResponseT]) None
Remove a future from the list of pending requests.
This prevents a future from receiving a response and executing its done callbacks.
- Parameters:
future – A future returned from
call_async()
- service_is_ready() bool
Check if there is a service server ready.
- Returns:
True
if a server is ready,False
otherwise.
- property service_name: str
- wait_for_service(timeout_sec: float | None = None) bool
Wait for a service server to become ready.
Returns as soon as a server becomes ready or if the timeout expires.
- Parameters:
timeout_sec – Seconds to wait. If
None
, then wait forever.- Returns:
True
if server became ready while waiting orFalse
on a timeout.