コード例 #1
0
    def create_publisher(
            self,
            msg_type,
            topic: str,
            *,
            qos_profile: QoSProfile = qos_profile_default) -> Publisher:
        """
        Create a new publisher.

        :param msg_type: The type of ROS messages the publisher will publish.
        :param topic: The name of the topic the publisher will publish to.
        :param qos_profile: The quality of service profile to apply to the publisher.
        :return: The new publisher.
        """
        # this line imports the typesupport for the message module if not already done
        check_for_type_support(msg_type)
        failed = False
        try:
            with self.handle as node_capsule:
                publisher_capsule = _rclpy.rclpy_create_publisher(
                    node_capsule, msg_type, topic,
                    qos_profile.get_c_qos_profile())
        except ValueError:
            failed = True
        if failed:
            self._validate_topic_or_service_name(topic)

        publisher_handle = Handle(publisher_capsule)
        publisher_handle.requires(self.handle)

        publisher = Publisher(publisher_handle, msg_type, topic, qos_profile)
        self.__publishers.append(publisher)
        return publisher
コード例 #2
0
ファイル: node.py プロジェクト: vinnamkim/rclpy
    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 create_subscription(self,
                            msg_type,
                            topic: str,
                            callback: Callable[[MsgType], None],
                            *,
                            qos_profile: QoSProfile = qos_profile_default,
                            callback_group: CallbackGroup = None,
                            raw: bool = False) -> Subscription:
        """
        Create a new subscription.

        :param msg_type: The type of ROS messages the subscription will subscribe to.
        :param topic: The name of the topic the subscription will subscribe to.
        :param callback: A user-defined callback function that is called when a message is
            received by the subscription.
        :param qos_profile: The quality of service profile to apply to the subscription.
        :param callback_group: The callback group for the subscription. If ``None``, then the
            nodes default callback group is used.
        :param raw: If ``True``, then received messages will be stored in raw binary
            representation.
        """
        if callback_group is None:
            callback_group = self.default_callback_group
        # this line imports the typesupport for the message module if not already done
        check_for_type_support(msg_type)
        failed = False
        try:
            with self.handle as capsule:
                subscription_capsule = _rclpy.rclpy_create_subscription(
                    capsule, msg_type, topic, qos_profile.get_c_qos_profile())
        except ValueError:
            failed = True
        if failed:
            self._validate_topic_or_service_name(topic)

        subscription_handle = Handle(subscription_capsule)
        subscription_handle.requires(self.handle)

        subscription = Subscription(subscription_handle, msg_type, topic,
                                    callback, callback_group, qos_profile, raw)
        self.__subscriptions.append(subscription)
        callback_group.add_entity(subscription)
        return subscription
コード例 #4
0
    def create_service(self,
                       srv_type,
                       srv_name: str,
                       callback: Callable[[SrvTypeRequest, SrvTypeResponse],
                                          SrvTypeResponse],
                       *,
                       qos_profile: QoSProfile = qos_profile_services_default,
                       callback_group: CallbackGroup = None) -> Service:
        """
        Create a new service server.

        :param srv_type: The service type.
        :param srv_name: The name of the service.
        :param callback: A user-defined callback function that is called when a service request
            received by the server.
        :param qos_profile: The quality of service profile to apply the service server.
        :param callback_group: The callback group for the service server. 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:
            with self.handle as node_capsule:
                service_capsule = _rclpy.rclpy_create_service(
                    node_capsule, 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)

        service_handle = Handle(service_capsule)
        service_handle.requires(self.handle)

        service = Service(service_handle, srv_type, srv_name, callback,
                          callback_group, qos_profile)
        self.__services.append(service)
        callback_group.add_entity(service)
        return service