def generate_launch_description():
    keystroke_node = Node(package='keystroke',
                          node_executable='keystroke_listen',
                          output='screen',
                          node_name='keystroke_listen',
                          parameters=[{
                              'exit_on_esc': True
                          }],
                          arguments=['__log_level:=warn'])
    twist_node = Node(package='keystroke',
                      node_executable='keystroke_arrows_to_twist',
                      output='screen',
                      node_name='arrows_to_twist',
                      parameters=[{
                          'publish_period': 0.1,
                          'linear_scale': 0.1,
                          'angular_scale': 0.2
                      }])
    return LaunchDescription([
        keystroke_node, twist_node,
        RegisterEventHandler(event_handler=OnProcessExit(
            target_action=keystroke_node,
            on_exit=[EmitEvent(event=Shutdown())],
        )),
        RegisterEventHandler(event_handler=OnProcessExit(
            target_action=twist_node,
            on_exit=[EmitEvent(event=Shutdown())],
        ))
    ])
Esempio n. 2
0
def generate_launch_description():
    share_dir = get_package_share_directory('ros2_ouster')
    parameter_file = LaunchConfiguration('params_file')
    node_name = 'ouster_driver'

    params_declare = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(share_dir, 'params', 'os1.yaml'),
        description='FPath to the ROS2 parameters file to use.')

    driver_node = LifecycleNode(
        package='ros2_ouster',
        executable='ouster_driver',
        name=node_name,
        output='screen',
        emulate_tty=True,
        parameters=[parameter_file],
        namespace='/',
    )

    configure_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=matches_action(driver_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
    ))

    activate_event = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=driver_node,
            goal_state='inactive',
            entities=[
                LogInfo(
                    msg="[LifecycleLaunch] Ouster driver node is activating."),
                EmitEvent(event=ChangeState(
                    lifecycle_node_matcher=matches_action(driver_node),
                    transition_id=lifecycle_msgs.msg.Transition.
                    TRANSITION_ACTIVATE,
                )),
            ],
        ))

    # TODO make lifecycle transition to shutdown before SIGINT
    shutdown_event = RegisterEventHandler(
        OnShutdown(on_shutdown=[
            EmitEvent(event=ChangeState(
                lifecycle_node_matcher=matches_node_name(node_name=node_name),
                transition_id=lifecycle_msgs.msg.Transition.
                TRANSITION_ACTIVE_SHUTDOWN,
            )),
            LogInfo(msg="[LifecycleLaunch] Ouster driver node is exiting."),
        ], ))

    return LaunchDescription([
        params_declare,
        driver_node,
        activate_event,
        configure_event,
        shutdown_event,
    ])
Esempio n. 3
0
 def _succeed(self, test_name, side_effect=None):
     """Mark test as a success and shutdown if all other tests have finished too."""
     assert test_name in self.__tests
     self.__tests[test_name] = 'succeeded'
     if all(status != 'armed' for status in self.__tests.values()):
         return [EmitEvent(event=Shutdown(reason='all tests finished'))]
     if side_effect == 'shutdown':
         return [EmitEvent(event=Shutdown(reason='shutdown after test'))]
     return []
def generate_launch_description():
    share_dir = get_package_share_directory('serial_driver')
    node_name = 'serial_bridge_node'

    params_declare = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(share_dir, 'params', 'example.params.yaml'),
        description='File path to the ROS2 parameters file to use')

    bridge_node = LifecycleNode(
        package='serial_driver',
        executable='serial_bridge',
        name=node_name,
        namespace=TextSubstitution(text=''),
        parameters=[LaunchConfiguration('params_file')],
        output='screen',
    )

    configure_event_handler = RegisterEventHandler(
        event_handler=OnProcessStart(
            target_action=bridge_node,
            on_start=[
                EmitEvent(event=ChangeState(
                    lifecycle_node_matcher=matches_action(bridge_node),
                    transition_id=Transition.TRANSITION_CONFIGURE,
                ), ),
            ],
        ))

    activate_event_handler = RegisterEventHandler(
        event_handler=OnStateTransition(
            target_lifecycle_node=bridge_node,
            start_state='configuring',
            goal_state='inactive',
            entities=[
                EmitEvent(event=ChangeState(
                    lifecycle_node_matcher=matches_action(bridge_node),
                    transition_id=Transition.TRANSITION_ACTIVATE,
                ), ),
            ],
        ))

    shutdown_event_handler = RegisterEventHandler(event_handler=OnShutdown(
        on_shutdown=[
            EmitEvent(event=ChangeState(
                lifecycle_node_matcher=matches_node_name(node_name),
                transition_id=Transition.TRANSITION_ACTIVE_SHUTDOWN,
            ))
        ]))

    return LaunchDescription([
        params_declare,
        bridge_node,
        configure_event_handler,
        activate_event_handler,
        shutdown_event_handler,
    ])
Esempio n. 5
0
def generate_launch_description():
    # Get the launch directory
    example_dir = get_package_share_directory('social_nav2_goal_updaters')

    stdout_linebuf_envvar = SetEnvironmentVariable(
        'RCUTILS_LOGGING_BUFFERED_STREAM', '1')

    # Specify the actions
    escort_cmd = LifecycleNode(package='social_nav2_goal_updaters',
                               executable='escort_goal_updater_node',
                               name='escort_goal_updater_node',
                               output='screen',
                               parameters=[])

    follow_cmd = LifecycleNode(package='social_nav2_goal_updaters',
                               executable='follow_goal_updater_node',
                               name='follow_goal_updater_node',
                               output='screen',
                               parameters=[])
    hri_cmd = LifecycleNode(package='social_nav2_goal_updaters',
                            executable='hri_goal_updater_node',
                            name='hri_goal_updater_node',
                            output='screen',
                            parameters=[])

    emit_event_to_request_that_escort_configure_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(escort_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))
    emit_event_to_request_that_follow_configure_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(follow_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))
    emit_event_to_request_that_hri_configure_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(hri_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))
    # Create the launch description and populate
    ld = LaunchDescription()

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

    # Declare the launch options
    ld.add_action(escort_cmd)
    ld.add_action(follow_cmd)
    ld.add_action(hri_cmd)

    ld.add_action(emit_event_to_request_that_escort_configure_transition)
    ld.add_action(emit_event_to_request_that_follow_configure_transition)
    ld.add_action(emit_event_to_request_that_hri_configure_transition)

    return ld
Esempio n. 6
0
def generate_launch_description():
    """Generate launch description."""
    test_params = os.path.join(
        get_package_share_directory('canopen_chain_node'),
        'test/config/chain_node_params.yaml'
    )

    chain_node = LifecycleNode(
        node_name='canopen_chain',
        package='canopen_chain_node',
        node_executable='manual_composition',
        output='screen',
        parameters=[
            test_params
        ]
    )

    ros2_web_bridge = ExecuteProcess(
        cmd=['node', '/opt/ros2-web-bridge/bin/rosbridge.js'],
        output='screen'
    )


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

    # When the node reaches the 'inactive' state, make it 'activate'
    register_event_handler_for_chain_node_reaches_inactive_state = launch.actions.RegisterEventHandler(  # noqa
      launch_ros.event_handlers.OnStateTransition(
        target_lifecycle_node=chain_node, goal_state='inactive',
        entities=[
         EmitEvent(event=launch_ros.events.lifecycle.ChangeState(
           lifecycle_node_matcher=launch.events.matches_action(chain_node),
           transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
         )),
        ],
      )
    )
    
    ld = launch.LaunchDescription()
    # Register nodes and event handlers before starting 'configure' transition
    ld.add_action(register_event_handler_for_chain_node_reaches_inactive_state)
    ld.add_action(chain_node)
    ld.add_action(ros2_web_bridge)
    ld.add_action(emit_event_request_that_chain_node_does_configure_transition)

    return ld
