Ejemplo n.º 1
0
Archivo: api.py Proyecto: cwyark/launch
def launch_a_python_launch_file(*,
                                python_launch_file_path,
                                launch_file_arguments,
                                debug=False):
    """Launch a given Python launch file (by path) and pass it the given launch file arguments."""
    launch_service = launch.LaunchService(argv=launch_file_arguments,
                                          debug=debug)
    context = rclpy.context.Context()
    rclpy.init(args=launch_file_arguments, context=context)
    launch_service.include_launch_description(
        launch_ros.get_default_launch_description(
            prefix_output_with_name=False,
            rclpy_context=context,
        ))
    parsed_launch_arguments = parse_launch_arguments(launch_file_arguments)
    # Include the user provided launch file using IncludeLaunchDescription so that the
    # location of the current launch file is set.
    launch_description = launch.LaunchDescription([
        launch.actions.IncludeLaunchDescription(
            launch.launch_description_sources.PythonLaunchDescriptionSource(
                python_launch_file_path),
            launch_arguments=parsed_launch_arguments,
        ),
    ])
    launch_service.include_launch_description(launch_description)
    ret = launch_service.run()
    context = rclpy.shutdown(context=context)
    return ret
Ejemplo n.º 2
0
def main(argv=sys.argv[1:]):
    """Main."""
    ld = LaunchDescription([
        launch_ros.actions.Node(package='demo_nodes_cpp',
                                node_executable='talker',
                                output='screen',
                                remappings=[('chatter', 'my_chatter')]),
        launch_ros.actions.Node(package='demo_nodes_cpp',
                                node_executable='listener',
                                output='screen',
                                remappings=[('chatter', 'my_chatter')]),
    ])

    print('Starting introspection of launch description...')
    print('')

    print(LaunchIntrospector().format_launch_description(ld))

    print('')
    print('Starting launch of launch description...')
    print('')

    # ls = LaunchService(debug=True)
    ls = LaunchService()
    ls.include_launch_description(
        get_default_launch_description(prefix_output_with_name=False))
    ls.include_launch_description(ld)
    return ls.run()
Ejemplo n.º 3
0
 def generate_preamble(self):
     return [launch.actions.IncludeLaunchDescription(
         launch_description_source=launch.LaunchDescriptionSource(
             launch_description=launch_ros.get_default_launch_description(
                 rclpy_context=self._rclpy_context,
             )
         )
     )]
Ejemplo n.º 4
0
def _launch(launch_description):
    loop = osrf_pycommon.process_utils.get_loop()
    ls = LaunchService()
    ls.include_launch_description(get_default_launch_description())
    ls.include_launch_description(launch_description)
    launch_task = loop.create_task(ls.run_async())
    loop.run_until_complete(asyncio.sleep(5, loop=loop))
    if not launch_task.done():
        loop.create_task(ls.shutdown())
        loop.run_until_complete(launch_task)
    rclpy.shutdown()
    return ls.context
Ejemplo n.º 5
0
def run_and_trace(
    base_path: str,
    session_name_prefix: str,
    ros_events: List[str],
    kernel_events: List[str],
    package_name: str,
    node_names: List[str],
) -> Tuple[int, str]:
    """
    Run a node while tracing.

    :param base_path: the base path where to put the trace directory
    :param session_name_prefix: the session name prefix for the trace directory
    :param ros_events: the list of ROS UST events to enable
    :param kernel_events: the list of kernel events to enable
    :param package_name: the name of the package to use
    :param node_names: the names of the nodes to execute
    :return: exit code, full generated path
    """
    session_name = append_timestamp(session_name_prefix)
    full_path = os.path.join(base_path, session_name)

    launch_actions = []
    # Add trace action
    launch_actions.append(
        Trace(
            session_name=session_name,
            append_timestamp=False,
            base_path=base_path,
            events_ust=ros_events,
            events_kernel=kernel_events,
        ))
    # Add nodes
    for node_name in node_names:
        n = Node(
            package=package_name,
            node_executable=node_name,
            output='screen',
        )
        launch_actions.append(n)
    ld = LaunchDescription(launch_actions)
    ls = LaunchService()
    ls.include_launch_description(get_default_launch_description())
    ls.include_launch_description(ld)

    exit_code = ls.run()

    return exit_code, full_path
