def subscriber(node: Node, topic_name: str, message_type: MsgType, callback: Callable[[MsgType], Any], qos_profile: QoSProfile) -> Optional[str]: """Initialize a node with a single subscription and spin.""" if message_type is None: topic_names_and_types = get_topic_names_and_types( node=node, include_hidden_topics=True) try: expanded_name = expand_topic_name(topic_name, node.get_name(), node.get_namespace()) except ValueError as e: raise RuntimeError(e) try: validate_full_topic_name(expanded_name) except rclpy.exceptions.InvalidTopicNameException as e: raise RuntimeError(e) for n, t in topic_names_and_types: if n == expanded_name: if len(t) > 1: raise RuntimeError( "Cannot echo topic '%s', as it contains more than one type: [%s]" % (topic_name, ', '.join(t))) message_type = t[0] break else: raise RuntimeError( 'Could not determine the type for the passed topic') msg_module = get_message(message_type) node.create_subscription(msg_module, topic_name, callback, qos_profile) rclpy.spin(node)
def __init__(self, node: Node, full_dof=False, stamped_pose_only=False): self.node = node self._logger = get_logger() self._points = None self._time = None self._this_pnt = None self._is_full_dof = full_dof self._stamped_pose_only = stamped_pose_only self._wp_interp_on = False self._wp_interp = WPTrajectoryGenerator( node.get_namespace(), full_dof=full_dof, stamped_pose_only=stamped_pose_only) self._has_started = False self._is_finished = False