def generate_launch_description():
    localization_benchmark_supervisor_node = Node(
        package='localization_performance_modelling',
        node_executable='localization_benchmark_supervisor',
        node_name='localization_benchmark_supervisor',
        output='screen',
        emulate_tty=True,
        parameters=[LaunchConfiguration('configuration')],
    )
    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        DeclareLaunchArgument('configuration',
                              description='Configuration yaml file path'),
        DeclareLaunchArgument('use_sim_time',
                              description='Use simulation/bag clock if true'),
        localization_benchmark_supervisor_node,
        Node(package='nav2_lifecycle_manager',
             node_executable='lifecycle_manager',
             node_name='lifecycle_manager',
             output='screen',
             parameters=[{
                 'use_sim_time': LaunchConfiguration('use_sim_time')
             }, {
                 'node_names': [
                     'map_server', 'amcl', 'controller_server',
                     'planner_server', 'recoveries_server', 'bt_navigator',
                     'waypoint_follower'
                 ]
             }]),
        RegisterEventHandler(event_handler=OnProcessExit(
            target_action=localization_benchmark_supervisor_node,
            on_exit=EmitEvent(event=Shutdown(reason='supervisor_finished')))),
    ])
Esempio n. 8
0
def generate_launch_description():
    return launch.LaunchDescription(
        [
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(
                    [get_package_share_directory(robot), "/launch/nav-core.py"]
                ),
                launch_arguments={
                    "namespace": robot,
                    "params_file": os.path.join(
                        get_package_share_directory(robot), "param", f"{robot}.yml"
                    ),
                }.items(),
            )
            for robot in robots
        ]
        + [
            RegisterEventHandler(
                event_handler=OnProcessExit(
                    on_exit=[
                        EmitEvent(event=Shutdown()),
                    ]
                )
            )
        ]
    )
Esempio n. 9
0
def generate_launch_description():
    teleop_config = Path(get_package_share_directory('openrover_demo'), 'config', 'teleop.yaml')
    assert teleop_config.is_file()

    nodes = [
        Node(
            package='keystroke', node_executable='keystroke_listen', output='screen',
            arguments=['__log_level:=warn'],
            parameters=[teleop_config]
        ),
        Node(
            package='keystroke', node_executable='keystroke_arrows_to_twist', output='screen',
            arguments=['__log_level:=info'],
            parameters=[teleop_config]
        )]

    events = [RegisterEventHandler(
        event_handler=OnProcessExit(
            target_action=n,
            on_exit=[EmitEvent(event=Shutdown())]
        )
    ) for n in nodes]

    return LaunchDescription([
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        *nodes,
        *events
    ])
Esempio n. 10
0
def generate_launch_description():
    return launch.LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                [get_package_share_directory(robot), "/launch/interfaces.py"]),
            launch_arguments={
                "namespace":
                robot,
                "params_file":
                os.path.join(get_package_share_directory(robot), "param",
                             f"{robot}.yml"),
            }.items(),
        ) for robot in robots
    ] + [
        GroupAction([
            Node(
                package="strategix",
                executable="strategix",
                output="screen",
            ),
        ])
    ] + [
        RegisterEventHandler(event_handler=OnProcessExit(on_exit=[
            EmitEvent(event=Shutdown()),
        ]))
    ])
Esempio n. 11
0
def generate_launch_description():
    return launch.LaunchDescription(
        [
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(
                    [get_package_share_directory(robot), "/launch/interfaces.py"]
                ),
                launch_arguments={
                    "namespace": robot,
                    "params_file": os.path.join(
                        get_package_share_directory(robot), "param", f"{robot}.yml"
                    ),
                }.items(),
            )
            for robot in robots
        ]
        + [
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(
                    [
                        get_package_share_directory("assurancetourix"),
                        "/launch/launch.py",
                    ]
                ),
                launch_arguments={
                    "namespace": "assurancetourix",
                    "params_file": os.path.join(
                        get_package_share_directory("assurancetourix"),
                        "param",
                        "assurancetourix.yml",
                    ),
                }.items(),
            )
        ]
        + [
            GroupAction(
                [
                    Node(
                        package="strategix",
                        executable="strategix",
                        output="screen",
                    ),
                    WebotsLauncher(
                        mode="realtime",
                        world="tools/simulation/worlds/cdr2022.wbt",
                    ),
                ]
            )
        ]
        + [
            RegisterEventHandler(
                event_handler=OnProcessExit(
                    on_exit=[
                        EmitEvent(event=Shutdown()),
                    ]
                )
            )
        ]
    )
Esempio n. 12
0
def generate_launch_description():
    set_tty_launch_config_action = launch.actions.SetLaunchConfiguration(
        "emulate_tty", "True")

    # Launch Description
    ld = launch.LaunchDescription()

    # Watchdog node
    watchdog_node = LifecycleNode(package='sw_watchdog',
                                  node_executable='simple_watchdog',
                                  node_namespace='',
                                  node_name='simple_docker_watchdog',
                                  output='screen',
                                  arguments=['220', '--publish', '--activate']
                                  #arguments=['__log_level:=debug']
                                  )

    # Make the Watchdog node take the 'activate' transition
    watchdog_activate_trans_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=launch.events.matches_action(watchdog_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
    ))

    # When the watchdog reaches the 'inactive' state from 'active', log message
    # and restart monitored entity (via docker)
    watchdog_inactive_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=watchdog_node,
            start_state='deactivating',
            goal_state='inactive',
            entities=[
                # Log
                LogInfo(msg="Watchdog transitioned to 'INACTIVE' state."),
                # Restart the monitored entity
                OpaqueFunction(function=docker_restart),
                # Change state event (inactive -> active)
                watchdog_activate_trans_event,
            ],
        ))

    # When Shutdown is requested, clean up docker
    shutdown_handler = RegisterEventHandler(
        OnShutdown(
            on_shutdown=[
                # Log
                LogInfo(msg="watchdog_in_docker was asked to shutdown."),
                # Clean up docker
                OpaqueFunction(function=docker_stop),
            ], ))

    # Add the actions to the launch description.
    # The order they are added reflects the order in which they will be executed
    ld.add_action(set_tty_launch_config_action)
    ld.add_action(OpaqueFunction(function=docker_run))
    ld.add_action(watchdog_node)
    ld.add_action(watchdog_inactive_handler)
    ld.add_action(shutdown_handler)

    return ld
Esempio n. 13
0
 def _fail(self, test_name, reason):
     """Mark test as a failure and shutdown, dropping the tests that are still in progress."""
     assert test_name in self.__tests
     self.__tests[test_name] = 'failed'
     for test_name in self.__tests:
         if self.__tests[test_name] == 'armed':
             self.__tests[test_name] = 'dropped'
     return [EmitEvent(event=Shutdown(reason=reason))]
Esempio n. 14
0
        def on_test_process_exit(event, context):
            nonlocal action
            nonlocal self
            self.__test_returncodes[action] = event.returncode

            if len(self.__test_returncodes) == len(self.__test_processes):
                shutdown_event = Shutdown(
                    reason='all test processes finished')
                return EmitEvent(event=shutdown_event)
Esempio n. 15
0
def generate_launch_description():

    params_file_path = os.path.join(
        get_package_share_directory('qualisys_driver'), 'config',
        'qualisys_driver_params.yaml')

    stdout_linebuf_envvar = SetEnvironmentVariable(
        'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1')

    # print('')
    # print('params_file_path: ', params_file_path)
    # print('')

    driver_node = LifecycleNode(
        node_name='qualisys_driver_node',
        package='qualisys_driver',
        node_executable='qualisys_driver_main',
        output='screen',
        parameters=[params_file_path],
    )

    # Make the driver node take the 'configure' transition
    driver_configure_trans_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=launch.events.matchers.matches_action(
            driver_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
    ))

    # Make the driver node take the 'activate' transition
    driver_activate_trans_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=launch.events.matchers.matches_action(
            driver_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
    ))

    # Create the launch description and populate
    ld = LaunchDescription()

    ld.add_action(stdout_linebuf_envvar)
    ld.add_action(driver_node)
    ld.add_action(driver_configure_trans_event)
    ld.add_action(driver_activate_trans_event)

    return ld
