Пример #1
0
def main(argv=sys.argv[1:]):
    # Get parameters from launch file
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-name", "--robot_name")
    parser.add_argument("-p", "--server_port")
    parser.add_argument("-key", "--encryption_key")
    parser.add_argument("-usename", "--use_name")
    parser.add_argument("-encrypt", "--use_encryption")
    args = parser.parse_args(remove_ros_args(args=argv))

    # Initialize rclpy and create node object
    rclpy.init(args=argv)
    server_node = ServerNode(
        args.robot_name,
        args.server_port,
        args.encryption_key,
        args.use_name,
        args.use_encryption,
    )

    # Spin the node
    rclpy.spin(server_node)

    try:
        server_node.destroy_node()
        rclpy.shutdown()
    except Exception as e:
        self.error_msg("Error:", e, "|rclpy shutdown failed")
Пример #2
0
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--reliable',
                        dest='reliable',
                        action='store_true',
                        help='set qos profile to reliable')
    parser.set_defaults(reliable=False)
    parser.add_argument('-n',
                        '--number_of_cycles',
                        type=int,
                        default=20,
                        help='max number of spin_once iterations')
    args = parser.parse_args(remove_ros_args(args=argv))

    rclpy.init(args=argv)

    if args.reliable:
        custom_qos_profile = QoSProfile(depth=10,
                                        reliability=QoSReliabilityPolicy.
                                        RMW_QOS_POLICY_RELIABILITY_RELIABLE)
    else:
        custom_qos_profile = qos_profile_sensor_data

    node = ListenerQos(custom_qos_profile)

    cycle_count = 0
    while rclpy.ok() and cycle_count < args.number_of_cycles:
        rclpy.spin_once(node)
        cycle_count += 1

    node.destroy_node()
    rclpy.shutdown()
Пример #3
0
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        description='Apply a Python operation to a topic.\n\n'
        'A node is created that subscribes to a topic,\n'
        'applies a Python expression to the topic (or topic\n'
        'field) message \"m\", and publishes the result\n'
        'through another topic.\n\n'
        'Usage:\n\tros2 run topic_tools transform '
        '<input topic> <output topic> <output type> '
        '[<expression on m>] [--import numpy tf] [--field <topic_field>]\n\n'
        'Example:\n\tros2 run topic_tools transform /imu --field orientation '
        '/norm std_msgs/Float64'
        '\"std_msgs.msg.Float64(data=sqrt(sum(array([m.x, m.y, m.z, m.w]))))\"'
        ' --import std_msgs')
    parser.add_argument('input', help='Input topic or topic field.')
    parser.add_argument('output_topic', help='Output topic.')
    parser.add_argument('output_type', help='Output topic type.')
    parser.add_argument(
        'expression',
        default='m',
        help='Python expression to apply on the input message \"m\".')
    parser.add_argument('-i',
                        '--import',
                        dest='modules',
                        nargs='+',
                        default=['numpy'],
                        help='List of Python modules to import.')
    parser.add_argument('--wait-for-start',
                        action='store_true',
                        help='Wait for input messages.')
    parser.add_argument(
        '--qos-profile',
        choices=rclpy.qos.QoSPresetProfiles.short_keys(),
        help=
        'Quality of service preset profile to subscribe with (default: sensor_data)'
    )
    default_profile = rclpy.qos.QoSPresetProfiles.get_from_short_key(
        'sensor_data')
    parser.add_argument('--qos-depth',
                        metavar='N',
                        type=int,
                        help='Queue size setting to subscribe with '
                        '(overrides depth value of --qos-profile option)')
    parser.add_argument(
        '--qos-history',
        choices=rclpy.qos.QoSHistoryPolicy.short_keys(),
        help='History of samples setting to subscribe with '
        '(overrides history value of --qos-profile option, default: {})'.
        format(default_profile.history.short_key))
    parser.add_argument(
        '--qos-reliability',
        choices=rclpy.qos.QoSReliabilityPolicy.short_keys(),
        help='Quality of service reliability setting to subscribe with '
        '(overrides reliability value of --qos-profile option, default: '
        'Automatically match existing publishers )')
    parser.add_argument(
        '--qos-durability',
        choices=rclpy.qos.QoSDurabilityPolicy.short_keys(),
        help='Quality of service durability setting to subscribe with '
        '(overrides durability value of --qos-profile option, default: '
        'Automatically match existing publishers )')
    parser.add_argument(
        '--field',
        type=str,
        default=None,
        help='Transform a selected field of a message. '
        "Use '.' to select sub-fields. "
        'For example, to transform the orientation x field of a sensor_msgs/msg/Imu message: '
        "'ros2 run topic_tools transform /imu --field orientatin.x'",
    )
    args = parser.parse_args(remove_ros_args(args=argv))
    rclpy.init(args=argv)

    node = Transform(args)
    try:
        rclpy.spin(node)
    except KeyboardInterrupt:
        print('transform stopped cleanly')
    except BaseException:
        print('exception in transform:', file=sys.stderr)
        raise
    finally:
        node.destroy_node()
        rclpy.shutdown()
def parse_arguments(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('message_type',
                        type=get_message,
                        help='Message type for the repeater to publish.')
    return parser.parse_args(args=remove_ros_args(args))