def main(argv=sys.argv[1:]):
    """Main."""
    ld = generate_launch_description()

    print('Starting introspection of launch description...')
    print('')

    print(LaunchIntrospector().format_launch_description(ld))

    print('')
    print('Starting launch of launch description...')
    print('')

    ls = LaunchService()
    ls.include_launch_description(get_default_launch_description())
    ls.include_launch_description(ld)
    return ls.run()
Ejemplo n.º 7
0
def launch_a_python_launch_file(*,
                                python_launch_file_path,
                                launch_file_arguments,
                                debug=False):
    """Launch a given Python launch file (by path) and pass it the given launch file arguments."""
    launch_service = launch.LaunchService(argv=launch_file_arguments,
                                          debug=debug)
    launch_service.include_launch_description(
        launch_ros.get_default_launch_description(
            prefix_output_with_name=False))
    # Include the user provided launch file using IncludeLaunchDescription so that the
    # location of the current launch file is set.
    launch_description = launch.LaunchDescription([
        launch.actions.IncludeLaunchDescription(
            launch.launch_description_sources.PythonLaunchDescriptionSource(
                python_launch_file_path))
    ])
    launch_service.include_launch_description(launch_description)
    return launch_service.run()
Ejemplo n.º 8
0
def generate_launch_description():
    """Main."""
    ld = LaunchDescription([
        launch_ros.actions.Node(package='demo_nodes_cpp',
                                node_executable='talker',
                                output='screen',
                                remappings=[('chatter', 'my_chatter')]),
        launch_ros.actions.Node(package='demo_nodes_cpp',
                                node_executable='listener',
                                output='screen',
                                remappings=[('chatter', 'my_chatter')]),
    ])

    print('Starting introspection of launch description...')
    print('')

    print(LaunchIntrospector().format_launch_description(ld))

    print('')
    print('Starting launch of launch description...')
    print('')
    return ld


if __name__ == '__main__':
    # ls = LaunchService(debug=True)
    ls = LaunchService()
    ls.include_launch_description(get_default_launch_description())
    ls.include_launch_description(generate_launch_description())
    ls.run()
Ejemplo n.º 9
0
def main(argv=sys.argv[1:]):
    """Main."""
    ld = launch.LaunchDescription()

    # Prepare the talker node.
    talker_node = launch_ros.actions.LifecycleNode(
        node_name='talker',
        package='lifecycle',
        node_executable='lifecycle_talker',
        output='screen')

    # When the talker reaches the 'inactive' state, make it take the 'activate' transition.
    register_event_handler_for_talker_reaches_inactive_state = launch.actions.RegisterEventHandler(
        launch_ros.event_handlers.OnStateTransition(
            target_lifecycle_node=talker_node,
            goal_state='inactive',
            entities=[
                launch.actions.LogInfo(
                    msg=
                    "node 'talker' reached the 'inactive' state, 'activating'."
                ),
                launch.actions.EmitEvent(
                    event=launch_ros.events.lifecycle.ChangeState(
                        lifecycle_node_matcher=launch.events.matches_action(
                            talker_node),
                        transition_id=lifecycle_msgs.msg.Transition.
                        TRANSITION_ACTIVATE,
                    )),
            ],
        ))

    # When the talker node reaches the 'active' state, log a message and start the listener node.
    register_event_handler_for_talker_reaches_active_state = launch.actions.RegisterEventHandler(
        launch_ros.event_handlers.OnStateTransition(
            target_lifecycle_node=talker_node,
            goal_state='active',
            entities=[
                launch.actions.LogInfo(
                    msg=
                    "node 'talker' reached the 'active' state, launching 'listener'."
                ),
                launch_ros.actions.LifecycleNode(
                    node_name='listener',
                    package='lifecycle',
                    node_executable='lifecycle_listener',
                    output='screen'),
            ],
        ))

    # Make the talker node take the 'configure' transition.
    emit_event_to_request_that_talker_does_configure_transition = launch.actions.EmitEvent(
        event=launch_ros.events.lifecycle.ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(talker_node),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))

    # Add the actions to the launch description.
    # The order they are added reflects the order in which they will be executed.
    ld.add_action(register_event_handler_for_talker_reaches_inactive_state)
    ld.add_action(register_event_handler_for_talker_reaches_active_state)
    ld.add_action(talker_node)
    ld.add_action(emit_event_to_request_that_talker_does_configure_transition)

    print('Starting introspection of launch description...')
    print('')

    print(launch.LaunchIntrospector().format_launch_description(ld))

    print('')
    print('Starting launch of launch description...')
    print('')

    # ls = launch.LaunchService(argv=argv, debug=True)
    ls = launch.LaunchService(argv=argv)
    ls.include_launch_description(get_default_launch_description())
    ls.include_launch_description(ld)
    return ls.run()