Esempio n. 16
0
def launch_gtest(test_path):
    """Launch a gtest."""
    ld = LaunchDescription([
        GTest(path=str(test_path),
              timeout=5.0,
              on_exit=[EmitEvent(event=Shutdown())])
    ])
    ls = LaunchService()
    ls.include_launch_description(ld)
    assert 0 == ls.run()
Esempio n. 17
0
def generate_launch_description():
    synchronization = LaunchConfiguration('synchronization')
    package = LaunchConfiguration('package')
    executable = LaunchConfiguration('executable')
    world = LaunchConfiguration('world')
    gui = LaunchConfiguration('gui')
    mode = LaunchConfiguration('mode')
    publish_tf = LaunchConfiguration('publish_tf')
    node_parameters = LaunchConfiguration('node_parameters')
    robot_name = LaunchConfiguration('robot_name')
    node_name = LaunchConfiguration('node_name')
    use_sim_time = LaunchConfiguration('use_sim_time')

    # Webots
    webots = WebotsLauncher(world=world, mode=mode, gui=gui)

    # Driver node
    controller = ControllerLauncher(
        package=package,
        executable=executable,
        parameters=[
            node_parameters, {
                'synchronization': synchronization,
                'use_joint_state_publisher': publish_tf
            }
        ],
        output='screen',
        arguments=[
            '--webots-robot-name', robot_name, '--webots-node-name', node_name
        ],
    )

    # Robot state publisher
    robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[{
            'robot_description': '<robot name=""><link name=""/></robot>',
            'use_sim_time': use_sim_time
        }],
        condition=launch.conditions.IfCondition(publish_tf))

    return LaunchDescription(ARGUMENTS + [
        robot_state_publisher,
        webots,
        controller,

        # Shutdown launch when Webots exits.
        RegisterEventHandler(event_handler=launch.event_handlers.OnProcessExit(
            target_action=webots,
            on_exit=[EmitEvent(event=launch.events.Shutdown())],
        ))
    ])
Esempio n. 18
0
 def on_fixture_process_exit(event, context):
     process_name = event.action.process_details['name']
     allowed_to_exit = exit_allowed
     if isinstance(exit_allowed, list):
         allowed_to_exit = event.returncode in exit_allowed
     if not context.is_shutdown and not allowed_to_exit:
         rc = event.returncode if event.returncode else 1
         self.__processes_rc[process_name] = rc
         return EmitEvent(event=Shutdown(
             reason='{} fixture process died!'.format(
                 process_name)))
Esempio n. 19
0
    def __init__(
        self,
        target_action,
        log_file,
        timeout=None,
        **kwargs
    ) -> None:
        """
        Construct a SystemMetricCollector action.

        Parameters
        ----------
        target_action : ExecuteProcess
            ExecuteProcess (or Node) instance to collect metrics on
        log_file : str or LaunchSubstitutionsType
            Path to where the collected metrics should be written to
        timeout : int or LaunchSubstitutionsType
            Maximum time to run the metrics collector if the target process does
            not exit

        """
        # These Node/ExecuteProcess arguments are invalid in this context
        # because we implicitly set them right here.
        assert 'arguments' not in kwargs
        assert 'package' not in kwargs
        assert 'executable' not in kwargs
        assert 'executable' not in kwargs

        self.__pid_var_name = '__PROCESS_ID_%d' % id(self)

        kwargs['package'] = 'buildfarm_perf_tests'
        kwargs['executable'] = 'system_metric_collector'
        kwargs['arguments'] = [
            '--log', log_file,
            '--process_pid', LocalSubstitution(self.__pid_var_name)]
        if timeout is not None:
            kwargs['arguments'] += [
                '--timeout',
                str(timeout) if isinstance(timeout, int) else timeout
            ]

        super().__init__(**kwargs)

        self.__target_start_handler = OnProcessStart(
            target_action=target_action, on_start=self.__on_target_start)
        self.__target_exit_handler = OnProcessExit(
            target_action=target_action, on_exit=EmitEvent(
                event=ShutdownProcess(
                    process_matcher=matches_action(self))))
Esempio n. 20
0
def generate_rviz_launch_description(namespace="robot"):
    # Get the launch directory
    titan_dir = get_package_share_directory("titan")

    rviz_config_file = os.path.join(titan_dir, "rviz", "namespaced_view.rviz")

    use_namespace = "true"

    namespaced_rviz_config_file = ReplaceString(
        source_file=rviz_config_file,
        replacements={"<robot_namespace>": ("/", namespace)},
    )

    start_namespaced_rviz_cmd = Node(
        condition=IfCondition(use_namespace),
        package="rviz2",
        executable="rviz2",
        name="rviz2",
        namespace=namespace,
        # TODO: FIX onload MUTEX ERROR
        # arguments=['-d', namespaced_rviz_config_file],
        output="screen",
        remappings=[
            ("/tf", "tf"),
            ("/tf_static", "tf_static"),
            ("/goal_pose", "goal_pose"),
            ("/clicked_point", "clicked_point"),
            ("/initialpose", "initialpose"),
        ],
    )

    exit_event_handler_namespaced = RegisterEventHandler(
        condition=IfCondition(use_namespace),
        event_handler=OnProcessExit(
            target_action=start_namespaced_rviz_cmd,
            on_exit=EmitEvent(event=Shutdown(reason="rviz exited")),
        ),
    )

    # Create the launch description and populate
    ld = LaunchDescription()

    # Add any conditioned actions
    ld.add_action(start_namespaced_rviz_cmd)

    # Add other nodes and processes we need
    ld.add_action(exit_event_handler_namespaced)

    return ld
Esempio n. 21
0
def generate_launch_description():
    # Webots
    arguments = [
        '--mode=realtime', '--world=' +
        os.path.join(get_package_share_directory('webots_ros2_epuck'),
                     'worlds', 'epuck_world.wbt')
    ]
    webots = Node(package='webots_ros2_core',
                  node_executable='webots_launcher',
                  arguments=arguments,
                  output='screen')

    # Controller node
    synchronization = LaunchConfiguration('synchronization', default=False)
    controller = ControllerLauncher(package='webots_ros2_epuck',
                                    node_executable='driver',
                                    parameters=[{
                                        'synchronization':
                                        synchronization
                                    }],
                                    output='screen')

    # Rviz node
    use_rviz = LaunchConfiguration('rviz', default=False)
    rviz_config = os.path.join(
        get_package_share_directory('webots_ros2_epuck'), 'resource',
        'all.rviz')

    rviz = Node(package='rviz2',
                node_executable='rviz2',
                output='screen',
                arguments=['--display-config=' + rviz_config],
                condition=launch.conditions.IfCondition(use_rviz))

    # Launch descriptor
    launch_entities = [
        webots,
        controller,
        rviz,

        # Shutdown launch when Webots exits.
        RegisterEventHandler(event_handler=launch.event_handlers.OnProcessExit(
            target_action=webots,
            on_exit=[EmitEvent(event=launch.events.Shutdown())],
        ))
    ]

    return LaunchDescription(launch_entities)
