コード例 #1
0
def test_launch_with_coroutine():
    default_launcher = DefaultLauncher()

    launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py')
    launch_descriptor = LaunchDescriptor()
    load_launch_file(launch_file, launch_descriptor, {})

    @asyncio.coroutine
    def coroutine():
        yield from asyncio.sleep(1)
        print('one', file=sys.stderr)
        yield from asyncio.sleep(1)
        print('two', file=sys.stderr)
        yield from asyncio.sleep(1)
        print('three', file=sys.stderr)

    @asyncio.coroutine
    def coroutine2():
        yield from asyncio.sleep(1)
        print('one mississippi', file=sys.stderr)
        yield from asyncio.sleep(1)
        print('two mississippi', file=sys.stderr)
        yield from asyncio.sleep(1)
        print('three mississippi', file=sys.stderr)

    launch_descriptor.add_coroutine(
        coroutine(), name='coroutine', exit_handler=primary_exit_handler)
    # launch_descriptor.add_coroutine(coroutine2())

    print('launch', file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done', rc, file=sys.stderr)
コード例 #2
0
def test_interrupt_default_launcher():
    desc = LaunchDescriptor()
    desc.add_process(
        cmd=[sys.executable, '-c', 'import time', 'time.sleep(30)'],
        name='test_interrupt_default_launcher__python_blocking'
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(desc)

    def thread_target():
        # wait up to 10 seconds to get to the point where at least all of the
        # asyncio-subprocess coroutines have been run (the processes are still
        # not guaranteed to be running yet)
        launcher.wait_on_processes_to_spawn(10)
        if not launcher.are_processes_spawned():
            # if the processes didn't launch after 10 seconds, fail the test
            _thread.interrupt_main()
            assert False, 'launcher never reported processes launched'
        launcher.interrupt_launch()
        # now wait for the launcher to finish and error if if doesn't
        launcher.wait_on_launch_to_finish(60)
        if launcher.is_launch_running():
            # if still running fail the test
            _thread.interrupt_main()
            assert False, 'launcher failed to shutdown'

    t = threading.Thread(target=thread_target)
    t.start()

    try:
        launcher.launch()
    except KeyboardInterrupt:
        assert False, 'failed by watchdog thread, see other AssertionErrors'
    t.join()
コード例 #3
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()
    package = 'topic_monitor'
    executable = get_executable_path(package_name=package,
                                     executable_name='data_publisher')

    # Strip the logger name from the message format in favor of the shorter executable name
    os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '[{severity}] {message}'
    os.environ[
        'PYTHONUNBUFFERED'] = '1'  # force unbuffered output to get prints to sync correctly

    launch_descriptor.add_process(
        cmd=[executable, 'sensor', '--best-effort'],
        name='sensor',
    )
    launch_descriptor.add_process(
        cmd=[executable, 'critical'],
        name='critical',
    )
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #4
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()

    package = 'topic_monitor'
    executable = get_executable_path(package_name=package, executable_name='data_publisher')

    os.environ['PYTHONUNBUFFERED'] = '1'  # force unbuffered output to get prints to sync correctly

    name = 'small'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '1', '--period', '4'],
        name=name,
    )
    name = 'medium'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '50000', '--period', '4'],
        name=name,
    )
    name = 'large'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '100000', '--period', '4'],
        name=name,
    )
    name = 'xlarge'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '150000', '--period', '4'],
        name=name,
    )
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #5
0
def test_logging_long_messages():
    launch_descriptor = LaunchDescriptor()

    output_file = os.path.join(os.path.dirname(__file__), 'test_logging_long_messages')
    handler = create_handler(
        'test_logging_long_messages', launch_descriptor, output_file)
    assert handler, 'Cannot find appropriate handler for %s' % output_file

    # Set the output format to a "verbose" format that is expected by the executable output
    os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = \
        '[{severity}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})'
    executable = os.path.join(os.getcwd(), 'test_logging_long_messages')
    if os.name == 'nt':
        executable += '.exe'
    launch_descriptor.add_process(
        cmd=[executable],
        name='test_logging_long_messages',
        exit_handler=ignore_exit_handler,  # The process will automatically exit after printing.
        output_handlers=[ConsoleOutput(), handler],
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'"

    handler.check()
コード例 #6
0
def test_logging_long_messages():
    launch_descriptor = LaunchDescriptor()

    output_file = os.path.join(os.path.dirname(__file__),
                               'test_logging_long_messages')
    filtered = get_default_filtered_prefixes()
    handler = create_handler('test_logging_long_messages',
                             launch_descriptor,
                             output_file,
                             filtered_prefixes=filtered)
    assert handler, 'Cannot find appropriate handler for %s' % output_file

    executable = os.path.join(os.getcwd(), 'test_logging_long_messages')
    if os.name == 'nt':
        executable += '.exe'
    launch_descriptor.add_process(
        cmd=[executable],
        name='test_logging_long_messages',
        exit_handler=default_exit_handler,
        output_handlers=[ConsoleOutput(), handler],
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'"

    handler.check()
コード例 #7
0
def test_launch_with_coroutine():
    default_launcher = DefaultLauncher()

    launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'launch_counter.py')
    launch_descriptor = LaunchDescriptor()
    load_launch_file(launch_file, launch_descriptor, {})

    async def coroutine():
        await asyncio.sleep(1)
        print('one', file=sys.stderr)
        await asyncio.sleep(1)
        print('two', file=sys.stderr)
        await asyncio.sleep(1)
        print('three', file=sys.stderr)

    async def coroutine2():
        await asyncio.sleep(1)
        print('one mississippi', file=sys.stderr)
        await asyncio.sleep(1)
        print('two mississippi', file=sys.stderr)
        await asyncio.sleep(1)
        print('three mississippi', file=sys.stderr)

    launch_descriptor.add_coroutine(coroutine(),
                                    name='coroutine',
                                    exit_handler=primary_exit_handler)
    # launch_descriptor.add_coroutine(coroutine2())

    print('launch', file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done', rc, file=sys.stderr)
コード例 #8
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()
    executable = 'topic_monitor_data_publisher'

    name = 'small'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '1', '--period', '4'],
        name=name,
    )
    name = 'medium'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '50000', '--period', '4'],
        name=name,
    )
    name = 'large'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '100000', '--period', '4'],
        name=name,
    )
    name = 'xlarge'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '150000', '--period', '4'],
        name=name,
    )
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #9
0
def test_non_primary_return_code():
    # since Python < 3.5 on Windows does not support signaling SIGINT to the subprocesses
    # we can't expect them to shutdown cleanly, therefore we ignore this test
    if os.name == 'nt':
        return

    default_launcher = DefaultLauncher()

    async def coroutine1():
        await asyncio.sleep(1)
        print('one', file=sys.stderr)
        await asyncio.sleep(1)
        print('two', file=sys.stderr)
        return 3

    async def coroutine2():
        await asyncio.sleep(1)
        print('one mississippi', file=sys.stderr)
        return 0

    launch_descriptor = LaunchDescriptor()
    launch_descriptor.add_coroutine(coroutine1(), name='coroutine1')
    launch_descriptor.add_coroutine(
        coroutine2(), name='coroutine2', exit_handler=primary_exit_handler)

    print('launch', file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done', rc, file=sys.stderr)
    assert rc == 3, 'Expected return code is 3'
コード例 #10
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()

    package = 'topic_monitor'
    executable = get_executable_path(package_name=package,
                                     executable_name='data_publisher')

    name = 'small'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '1', '--period', '4'],
        name=name,
    )
    name = 'medium'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '50000', '--period', '4'],
        name=name,
    )
    name = 'large'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '100000', '--period', '4'],
        name=name,
    )
    name = 'xlarge'
    launch_descriptor.add_process(
        cmd=[executable, name, '--payload-size', '150000', '--period', '4'],
        name=name,
    )
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #11
0
def setup():
    global async_launcher
    default_launcher = DefaultLauncher()

    launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py')
    launch_descriptor = LaunchDescriptor()
    load_launch_file(launch_file, launch_descriptor, {})
    default_launcher.add_launch_descriptor(launch_descriptor)

    async_launcher = AsynchronousLauncher(default_launcher)
    async_launcher.start()
