예제 #1
0
def talker(message_name, number_of_cycles):
    from message_fixtures import get_test_msg
    import rclpy
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from rclpy.qos import qos_profile_default

    message_pkg = 'test_communication'
    module = importlib.import_module(message_pkg + '.msg')
    msg_mod = getattr(module, message_name)

    select_rmw_implementation(os.environ['RCLPY_IMPLEMENTATION'])

    rclpy.init([])

    node = rclpy.create_node('talker')

    chatter_pub = node.create_publisher(msg_mod,
                                        'test_message_' + message_name,
                                        qos_profile_default)

    cycle_count = 0
    print('talker: beginning loop')
    msgs = get_test_msg(message_name)
    while rclpy.ok() and cycle_count < number_of_cycles:
        cycle_count += 1
        msg_count = 0
        for msg in msgs:
            chatter_pub.publish(msg)
            msg_count += 1
            print('publishing message #%d' % msg_count)
        time.sleep(1)
    rclpy.shutdown()
예제 #2
0
def replier(service_name, number_of_cycles):
    from service_fixtures import get_test_srv
    import rclpy
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from rclpy.qos import qos_profile_services_default

    service_pkg = 'test_communication'
    module = importlib.import_module(service_pkg + '.srv')
    srv_mod = getattr(module, service_name)

    select_rmw_implementation(os.environ['RCLPY_IMPLEMENTATION'])

    rclpy.init([])

    node = rclpy.create_node('replier')

    srv_fixtures = get_test_srv(service_name)

    chatter_callback = functools.partial(
        replier_callback, srv_fixtures=srv_fixtures)

    node.create_service(
        srv_mod, 'test_service_' + service_name, chatter_callback,
        qos_profile_services_default)

    spin_count = 1
    print('replier: beginning loop')
    while rclpy.ok() and spin_count < number_of_cycles:
        rclpy.spin_once(node, 2)
        spin_count += 1
        print('spin_count: ' + str(spin_count))
    rclpy.shutdown()
예제 #3
0
def talker(message_name, rmw_implementation, number_of_cycles):
    import rclpy
    from rclpy.qos import qos_profile_default
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from message_fixtures import get_test_msg

    message_pkg = 'test_communication'
    module = importlib.import_module(message_pkg + '.msg')
    msg_mod = getattr(module, message_name)

    select_rmw_implementation(rmw_implementation)

    rclpy.init([])

    node = rclpy.create_node('talker')

    chatter_pub = node.create_publisher(
        msg_mod, 'test_message_' + message_name, qos_profile_default)

    cycle_count = 0
    print('talker: beginning loop')
    msgs = get_test_msg(message_name)
    while rclpy.ok() and cycle_count < number_of_cycles:
        cycle_count += 1
        msg_count = 0
        for msg in msgs:
            chatter_pub.publish(msg)
            msg_count += 1
            print('publishing message #%d' % msg_count)
            time.sleep(0.1)
        time.sleep(1)
    rclpy.shutdown()
예제 #4
0
def func_import_each_available_rmw_implementation(rmw_implementation):
    import rclpy
    from rclpy.impl.rmw_implementation_tools import get_rmw_implementations
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation

    rmw_implementations = get_rmw_implementations()
    assert(rmw_implementation in rmw_implementations)

    select_rmw_implementation(rmw_implementation)
    rclpy.init([])

    set_rmw = rclpy.get_rmw_implementation_identifier()

    assert set_rmw == rmw_implementation, \
        "expected '{0}' but got '{1}'".format(
            rmw_implementation, set_rmw)
    return ctypes.c_bool(True)
예제 #5
0
def init(args=None):
    rclpy_rmw_env = os.getenv(RCLPY_IMPLEMENTATION_ENV_NAME, None)
    if rclpy_rmw_env is not None:
        available_rmw_implementations = rmw_implementation_tools.get_rmw_implementations(
        )
        if rclpy_rmw_env not in available_rmw_implementations:
            logger = logging.getLogger('rclpy')
            logger.error(
                "The rmw implementation specified in 'RCLPY_IMPLEMENTATION={0}', "
                "is not one of the available implementations: {1}".format(
                    rclpy_rmw_env, available_rmw_implementations))
            raise InvalidRCLPYImplementation()
        rmw_implementation_tools.select_rmw_implementation(rclpy_rmw_env)
    # This line changes what is in "_rclpy" to be the rmw implementation module that was imported.
    implementation_singleton.set_rclpy_implementation(
        rmw_implementation_tools.import_rmw_implementation())

    # Now we can use _rclpy to call the implementation specific rclpy_init().
    return _rclpy.rclpy_init(args if args is not None else sys.argv)
예제 #6
0
파일: __init__.py 프로젝트: erlerobot/rclpy
def init(args=None):
    rclpy_rmw_env = os.getenv('RCLPY_IMPLEMENTATION', None)
    if rclpy_rmw_env is not None:
        available_rmw_implementations = rmw_implementation_tools.get_rmw_implementations()
        if rclpy_rmw_env not in available_rmw_implementations:
            logger = logging.getLogger('rclpy')
            logger.error(
                "The rmw implementation specified in 'RCLPY_IMPLEMENTATION={0}', "
                "is not one of the available implementations: {1}"
                .format(rclpy_rmw_env, available_rmw_implementations)
            )
            raise InvalidRCLPYImplementation()
        rmw_implementation_tools.select_rmw_implementation(rclpy_rmw_env)
    # This line changes what is in "_rclpy" to be the rmw implementation module that was imported.
    implementation_singleton.set_rclpy_implementation(
        rmw_implementation_tools.import_rmw_implementation()
    )

    # Now we can use _rclpy to call the implementation specific rclpy_init().
    return _rclpy.rclpy_init(args if args is not None else sys.argv)