Esempio n. 22
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('amazon_robot_bringup')

    # Create the launch configuration variables
    namespace = LaunchConfiguration('namespace')
    use_namespace = LaunchConfiguration('use_namespace')
    rviz_config_file = LaunchConfiguration('rviz_config')

    # Declare the launch arguments
    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace',
        default_value='navigation',
        description=('Top-level namespace. The value will be used to replace the '
                     '<robot_namespace> keyword on the rviz config file.'))

    declare_use_namespace_cmd = DeclareLaunchArgument(
        'use_namespace',
        default_value='false',
        description='Whether to apply a namespace to the navigation stack')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config',
        default_value=os.path.join(bringup_dir, 'rviz', 'amazon_robot_default_view.rviz'),
        description='Full path to the RVIZ config file to use')

    # Launch rviz
    start_rviz_cmd = Node(
        condition=UnlessCondition(use_namespace),
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=['-d', rviz_config_file],
        output='screen')

    namespaced_rviz_config_file = ReplaceString(
            source_file=rviz_config_file,
            replacements={'<robot_namespace>': ('/', namespace)})

    start_namespaced_rviz_cmd = Node(
        condition=IfCondition(use_namespace),
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        namespace=namespace,
        arguments=['-d', namespaced_rviz_config_file],
        output='screen',
        remappings=[('/tf', 'tf'),
                    ('/tf_static', 'tf_static'),
                    ('/goal_pose', 'goal_pose'),
                    ('/clicked_point', 'clicked_point'),
                    ('/initialpose', 'initialpose')])

    exit_event_handler = RegisterEventHandler(
        condition=UnlessCondition(use_namespace),
        event_handler=OnProcessExit(
            target_action=start_rviz_cmd,
            on_exit=EmitEvent(event=Shutdown(reason='rviz exited'))))

    exit_event_handler_namespaced = RegisterEventHandler(
        condition=IfCondition(use_namespace),
        event_handler=OnProcessExit(
            target_action=start_namespaced_rviz_cmd,
            on_exit=EmitEvent(event=Shutdown(reason='rviz exited'))))

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_namespace_cmd)
    ld.add_action(declare_rviz_config_file_cmd)

    # Add any conditioned actions
    ld.add_action(start_rviz_cmd)
    ld.add_action(start_namespaced_rviz_cmd)

    # Add other nodes and processes we need
    ld.add_action(exit_event_handler)
    ld.add_action(exit_event_handler_namespaced)

    return ld
Esempio n. 23
0
def generate_launch_description():
    # Get the launch directory
    social_bringup_dir = get_package_share_directory('social_nav2_bringup')
    nav_bringup_dir = get_package_share_directory('nav2_bringup')
    launch_dir = os.path.join(nav_bringup_dir, 'launch')

    # Create the launch configuration variables
    namespace = LaunchConfiguration('namespace')
    use_namespace = LaunchConfiguration('use_namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    bt_xml_file = LaunchConfiguration('bt_xml_file')
    autostart = LaunchConfiguration('autostart')
    use_remappings = LaunchConfiguration('use_remappings')

    # Launch configuration variables specific to simulation
    rviz_config_file = LaunchConfiguration('rviz_config_file')
    use_simulator = LaunchConfiguration('use_simulator')
    use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
    use_rviz = LaunchConfiguration('use_rviz')
    headless = LaunchConfiguration('headless')
    world = LaunchConfiguration('world')

    # Map fully qualified names to relative ones so the node's namespace can be prepended.
    # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
    # https://github.com/ros/geometry2/issues/32
    # https://github.com/ros/robot_state_publisher/pull/30
    # TODO(orduno) Substitute with `PushNodeRemapping`
    #              https://github.com/ros2/launch_ros/issues/56
    remappings = [('/tf', 'tf'), ('/tf_static', 'tf_static')]

    # Declare the launch arguments
    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace', default_value='', description='Top-level namespace')

    declare_use_namespace_cmd = DeclareLaunchArgument(
        'use_namespace',
        default_value='false',
        description='Whether to apply a namespace to the navigation stack')

    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value=os.path.join(social_bringup_dir, 'maps',
                                   'turtlebot3_house.yaml'),
        description='Full path to map file to load')

    declare_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time',
        default_value='true',
        description='Use simulation (Gazebo) clock if true')

    declare_use_remappings_cmd = DeclareLaunchArgument(
        'use_remappings',
        default_value='false',
        description='Arguments to pass to all nodes launched by the file')

    declare_params_file_cmd = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(social_bringup_dir, 'params',
                                   'nav2_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    declare_bt_xml_cmd = DeclareLaunchArgument(
        'bt_xml_file',
        default_value=os.path.join(
            get_package_share_directory('social_nav2_bringup'),
            'behavior_trees', 'follow_point.xml'),
        description='Full path to the behavior tree xml file to use')

    declare_autostart_cmd = DeclareLaunchArgument(
        'autostart',
        default_value='true',
        description='Automatically startup the nav2 stack')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config_file',
        default_value=os.path.join(social_bringup_dir, 'rviz',
                                   'nav2_default_view.rviz'),
        description='Full path to the RVIZ config file to use')

    declare_use_simulator_cmd = DeclareLaunchArgument(
        'use_simulator',
        default_value='True',
        description='Whether to start the simulator')

    declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
        'use_robot_state_pub',
        default_value='True',
        description='Whether to start the robot state publisher')

    declare_use_rviz_cmd = DeclareLaunchArgument(
        'use_rviz', default_value='True', description='Whether to start RVIZ')

    declare_simulator_cmd = DeclareLaunchArgument(
        'headless',
        default_value='False',
        description='Whether to execute gzclient)')

    declare_world_cmd = DeclareLaunchArgument(
        'world',
        # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
        #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
        # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
        #                            'worlds/turtlebot3_worlds/waffle.model'),
        default_value=os.path.join(social_bringup_dir, 'worlds',
                                   'waffle_house.model'),
        description='Full path to world model file to load')

    # Specify the actions
    start_gazebo_server_cmd = ExecuteProcess(
        condition=IfCondition(use_simulator),
        cmd=[
            'gzserver', '-s', 'libgazebo_ros_init.so', '-s',
            'libgazebo_ros_factory.so', world
        ],
        cwd=[launch_dir],
        output='screen')

    start_gazebo_client_cmd = ExecuteProcess(condition=IfCondition(
        PythonExpression([use_simulator, ' and not ', headless])),
                                             cmd=['gzclient'],
                                             cwd=[launch_dir],
                                             output='screen')

    urdf = os.path.join(social_bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')

    start_robot_state_publisher_cmd = Node(
        condition=IfCondition(use_robot_state_pub),
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='robot_state_publisher',
        namespace=namespace,
        output='screen',
        parameters=[{
            'use_sim_time': use_sim_time
        }],
        remappings=remappings,
        arguments=[urdf])

    start_rviz_cmd = Node(
        condition=IfCondition(use_rviz),
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=['-d', rviz_config_file],
        output='screen',
    )

    exit_event_handler = RegisterEventHandler(
        event_handler=OnProcessExit(target_action=start_rviz_cmd,
                                    on_exit=EmitEvent(event=Shutdown(
                                        reason='rviz exited'))))

    agent_spawner_cmd = Node(package='pedsim_gazebo_plugin',
                             executable='spawn_pedsim_agents.py',
                             name='spawn_pedsim_agents',
                             output='screen')

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_namespace_cmd)
    ld.add_action(declare_map_yaml_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_bt_xml_cmd)
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_use_remappings_cmd)

    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_use_simulator_cmd)
    ld.add_action(declare_use_robot_state_pub_cmd)
    ld.add_action(declare_use_rviz_cmd)
    ld.add_action(declare_simulator_cmd)
    ld.add_action(declare_world_cmd)

    # Add any conditioned actions
    ld.add_action(start_gazebo_server_cmd)
    ld.add_action(start_gazebo_client_cmd)
    ld.add_action(agent_spawner_cmd)
    ld.add_action(start_rviz_cmd)

    ld.add_action(exit_event_handler)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(start_robot_state_publisher_cmd)

    return ld