コード例 #12
0
ファイル: launch_depth_demo.py プロジェクト: rohbotics/demos
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()
    add_process_to_descriptor(launch_descriptor, 'small', 1)
    add_process_to_descriptor(launch_descriptor, 'small', 50)
    add_process_to_descriptor(launch_descriptor, 'large', 1)
    add_process_to_descriptor(launch_descriptor, 'large', 50)
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #13
0
ファイル: launch_depth_demo.py プロジェクト: deCourier/demos
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()
    add_process_to_descriptor(launch_descriptor, 'small', 1)
    add_process_to_descriptor(launch_descriptor, 'small', 50)
    add_process_to_descriptor(launch_descriptor, 'large', 1)
    add_process_to_descriptor(launch_descriptor, 'large', 50)
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #14
0
def launch(index):
    default_launcher = DefaultLauncher()

    async def coroutine():
        await asyncio.sleep(1)
        print('message %d' % index, file=sys.stderr)

    launch_descriptor = LaunchDescriptor()
    launch_descriptor.add_coroutine(coroutine(), name='coroutine%d' % index)

    print('launch %d' % index, file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done %d' % index, rc, file=sys.stderr)
コード例 #15
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()

    os.environ[
        'PYTHONUNBUFFERED'] = '1'  # force unbuffered output to get prints to sync correctly

    add_process_to_descriptor(launch_descriptor, 'small', 1)
    add_process_to_descriptor(launch_descriptor, 'small', 50)
    add_process_to_descriptor(launch_descriptor, 'large', 1)
    add_process_to_descriptor(launch_descriptor, 'large', 50)
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #16
0
ファイル: main.py プロジェクト: bponsler/launch
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        description='Launch the processes specified in a launch file.')
    parser.add_argument('launch_file',
                        type=file_exists,
                        nargs='+',
                        help='The launch file.')
    args = parser.parse_args(argv)

    arguments = {}

    launcher = DefaultLauncher()
    for launch_file in args.launch_file:
        launch_descriptor = LaunchDescriptor()
        load_launch_file(launch_file, launch_descriptor, arguments)
        launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()
    return rc
