Пример #1
0
    def destroy_client(self, client: Client) -> bool:
        """
        Destroy a service client created by the node.

        :return: ``True`` if successful, ``False`` otherwise.
        """
        if client in self.__clients:
            self.__clients.remove(client)
            try:
                client.destroy()
            except InvalidHandle:
                return False
            return True
        return False
Пример #2
0
    def create_client(self,
                      srv_type,
                      srv_name: str,
                      *,
                      qos_profile: QoSProfile = qos_profile_services_default,
                      callback_group: CallbackGroup = None) -> Client:
        """
        Create a new service client.

        :param srv_type: The service type.
        :param srv_name: The name of the service.
        :param qos_profile: The quality of service profile to apply the service client.
        :param callback_group: The callback group for the service client. If ``None``, then the
            nodes default callback group is used.
        """
        if callback_group is None:
            callback_group = self.default_callback_group
        check_for_type_support(srv_type)
        failed = False
        try:
            [client_handle, client_pointer
             ] = _rclpy.rclpy_create_client(self.handle, srv_type, srv_name,
                                            qos_profile.get_c_qos_profile())
        except ValueError:
            failed = True
        if failed:
            self._validate_topic_or_service_name(srv_name, is_service=True)
        client = Client(self.handle, self.context, client_handle,
                        client_pointer, srv_type, srv_name, qos_profile,
                        callback_group)
        self.clients.append(client)
        callback_group.add_entity(client)
        return client
Пример #3
0
def wait_for_service(
    node: Node, client: Client, timeout: Optional[float] = SERVICE_TIMEOUT
):
    """
    Wait for a service to become available.

    :param node: Node to use for logging
    :param client: Client of the service.
    :param timeout: Optional timeout to wait before logging again
    """
    while not client.wait_for_service(timeout_sec=timeout):
        node.get_logger().info(f"Waiting for {client.srv_name} to become available")
Пример #4
0
 def create_client(self, srv_type, srv_name, qos_profile=qos_profile_services_default):
     if srv_type.__class__._TYPE_SUPPORT is None:
         srv_type.__class__.__import_type_support__()
     if srv_type.__class__._TYPE_SUPPORT is None:
         raise NoTypeSupportImportedException
     [client_handle, client_pointer] = _rclpy.rclpy_create_client(
         self.handle,
         srv_type,
         srv_name,
         qos_profile.get_c_qos_profile())
     client = Client(
         self.handle, client_handle, client_pointer, srv_type, srv_name, qos_profile)
     self.clients.append(client)
     return client
Пример #5
0
 def create_client(self,
                   srv_type,
                   srv_name,
                   *,
                   qos_profile=qos_profile_services_default,
                   callback_group=None):
     if callback_group is None:
         callback_group = self._default_callback_group
     check_for_type_support(srv_type)
     failed = False
     try:
         [client_handle, client_pointer
          ] = _rclpy.rclpy_create_client(self.handle, srv_type, srv_name,
                                         qos_profile.get_c_qos_profile())
     except ValueError:
         failed = True
     if failed:
         self._validate_topic_or_service_name(srv_name, is_service=True)
     client = Client(self.handle, client_handle, client_pointer, srv_type,
                     srv_name, qos_profile, callback_group)
     self.clients.append(client)
     callback_group.add_entity(client)
     return client