Esempio n. 24
0
def generate_launch_description():
    package_name = 'ifm3d_ros2'
    node_namespace = 'ifm3d'
    node_name = 'camera'
    node_exe = 'camera_standalone'

    # os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = \
    #   "[{%s}] {%s} [{%s}]: {%s}\n({%s}() at {%s}:{%s})" % \
    #    ("severity", "time", "name", "message",
    #      "function_name", "file_name", "line_number")
    os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = \
      "[{%s}] {%s} [{%s}]: {%s}" % ("severity", "time", "name", "message")

    # XXX: This is a hack, there does not seem to be a nice way (or at least
    # finding the docs is not obvious) to do this with the ROS2 launch api
    #
    # Basically, we are trying to allow for passing through the command line
    # args to the launch file through to the node executable itself (like ROS
    # 1).
    #
    # My assumption is that either:
    # 1. This stuff exists somewhere in ROS2 and I don't know about it yet
    # 2. This stuff will exist in ROS2 soon, so, this will likely get factored
    #    out (hopefully soon)
    #
    parameters = []
    remaps = []
    for arg in sys.argv:
        if ':=' in arg:
            split_arg = arg.split(sep=':=', maxsplit=1)
            assert len(split_arg) == 2

            if arg.startswith("ns"):
                node_namespace = split_arg[1]
            elif arg.startswith("node"):
                node_name = split_arg[1]
            elif arg.startswith("params"):
                parameters.append(tuple(split_arg)[1])
            else:
                remaps.append(tuple(split_arg))

    def add_prefix(tup):
        assert len(tup) == 2
        if node_namespace.startswith("/"):
            prefix = "%s/%s" % (node_namespace, node_name)
        else:
            prefix = "/%s/%s" % (node_namespace, node_name)

        retval = [None, None]

        if not tup[0].startswith(prefix):
            retval[0] = prefix + '/' + tup[0]
        else:
            retval[0] = tup[0]

        if not tup[1].startswith(prefix):
            retval[1] = prefix + '/' + tup[1]
        else:
            retval[1] = tup[1]

        return tuple(retval)

    remaps = list(map(add_prefix, remaps))

    #------------------------------------------------------------
    # Nodes
    #------------------------------------------------------------

    #
    # Coord frame transform from camera_optical_link to camera_link
    #
    tf_node = \
      ExecuteProcess(
          cmd=['ros2', 'run', 'tf2_ros', 'static_transform_publisher',
               '0', '0', '0', str(-pi/2.), '0', str(-pi/2.),
               str(node_name + "_link"), str(node_name + "_optical_link")],
               #output='screen',
               log_cmd=True
          )

    #
    # The camera component
    #
    camera_node = \
      LifecycleNode(
          package=package_name,
          node_executable=node_exe,
          node_namespace=node_namespace,
          node_name=node_name,
          output='screen',
          parameters=parameters,
          remappings=remaps,
          log_cmd=True,
          )

    #------------------------------------------------------------
    # Events we need to emit to induce state transitions
    #------------------------------------------------------------

    camera_configure_evt = \
      EmitEvent(
          event=ChangeState(
              lifecycle_node_matcher = \
                launch.events.matches_action(camera_node),
              transition_id = lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE
              )
          )

    camera_activate_evt = \
      EmitEvent(
          event=ChangeState(
              lifecycle_node_matcher = \
                launch.events.matches_action(camera_node),
              transition_id = lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE
              )
          )

    camera_cleanup_evt = \
      EmitEvent(
          event=ChangeState(
              lifecycle_node_matcher = \
                launch.events.matches_action(camera_node),
              transition_id = lifecycle_msgs.msg.Transition.TRANSITION_CLEANUP
              )
          )

    camera_shutdown_evt = EmitEvent(event=launch.events.Shutdown())

    #------------------------------------------------------------
    # These are the edges of the state machine graph we want to autonomously
    # manage
    #------------------------------------------------------------

    #
    # unconfigured -> configuring -> inactive
    #
    camera_node_unconfigured_to_inactive_handler = \
      RegisterEventHandler(
          OnStateTransition(
              target_lifecycle_node = camera_node,
              start_state = 'configuring',
              goal_state = 'inactive',
              entities = [
                  LogInfo(msg = "Emitting 'TRANSITION_ACTIVATE' event"),
                  camera_activate_evt,
                  ],
              )
          )

    #
    # active -> deactivating -> inactive
    #
    camera_node_active_to_inactive_handler = \
      RegisterEventHandler(
          OnStateTransition(
              target_lifecycle_node = camera_node,
              start_state = 'deactivating',
              goal_state = 'inactive',
              entities = [
                  LogInfo(msg = "Emitting 'TRANSITION_CLEANUP' event"),
                  camera_cleanup_evt,
                  ],
              )
          )

    #
    # inactive -> cleaningup -> unconfigured
    #
    camera_node_inactive_to_unconfigured_handler = \
      RegisterEventHandler(
          OnStateTransition(
              target_lifecycle_node = camera_node,
              start_state = 'cleaningup',
              goal_state = 'unconfigured',
              entities = [
                  LogInfo(msg = "Emitting 'TRANSITION_CONFIGURE' event"),
                  camera_configure_evt,
                  ],
              )
          )

    #
    # * -> errorprocessing -> unconfigured
    #
    camera_node_errorprocessing_to_unconfigured_handler = \
      RegisterEventHandler(
          OnStateTransition(
              target_lifecycle_node = camera_node,
              start_state = 'errorprocessing',
              goal_state = 'unconfigured',
              entities = [
                  LogInfo(msg = "Emitting 'TRANSITION_CONFIGURE' event"),
                  camera_configure_evt,
                  ],
              )
          )

    #
    # * -> shuttingdown -> finalized
    #
    camera_node_shuttingdown_to_finalized_handler = \
      RegisterEventHandler(
          OnStateTransition(
              target_lifecycle_node = camera_node,
              start_state = 'shuttingdown',
              goal_state = 'finalized',
              entities = [
                  LogInfo(msg = "Emitting 'SHUTDOWN' event"),
                  camera_shutdown_evt,
                  ],
              )
          )

    #------------------------------------------------------------
    # Now, add all the actions to a launch description and return it
    #------------------------------------------------------------

    ld = LaunchDescription()
    ld.add_action(camera_node_unconfigured_to_inactive_handler)
    ld.add_action(camera_node_active_to_inactive_handler)
    ld.add_action(camera_node_inactive_to_unconfigured_handler)
    ld.add_action(camera_node_errorprocessing_to_unconfigured_handler)
    ld.add_action(camera_node_shuttingdown_to_finalized_handler)
    ld.add_action(tf_node)
    ld.add_action(camera_node)
    ld.add_action(camera_configure_evt)

    return ld