Ejemplo n.º 10
0
def generate_launch_description():
    """Setup Logging"""
    log = Logger()

    """Load Configuration File"""
    param_file = os.getcwd() + '/params.yaml'
    # this prevents everything crashing if you deleted the config.yaml
    node_remaps = []
    if os.path.isfile(param_file):
        node_remaps += [('__params', param_file)]
        launch_print("Using parameters file: " + param_file)
    else:
        launch_print("Parameters file not found: " + param_file)

    """Generate launch description with multiple components."""
    ld = get_default_launch_description()

    ld.add_action(launch.actions.DeclareLaunchArgument(
        'gdb',
        default_value='false',
        description="Launch using GDB."
    ))
    ld.add_action(launch.actions.SetLaunchConfiguration(
        name='launch-prefix',
        value='gdbserver :2000',
        condition=IfCondition(LaunchConfiguration('gdb'))
    ))

    ld.add_action(ComposableNodeContainer(
        node_name='example_container',
        node_namespace=[],
        package='rclcpp_components',
        node_executable='component_container',

        composable_node_descriptions=[

                ComposableNode(
                    package='example',
                    node_plugin='ExampleConfig',
                    node_name='exampleConfig',
                    remappings=node_remaps),

                ComposableNode(
                    package='example',
                    node_plugin='ExamplePub',
                    node_name='examplePub',
                    remappings=node_remaps),
                ComposableNode(
                    package='example',
                    node_plugin='ExampleSub',
                    node_name='exampleSub',
                    remappings=node_remaps),

                ComposableNode(
                    package='example',
                    node_plugin='ExampleTime',
                    node_name='exampleTime',
                    remappings=node_remaps),

                ComposableNode(
                    package='example',
                    node_plugin='ExampleLog',
                    node_name='exampleLog',
                    remappings=node_remaps),

                ComposableNode(
                    package='example',
                    node_plugin='ExampleTF',
                    node_name='example_tf_node',
                    remappings=node_remaps),

                ComposableNode(
                    package='example',
                    node_plugin='ExampleTF_filter',
                    node_name='example_tf_filter_node',
                    remappings=node_remaps),
        ],
        output='screen',
        # arguments=[('__log_level:=debug')]
    ))
    ld.add_action(
        launch.actions.RegisterEventHandler(
            event_handler=launch.event_handlers.OnProcessIO(
                on_stdout=lambda info: log.write(info.text),
                on_stderr=lambda info: log.write(info.text),
            ))
    )
    # broadcast static tf.
    # Example of reading this trasnformation is in example_tf.cc
    # translation: 2m in x axis, 0m in y axis, 2m in z axis
    # rotation: 0 degrees in x axis, 0 degrees in y axis, 0 degrees in z axis
    ld.add_action(Node(
        package='tf2_ros',
        node_executable='static_transform_publisher',
        arguments=['2', '0', '2', '0', '0', '0', 'parent', 'child'],
        output='both',
    ))
    return ld