Exemplo n.º 1
0
def replier(service_name, number_of_cycles):
    from service_fixtures import get_test_srv
    import rclpy

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

    rclpy.init(args=[])

    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)

    spin_count = 1
    print('replier: beginning loop')
    while rclpy.ok() and spin_count < number_of_cycles:
        rclpy.spin_once(node, timeout_sec=2)
        spin_count += 1
        print('spin_count: ' + str(spin_count))
    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 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()
Exemplo n.º 3
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 !')