Esempio n. 25
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')
    launch_dir = os.path.join(bringup_dir, 'launch')

    # Create the launch configuration variables
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    bt_xml_file = LaunchConfiguration('bt_xml_file')
    autostart = LaunchConfiguration('autostart')

    # Launch configuration variables specific to simulation
    rviz_config_file = LaunchConfiguration('rviz_config_file')
    use_simulator = LaunchConfiguration('use_simulator')
    simulator = LaunchConfiguration('simulator')
    world = LaunchConfiguration('world')

    # Declare the launch arguments
    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value=os.path.join(bringup_dir, 'maps',
                                   'turtlebot3_world.yaml'),
        description='Full path to map file to load')

    declare_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time',
        default_value='true',
        description='Use simulation (Gazebo) clock if true')

    declare_params_file_cmd = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    declare_bt_xml_cmd = DeclareLaunchArgument(
        'bt_xml_file',
        default_value=os.path.join(get_package_prefix('nav2_bt_navigator'),
                                   'behavior_trees',
                                   'navigate_w_replanning_and_recovery.xml'),
        description='Full path to the behavior tree xml file to use')

    declare_autostart_cmd = DeclareLaunchArgument(
        'autostart',
        default_value='false',
        description='Automatically startup the nav2 stack')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config_file',
        default_value=os.path.join(bringup_dir, 'rviz',
                                   'nav2_default_view.rviz'),
        description='Full path to the RVIZ config file to use')

    declare_use_simulator_cmd = DeclareLaunchArgument(
        'use_simulator',
        default_value='True',
        description='Whether to start the simulator')

    declare_simulator_cmd = DeclareLaunchArgument(
        'simulator',
        default_value='gazebo',
        description='The simulator to use (gazebo or gzserver)')

    declare_world_cmd = DeclareLaunchArgument(
        'world',
        # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
        #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
        # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
        #                            'worlds/turtlebot3_worlds/waffle.model'),
        default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'),
        description='Full path to world model file to load')

    # Specify the actions
    start_gazebo_cmd = ExecuteProcess(
        condition=IfCondition(use_simulator),
        cmd=[simulator, '-s', 'libgazebo_ros_init.so', world],
        cwd=[launch_dir],
        output='screen')

    urdf = os.path.join(get_package_share_directory('turtlebot3_description'),
                        'urdf', 'turtlebot3_waffle.urdf')

    start_robot_state_publisher_cmd = Node(
        package='robot_state_publisher',
        node_executable='robot_state_publisher',
        node_name='robot_state_publisher',
        output='screen',
        parameters=[{
            'use_sim_time': use_sim_time
        }],
        arguments=[urdf])

    # TODO(orduno) RVIZ crashing if launched as a node: https://github.com/ros2/rviz/issues/442
    #              Launching as node works after applying the change described on the github issue.
    # start_rviz_cmd = Node(
    #     package='rviz2',
    #     node_executable='rviz2',
    #     node_name='rviz2',
    #     arguments=['-d', rviz_config_file],
    #     output='screen')

    start_rviz_cmd = ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('rviz2'), 'lib/rviz2/rviz2'),
        ['-d', rviz_config_file]
    ],
                                    cwd=[launch_dir],
                                    output='screen')

    exit_event_handler = RegisterEventHandler(
        event_handler=OnProcessExit(target_action=start_rviz_cmd,
                                    on_exit=EmitEvent(event=Shutdown(
                                        reason='rviz exited'))))

    bringup_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource(
        os.path.join(launch_dir, 'nav2_bringup_launch.py')),
                                           launch_arguments={
                                               'map': map_yaml_file,
                                               'use_sim_time': use_sim_time,
                                               'params_file': params_file,
                                               'bt_xml_file': bt_xml_file,
                                               'autostart': autostart
                                           }.items())

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_map_yaml_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_bt_xml_cmd)
    ld.add_action(declare_autostart_cmd)

    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_use_simulator_cmd)
    ld.add_action(declare_simulator_cmd)
    ld.add_action(declare_world_cmd)

    # Add any actions to launch in simulation (conditioned on 'use_simulator')
    ld.add_action(start_gazebo_cmd)

    # Add other nodes and processes we need
    ld.add_action(start_rviz_cmd)
    ld.add_action(exit_event_handler)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(start_robot_state_publisher_cmd)
    ld.add_action(bringup_cmd)

    return ld
def generate_launch_description():

    # use: 'zed' for "ZED" camera - 'zedm' for "ZED mini" camera
    camera_model = 'zed'

    # URDF file to be loaded by Robot State Publisher
    urdf = os.path.join(get_package_share_directory('stereolabs_zed'), 'urdf',
                        camera_model + '.urdf')

    # ZED Configurations to be loaded by ZED Node
    config_common = os.path.join(get_package_share_directory('stereolabs_zed'),
                                 'config', 'common.yaml')

    config_camera = os.path.join(get_package_share_directory('stereolabs_zed'),
                                 'config', camera_model + '.yaml')

    # Set LOG format
    os.environ[
        'RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '{time}: [{name}] [{severity}]\t{message}'

    # Launch Description
    ld = launch.LaunchDescription()

    # Prepare the ZED node
    zed_node = LifecycleNode(
        node_namespace='zed',  # must match the namespace in config -> YAML
        node_name='zed_node',  # must match the node name in config -> YAML
        package='stereolabs_zed',
        node_executable='zed_wrapper_node',
        output='screen',
        parameters=[
            config_common,  # Common parameters
            config_camera,  # Camera related parameters
        ])

    # Prepare the Robot State Publisher node
    rsp_node = Node(node_name='zed_state_publisher',
                    package='robot_state_publisher',
                    node_executable='robot_state_publisher',
                    output='screen',
                    arguments=[urdf, 'robot_description:=zed_description'])

    # Make the ZED node take the 'configure' transition
    zed_configure_trans_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=launch.events.matches_action(zed_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
    ))

    # Make the ZED node take the 'activate' transition
    zed_activate_trans_event = EmitEvent(event=ChangeState(
        lifecycle_node_matcher=launch.events.matches_action(zed_node),
        transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
    ))

    # Shutdown event
    shutdown_event = EmitEvent(event=launch.events.Shutdown())

    # When the ZED node reaches the 'inactive' state from 'unconfigured', make it take the 'activate' transition and start the Robot State Publisher
    zed_inactive_from_unconfigured_state_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=zed_node,
            start_state='configuring',
            goal_state='inactive',
            entities=[
                # Log
                LogInfo(
                    msg=
                    "'ZED' reached the 'INACTIVE' state, start the 'Robot State Publisher' node and 'activating'."
                ),
                # Robot State Publisher
                rsp_node,
                # Change State event ( inactive -> active )
                zed_activate_trans_event,
            ],
        ))

    # When the ZED node reaches the 'inactive' state from 'active', it has been deactivated and it will wait for a manual activation
    zed_inactive_from_active_state_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=zed_node,
            start_state='deactivating',
            goal_state='inactive',
            entities=[
                # Log
                LogInfo(
                    msg=
                    "'ZED' reached the 'INACTIVE' state from 'ACTIVE' state. Waiting for manual activation..."
                )
            ],
        ))

    # When the ZED node reaches the 'active' state, log a message.
    zed_active_state_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=zed_node,
            goal_state='active',
            entities=[
                # Log
                LogInfo(msg="'ZED' reached the 'ACTIVE' state"),
            ],
        ))

    # When the ZED node reaches the 'finalized' state, log a message and exit.
    zed_finalized_state_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=zed_node,
            goal_state='finalized',
            entities=[
                # Log
                LogInfo(
                    msg=
                    "'ZED' reached the 'FINALIZED' state. Killing the node..."
                ),
                shutdown_event,
            ],
        ))

    # Add the actions to the launch description.
    # The order they are added reflects the order in which they will be executed.
    ld.add_action(zed_inactive_from_unconfigured_state_handler)
    ld.add_action(zed_inactive_from_active_state_handler)
    ld.add_action(zed_active_state_handler)
    ld.add_action(zed_finalized_state_handler)
    ld.add_action(zed_node)
    ld.add_action(zed_configure_trans_event)

    return ld