コード例 #17
0
def launch():
    ld = LaunchDescriptor()

    ld.add_process(cmd=['dummy_laser'], )
    ld.add_process(cmd=['dummy_map_server'], )

    ld.add_process(cmd=[
        'robot_state_publisher',
        os.path.join(file_path, 'single_rrbot.urdf')
    ])

    ld.add_process(cmd=['dummy_joint_states'])

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(ld)
    rc = launcher.launch()

    assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
コード例 #18
0
def main():
    launcher = DefaultLauncher()
    launch_descriptor = LaunchDescriptor()
    executable = 'topic_monitor_data_publisher'

    launch_descriptor.add_process(
        cmd=[executable, 'sensor', '--best-effort'],
        name='sensor',
    )
    launch_descriptor.add_process(
        cmd=[executable, 'critical'],
        name='critical',
    )
    launcher.add_launch_descriptor(launch_descriptor)

    rc = launcher.launch()
    if rc != 0:
        print('Something went wrong. Return code: ' + str(rc), file=sys.stderr)
        exit(rc)
コード例 #19
0
ファイル: main.py プロジェクト: csherstan/launch
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        description='Launch the processes specified in a launch file.')
    parser.add_argument(
        'launch_file',
        type=file_exists,
        nargs='+',
        help='The launch file.')
    args = parser.parse_args(argv)

    arguments = {}

    launcher = DefaultLauncher()
    for launch_file in args.launch_file:
        launch_descriptor = LaunchDescriptor()
        load_launch_file(launch_file, launch_descriptor, arguments)
        launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()
    return rc