def func_import_each_available_rmw_implementation(rmw_implementation):
    import rclpy
    from rclpy.impl.rmw_implementation_tools import get_rmw_implementations
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation

    rmw_implementations = get_rmw_implementations()
    assert(rmw_implementation in rmw_implementations)

    select_rmw_implementation(rmw_implementation)
    rclpy.init([])

    set_rmw = rclpy.get_rmw_implementation_identifier()

    assert set_rmw in identifiers_map, \
        "expected identifier '{0}' to be in the map '{1}'".format(set_rmw, identifiers_map)

    set_rmw_equivalent = identifiers_map[set_rmw]
    assert set_rmw_equivalent == rmw_implementation, \
        "expected '{0}' but got '{1}' (aka '{2}')".format(
            rmw_implementation, set_rmw_equivalent, set_rmw)
    return ctypes.c_bool(True)
예제 #8
0
def requester(service_name, number_of_cycles):
    from service_fixtures import get_test_srv
    import rclpy
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from rclpy.qos import qos_profile_services_default

    service_pkg = 'test_communication'
    module = importlib.import_module(service_pkg + '.srv')
    srv_mod = getattr(module, service_name)

    select_rmw_implementation(os.environ['RCLPY_IMPLEMENTATION'])

    rclpy.init([])

    node = rclpy.create_node('requester')

    srv_fixtures = get_test_srv(service_name)

    client = node.create_client(srv_mod, 'test_service_' + service_name,
                                qos_profile_services_default)

    spin_count = 1
    received_replies = []
    print('requester: beginning loop')
    while rclpy.ok() and spin_count < number_of_cycles:
        for req, resp in srv_fixtures:
            client.call(req)
            client.wait_for_future()
            assert repr(client.response) == repr(resp), \
                'received unexpected response %r\n\nwas expecting %r' % (client.response, resp)
            print('received reply #%d of %d' %
                  (srv_fixtures.index([req, resp]) + 1, len(srv_fixtures)))
            received_replies.append(resp)
            spin_count += 1
            print('spin_count: ' + str(spin_count))
        break
    rclpy.shutdown()
    assert len(received_replies) == len(srv_fixtures), \
        'Should have received %d responsed from replier' % len(srv_fixtures)
    print('everything went well !')
예제 #9
0
def listener(message_name, number_of_cycles):
    from message_fixtures import get_test_msg
    import rclpy
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from rclpy.qos import qos_profile_default

    message_pkg = 'test_communication'
    module = importlib.import_module(message_pkg + '.msg')
    msg_mod = getattr(module, message_name)

    select_rmw_implementation(os.environ['RCLPY_IMPLEMENTATION'])

    rclpy.init([])

    node = rclpy.create_node('listener')

    received_messages = []
    expected_msgs = get_test_msg(message_name)

    chatter_callback = functools.partial(listener_cb,
                                         received_messages=received_messages,
                                         expected_msgs=expected_msgs)

    node.create_subscription(msg_mod, 'test_message_' + message_name,
                             chatter_callback, qos_profile_default)

    spin_count = 1
    print('subscriber: beginning loop')
    while (rclpy.ok() and spin_count < number_of_cycles
           and len(received_messages) != len(expected_msgs)):
        rclpy.spin_once(node)
        spin_count += 1
        print('spin_count: ' + str(spin_count))
    rclpy.shutdown()

    assert len(received_messages) == len(expected_msgs),\
        'Should have received {} {} messages from talker'.format(len(expected_msgs), message_name)
예제 #10
0
def listener(message_name, rmw_implementation, number_of_cycles):
    import rclpy
    from rclpy.qos import qos_profile_default
    from rclpy.impl.rmw_implementation_tools import select_rmw_implementation
    from message_fixtures import get_test_msg

    message_pkg = 'test_communication'
    module = importlib.import_module(message_pkg + '.msg')
    msg_mod = getattr(module, message_name)

    select_rmw_implementation(rmw_implementation)

    rclpy.init([])

    node = rclpy.create_node('listener')

    received_messages = []
    expected_msgs = get_test_msg(message_name)

    chatter_callback = functools.partial(
        listener_cb, received_messages=received_messages, expected_msgs=expected_msgs)

    node.create_subscription(
        msg_mod, 'test_message_' + message_name, chatter_callback,
        qos_profile_default)

    spin_count = 1
    print('subscriber: beginning loop')
    while (rclpy.ok() and spin_count < number_of_cycles and
           len(received_messages) != len(expected_msgs)):
        rclpy.spin_once(node)
        spin_count += 1
    rclpy.shutdown()

    assert len(received_messages) == len(expected_msgs),\
        'Should have received {} {} messages from talker'.format(len(expected_msgs), message_name)