def destroy_subscription(self, subscription: Subscription) -> bool: """ Destroy a subscription created by the node. :return: ``True`` if succesful, ``False`` otherwise. """ if subscription in self.__subscriptions: self.__subscriptions.remove(subscription) try: subscription.destroy() except InvalidHandle: return False return True return False
def create_subscription(self, msg_type, topic, callback, *, qos_profile=qos_profile_default, callback_group=None): 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: [subscription_handle, subscription_pointer] = _rclpy.rclpy_create_subscription( self.handle, msg_type, topic, qos_profile.get_c_qos_profile()) except ValueError: failed = True if failed: self._validate_topic_or_service_name(topic) subscription = Subscription(subscription_handle, subscription_pointer, msg_type, topic, callback, callback_group, qos_profile, self.handle) self.subscriptions.append(subscription) callback_group.add_entity(subscription) return subscription
def create_subscription(self, msg_type, topic, callback, qos_profile=qos_profile_default): # this line imports the typesupport for the message module if not already done if msg_type.__class__._TYPE_SUPPORT is None: msg_type.__class__.__import_type_support__() if msg_type.__class__._TYPE_SUPPORT is None: raise NoTypeSupportImportedException [subscription_handle, subscription_pointer] = _rclpy.rclpy_create_subscription( self.handle, msg_type, topic, qos_profile.get_c_qos_profile()) subscription = Subscription( subscription_handle, subscription_pointer, msg_type, topic, callback, qos_profile, self.handle) self.subscriptions.append(subscription) return subscription
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