コード例 #20
0
def lifecycle_demo():
    ld = LaunchDescriptor()

    ld.add_process(
        cmd=['lifecycle_talker'],
    )

    ld.add_process(
        cmd=['lifecycle_listener'],
    )

    ld.add_process(
        cmd=['lifecycle_service_client'],
        exit_handler=primary_exit_handler,
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(ld)
    rc = launcher.launch()

    assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
コード例 #21
0
def test_interrupt_default_launcher():
    desc = LaunchDescriptor()
    desc.add_process(
        cmd=[sys.executable, '-c', 'import time', 'time.sleep(30)'],
        name='test_interrupt_default_launcher__python_blocking')

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(desc)

    def thread_target():
        # wait up to 10 seconds to get to the point where at least all of the
        # asyncio-subprocess coroutines have been run (the processes are still
        # not guaranteed to be running yet)
        launcher.wait_on_processes_to_spawn(10)
        if not launcher.are_processes_spawned():
            # if the processes didn't launch after 10 seconds, fail the test
            _thread.interrupt_main()
            assert False, 'launcher never reported processes launched'
        launcher.interrupt_launch()
        # now wait for the launcher to finish and error if if doesn't
        launcher.wait_on_launch_to_finish(60)
        if launcher.is_launch_running():
            # if still running fail the test
            _thread.interrupt_main()
            assert False, 'launcher failed to shutdown'

    t = threading.Thread(target=thread_target)
    t.start()

    try:
        launcher.launch()
    except KeyboardInterrupt:
        assert False, 'failed by watchdog thread, see other AssertionErrors'
    t.join()
コード例 #22
0
def test_interrupt_asynchronous_launcher():
    desc = LaunchDescriptor()
    desc.add_process(
        cmd=[sys.executable, '-c', 'import time', 'time.sleep(30)'],
        name='test_interrupt_asynchronous_launcher__python_blocking'
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(desc)
    async_launcher = AsynchronousLauncher(launcher)
    async_launcher.start()

    # wait up to 10 seconds to get to the point where at least all of the
    # asyncio-subprocess coroutines have been run (the processes are still
    # not guaranteed to be running yet)
    launcher.wait_on_processes_to_spawn(10)
    if not launcher.are_processes_spawned():
        # if the processes didn't launch after 10 seconds, fail the test
        assert False, 'launcher never reported processes launched'
    async_launcher.terminate()
    # now wait for the launcher to finish and error if if doesn't
    async_launcher.join(60)
    if async_launcher.is_alive():
        # if still running fail the test
        assert False, 'async launcher failed to shutdown'
コード例 #23
0
ファイル: test_matching.py プロジェクト: oroulet/launch
def test_matching():
    output_handlers = []

    launch_descriptor = LaunchDescriptor()

    # This temporary directory and files contained in it will be deleted when the process ends.
    tempdir = tempfile.mkdtemp()
    output_file = tempdir + os.sep + 'testfile'
    full_output_file = output_file + '.regex'
    with open(full_output_file, 'w+') as f:
        f.write('this is line \d\nthis is line [a-z]')

    name = 'test_executable_0'

    handler = create_handler(name, launch_descriptor, output_file)

    assert handler, 'Cannot find appropriate handler for %s' % output_file

    output_handlers.append(handler)

    executable_command = [
        sys.executable,
        os.path.join(os.path.abspath(os.path.dirname(__file__)), 'matching.py')
    ]

    launch_descriptor.add_process(cmd=executable_command,
                                  name=name,
                                  exit_handler=ignore_exit_handler,
                                  output_handlers=output_handlers)

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'. "

    for handler in output_handlers:
        handler.check()
コード例 #24
0
ファイル: test_matching.py プロジェクト: csherstan/launch
def test_matching():
    output_handlers = []

    launch_descriptor = LaunchDescriptor()

    # This temporary directory and files contained in it will be deleted when the process ends.
    tempdir = tempfile.mkdtemp()
    output_file = tempdir + os.sep + "testfile"
    full_output_file = output_file + ".regex"
    with open(full_output_file, 'w+') as f:
        f.write('this is line \d\nthis is line [a-z]')

    name = "test_executable_0"

    handler = create_handler(name, launch_descriptor, output_file)

    assert handler, 'Cannot find appropriate handler for %s' % output_file

    output_handlers.append(handler)

    executable_command = [
        sys.executable,
        os.path.join(os.path.abspath(os.path.dirname(__file__)), 'matching.py')]

    launch_descriptor.add_process(
        cmd=executable_command,
        name=name,
        exit_handler=ignore_exit_handler,
        output_handlers=output_handlers)

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'. "

    for handler in output_handlers:
        handler.check()
コード例 #25
0
ファイル: test_talker_listener.py プロジェクト: dhood/rclpy
def test_talker_listener():
    launch_desc = LaunchDescriptor()
    launch_desc.add_process(
        cmd=[sys.executable, os.path.join(this_dir, 'talker.py')],
        name='test_talker_listener__talker'
    )
    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_desc)
    async_launcher = AsynchronousLauncher(launcher)
    async_launcher.start()

    import rclpy

    rclpy.init([])

    from rclpy.qos import qos_profile_default

    from std_msgs.msg import String
    assert String.__class__._TYPE_SUPPORT is not None

    node = rclpy.create_node('listener')

    received_messages = []

    chatter_callback = functools.partial(
        listener_callback, received_messages=received_messages)
    # TODO(wjwwood): should the subscription object hang around?
    node.create_subscription(String, 'chatter', chatter_callback, qos_profile_default)

    spin_count = 0
    while len(received_messages) == 0 and spin_count < 10 and launcher.is_launch_running():
        rclpy.spin_once(node)  # This will wait 1 second or until something has been done.
        spin_count += 1

    async_launcher.terminate()
    async_launcher.join()

    assert len(received_messages) > 0, "Should have received a message from talker"
コード例 #26
0
ファイル: main.py プロジェクト: oroulet/launch
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        description='Launch the processes specified in a launch file.')
    parser.add_argument('launch_file',
                        type=file_exists,
                        nargs='+',
                        help='The launch file.')
    parser.add_argument(
        '--args',
        metavar='arg',
        type=str,
        nargs='+',
        help='An argument to the launch file (e.g., arg_name:=value). All '
        'arguments will be passed to each launch file.')
    args = parser.parse_args(argv)

    launcher = DefaultLauncher()
    for launch_file in args.launch_file:
        launch_descriptor = LaunchDescriptor()
        load_launch_file(launch_file, launch_descriptor, args.args)
        launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()
    return rc