Esempio n. 27
0
def generate_launch_description():
    # Get the launch directory
    pkg_dir = get_package_share_directory('clean_up')
    nav_dir = get_package_share_directory('gb_navigation')
    manipulation_dir = get_package_share_directory('gb_manipulation')
    gb_world_model_dir = get_package_share_directory('gb_world_model')
    world_config_dir = os.path.join(gb_world_model_dir, 'config')

    namespace = LaunchConfiguration('namespace')
    dope_params_file = LaunchConfiguration('dope_params_file')

    declare_dope_params_cmd = DeclareLaunchArgument(
        'dope_params_file',
        default_value=os.path.join(get_package_share_directory('dope_launch'),
                                   'config', 'config_pose.yaml'),
        description='Full path to the TF Pose Estimation parameters file to use'
    )

    declare_namespace_cmd = DeclareLaunchArgument('namespace',
                                                  default_value='',
                                                  description='Namespace')

    stdout_linebuf_envvar = SetEnvironmentVariable(
        'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1')

    gb_manipulation_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(get_package_share_directory('gb_manipulation'),
                         'launch', 'gb_manipulation_launch.py')))

    gb_navigation_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(get_package_share_directory('gb_navigation'),
                         'launch', 'nav2_tiago_launch.py')))

    plansys2_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(get_package_share_directory('plansys2_bringup'),
                         'launch', 'plansys2_bringup_launch_monolithic.py')),
        launch_arguments={
            'model_file':
            pkg_dir + '/pddl/domain.pddl:' + nav_dir + '/pddl/domain.pddl'
        }.items())

    dope_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(get_package_share_directory('dope_launch'), 'launch',
                         'dope_launch.py')),
        launch_arguments={'dope_params_file': dope_params_file}.items())

    # Specify the actions
    clean_up_executor_cmd = LifecycleNode(package='clean_up',
                                          executable='cleanup_executor_node',
                                          name='cleanup_executor_node')

    emit_event_to_request_that_clean_up_executor_configure_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(
                clean_up_executor_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))

    emit_event_to_request_that_clean_up_executor_activate_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(
                clean_up_executor_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE,
        ))

    on_configure_clean_up_executor_handler = RegisterEventHandler(
        OnStateTransition(
            target_lifecycle_node=clean_up_executor_cmd,
            goal_state='inactive',
            entities=[
                emit_event_to_request_that_clean_up_executor_activate_transition
            ]))

    # Specify the dependencies
    vision_cmd = LifecycleNode(package='clean_up',
                               executable='vision_sim_node',
                               name='vision')
    emit_event_to_request_that_vision_configure_transition = EmitEvent(
        event=ChangeState(
            lifecycle_node_matcher=launch.events.matches_action(vision_cmd),
            transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
        ))

    attention_manager_cmd = Node(package='gb_attention',
                                 executable='attention_server',
                                 output='screen')

    wm_cmd = Node(package='gb_world_model',
                  executable='world_model_main',
                  output='screen',
                  parameters=[world_config_dir + '/world.yml'])

    ld = LaunchDescription()

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_dope_params_cmd)

    # Declare the launch options

    # Event handlers
    ld.add_action(on_configure_clean_up_executor_handler)

    ld.add_action(gb_manipulation_cmd)
    ld.add_action(gb_navigation_cmd)
    ld.add_action(plansys2_cmd)
    ld.add_action(clean_up_executor_cmd)
    ld.add_action(vision_cmd)

    ld.add_action(emit_event_to_request_that_vision_configure_transition)
    ld.add_action(
        emit_event_to_request_that_clean_up_executor_configure_transition)

    ld.add_action(attention_manager_cmd)
    ld.add_action(wm_cmd)
    ld.add_action(dope_cmd)

    return ld
Esempio n. 28
0
def generate_launch_description():

    namespace = LaunchConfiguration('namespace')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    bt_xml_file = LaunchConfiguration('bt_xml_file')
    use_remappings = LaunchConfiguration('use_remappings')

    # TODO(orduno) Remove once `PushNodeRemapping` is resolved
    #              https://github.com/ros2/launch_ros/issues/56
    remappings = [((namespace, '/tf'), '/tf'),
                  ((namespace, '/tf_static'), '/tf_static'), ('/tf', 'tf'),
                  ('/tf_static', 'tf_static')]

    # Create our own temporary YAML files that include substitutions
    param_substitutions = {
        'use_sim_time': use_sim_time,
        'bt_xml_filename': bt_xml_file,
    }

    configured_params = RewrittenYaml(source_file=params_file,
                                      root_key=namespace,
                                      param_rewrites=param_substitutions,
                                      convert_types=True)

    return LaunchDescription([
        DeclareLaunchArgument('namespace',
                              default_value='',
                              description='Top-level namespace'),
        DeclareLaunchArgument('use_sim_time',
                              default_value='false',
                              description='Use simulation/bag clock if true'),
        DeclareLaunchArgument(
            'params_file',
            description='Full path to the ROS2 parameters file to use'),
        DeclareLaunchArgument(
            'bt_xml_file',
            default_value=os.path.join(
                get_package_share_directory('nav2_bt_navigator'),
                'behavior_trees', 'navigate_w_replanning_and_recovery.xml'),
            description='Full path to the behavior tree xml file to use'),
        DeclareLaunchArgument(
            'use_remappings',
            default_value='false',
            description='Arguments to pass to all nodes launched by the file'),
        Node(
            package='nav2_controller',
            node_executable='controller_server',
            output='log',
            parameters=[configured_params],
            use_remappings=IfCondition(use_remappings),
            remappings=remappings,
            on_exit=EmitEvent(event=Shutdown(reason='nav2_controller_error'))),
        Node(package='nav2_planner',
             node_executable='planner_server',
             node_name='planner_server',
             output='log',
             parameters=[configured_params],
             use_remappings=IfCondition(use_remappings),
             remappings=remappings,
             on_exit=EmitEvent(event=Shutdown(reason='nav2_planner_error'))),
        Node(
            package='nav2_recoveries',
            node_executable='recoveries_server',
            node_name='recoveries_server',
            output='log',
            parameters=[{
                'use_sim_time': use_sim_time
            }],
            use_remappings=IfCondition(use_remappings),
            remappings=remappings,
            on_exit=EmitEvent(event=Shutdown(reason='nav2_recoveries_error'))),
        Node(package='nav2_bt_navigator',
             node_executable='bt_navigator',
             node_name='bt_navigator',
             output='log',
             parameters=[configured_params],
             use_remappings=IfCondition(use_remappings),
             remappings=remappings,
             on_exit=EmitEvent(event=Shutdown(
                 reason='nav2_bt_navigator_error'))),
        Node(package='nav2_waypoint_follower',
             node_executable='waypoint_follower',
             node_name='waypoint_follower',
             output='log',
             parameters=[configured_params],
             use_remappings=IfCondition(use_remappings),
             remappings=remappings,
             on_exit=EmitEvent(event=Shutdown(
                 reason='nav2_waypoint_follower_error'))),
    ])
Esempio n. 29
0
def generate_launch_description():
    # Get the launch directory
    nav2_bringup_dir = get_package_share_directory('nav2_bringup')
    marathon_dir = get_package_share_directory('marathon_ros2_bringup')
    marathon_launch_dir = os.path.join(marathon_dir, 'launch')

    # Create the launch configuration variables
    namespace = LaunchConfiguration('namespace')
    use_namespace = LaunchConfiguration('use_namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    bt_xml_file = LaunchConfiguration('bt_xml_file')
    autostart = LaunchConfiguration('autostart')
    cmd_vel_topic = LaunchConfiguration('cmd_vel_topic')

    # Launch configuration variables specific to simulation
    rviz_config_file = LaunchConfiguration('rviz_config_file')
    use_rviz = LaunchConfiguration('use_rviz')

    # TODO(orduno) Remove once `PushNodeRemapping` is resolved
    #              https://github.com/ros2/launch_ros/issues/56
    remappings = [((namespace, '/tf'), '/tf'),
                  ((namespace, '/tf_static'), '/tf_static'), ('/tf', 'tf'),
                  ('/tf_static', 'tf_static')]

    # Declare the launch arguments
    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace', default_value='', description='Top-level namespace')
    declare_use_namespace_cmd = DeclareLaunchArgument(
        'use_namespace',
        default_value='false',
        description='Whether to apply a namespace to the navigation stack')
    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value=os.path.join(marathon_dir, 'maps/aulario', 'map.yaml'),
        description='Full path to map file to load')

    declare_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time',
        default_value='false',
        description='Use simulation (Gazebo) clock if true')

    declare_params_file_cmd = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(marathon_dir, 'params',
                                   'nav2_marathon_teb_tiago_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    #declare_params_file_cmd = DeclareLaunchArgument(
    #    'params_file',
    #    default_value=os.path.join(nav2_bringup_dir, 'params', 'nav2_params.yaml'),
    #    description='Full path to the ROS2 parameters file to use for all launched nodes')

    declare_bt_xml_cmd = DeclareLaunchArgument(
        'bt_xml_file',
        default_value=os.path.join(
            get_package_share_directory('marathon_ros2_bringup'),
            'behavior_trees', 'navigate_w_replanning_and_recovery.xml'),
        description='Full path to the behavior tree xml file to use')

    declare_autostart_cmd = DeclareLaunchArgument(
        'autostart',
        default_value='true',
        description='Automatically startup the nav2 stack')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config_file',
        default_value=os.path.join(nav2_bringup_dir, 'rviz',
                                   'nav2_default_view.rviz'),
        description='Full path to the RVIZ config file to use')

    declare_use_rviz_cmd = DeclareLaunchArgument(
        'use_rviz', default_value='True', description='Whether to start RVIZ')
    declare_cmd_vel_topic_cmd = DeclareLaunchArgument(
        'cmd_vel_topic',
        default_value='nav_vel',
        description='Command velocity topic')

    start_rviz_cmd = Node(condition=IfCondition(use_rviz),
                          package='rviz2',
                          node_executable='rviz2',
                          arguments=['-d', rviz_config_file],
                          output='log',
                          remappings=[('/tf', 'tf'),
                                      ('/tf_static', 'tf_static'),
                                      ('goal_pose', 'goal_pose'),
                                      ('/clicked_point', 'clicked_point'),
                                      ('/initialpose', 'initialpose')])

    exit_event_handler = RegisterEventHandler(
        event_handler=OnProcessExit(target_action=start_rviz_cmd,
                                    on_exit=EmitEvent(event=Shutdown(
                                        reason='rviz exited'))))

    bringup_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource(
        os.path.join(marathon_launch_dir, 'nav2_bringup_launch.py')),
                                           launch_arguments={
                                               'namespace': namespace,
                                               'use_namespace': use_namespace,
                                               'map': map_yaml_file,
                                               'use_sim_time': use_sim_time,
                                               'params_file': params_file,
                                               'bt_xml_file': bt_xml_file,
                                               'autostart': autostart,
                                               'cmd_vel_topic': cmd_vel_topic
                                           }.items())

    marathon_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource(
        os.path.join(marathon_launch_dir, 'nav2_marathon_launch.py')),
                                            launch_arguments={
                                                'total_distance_sum': '0.25',
                                                'next_wp': '0'
                                            }.items())

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_namespace_cmd)
    ld.add_action(declare_map_yaml_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_bt_xml_cmd)
    ld.add_action(declare_autostart_cmd)

    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_use_rviz_cmd)
    ld.add_action(declare_cmd_vel_topic_cmd)

    # Add any conditioned actions
    ld.add_action(start_rviz_cmd)

    # Add other nodes and processes we need
    ld.add_action(exit_event_handler)

    ld.add_action(marathon_cmd)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(bringup_cmd)

    return ld
