rclpy.service module

class rclpy.service.Service(service_impl: rpyutils.import_c_library.Service.(~SrvRequestT, ~SrvResponseT), srv_type: ~typing.Type[~rclpy.type_support.Srv[~rclpy.type_support.SrvRequestT, ~rclpy.type_support.SrvResponseT]], srv_name: str, callback: ~typing.Callable[[~rclpy.type_support.SrvRequestT, ~rclpy.type_support.SrvResponseT], ~rclpy.type_support.SrvResponseT], callback_group: ~rclpy.callback_groups.CallbackGroup, qos_profile: rclpy.qos.QoSProfile)

Bases: Generic[SrvRequestT, SrvResponseT]

Create a container for a ROS service server.

Warning

Users should not create a service server with this constructor, instead they should call Node.create_service().

Parameters:
  • service_impl_rclpy.Service wrapping the underlying rcl_service_t object.

  • srv_type – The service type.

  • srv_name – The name of the service.

  • callback – The callback that should be called to handle the request.

  • callback_group – The callback group for the service server. If None, then the nodes default callback group is used.

  • qos_profile – The quality of service profile to apply the service server.

configure_introspection(clock: rclpy.clock.Clock, service_event_qos_profile: rclpy.qos.QoSProfile, introspection_state: rpyutils.import_c_library.service_introspection.ServiceIntrospectionState) None

Configure service 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 server.

Warning

Users should not destroy a service server with this destructor, instead they should call Node.destroy_service().

property handle: rpyutils.import_c_library.Service.(~SrvRequestT, ~SrvResponseT)
send_response(response: SrvResponseT, header: rpyutils.import_c_library.rmw_service_info_t | rpyutils.import_c_library.rmw_request_id_t) None

Send a service response.

Parameters:
  • response – The service response.

  • header – Service header from the original request.

Raises:

TypeError if the type of the passed response isn’t an instance of the Response type of the provided service when the service was constructed.

property service_name: str