def _rostopic_bw(node, topic, window_size=DEFAULT_WINDOW_SIZE): """Periodically print the received bandwidth of a topic to console until shutdown.""" # pause bw until topic is published msg_class = get_msg_class(node, topic, blocking=True, include_hidden_topics=True) if msg_class is None: node.destroy_node() return rt = ROSTopicBandwidth(node, window_size) node.create_subscription(msg_class, topic, rt.callback, qos_profile_sensor_data, raw=True) print(f'Subscribed to [{topic}]') timer = node.create_timer(1, rt.print_bw) while rclpy.ok(): rclpy.spin_once(node) node.destroy_timer(timer) node.destroy_node() rclpy.shutdown()
def main(args): if not args.csv: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb(truncate_length, args.no_arr, args.no_str) else: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb_csv(truncate_length, args.no_arr, args.no_str) qos_profile = qos_profile_from_short_keys(args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability, depth=args.qos_depth, history=args.qos_history) with NodeStrategy(args) as node: if args.message_type is None: message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True) else: message_type = get_message(args.message_type) if message_type is None: raise RuntimeError( 'Could not determine the type for the passed topic') future = None if args.once: future = Future() callback = subscriber_cb_once_decorator(callback, future) subscriber(node, args.topic_name, message_type, callback, qos_profile, args.lost_messages, future, args.timeout)
def _rostopic_delay(node, topic, window_size=DEFAULT_WINDOW_SIZE): """ Periodically print the publishing delay of a topic to console until shutdown. :param topic: topic name, ``str`` :param window_size: number of messages to average over, ``unsigned_int`` :param blocking: pause delay until topic is published, ``bool`` """ # pause hz until topic is published msg_class = get_msg_class(node, topic, blocking=True, include_hidden_topics=True) if msg_class is None: node.destroy_node() return rt = ROSTopicDelay(node, window_size) node.create_subscription(msg_class, topic, rt.callback_delay, qos_profile_sensor_data) timer = node.create_timer(1, rt.print_delay) while rclpy.ok(): rclpy.spin_once(node) node.destroy_timer(timer) node.destroy_node() rclpy.shutdown()
def main(args): if not args.csv: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb(truncate_length, args.no_arr, args.no_str) else: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb_csv(truncate_length, args.no_arr, args.no_str) qos_profile = qos_profile_from_short_keys(args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability, depth=args.qos_depth, history=args.qos_history) with NodeStrategy(args) as node: if args.message_type is None: message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True) else: try: message_type = get_message(args.message_type) except (AttributeError, ModuleNotFoundError, ValueError): raise RuntimeError('The passed message type is invalid') if message_type is None: raise RuntimeError( 'Could not determine the type for the passed topic') subscriber(node, args.topic_name, message_type, callback, qos_profile, args.lost_messages, args.raw)
def _rostopic_hz(node, topic, window_size=DEFAULT_WINDOW_SIZE, filter_expr=None, use_wtime=False): """ Periodically print the publishing rate of a topic to console until shutdown. :param topic: topic name, ``list`` of ``str`` :param window_size: number of messages to average over, -1 for infinite, ``int`` :param filter_expr: Python filter expression that is called with m, the message instance """ # pause hz until topic is published msg_class = get_msg_class( node, topic, blocking=True, include_hidden_topics=True) if msg_class is None: node.destroy_node() return rt = ROSTopicHz(node, window_size, filter_expr=filter_expr, use_wtime=use_wtime) node.create_subscription( msg_class, topic, functools.partial(rt.callback_hz, topic=topic), qos_profile_sensor_data) while rclpy.ok(): rclpy.spin_once(node) rt.print_hz(topic) node.destroy_node() rclpy.shutdown()
def main(self, *, args): if args.lost_messages: print( "WARNING: '--lost-messages' is deprecated; lost messages are reported by default", file=sys.stderr) self.csv = args.csv # Validate field selection self.field = args.field if self.field is not None: self.field = list(filter(None, self.field.split('.'))) if not self.field: raise RuntimeError(f"Invalid field value '{args.field}'") self.truncate_length = args.truncate_length if not args.full_length else None self.no_arr = args.no_arr self.no_str = args.no_str self.flow_style = args.flow_style self.filter_fn = None if args.filter_expr: self.filter_fn = _expr_eval(args.filter_expr) self.future = None if args.once: self.future = Future() self.include_message_info = args.include_message_info with NodeStrategy(args) as node: qos_profile = self.choose_qos(node, args) if args.message_type is None: message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True) else: try: message_type = get_message(args.message_type) except (AttributeError, ModuleNotFoundError, ValueError): raise RuntimeError('The passed message type is invalid') if message_type is None: raise RuntimeError( 'Could not determine the type for the passed topic') self.subscribe_and_spin(node, args.topic_name, message_type, qos_profile, args.no_lost_messages, args.raw)
def main(args): if not args.csv: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb(truncate_length, args.no_arr, args.no_str) else: truncate_length = args.truncate_length if not args.full_length else None callback = subscriber_cb_csv(truncate_length, args.no_arr, args.no_str) qos_profile = qos_profile_from_short_keys( args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability) with NodeStrategy(args) as node: if args.message_type is None: message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True) else: message_type = get_message(args.message_type) subscriber( node, args.topic_name, message_type, callback, qos_profile)
def __init__(self, args): super().__init__(f'transform_{os.getpid()}') self.modules = {} for module in args.modules: try: mod = importlib.import_module(module) except ImportError: print(f'Failed to import module: {module}', file=sys.stderr) else: self.modules[module] = mod self.expression = args.expression input_topic_in_ns = args.input if not input_topic_in_ns.startswith('/'): input_topic_in_ns = self.get_namespace() + args.input input_class = get_msg_class(self, input_topic_in_ns, blocking=args.wait_for_start, include_hidden_topics=True) if input_class is None: raise RuntimeError( f'ERROR: Wrong input topic: {input_topic_in_ns}') self.field = args.field if self.field is not None: self.field = list(filter(None, self.field.split('.'))) if not self.field: raise RuntimeError(f"Invalid field value '{args.field}'") self.output_class = get_message(args.output_type) qos_profile = self.choose_qos(args, input_topic_in_ns) self.pub = self.create_publisher(self.output_class, args.output_topic, qos_profile) self.sub = self.create_subscription(input_class, input_topic_in_ns, self.callback, qos_profile)
def main(self, *, args): # Select print function self.print_func = _print_yaml if args.csv: self.print_func = _print_csv # Validate field selection self.field = args.field if self.field is not None: self.field = list(filter(None, self.field.split('.'))) if not self.field: raise RuntimeError(f"Invalid field value '{args.field}'") self.truncate_length = args.truncate_length if not args.full_length else None self.no_arr = args.no_arr self.no_str = args.no_str qos_profile = qos_profile_from_short_keys( args.qos_profile, reliability=args.qos_reliability, durability=args.qos_durability, depth=args.qos_depth, history=args.qos_history) with NodeStrategy(args) as node: if args.message_type is None: message_type = get_msg_class(node, args.topic_name, include_hidden_topics=True) else: try: message_type = get_message(args.message_type) except (AttributeError, ModuleNotFoundError, ValueError): raise RuntimeError('The passed message type is invalid') if message_type is None: raise RuntimeError( 'Could not determine the type for the passed topic') self.subscribe_and_spin(node, args.topic_name, message_type, qos_profile, args.lost_messages, args.raw)