コード例 #27
0
ファイル: test_env_passing.py プロジェクト: rohbotics/launch
def test_env():
    ld = LaunchDescriptor()

    sub_env = copy.deepcopy(os.environ)
    sub_env['testenv1'] = 'testval1'
    os.environ['testenv2'] = 'testval2'
    ld.add_process(
        cmd=[
            sys.executable,
            os.path.join(
                os.path.abspath(
                    os.path.dirname(__file__)),
                'check_env.py')],
        name='test_env',
        env=sub_env,
        exit_handler=primary_exit_handler,
    )
    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(ld)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'. "
コード例 #28
0
ファイル: test_env_passing.py プロジェクト: oroulet/launch
def test_env():
    ld = LaunchDescriptor()

    sub_env = copy.deepcopy(os.environ)
    sub_env['testenv1'] = 'testval1'
    os.environ['testenv2'] = 'testval2'
    ld.add_process(
        cmd=[
            sys.executable,
            os.path.join(
                os.path.abspath(
                    os.path.dirname(__file__)),
                'check_env.py')],
        name='test_env',
        env=sub_env,
        exit_handler=primary_exit_handler,
    )
    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(ld)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'. "
コード例 #29
0
def launch():
    parser = argparse.ArgumentParser()
    parser.add_argument("-t",
                        "--linemod_templates",
                        help="Path to a .yml file"
                        "containing the LINEMOD templates for the objects to "
                        "be detected. These could be generated with virtual "
                        "kinect (real) training methods. The file must "
                        "contain sequential class IDs and mesh paths for "
                        "each class to allow the pipeline to execute "
                        "correctly. ",
                        type=str)
    parser.add_argument("-c",
                        "--calibration_file",
                        help="Path to a YAML "
                        "calibration file definining the transform from the "
                        "world frame to the camera frame used to collect "
                        "vision data. Please see launch/osrf_calib.yaml for "
                        "an example.",
                        type=str)
    parser.add_argument("-p",
                        "--push-pasta",
                        help="Push pasta boxes off of "
                        "the table.",
                        type=bool)
    parser.add_argument("-r",
                        "--push-ramen",
                        help="Push ramen containers off "
                        "of the table.",
                        type=bool)
    args = parser.parse_args()

    if args.linemod_templates:
        linemod_templates = args.linemod_templates
    else:
        linemod_templates = (get_package_share_directory("picky_robot") +
                             os.sep + 'linemod/cupnoodles_penne.yml')

    if args.calibration_file:
        calibration_file = args.calibration_file
    else:
        calibration_file = (get_package_share_directory("picky_robot") +
                            os.sep + "launch" + os.sep + "osrf_calib.yaml")

    if args.push_pasta:
        push_pasta = args.push_pasta
    else:
        push_pasta = False

    if args.push_ramen:
        push_ramen = args.push_ramen
    else:
        push_ramen = False

    if not push_pasta and not push_ramen:
        push_ramen = True
        push_pasta = True

    if push_pasta and push_ramen:
        push_flag = ""
    elif push_pasta:
        push_flag = "pasta"
    else:
        push_flag = "ramen"

    # parse a YAML file to get the calibration
    with open(calibration_file, 'r') as f:
        doc = yaml.load(f)
        x_offset = doc["x"]
        y_offset = doc["y"]
        z_offset = doc["z"]
        yaw_offset = doc["yaw"]
        pitch_offset = doc["pitch"]
        roll_offset = doc["roll"]
        parent_frame = doc["parent_frame"]
        child_frame = doc["child_frame"]

    ld = LaunchDescriptor()
    ld.add_process(cmd=[
        get_executable_path(package_name='robot_state_publisher',
                            executable_name='robot_state_publisher'),
        (get_package_share_directory("picky_robot") + os.sep + "launch" +
         os.sep + "ur5.urdf")
    ])

    ld.add_process(cmd=[
        get_executable_path(package_name='tf2_ros',
                            executable_name='static_transform_publisher'),
        str(doc["x"]),
        str(doc["y"]),
        str(doc["z"]),
        str(doc["yaw"]),
        str(doc["pitch"]),
        str(doc["roll"]),
        str(doc["parent_frame"]),
        str(doc["child_frame"])
    ])

    ld.add_process(cmd=[
        get_executable_path(package_name='depth_to_pointcloud',
                            executable_name='depth_to_pointcloud_node')
    ])

    ld.add_process(cmd=[
        get_executable_path(package_name='picky_robot',
                            executable_name='linemod_pipeline'),
        linemod_templates, 'b', 'b'
    ])

    ld.add_process(cmd=[
        get_executable_path(package_name='picky_robot',
                            executable_name='picky_robot.py'), push_flag
    ])

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(ld)
    print("launching...")
    rc = launcher.launch()

    assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