Esempio n. 30
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')
    launch_dir = os.path.join(bringup_dir, 'launch')

    # Create the launch configuration variables
    namespace = LaunchConfiguration('namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    bt_xml_file = LaunchConfiguration('bt_xml_file')
    autostart = LaunchConfiguration('autostart')
    use_remappings = LaunchConfiguration('use_remappings')

    # Launch configuration variables specific to simulation
    rviz_config_file = LaunchConfiguration('rviz_config_file')
    use_simulator = LaunchConfiguration('use_simulator')
    use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
    use_rviz = LaunchConfiguration('use_rviz')
    simulator = LaunchConfiguration('simulator')
    world = LaunchConfiguration('world')

    # TODO(orduno) Remove once `PushNodeRemapping` is resolved
    #              https://github.com/ros2/launch_ros/issues/56
    remappings = [((namespace, '/tf'), '/tf'),
                  ((namespace, '/tf_static'), '/tf_static'), ('/scan', 'scan'),
                  ('/tf', 'tf'), ('/tf_static', 'tf_static'),
                  ('/cmd_vel', 'cmd_vel'), ('/map', 'map')]

    # Declare the launch arguments
    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace', default_value='', description='Top-level namespace')

    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value=os.path.join(bringup_dir, 'maps',
                                   'turtlebot3_world.yaml'),
        description='Full path to map file to load')

    declare_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time',
        default_value='true',
        description='Use simulation (Gazebo) clock if true')

    declare_params_file_cmd = DeclareLaunchArgument(
        'params_file',
        default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    declare_bt_xml_cmd = DeclareLaunchArgument(
        'bt_xml_file',
        default_value=os.path.join(
            get_package_share_directory('nav2_bt_navigator'), 'behavior_trees',
            'navigate_w_replanning_and_recovery.xml'),
        description='Full path to the behavior tree xml file to use')

    declare_autostart_cmd = DeclareLaunchArgument(
        'autostart',
        default_value='false',
        description='Automatically startup the nav2 stack')

    declare_use_remappings_cmd = DeclareLaunchArgument(
        'use_remappings',
        default_value='false',
        description='Arguments to pass to all nodes launched by the file')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config_file',
        default_value=os.path.join(bringup_dir, 'rviz',
                                   'nav2_default_view.rviz'),
        description='Full path to the RVIZ config file to use')

    declare_use_simulator_cmd = DeclareLaunchArgument(
        'use_simulator',
        default_value='True',
        description='Whether to start the simulator')

    declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
        'use_robot_state_pub',
        default_value='True',
        description='Whether to start the robot state publisher')

    declare_use_rviz_cmd = DeclareLaunchArgument(
        'use_rviz', default_value='True', description='Whether to start RVIZ')

    declare_simulator_cmd = DeclareLaunchArgument(
        'simulator',
        default_value='gazebo',
        description='The simulator to use (gazebo or gzserver)')

    declare_world_cmd = DeclareLaunchArgument(
        'world',
        # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
        #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
        # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
        #                            'worlds/turtlebot3_worlds/waffle.model'),
        default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'),
        description='Full path to world model file to load')

    # Specify the actions
    start_gazebo_cmd = ExecuteProcess(
        condition=IfCondition(use_simulator),
        cmd=[simulator, '-s', 'libgazebo_ros_init.so', world],
        cwd=[launch_dir],
        output='screen')

    urdf = os.path.join(get_package_share_directory('turtlebot3_description'),
                        'urdf', 'turtlebot3_waffle.urdf')

    start_robot_state_publisher_cmd = Node(
        condition=IfCondition(use_robot_state_pub),
        package='robot_state_publisher',
        node_executable='robot_state_publisher',
        node_name='robot_state_publisher',
        output='screen',
        parameters=[{
            'use_sim_time': use_sim_time
        }],
        use_remappings=IfCondition(use_remappings),
        remappings=remappings,
        arguments=[urdf])

    start_rviz_cmd = Node(condition=IfCondition(use_rviz),
                          package='rviz2',
                          node_executable='rviz2',
                          node_name='rviz2',
                          arguments=['-d', rviz_config_file],
                          output='screen',
                          use_remappings=IfCondition(use_remappings),
                          remappings=[('/tf', 'tf'),
                                      ('/tf_static', 'tf_static'),
                                      ('goal_pose', 'goal_pose'),
                                      ('/clicked_point', 'clicked_point'),
                                      ('/initialpose', 'initialpose')])

    exit_event_handler = RegisterEventHandler(
        event_handler=OnProcessExit(target_action=start_rviz_cmd,
                                    on_exit=EmitEvent(event=Shutdown(
                                        reason='rviz exited'))))

    bringup_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource(
        os.path.join(launch_dir, 'nav2_bringup_launch.py')),
                                           launch_arguments={
                                               'namespace': namespace,
                                               'map': map_yaml_file,
                                               'use_sim_time': use_sim_time,
                                               'params_file': params_file,
                                               'bt_xml_file': bt_xml_file,
                                               'autostart': autostart,
                                               'use_remappings': use_remappings
                                           }.items())

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_map_yaml_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_bt_xml_cmd)
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_use_remappings_cmd)

    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_use_simulator_cmd)
    ld.add_action(declare_use_robot_state_pub_cmd)
    ld.add_action(declare_use_rviz_cmd)
    ld.add_action(declare_simulator_cmd)
    ld.add_action(declare_world_cmd)

    # Add any conditioned actions
    ld.add_action(start_gazebo_cmd)
    ld.add_action(start_rviz_cmd)

    # Add other nodes and processes we need
    ld.add_action(exit_event_handler)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(start_robot_state_publisher_cmd)
    ld.add_action(bringup_cmd)

    return ld