コード例 #30
0
def main(argv=sys.argv[1:]):
    launcher = DefaultLauncher()
    launch_descriptor = launch(LaunchDescriptor(), argv)
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()
    return rc
コード例 #31
0
def test_logging_output_format():
    launch_descriptor = LaunchDescriptor()

    # Re-use the test_logging_long_messages test binary and modify the output format from an
    # environment variable.
    executable = os.path.join(os.getcwd(), 'test_logging_long_messages')
    if os.name == 'nt':
        executable += '.exe'
    env_long = dict(os.environ)
    # In this custom output, the long message is output twice, to test both dynamic allocation and
    # re-allocation.
    env_long['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = \
        '[{{name}}].({severity}) output: {file_name}:{line_number} {message}, again: {message} ({function_name}()){'  # noqa
    name = 'test_logging_output_format_long'
    output_file = os.path.join(os.path.dirname(__file__), name)
    handler = create_handler(name, launch_descriptor, output_file)
    assert handler, 'Cannot find appropriate handler for %s' % output_file
    launch_descriptor.add_process(
        cmd=[executable],
        env=env_long,
        name=name,
        exit_handler=ignore_exit_handler,
        output_handlers=[ConsoleOutput(), handler],
    )

    env_edge_cases = dict(os.environ)
    # This custom output is to check different edge cases of the output format string parsing.
    env_edge_cases[
        'RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '{}}].({unknown_token}) {{{{'
    name = 'test_logging_output_format_edge_cases'
    output_file = os.path.join(os.path.dirname(__file__), name)
    handler = create_handler(name, launch_descriptor, output_file)
    assert handler, 'Cannot find appropriate handler for %s' % output_file
    launch_descriptor.add_process(
        cmd=[executable],
        env=env_edge_cases,
        name=name,
        exit_handler=ignore_exit_handler,
        output_handlers=[ConsoleOutput(), handler],
    )

    env_no_tokens = dict(os.environ)
    # This custom output is to check that there are no issues when no tokens are used.
    env_no_tokens['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = 'no_tokens'
    name = 'test_logging_output_format_no_tokens'
    output_file = os.path.join(os.path.dirname(__file__), name)
    handler = create_handler(name, launch_descriptor, output_file)
    assert handler, 'Cannot find appropriate handler for %s' % output_file
    launch_descriptor.add_process(
        cmd=[executable],
        env=env_no_tokens,
        name=name,
        exit_handler=ignore_exit_handler,
        output_handlers=[ConsoleOutput(), handler],
    )

    launcher = DefaultLauncher()
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()

    assert rc == 0, \
        "The launch file failed with exit code '" + str(rc) + "'"

    handler.check()
コード例 #32
0
def main(argv=sys.argv[1:]):
    launcher = DefaultLauncher()
    launch_descriptor = launch(LaunchDescriptor(), argv)
    launcher.add_launch_descriptor(launch_descriptor)
    rc = launcher.launch()
    return rc