def generate_launch_description():
    map_yaml_file = os.getenv('TEST_MAP')
    world = os.getenv('TEST_WORLD')

    bt_navigator_xml = os.path.join(get_package_share_directory('nav2_bt_navigator'),
                                    'behavior_trees',
                                    os.getenv('BT_NAVIGATOR_XML'))

    bringup_dir = get_package_share_directory('nav2_bringup')
    params_file = os.path.join(bringup_dir, 'params', 'nav2_params.yaml')

    # Replace the `use_astar` setting on the params file
    param_substitutions = {
        'planner_server.ros__parameters.GridBased.use_astar': 'False'}
    configured_params = RewrittenYaml(
        source_file=params_file,
        root_key='',
        param_rewrites=param_substitutions,
        convert_types=True)

    context = LaunchContext()
    new_yaml = configured_params.perform(context)
    return LaunchDescription([
        SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),
        SetEnvironmentVariable('RCUTILS_LOGGING_USE_STDOUT', '1'),

        # Launch gazebo server for simulation
        ExecuteProcess(
            cmd=['gzserver', '-s', 'libgazebo_ros_init.so',
                 '--minimal_comms', world],
            output='screen'),

        # TODO(orduno) Launch the robot state publisher instead
        #              using a local copy of TB3 urdf file
        Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            output='screen',
            arguments=['0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link']),

        Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            output='screen',
            arguments=['0', '0', '0', '0', '0', '0', 'base_link', 'base_scan']),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(bringup_dir, 'launch', 'bringup_launch.py')),
            launch_arguments={'namespace': '',
                              'use_namespace': 'False',
                              'map': map_yaml_file,
                              'use_sim_time': 'True',
                              'params_file': new_yaml,
                              'bt_xml_file': bt_navigator_xml,
                              'autostart': 'True'}.items()),
    ])
def generate_launch_description():
    '''    
    Run the given nodes in the robot's namespace
    '''
    
    sl = SimpleLauncher()
    sl.declare_arg('robot',default_value='turtlebot1')
    
    with sl.group(ns=sl.arg('robot')):
        
        configured_params = RewrittenYaml(
                source_file=sl.find('nav_tutorial', 'xbox.yaml'),
                root_key=sl.arg('robot'),
                convert_types=True,
                param_rewrites={})
        
        sl.node('joy','joy_node',
                parameters=[{
                'dev': '/dev/input/js0',
                'deadzone': 0.3,
                'autorepeat_rate': 20.0,
            }])
                
        sl.node('teleop_twist_joy', 'teleop_node', name='teleop_twist_joy_node', parameters=[configured_params])
        
    return sl.launch_description()
def generate_launch_description():
    ros2_cpp_params_example_dir = get_package_share_directory('ros2_cpp_params_example')

    original_params_file = path.join(
        ros2_cpp_params_example_dir, 'params', 'params.yaml')

    overrides_file = path.join(
        ros2_cpp_params_example_dir, 'params', 'overrides.yaml')

    with open(overrides_file) as file:
        param_substitutions = yaml.load(file, Loader=yaml.FullLoader)

    param_substitutions = {key: str(value) for key, value in param_substitutions.items()}

    configured_params = RewrittenYaml(
        source_file=original_params_file,
        param_rewrites=param_substitutions,
        convert_types=True)

    ros2_cpp_params_example_launch_file = path.join(
        get_package_share_directory('ros2_cpp_params_example'),
        'launch', 'ex_3_params_file.launch.py')

    return LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(ros2_cpp_params_example_launch_file),
            launch_arguments={'params_file': configured_params}.items())
    ])
Exemple #4
0
 def configure(rewrites):
     rewrites.update({'use_sim_time': sl.arg('use_sim_time')})
     return RewrittenYaml(
         #source_file=sl.find('nav2_bringup', 'nav2_params.yaml'),
         source_file=sl.find('nav_tutorial', 'nav_param.yaml'),
         root_key=robot,
         param_rewrites=rewrites,
         convert_types=True)
Exemple #5
0
def generate_launch_description():
    map_yaml_file = launch.substitutions.LaunchConfiguration('map')
    use_sim_time = launch.substitutions.LaunchConfiguration('use_sim_time',
                                                            default='false')
    autostart = launch.substitutions.LaunchConfiguration('autostart')
    params_file = launch.substitutions.LaunchConfiguration('params')

    # Create our own temporary YAML files that include substitutions
    param_substitutions = {
        'use_sim_time': use_sim_time,
        'yaml_filename': map_yaml_file
    }
    configured_params = RewrittenYaml(source_file=params_file,
                                      rewrites=param_substitutions,
                                      convert_types=True)

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        launch.actions.SetEnvironmentVariable(
            'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        launch.actions.DeclareLaunchArgument(
            'map', description='Full path to map file to load'),
        launch.actions.DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        launch.actions.DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        launch.actions.DeclareLaunchArgument(
            'params',
            default_value=[
                launch.substitutions.ThisLaunchFileDir(), '/nav2_params.yaml'
            ],
            description='Full path to the ROS2 parameters file to use'),
        launch_ros.actions.Node(package='nav2_map_server',
                                node_executable='map_server',
                                node_name='map_server',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='nav2_amcl',
                                node_executable='amcl',
                                node_name='amcl',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='nav2_lifecycle_manager',
                                node_executable='lifecycle_manager',
                                node_name='lifecycle_manager_localize',
                                output='screen',
                                parameters=[{
                                    'use_sim_time': use_sim_time
                                }, {
                                    'autostart': autostart
                                }, {
                                    'node_names': ['map_server', 'amcl']
                                }]),
    ])
Exemple #6
0
def generate_launch_description():
    ros2_cpp_params_example_dir = get_package_share_directory('ros2_cpp_params_example')

    original_params_file = path.join(
        ros2_cpp_params_example_dir, 'params', 'params.yaml')

    param_substitutions = {'my_parameter': 'Parameter overridden with RewrittenYaml!',
                           'my_float_number': '2.71828'}

    configured_params = RewrittenYaml(
        source_file=original_params_file,
        param_rewrites=param_substitutions,
        convert_types=True)

    ros2_cpp_params_example_launch_file = path.join(
        get_package_share_directory('ros2_cpp_params_example'),
        'launch', 'ex_3_params_file.launch.py')

    return LaunchDescription([
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(ros2_cpp_params_example_launch_file),
            launch_arguments={'params_file': configured_params}.items())
    ])
Exemple #7
0
def generate_launch_description():
    # Get the launch directory
    pkg_dir = get_package_share_directory('service_test')

    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')

    param_substitutions = {
        'use_sim_time': use_sim_time
    }

    configured_params = RewrittenYaml(
        source_file=params_file,
        root_key="",
        param_rewrites=param_substitutions,
        convert_types=True)
    
    return LaunchDescription([

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

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

        Node(
            package="service_test",
            executable='service_test',
            name='cabot_publisher',
            output='screen',
            parameters=[configured_params])
    ])
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('robot_slam')

    namespace = LaunchConfiguration('namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    lifecycle_nodes = ['map_server', 'amcl']

    remappings = [('/tf', 'tf'),
                  ('/tf_static', 'tf_static'),
                  ('scan', 'base_scan')]

    param_substitutions = {
        'use_sim_time': use_sim_time,
        'yaml_filename': map_yaml_file}

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

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),

        DeclareLaunchArgument(
            'namespace', default_value='',
            description='Top-level namespace'),

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

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

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

        DeclareLaunchArgument(
            'params_file',
            default_value=os.path.join(bringup_dir, 'config', 'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),

        Node(
            package='nav2_map_server',
            executable='map_server',
            name='map_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        Node(
            package='nav2_amcl',
            executable='amcl',
            name='amcl',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),
        
        Node(
            package='nav2_lifecycle_manager',
            executable='lifecycle_manager',
            name='lifecycle_manager_localization',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time},
                        {'autostart': autostart},
                        {'node_names': lifecycle_nodes}]),
    ])
Exemple #9
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')

    namespace = LaunchConfiguration('namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    use_lifecycle_mgr = LaunchConfiguration('use_lifecycle_mgr')
    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,
        'yaml_filename': map_yaml_file
    }

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

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        DeclareLaunchArgument('namespace',
                              default_value='',
                              description='Top-level namespace'),
        DeclareLaunchArgument(
            'map',
            default_value=os.path.join(bringup_dir, 'maps',
                                       'turtlebot3_world.yaml'),
            description='Full path to map yaml file to load'),
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        DeclareLaunchArgument(
            'params_file',
            default_value=os.path.join(bringup_dir, 'params',
                                       'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),
        DeclareLaunchArgument(
            'use_lifecycle_mgr',
            default_value='true',
            description='Whether to launch the lifecycle manager'),
        DeclareLaunchArgument(
            'use_remappings',
            default_value='false',
            description='Arguments to pass to all nodes launched by the file'),
        Node(package='nav2_map_server',
             node_executable='map_server',
             node_name='map_server',
             output='screen',
             parameters=[configured_params],
             use_remappings=IfCondition(use_remappings),
             remappings=remappings),
        Node(package='nav2_amcl',
             node_executable='amcl',
             node_name='amcl',
             output='screen',
             parameters=[configured_params],
             use_remappings=IfCondition(use_remappings),
             remappings=remappings),
        Node(condition=IfCondition(use_lifecycle_mgr),
             package='nav2_lifecycle_manager',
             node_executable='lifecycle_manager',
             node_name='lifecycle_manager_localization',
             output='screen',
             parameters=[{
                 'use_sim_time': use_sim_time
             }, {
                 'autostart': autostart
             }, {
                 'node_names': ['map_server', 'amcl']
             }])
    ])
Exemple #10
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')
    use_namespace = LaunchConfiguration('use_namespace')
    slam = LaunchConfiguration('slam')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_file')
    autostart = LaunchConfiguration('autostart')
    use_composition = LaunchConfiguration('use_composition')

    # 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')]

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

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

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

    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_slam_cmd = DeclareLaunchArgument('slam',
                                             default_value='False',
                                             description='Whether run a SLAM')

    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map', description='Full path to map yaml 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(bringup_dir, 'params', 'nav2_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

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

    declare_use_composition_cmd = DeclareLaunchArgument(
        'use_composition',
        default_value='True',
        description='Whether to use composed bringup')

    # Specify the actions
    bringup_cmd_group = GroupAction([
        PushRosNamespace(condition=IfCondition(use_namespace),
                         namespace=namespace),
        IncludeLaunchDescription(PythonLaunchDescriptionSource(
            os.path.join(launch_dir, 'slam_launch.py')),
                                 condition=IfCondition(slam),
                                 launch_arguments={
                                     'namespace': namespace,
                                     'use_sim_time': use_sim_time,
                                     'autostart': autostart,
                                     'params_file': params_file
                                 }.items()),
        IncludeLaunchDescription(PythonLaunchDescriptionSource(
            os.path.join(launch_dir, 'localization_launch.py')),
                                 condition=IfCondition(
                                     PythonExpression(['not ', slam])),
                                 launch_arguments={
                                     'namespace': namespace,
                                     'map': map_yaml_file,
                                     'use_sim_time': use_sim_time,
                                     'autostart': autostart,
                                     'params_file': params_file
                                 }.items()),
        Node(condition=IfCondition(use_composition),
             package='nav2_bringup',
             executable='composed_bringup',
             output='screen',
             parameters=[configured_params, {
                 'autostart': autostart
             }],
             remappings=remappings),
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(launch_dir, 'navigation_launch.py')),
            condition=IfCondition(PythonExpression(['not ', use_composition])),
            launch_arguments={
                'namespace': namespace,
                'use_sim_time': use_sim_time,
                'autostart': autostart,
                'params_file': params_file
            }.items()),
    ])

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

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_namespace_cmd)
    ld.add_action(declare_slam_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_autostart_cmd)
    ld.add_action(declare_use_composition_cmd)

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

    return ld
Exemple #11
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')
    rover_config_dir = os.path.join(get_package_share_directory('rover_config'))

    namespace = LaunchConfiguration('namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    executables = ['map_server']  # ,'amcl']

    # 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')]

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

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

    return LaunchDescription([
        # Set env var to print messages colored. The ANSI color codes will appear in a log.
        SetEnvironmentVariable('RCUTILS_COLORIZED_OUTPUT', '1'),

        DeclareLaunchArgument(
            'namespace', default_value='',
            description='Top-level namespace'),

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

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

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

        DeclareLaunchArgument(
            'params_file',
            default_value=os.path.join(rover_config_dir, 'config', 'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),

        Node(
            package='nav2_map_server',
            executable='map_server',
            name='map_server',
            output='screen',
            parameters=[configured_params],
            remappings=remappings),

        # Node(
        #     package='nav2_amcl',
        #     executable='amcl',
        #     name='amcl',
        #     output='screen',
        #     parameters=[configured_params],
        #     remappings=remappings),

        Node(
            package='nav2_lifecycle_manager',
            executable='lifecycle_manager',
            name='lifecycle_manager_localization',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time},
                        {'autostart': autostart},
                        {'node_names': executables}])
    ])
def generate_launch_description():
    # Get the launch directory
    launch_dir = os.path.join(get_package_share_directory('nav2_bringup'), 'launch')

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

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

    stdout_linebuf_envvar = launch.actions.SetEnvironmentVariable(
        'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1')

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

    configured_params = RewrittenYaml(
        source_file=params_file, rewrites=param_substitutions,
        convert_types=True)

    # Declare the launch arguments
    declare_map_yaml_cmd = launch.actions.DeclareLaunchArgument(
        'map',
        default_value='test_map.yaml',
        description='Full path to map file to load')

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

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

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

    declare_bt_xml_cmd = launch.actions.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')


    start_robot_state_publisher_cmd = launch_ros.actions.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]
        )

    start_map_server_cmd = launch_ros.actions.Node(
        package='nav2_map_server',
        node_executable='map_server',
        node_name='map_server',
        output='screen',
        parameters=[configured_params])
    
    start_guidebot_node_cmd = launch_ros.actions.Node(
        package='guidebot_node',
        node_executable='guidebot_odom',
        node_name='guidebot_node',
        output='screen'
        )

    # start_localizer_cmd = launch_ros.actions.Node(
    #     package='nav2_amcl',
    #     node_executable='amcl',
    #     node_name='amcl',
    #     output='screen',
    #     parameters=[configured_params])

    start_world_model_cmd = launch_ros.actions.Node(
        package='nav2_world_model',
        node_executable='world_model',
        output='screen',
        parameters=[configured_params])

    start_dwb_cmd = launch_ros.actions.Node(
        package='dwb_controller',
        node_executable='dwb_controller',
        output='screen',
        parameters=[configured_params],
        remappings=[('/cmd_vel', '/hapirobo/cmd_vel')])

    start_planner_cmd = launch_ros.actions.Node(
        package='nav2_navfn_planner',
        node_executable='navfn_planner',
        node_name='navfn_planner',
        output='screen',
        parameters=[configured_params])

    start_recovery_cmd = launch_ros.actions.Node(
        package='nav2_recoveries',
        node_executable='recoveries_node',
        node_name='recoveries',
        output='screen',
        parameters=[{'use_sim_time': use_sim_time}],
        remappings=[('/amcl_pose', '/initialpose'), ('/cmd_vel', '/hapirobo/cmd_vel')])

    start_navigator_cmd = launch_ros.actions.Node(
        package='nav2_bt_navigator',
        node_executable='bt_navigator',
        node_name='bt_navigator',
        output='screen',
        parameters=[configured_params])

    start_lifecycle_manager_cmd = launch_ros.actions.Node(
        package='nav2_lifecycle_manager',
        node_executable='lifecycle_manager',
        node_name='lifecycle_manager',
        output='screen',
        parameters=[configured_params])

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

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

    # 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_autostart_cmd)
    ld.add_action(declare_bt_xml_cmd)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(start_lifecycle_manager_cmd)
    ld.add_action(start_map_server_cmd)
    ld.add_action(start_guidebot_node_cmd)
    # ld.add_action(start_localizer_cmd)
    ld.add_action(start_world_model_cmd)
    ld.add_action(start_dwb_cmd)
    ld.add_action(start_planner_cmd)
    ld.add_action(start_recovery_cmd)
    ld.add_action(start_navigator_cmd)

    ld.add_action(start_robot_state_publisher_cmd)

    return ld
def generate_launch_description():
    map_yaml_file = os.getenv('TEST_MAP')
    filter_mask_file = os.getenv('TEST_MASK')
    world = os.getenv('TEST_WORLD')

    bt_navigator_xml = os.path.join(
        get_package_share_directory('nav2_bt_navigator'), 'behavior_trees',
        os.getenv('BT_NAVIGATOR_XML'))

    bringup_dir = get_package_share_directory('nav2_bringup')
    script_dir = os.path.dirname(os.path.realpath(__file__))
    params_file = os.path.join(script_dir, 'keepout_params.yaml')

    # Replace the `use_astar` setting on the params file
    param_substitutions = {
        'planner_server.ros__parameters.GridBased.use_astar':
        os.getenv('ASTAR'),
        'filter_mask_server.ros__parameters.yaml_filename': filter_mask_file,
        'yaml_filename': filter_mask_file
    }
    configured_params = RewrittenYaml(source_file=params_file,
                                      root_key='',
                                      param_rewrites=param_substitutions,
                                      convert_types=True)

    return LaunchDescription([
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),

        # Launch gazebo server for simulation
        ExecuteProcess(cmd=[
            'gzserver', '-s', 'libgazebo_ros_init.so', '--minimal_comms', world
        ],
                       output='screen'),

        # TODO(orduno) Launch the robot state publisher instead
        #              using a local copy of TB3 urdf file
        Node(package='tf2_ros',
             executable='static_transform_publisher',
             output='screen',
             arguments=[
                 '0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link'
             ]),
        Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            output='screen',
            arguments=['0', '0', '0', '0', '0', '0', 'base_link',
                       'base_scan']),
        Node(package='nav2_lifecycle_manager',
             executable='lifecycle_manager',
             name='lifecycle_manager_filters',
             output='screen',
             parameters=[{
                 'node_names':
                 ['filter_mask_server', 'costmap_filter_info_server']
             }, {
                 'autostart': True
             }]),

        # Nodes required for Costmap Filters configuration
        Node(package='nav2_map_server',
             executable='map_server',
             name='filter_mask_server',
             output='screen',
             parameters=[configured_params]),
        Node(package='nav2_map_server',
             executable='costmap_filter_info_server',
             name='costmap_filter_info_server',
             output='screen',
             parameters=[configured_params]),
        IncludeLaunchDescription(PythonLaunchDescriptionSource(
            os.path.join(bringup_dir, 'launch', 'bringup_launch.py')),
                                 launch_arguments={
                                     'namespace': '',
                                     'use_namespace': 'False',
                                     'map': map_yaml_file,
                                     'use_sim_time': 'True',
                                     'params_file': configured_params,
                                     'bt_xml_file': bt_navigator_xml,
                                     'autostart': 'True'
                                 }.items()),
    ])
def generate_launch_description():
    # Get the launch directory
    costmap_filters_demo_dir = get_package_share_directory(
        'nav2_costmap_filters_demo')

    # Create our own temporary YAML files that include substitutions
    lifecycle_nodes = ['filter_mask_server', 'costmap_filter_info_server']

    # Parameters
    namespace = LaunchConfiguration('namespace')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    mask_yaml_file = LaunchConfiguration('mask')

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

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

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

    declare_params_file_cmd = DeclareLaunchArgument(
        'params_file',
        description='Full path to the ROS2 parameters file to use')

    declare_mask_yaml_file_cmd = DeclareLaunchArgument(
        'mask', description='Full path to filter mask yaml file to load')

    # Make re-written yaml
    param_substitutions = {
        'use_sim_time': use_sim_time,
        'yaml_filename': mask_yaml_file
    }

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

    # Nodes launching commands
    start_lifecycle_manager_cmd = Node(
        package='nav2_lifecycle_manager',
        executable='lifecycle_manager',
        name='lifecycle_manager_costmap_filters',
        namespace=namespace,
        output='screen',
        emulate_tty=True,  # https://github.com/ros2/launch/issues/188
        parameters=[{
            'use_sim_time': use_sim_time
        }, {
            'autostart': autostart
        }, {
            'node_names': lifecycle_nodes
        }])

    start_map_server_cmd = Node(
        package='nav2_map_server',
        executable='map_server',
        name='filter_mask_server',
        namespace=namespace,
        output='screen',
        emulate_tty=True,  # https://github.com/ros2/launch/issues/188
        parameters=[configured_params])

    start_costmap_filter_info_server_cmd = Node(
        package='nav2_map_server',
        executable='costmap_filter_info_server',
        name='costmap_filter_info_server',
        namespace=namespace,
        output='screen',
        emulate_tty=True,  # https://github.com/ros2/launch/issues/188
        parameters=[configured_params])

    ld = LaunchDescription()

    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_mask_yaml_file_cmd)

    ld.add_action(start_lifecycle_manager_cmd)
    ld.add_action(start_map_server_cmd)
    ld.add_action(start_costmap_filter_info_server_cmd)

    return ld
Exemple #15
0
def generate_launch_description():
    tf_remappings = [('/tf', 'tf'), ('/tf_static', 'tf_static')]

    lifecycle_nodes = ['controller_server',
                       'planner_server',
                       'recoveries_server',
                       'bt_navigator']

    default_behavior_tree = os.path.join(get_package_share_directory(
        'rj_training_bringup'), 'behavior_trees', 'navigate.xml')

    params_file = LaunchConfiguration('params_file')

    use_sim_time = LaunchConfiguration('use_sim_time')

    param_substitutions = {
        'use_sim_time': use_sim_time,
        'default_bt_xml_filename': LaunchConfiguration('behavior_tree')
    }

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

    return LaunchDescription([
        DeclareLaunchArgument(
            name='use_sim_time',
            default_value='false'
        ),
        DeclareLaunchArgument(
            name='params_file',
            default_value=os.path.join(get_package_share_directory(
                'rj_training_bringup'), 'config', 'nav_params.yaml')
        ),
        DeclareLaunchArgument(
            name='behavior_tree',
            default_value=default_behavior_tree
        ),
        Node(
            package='nav2_bt_navigator',
            executable='bt_navigator',
            name='bt_navigator',
            output='screen',
            parameters=[configured_params],
            remappings=tf_remappings
        ),
        Node(
            package='nav2_controller',
            executable='controller_server',
            output='screen',
            parameters=[configured_params],
            remappings=tf_remappings
        ),
        Node(
            package='nav2_planner',
            executable='planner_server',
            name='planner_server',
            output='screen',
            parameters=[configured_params],
            remappings=tf_remappings
        ),
        Node(
            package='nav2_recoveries',
            executable='recoveries_server',
            name='recoveries_server',
            output='screen',
            parameters=[configured_params],
            remappings=tf_remappings
        ),
        Node(
            package='nav2_lifecycle_manager',
            executable='lifecycle_manager',
            name='lifecycle_manager_navigation',
            output='screen',
            parameters=[
                {'use_sim_time': use_sim_time},
                {'autostart': True},
                {'node_names': lifecycle_nodes}
            ]
        )
    ])
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')

    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    use_lifecycle_mgr = LaunchConfiguration('use_lifecycle_mgr')

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

    configured_params = RewrittenYaml(source_file=params_file,
                                      rewrites=param_substitutions,
                                      convert_types=True)

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        DeclareLaunchArgument(
            'map',
            default_value=os.path.join(bringup_dir, 'maps',
                                       'turtlebot3_world.yaml'),
            description='Full path to map yaml file to load'),
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        DeclareLaunchArgument(
            'params_file',
            default_value=os.path.join(bringup_dir, 'params',
                                       'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),
        DeclareLaunchArgument(
            'use_lifecycle_mgr',
            default_value='true',
            description='Whether to launch the lifecycle manager'),
        Node(package='nav2_map_server',
             node_executable='map_server',
             node_name='map_server',
             output='screen',
             parameters=[configured_params]),
        Node(package='nav2_amcl',
             node_executable='amcl',
             node_name='amcl',
             output='screen',
             parameters=[configured_params]),
        Node(condition=IfCondition(use_lifecycle_mgr),
             package='nav2_lifecycle_manager',
             node_executable='lifecycle_manager',
             node_name='lifecycle_manager_localization',
             output='screen',
             parameters=[{
                 'use_sim_time': use_sim_time
             }, {
                 'autostart': autostart
             }, {
                 'node_names': ['map_server', 'amcl']
             }])
    ])
def generate_launch_description():
    # Get the launch directory
    launch_dir = os.path.join(get_package_share_directory('nav2_bringup'),
                              'launch')

    # Create the launch configuration variables
    autostart = launch.substitutions.LaunchConfiguration('autostart')
    bt_xml_file = launch.substitutions.LaunchConfiguration('bt')
    params_file = launch.substitutions.LaunchConfiguration('params')

    # Create our own temporary YAML files that include the following parameter substitutions
    param_substitutions = {
        'autostart': autostart,
        'bt_xml_filename': bt_xml_file,
    }
    configured_params = RewrittenYaml(source_file=params_file,
                                      rewrites=param_substitutions,
                                      convert_types=True)

    # Declare the launch arguments
    declare_autostart_cmd = launch.actions.DeclareLaunchArgument(
        'autostart',
        default_value='true',
        description='Automatically startup the nav2 stack')

    declare_bt_xml_cmd = launch.actions.DeclareLaunchArgument(
        'bt',
        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 for the BT navigator')

    declare_params_file_cmd = launch.actions.DeclareLaunchArgument(
        'params',
        default_value=[
            launch.substitutions.ThisLaunchFileDir(),
            '/../params/nav2_params.yaml'
        ],
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    stdout_linebuf_envvar = launch.actions.SetEnvironmentVariable(
        'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1')

    # Specify the actions
    start_world_model_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_world_model'),
                     'lib/nav2_world_model/world_model'),
        ['__params:=', configured_params]
    ],
                                                          cwd=[launch_dir],
                                                          output='screen')

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

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

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

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

    return ld
Exemple #18
0
def generate_launch_description():
    launch_dir = os.path.join(get_package_share_directory('tms_rc_bot'),
                              'launch')
    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    map_dir = LaunchConfiguration(
        'map',
        default=os.path.join(get_package_share_directory('tms_rc_bot'), 'maps',
                             'map_bsen.yaml'))

    # map_yaml_file = LaunchConfiguration('map')

    # bt_navigator_xml=os.path.join(get_package_share_directory('tms_rc_bot'), 'behavior_trees', 'navigate_w_recovery_retry.xml')

    params_file = 'guidebot_params.yaml'
    params_file_dir = LaunchConfiguration(
        'params',
        default=os.path.join(get_package_share_directory('tms_rc_bot'),
                             'params', params_file))

    bt_xml_file = LaunchConfiguration('bt_xml_file')
    autostart = LaunchConfiguration('autostart')

    # nav2_launch_file_dir = os.path.join(get_package_share_directory('nav2_bringup'), 'launch')

    # bt_navigator_install_path = get_package_prefix('nav2_bt_navigator')
    # bt_navigator_xml = os.path.join(bt_navigator_install_path,
    #                                 'behavior_trees',
    #                                 'navigate_w_recovery_retry.xml') # TODO(mkhansen): change to an input parameter

    # rviz_config_dir = os.path.join(get_package_share_directory('tms_rc_bot'), 'rviz', 'tb3_navigation2.rviz')

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

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

    param_substitutions = {
        'use_sim_time': use_sim_time,
        'yaml_filename': map_dir,
        'bt_xml_filename': bt_xml_file,
        'autostart': autostart
    }

    configured_params = RewrittenYaml(source_file=params_file_dir,
                                      rewrites=param_substitutions,
                                      convert_types=True)

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

    declare_params_file_cmd = DeclareLaunchArgument(
        'params',
        default_value=os.path.join(get_package_share_directory('tms_rc_bot'),
                                   'params', params_file),
        description='Full path to param file to load')

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

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

    # 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_bt_xml_cmd = DeclareLaunchArgument(
        'bt_xml_file',
        default_value=os.path.join(
            get_package_share_directory('tms_rc_bot'), 'behavior_trees',
            'navigate_w_replanning_without_recovery.xml'),
        description='Full path to the behavior tree xml file to use')

    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])

    start_double_node_cmd = Node(package='doublenode',
                                 node_executable='double_odom',
                                 node_name='double_node',
                                 output='screen')

    # start_map_server_cmd = Node(
    #     package='nav2_map_server',
    #     node_executable='map_server',
    #     node_name='map_server',
    #     output='screen',
    #     parameters=[{ 'use_sim_time': use_sim_time}, { 'yaml_filename': map_dir}]
    #     )

    start_map_server_cmd = Node(package='nav2_map_server',
                                node_executable='map_server',
                                node_name='map_server',
                                output='screen',
                                parameters=[configured_params])

    # start_localizer_cmd = Node(
    #     package='nav2_amcl',
    #     node_executable='amcl',
    #     node_name='amcl',
    #     output='screen',
    #     parameters=[configured_params])

    start_localizer_cmd = Node(package='robot_localization',
                               node_executable='se_node',
                               node_name='ekf_localization_node',
                               output='screen',
                               parameters=[params_file_dir],
                               remappings=[('/set_pose', '/initialpose')])

    start_world_model_cmd = Node(package='nav2_world_model',
                                 node_executable='world_model',
                                 output='screen',
                                 parameters=[configured_params])

    start_dwb_cmd = Node(package='dwb_controller',
                         node_executable='dwb_controller',
                         output='screen',
                         parameters=[configured_params],
                         remappings=[('/cmd_vel', '/cmd2vel'),
                                     ('/odom', '/odometry/vicon')])

    # start_planner_cmd = Node(
    #     package='nav2_navfn_planner',
    #     node_executable='navfn_planner',
    #     node_name='navfn_planner',
    #     output='screen',
    #     parameters=[{'use_sim_time': use_sim_time}],
    #     remappings=[('/amcl_pose', '/initialpose'), ('/cmd_vel', '/hapirobo/cmd_vel')]
    #     )

    start_planner_cmd = Node(
        package='nav2_navfn_planner',
        node_executable='navfn_planner',
        node_name='navfn_planner',
        output='screen',
        parameters=[configured_params]
        # remappings=[('/amcl_pose', '/initialpose'), ('/cmd_vel', '/hapirobo/cmd_vel')]
    )

    start_recovery_cmd = Node(package='nav2_recoveries',
                              node_executable='recoveries_node',
                              node_name='recoveries',
                              output='screen',
                              parameters=[{
                                  'use_sim_time': use_sim_time
                              }],
                              remappings=[('/amcl_pose', '/initialpose'),
                                          ('/cmd_vel', '/cmd2vel'),
                                          ('/odom', '/odometry/vicon')])

    start_navigator_cmd = Node(package='nav2_bt_navigator',
                               node_executable='bt_navigator',
                               node_name='bt_navigator',
                               output='screen',
                               parameters=[configured_params])

    start_lifecycle_manager_cmd = Node(package='nav2_lifecycle_manager',
                                       node_executable='lifecycle_manager',
                                       node_name='lifecycle_manager',
                                       output='screen',
                                       parameters=[configured_params])

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

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

    # 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_autostart_cmd)
    ld.add_action(declare_bt_xml_cmd)

    # Add the actions to launch all of the navigation nodes
    ld.add_action(start_lifecycle_manager_cmd)
    ld.add_action(start_double_node_cmd)
    ld.add_action(start_map_server_cmd)
    # ld.add_action(start_localizer_cmd)
    ld.add_action(start_world_model_cmd)
    ld.add_action(start_dwb_cmd)
    ld.add_action(start_planner_cmd)
    ld.add_action(start_recovery_cmd)
    ld.add_action(start_navigator_cmd)

    ld.add_action(start_robot_state_publisher_cmd)

    return ld
def generate_launch_description():
    '''    
    Example of AMCL (pure localization) for BB8
    '''

    sl = SimpleLauncher()

    sl.declare_arg('robot', 'bb8')
    robot = sl.arg('robot')
    robot_type = sl.py_eval("''.join(c for c in '", robot,
                            "' if not c.isdigit())")

    sl.declare_arg('use_nav', False)
    use_nav = sl.arg('use_nav')

    nav_nodes = [('nav2_controller', 'controller_server'),
                 ('nav2_planner', 'planner_server'),
                 ('nav2_bt_navigator', 'bt_navigator')]
    node_names = []
    print(robot.describe())

    with sl.group(ns=robot):

        sl.node('lab4_navigation',
                'vel2joints.py',
                parameters=[{
                    'static_tf': True
                }])

        # generate description
        sl.robot_state_publisher('lab4_navigation',
                                 sl.name_join(robot_type, '.xacro'),
                                 'urdf',
                                 xacro_args={'name': robot})

        with sl.group(unless_arg='use_nav'):
            # fire up slider publisher for cmd_vel
            cmd_file = sl.find('lab4_navigation', 'cmd_sliders.yaml')
            sl.node('slider_publisher',
                    'slider_publisher',
                    name='cmd_vel_manual',
                    arguments=[cmd_file])

        with sl.group(if_arg='use_nav'):
            # launch navigation nodes with remappings
            for pkg, executable in nav_nodes:
                robot_rad = sl.py_eval("'", robot_type,
                                       "'=='bb'and .27 or .16")
                configured_params = RewrittenYaml(
                    source_file=sl.find('lab4_navigation', 'nav_param.yaml'),
                    root_key=robot,
                    param_rewrites={
                        'robot_base_frame':
                        sl.py_eval("''.join(c for c in '", robot,
                                   "') + '/base_link'"),
                        'global_frame':
                        sl.py_eval("''.join(c for c in '", robot,
                                   "') + '/odom'"),
                        'topic':
                        sl.py_eval("'/' + ''.join(c for c in '", robot,
                                   "') + '/scan'"),
                        'robot_radius':
                        robot_rad,
                        'default_bt_xml_filename':
                        sl.find('nav2_bt_navigator',
                                'navigate_w_replanning_time.xml')
                    },
                    convert_types=True)
                sl.node(
                    pkg,
                    executable,
                    name=executable,
                    parameters=[configured_params],
                )
                node_names.append(executable)
            # run lifecycle manager just for navigation nodes
            sl.node('nav2_lifecycle_manager',
                    'lifecycle_manager',
                    name='lifecycle_manager',
                    output='screen',
                    parameters=[{
                        'autostart': True,
                        'node_names': node_names
                    }])

    return sl.launch_description()
Exemple #20
0
def generate_launch_description():
    map_yaml_file = os.getenv('TEST_MAP')
    world = os.getenv('TEST_WORLD')

    bt_navigator_xml = os.path.join(get_package_share_directory('nav2_bt_navigator'),
                                    'behavior_trees',
                                    os.getenv('BT_NAVIGATOR_XML'))

    bringup_dir = get_package_share_directory('nav2_bringup')
    params_file = os.path.join(bringup_dir, 'params', 'nav2_params.yaml')

    # Replace the default parameter values for testing special features
    # without having multiple params_files inside the nav2 stack
    context = LaunchContext()
    param_substitutions = {}

    if (os.getenv('ASTAR') == 'True'):
        param_substitutions.update({'use_astar': 'True'})

    if (os.getenv('GROOT_MONITORING') == 'True'):
        param_substitutions.update({'enable_groot_monitoring': 'True'})

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

    new_yaml = configured_params.perform(context)
    return LaunchDescription([
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),

        # Launch gazebo server for simulation
        ExecuteProcess(
            cmd=['gzserver', '-s', 'libgazebo_ros_init.so',
                 '--minimal_comms', world],
            output='screen'),

        # TODO(orduno) Launch the robot state publisher instead
        #              using a local copy of TB3 urdf file
        Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            output='screen',
            arguments=['0', '0', '0', '0', '0', '0', 'base_footprint', 'base_link']),

        Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            output='screen',
            arguments=['0', '0', '0', '0', '0', '0', 'base_link', 'base_scan']),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(bringup_dir, 'launch', 'bringup_launch.py')),
            launch_arguments={'namespace': '',
                              'use_namespace': 'False',
                              'map': map_yaml_file,
                              'use_sim_time': 'True',
                              'params_file': new_yaml,
                              'bt_xml_file': bt_navigator_xml,
                              'autostart': 'True'}.items()),
    ])
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory("nav2_bringup")

    namespace = LaunchConfiguration("namespace")
    map_yaml_file = LaunchConfiguration("map")
    use_sim_time = LaunchConfiguration("use_sim_time")
    autostart = LaunchConfiguration("autostart")
    params_file = LaunchConfiguration("params_file")
    lifecycle_nodes = ["map_server", "amcl"]

    # 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")]

    # Create our own temporary YAML files that include substitutions
    param_substitutions = {"use_sim_time": use_sim_time, "yaml_filename": map_yaml_file}

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

    return LaunchDescription(
        [
            # Set env var to print messages to stdout immediately
            SetEnvironmentVariable("RCUTILS_LOGGING_BUFFERED_STREAM", "1"),
            DeclareLaunchArgument(
                "namespace", default_value="", description="Top-level namespace"
            ),
            DeclareLaunchArgument(
                "map",
                default_value=os.path.join(bringup_dir, "maps", "turtlebot3_world.yaml"),
                description="Full path to map yaml file to load",
            ),
            DeclareLaunchArgument(
                "use_sim_time",
                default_value="false",
                description="Use simulation (Gazebo) clock if true",
            ),
            DeclareLaunchArgument(
                "autostart",
                default_value="true",
                description="Automatically startup the nav2 stack",
            ),
            DeclareLaunchArgument(
                "params_file",
                default_value=os.path.join(bringup_dir, "params", "nav2_params.yaml"),
                description="Full path to the ROS2 parameters file to use",
            ),
            Node(
                package="nav2_map_server",
                executable="map_server",
                name="map_server",
                output="screen",
                parameters=[configured_params],
                remappings=remappings,
            ),
            Node(
                package="nav2_amcl",
                executable="amcl",
                name="amcl",
                output="screen",
                parameters=[configured_params],
                remappings=remappings,
            ),
            Node(
                package="nav2_lifecycle_manager",
                executable="lifecycle_manager",
                name="lifecycle_manager_localization",
                output="screen",
                parameters=[
                    {"use_sim_time": use_sim_time},
                    {"autostart": autostart},
                    {"node_names": lifecycle_nodes},
                ],
            ),
        ]
    )
Exemple #22
0
def generate_launch_description():
    namespace = LaunchConfiguration('namespace')
    map_yaml_file = LaunchConfiguration('map')
    use_sim_time = LaunchConfiguration('use_sim_time')
    params_file = LaunchConfiguration('params_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,
        'yaml_filename': map_yaml_file}

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

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),

        DeclareLaunchArgument(
            'namespace',
            default_value='',
            description='Top-level namespace'),

        DeclareLaunchArgument(
            'map',
            description='Full path to map yaml file to load'),

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

        DeclareLaunchArgument(
            'params_file',
            description='Full path to the ROS2 parameters file to use'),

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

        Node(
            package='nav2_map_server',
            node_executable='map_server',
            node_name='map_server',
            output='screen',
            parameters=[configured_params],
            use_remappings=IfCondition(use_remappings),
            remappings=remappings),

        Node(
            package='nav2_amcl',
            node_executable='amcl',
            node_name='amcl',
            output='screen',
            parameters=[configured_params],
            use_remappings=IfCondition(use_remappings),
            remappings=remappings),

    ])
Exemple #23
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'))),
    ])
Exemple #24
0
def generate_launch_description():
    # Input parameters declaration
    namespace = LaunchConfiguration('namespace')
    params_file = LaunchConfiguration('params_file')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')

    # Variables
    lifecycle_nodes = ['map_saver']

    # Getting directories and launch-files
    bringup_dir = get_package_share_directory('nav2_bringup')
    slam_toolbox_dir = get_package_share_directory('slam_toolbox')
    slam_launch_file = os.path.join(slam_toolbox_dir, 'launch',
                                    'online_sync_launch.py')

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

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

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

    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_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time',
        default_value='True',
        description='Use simulation (Gazebo) clock if true')

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

    # Nodes launching commands

    start_map_saver_server_cmd = Node(package='nav2_map_server',
                                      executable='map_saver_server',
                                      output='screen',
                                      parameters=[configured_params])

    start_lifecycle_manager_cmd = Node(package='nav2_lifecycle_manager',
                                       executable='lifecycle_manager',
                                       name='lifecycle_manager_slam',
                                       output='screen',
                                       parameters=[{
                                           'use_sim_time': use_sim_time
                                       }, {
                                           'autostart': autostart
                                       }, {
                                           'node_names':
                                           lifecycle_nodes
                                       }])

    # If the provided param file doesn't have slam_toolbox params, we must remove the 'params_file'
    # LaunchConfiguration, or it will be passed automatically to slam_toolbox and will not load
    # the default file
    has_slam_toolbox_params = HasNodeParams(source_file=params_file,
                                            node_name='slam_toolbox')

    start_slam_toolbox_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(slam_launch_file),
        launch_arguments={'use_sim_time': use_sim_time}.items(),
        condition=UnlessCondition(has_slam_toolbox_params))

    start_slam_toolbox_cmd_with_params = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(slam_launch_file),
        launch_arguments={
            'use_sim_time': use_sim_time,
            'slam_params_file': params_file
        }.items(),
        condition=IfCondition(has_slam_toolbox_params))

    ld = LaunchDescription()

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

    # Running Map Saver Server
    ld.add_action(start_map_saver_server_cmd)
    ld.add_action(start_lifecycle_manager_cmd)

    # Running SLAM Toolbox (Only one of them will be run)
    ld.add_action(start_slam_toolbox_cmd)
    ld.add_action(start_slam_toolbox_cmd_with_params)

    return ld
Exemple #25
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('mammoth_gazebo')

    namespace = LaunchConfiguration('namespace')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('config')
    default_bt_xml_filename = LaunchConfiguration('default_bt_xml_filename')
    map_subscribe_transient_local = LaunchConfiguration(
        'map_subscribe_transient_local')

    lifecycle_nodes = [
        'controller_server', 'planner_server', 'recoveries_server',
        'bt_navigator', 'waypoint_follower'
    ]

    remappings = [('/tf', 'tf'), ('/tf_static', 'tf_static'),
                  ('/cmd_vel', '/nav_vel')]

    param_substitutions = {
        'use_sim_time': use_sim_time,
        'default_bt_xml_filename': default_bt_xml_filename,
        'autostart': autostart,
        'map_subscribe_transient_local': map_subscribe_transient_local
    }

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

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),
        DeclareLaunchArgument('namespace',
                              default_value='',
                              description='Top-level namespace'),
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        DeclareLaunchArgument(
            'config',
            default_value=os.path.join(bringup_dir, 'config/navigation',
                                       'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),
        DeclareLaunchArgument(
            'default_bt_xml_filename',
            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(
            'map_subscribe_transient_local',
            default_value='false',
            description=
            'Whether to set the map subscriber QoS to transient local'),
        Node(package='nav2_controller',
             executable='controller_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_planner',
             executable='planner_server',
             name='planner_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_recoveries',
             executable='recoveries_server',
             name='recoveries_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_bt_navigator',
             executable='bt_navigator',
             name='bt_navigator',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_waypoint_follower',
             executable='waypoint_follower',
             name='waypoint_follower',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_lifecycle_manager',
             executable='lifecycle_manager',
             name='lifecycle_manager_navigation',
             output='screen',
             parameters=[{
                 'use_sim_time': use_sim_time
             }, {
                 'autostart': autostart
             }, {
                 'node_names': lifecycle_nodes
             }]),
    ])
def generate_launch_description():
    # Get the launch directory
    launch_dir = os.path.join(get_package_share_directory('nav2_bringup'),
                              'launch')

    # Create the launch configuration variables
    autostart = launch.substitutions.LaunchConfiguration('autostart')
    bt_xml_file = launch.substitutions.LaunchConfiguration('bt')
    map_yaml_file = launch.substitutions.LaunchConfiguration('map')
    params_file = launch.substitutions.LaunchConfiguration('params')
    rviz_config_file = launch.substitutions.LaunchConfiguration('rviz_config')
    simulator = launch.substitutions.LaunchConfiguration('simulator')
    use_sim_time = launch.substitutions.LaunchConfiguration('use_sim_time')
    use_simulation = launch.substitutions.LaunchConfiguration('use_simulation')
    world = launch.substitutions.LaunchConfiguration('world')

    # Create our own temporary YAML files that include the following parameter substitutions
    param_substitutions = {
        'autostart': autostart,
        'bt_xml_filename': bt_xml_file,
        'use_sim_time': use_sim_time,
        'yaml_filename': map_yaml_file
    }
    configured_params = RewrittenYaml(source_file=params_file,
                                      rewrites=param_substitutions,
                                      convert_types=True)

    # Declare the launch arguments
    declare_autostart_cmd = launch.actions.DeclareLaunchArgument(
        'autostart',
        default_value='false',
        description='Automatically startup the nav2 stack')

    declare_bt_xml_cmd = launch.actions.DeclareLaunchArgument(
        'bt',
        default_value=os.path.join(get_package_prefix('nav2_bt_navigator'),
                                   'behavior_trees/navigate_w_replanning.xml'),
        description=
        'Full path to the Behavior Tree XML file to use for the BT navigator')

    declare_map_yaml_cmd = launch.actions.DeclareLaunchArgument(
        'map',
        default_value='turtlebot3_world.yaml',
        description='Full path to map file to load')

    declare_params_file_cmd = launch.actions.DeclareLaunchArgument(
        'params',
        default_value=[
            launch.substitutions.ThisLaunchFileDir(), '/nav2_params.yaml'
        ],
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

    declare_rviz_config_file_cmd = launch.actions.DeclareLaunchArgument(
        'rviz_config',
        default_value='nav2_default_view.rviz',
        description='Full path to the RVIZ config file to use')

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

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

    declare_use_simulation_cmd = launch.actions.DeclareLaunchArgument(
        'use_simulation',
        default_value='True',
        description='Whether to run in simulation')

    declare_world_cmd = launch.actions.DeclareLaunchArgument(
        'world',
        default_value=os.path.join(
            get_package_share_directory('turtlebot3_gazebo'),
            'worlds/turtlebot3_worlds/waffle.model'),
        description='Full path to world file to load')

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

    start_robot_state_publisher_cmd = launch.actions.ExecuteProcess(
        cmd=[
            os.path.join(get_package_prefix('robot_state_publisher'),
                         'lib/robot_state_publisher/robot_state_publisher'),
            os.path.join(get_package_share_directory('turtlebot3_description'),
                         'urdf', 'turtlebot3_waffle.urdf'),
            ['__params:=', configured_params]
        ],
        cwd=[launch_dir],
        output='screen')

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

    exit_event_handler = launch.actions.RegisterEventHandler(
        event_handler=launch.event_handlers.OnProcessExit(
            target_action=start_rviz_cmd,
            on_exit=launch.actions.EmitEvent(event=launch.events.Shutdown(
                reason='rviz exited'))))

    start_map_server_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_map_server'),
                     'lib/nav2_map_server/map_server'),
        ['__params:=', configured_params]
    ],
                                                         cwd=[launch_dir],
                                                         output='screen')

    start_localizer_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_amcl'), 'lib/nav2_amcl/amcl'),
        ['__params:=', configured_params]
    ],
                                                        cwd=[launch_dir],
                                                        output='screen')

    start_world_model_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_world_model'),
                     'lib/nav2_world_model/world_model'),
        ['__params:=', configured_params]
    ],
                                                          cwd=[launch_dir],
                                                          output='screen')

    start_dwb_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('dwb_controller'),
                     'lib/dwb_controller/dwb_controller'),
        ['__params:=', configured_params]
    ],
                                                  cwd=[launch_dir],
                                                  output='screen')

    start_planner_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_navfn_planner'),
                     'lib/nav2_navfn_planner/navfn_planner'),
        ['__params:=', configured_params]
    ],
                                                      cwd=[launch_dir],
                                                      output='screen')

    start_navigator_cmd = launch.actions.ExecuteProcess(cmd=[
        os.path.join(get_package_prefix('nav2_bt_navigator'),
                     'lib/nav2_bt_navigator/bt_navigator'),
        ['__params:=', configured_params]
    ],
                                                        cwd=[launch_dir],
                                                        output='screen')

    start_motion_primitives_cmd = launch.actions.ExecuteProcess(
        cmd=[
            os.path.join(get_package_prefix('nav2_motion_primitives'),
                         'lib/nav2_motion_primitives/motion_primitives_node'),
            ['__params:=', configured_params]
        ],
        cwd=[launch_dir],
        output='screen')

    start_lifecycle_manager_cmd = launch.actions.ExecuteProcess(
        cmd=[
            os.path.join(get_package_prefix('nav2_lifecycle_manager'),
                         'lib/nav2_lifecycle_manager/lifecycle_manager'),
            ['__params:=', configured_params]
        ],
        cwd=[launch_dir],
        output='screen')

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

    # Declare the launch options
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_bt_xml_cmd)
    ld.add_action(declare_map_yaml_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_simulator_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_use_simulation_cmd)
    ld.add_action(declare_world_cmd)

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

    # Add other nodes and processes we need
    ld.add_action(start_robot_state_publisher_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_lifecycle_manager_cmd)
    ld.add_action(start_map_server_cmd)
    ld.add_action(start_localizer_cmd)
    ld.add_action(start_world_model_cmd)
    ld.add_action(start_dwb_cmd)
    ld.add_action(start_planner_cmd)
    ld.add_action(start_navigator_cmd)
    ld.add_action(start_motion_primitives_cmd)

    return ld
Exemple #27
0
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')

    namespace = LaunchConfiguration('namespace')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    use_composition = LaunchConfiguration('use_composition')
    container_name = LaunchConfiguration('container_name')

    lifecycle_nodes = [
        'controller_server', 'smoother_server', 'planner_server',
        'behavior_server', 'bt_navigator', 'waypoint_follower'
    ]

    # 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')]

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

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

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

    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace', default_value='', description='Top-level namespace')

    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(bringup_dir, 'params', 'nav2_params.yaml'),
        description=
        'Full path to the ROS2 parameters file to use for all launched nodes')

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

    declare_use_composition_cmd = DeclareLaunchArgument(
        'use_composition',
        default_value='False',
        description='Use composed bringup if True')

    declare_container_name_cmd = DeclareLaunchArgument(
        'container_name',
        default_value='nav2_container',
        description=
        'the name of conatiner that nodes will load in if use composition')

    load_nodes = GroupAction(condition=IfCondition(
        PythonExpression(['not ', use_composition])),
                             actions=[
                                 Node(package='nav2_controller',
                                      executable='controller_server',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_smoother',
                                      executable='smoother_server',
                                      name='smoother_server',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_planner',
                                      executable='planner_server',
                                      name='planner_server',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_behaviors',
                                      executable='behavior_server',
                                      name='behavior_server',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_bt_navigator',
                                      executable='bt_navigator',
                                      name='bt_navigator',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_waypoint_follower',
                                      executable='waypoint_follower',
                                      name='waypoint_follower',
                                      output='screen',
                                      parameters=[configured_params],
                                      remappings=remappings),
                                 Node(package='nav2_lifecycle_manager',
                                      executable='lifecycle_manager',
                                      name='lifecycle_manager_navigation',
                                      output='screen',
                                      parameters=[{
                                          'use_sim_time': use_sim_time
                                      }, {
                                          'autostart': autostart
                                      }, {
                                          'node_names': lifecycle_nodes
                                      }]),
                             ])

    load_composable_nodes = LoadComposableNodes(
        condition=IfCondition(use_composition),
        target_container=container_name,
        composable_node_descriptions=[
            ComposableNode(package='nav2_controller',
                           plugin='nav2_controller::ControllerServer',
                           name='controller_server',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_smoother',
                           plugin='nav2_smoother::SmootherServer',
                           name='smoother_server',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_planner',
                           plugin='nav2_planner::PlannerServer',
                           name='planner_server',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_behaviors',
                           plugin='behavior_server::BehaviorServer',
                           name='behavior_server',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_bt_navigator',
                           plugin='nav2_bt_navigator::BtNavigator',
                           name='bt_navigator',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_waypoint_follower',
                           plugin='nav2_waypoint_follower::WaypointFollower',
                           name='waypoint_follower',
                           parameters=[configured_params],
                           remappings=remappings),
            ComposableNode(package='nav2_lifecycle_manager',
                           plugin='nav2_lifecycle_manager::LifecycleManager',
                           name='lifecycle_manager_navigation',
                           parameters=[{
                               'use_sim_time': use_sim_time,
                               'autostart': autostart,
                               'node_names': lifecycle_nodes
                           }]),
        ],
    )

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

    # Set environment variables
    ld.add_action(stdout_linebuf_envvar)

    # Declare the launch options
    ld.add_action(declare_namespace_cmd)
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_use_composition_cmd)
    ld.add_action(declare_container_name_cmd)

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

    return ld
Exemple #28
0
def generate_launch_description():


    use_sim_time  = LaunchConfiguration('use_sim_time', default='false')

    urdf_system   = xacro_to_urdf("ros2_assembly", "urdf", "system.urdf.xacro")
    urdf_sweepee  = xacro_to_urdf("ros2_assembly", "urdf/sweepee", "sweepee.urdf.xacro")
    urdf_ur5      = xacro_to_urdf("ros2_assembly", "urdf", "ur5.urdf.xacro")
    urdf_ur10     = xacro_to_urdf("ros2_assembly", "urdf", "ur10.urdf.xacro")
#     urdf_env     = xacro_to_urdf("ros2_assembly", "urdf", "env.urdf.xacro")

    sweepee_description_config = ""
    with open(urdf_sweepee, 'r') as file:
            sweepee_description_config = file.read()
    sweepee_description = {'robot_description' : sweepee_description_config}

    ur5_description_config = ""
    with open(urdf_ur5, 'r') as file:
            ur5_description_config = file.read()
    ur5_description = {'robot_description' : ur5_description_config}

    ur10_description_config = ""
    with open(urdf_ur10, 'r') as file:
            ur10_description_config = file.read()
    ur10_description = {'robot_description' : ur10_description_config}


    robot_description_config = ""
    with open(urdf_system, 'r') as file:
            robot_description_config = file.read()
    system_description = {'robot_description'         : robot_description_config,
                          'robot_description_ur10'    : ur10_description_config,
                          'robot_description_ur5'     : ur5_description_config,
                          'robot_description_sweepee' : sweepee_description_config,}

#     env_description_config = ""
#     with open(urdf_env, 'r') as file:
#             env_description_config = file.read()
#     env_description = {'env_description' : env_description_config}

    rviz_config_file = "/home/kolmogorov/ros2/ros2_extra/src/ros2_assembly/rviz/model.rviz"

    param_substitutions = {
        'use_sim_time': 'true',
        'yaml_filename': '/home/kolmogorov/ros2/ros2_extra/src/ros2_assembly/map/second.yaml'}

    configured_params = RewrittenYaml(
        source_file=os.path.join(get_package_share_directory("ros2_assembly"), "config", "map.yaml"),
        root_key='/',
        param_rewrites=param_substitutions,
        convert_types=True)

    rviz2_node    = Node(
            package='rviz2',
            node_executable='rviz2',
            node_name='rviz2',
            output='screen',
            arguments=['-d', rviz_config_file],
            parameters=[system_description])

    param_node    = Node(
            package='ros2_assembly',
            node_executable='param_node',
            node_name='param_node',
            output='screen',
            parameters=[system_description])

    map_serv_node = Node(
            package='nav2_map_server',
            node_executable='map_server',
            node_name='map_server',
            output='screen',
            parameters=[configured_params])
  
    rs_sweepee    = Node(
            package='robot_state_publisher',
            node_executable='robot_state_publisher',
            node_name='robot_state_publisher_sweepee',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time}],
            node_namespace='sweepee',
            arguments=[urdf_sweepee])

    rs_ur10       = Node(
            package='robot_state_publisher',
            node_executable='robot_state_publisher',
            node_name='robot_state_publisher_ur10',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time}],
            node_namespace='ur10',
            arguments=[urdf_ur10])


    rs_ur5        = Node(
            package='robot_state_publisher',
            node_executable='robot_state_publisher',
            node_name='robot_state_publisher_ur5',
            output='screen',
            parameters=[{'use_sim_time': use_sim_time}],
            node_namespace='ur5',
            arguments=[urdf_ur5])

    fk_ur10       = Node(
            package='fake_joint_driver',
            node_executable='fake_joint_driver_node',
            node_namespace ='ur10',
            #node_name='fake_joint_driver_node_try',
            parameters=[os.path.join(get_package_share_directory("ros2_assembly"), "config", "ur10_controllers.yaml"),
                        os.path.join(get_package_share_directory("ros2_assembly"), "config", "ur10_start_positions.yaml"),
                        ur10_description]
            )

    fk_sweepee    = Node(
            package='fake_joint_driver',
            node_executable='fake_joint_driver_node',
            node_namespace ='sweepee',
            #node_name='fake_joint_driver_node_try',
            parameters=[os.path.join(get_package_share_directory("ros2_assembly"), "config", "sweepee_controllers.yaml"),
                        os.path.join(get_package_share_directory("ros2_assembly"), "config", "sweepee_start_positions.yaml"),
                        sweepee_description]
            )
      
    fk_ur5        = Node(
            package='fake_joint_driver',
            node_executable='fake_joint_driver_node',
            node_namespace ='ur5',
            #node_name='fake_joint_driver_node_try',
            parameters=[os.path.join(get_package_share_directory("ros2_assembly"), "config", "ur5_controllers.yaml"),
                        os.path.join(get_package_share_directory("ros2_assembly"), "config", "ur5_start_positions.yaml"),
                        ur5_description]
            )

    tf1           = Node(
            package='tf2_ros',
            node_executable='static_transform_publisher',
            node_name='static_transform_publisher_1',
            output='screen',
            arguments=['0.0', '0.0', '0.0', '0.0', '0.0', '0.0', 'world', 'map'])

    tf2           = Node(
            package='tf2_ros',
            node_executable='static_transform_publisher',
            node_name='static_transform_publisher_2',
            output='screen',
            arguments=['0.0', '0.0', '0.0', '0.0', '0.0', '0.0', 'map', 'base_footprint'])
   
    tf_sweepee_ur10   = Node(
            package='tf2_ros',
            node_executable='static_transform_publisher',
            node_name='static_transform_publisher_sweepee_ur10',
            output='screen',
            arguments=['0.0', '0.0', '0.3', '0.0', '0.0', '0.0', 'base_footprint', 'ur10_base_link'])


    moveit_params_file = get_package_share_directory('ros2_assembly') + "/config/moveit_params.yaml"

    robot_description_semantic_config = load_file('ros2_assembly', 'config/srdf/ur10.srdf')
    ur10_description_semantic      = {'robot_description_semantic' : robot_description_semantic_config}

    ompl_planning_pipeline_config = { 'ompl' : {
        'planning_plugin' : 'ompl_interface/OMPLPlanner',
        'request_adapters' : """default_planner_request_adapters/AddTimeOptimalParameterization default_planner_request_adapters/FixWorkspaceBounds default_planner_request_adapters/FixStartStateBounds default_planner_request_adapters/FixStartStateCollision default_planner_request_adapters/FixStartStatePathConstraints""" ,
        'start_state_max_bounds_error' : 0.1 } }
    ompl_planning_yaml = load_yaml('ros2_assembly', 'config/ompl_planning.yaml')
#     ompl_planning_pipeline_config['ompl'].update(ompl_planning_yaml)
    

    kinematics_yaml = load_yaml('ros2_assembly', 'config/kinematics.yaml')
    robot_description_kinematics = { 'robot_description_kinematics' : kinematics_yaml }

    controllers_yaml = load_yaml('ros2_assembly', 'config/controllers.yaml')
    moveit_controllers = { 'moveit_simple_controller_manager' : controllers_yaml }

    # MoveItCpp demo executable
    run_moveit_cpp_node = Node(node_name='run_moveit_cpp',
                               package='ros2_assembly',
                               prefix='xterm -e gdb --args',
                               node_namespace='ur10',
                               node_executable='run_moveit_cpp',
                               output='screen',
                               parameters=[moveit_params_file,
                                           ur10_description,
                                           ur10_description_semantic,
                                           kinematics_yaml,
                                           ompl_planning_pipeline_config,
                                           moveit_controllers])


    ld = LaunchDescription()

#     ld.add_action(map_serv_node)

    ld.add_action(rviz2_node)
    ld.add_action(param_node)

    ld.add_action(rs_sweepee)
    ld.add_action(rs_ur5)
    ld.add_action(rs_ur10)

    # ld.add_action(fk_sweepee)
    ld.add_action(fk_ur10)
    ld.add_action(fk_ur5)

    ld.add_action(tf1)
    ld.add_action(tf2)
    ld.add_action(tf_sweepee_ur10)

    ld.add_action(run_moveit_cpp_node)

    return ld
def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')

    namespace = LaunchConfiguration('namespace')
    use_sim_time = LaunchConfiguration('use_sim_time')
    autostart = LaunchConfiguration('autostart')
    params_file = LaunchConfiguration('params_file')
    default_bt_xml_filename = LaunchConfiguration('default_bt_xml_filename')
    map_subscribe_transient_local = LaunchConfiguration(
        'map_subscribe_transient_local')
    cmd_vel_topic = LaunchConfiguration('cmd_vel_topic')

    lifecycle_nodes = [
        'controller_server', 'planner_server', 'recoveries_server',
        'bt_navigator', 'waypoint_follower'
    ]

    # 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'),
                  ('cmd_vel', cmd_vel_topic)]

    # Create our own temporary YAML files that include substitutions
    param_substitutions = {
        'use_sim_time': use_sim_time,
        'default_bt_xml_filename': default_bt_xml_filename,
        'autostart': autostart,
        'map_subscribe_transient_local': map_subscribe_transient_local
    }

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

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),
        DeclareLaunchArgument('namespace',
                              default_value='',
                              description='Top-level namespace'),
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        DeclareLaunchArgument(
            'params_file',
            default_value=os.path.join(bringup_dir, 'params',
                                       'nav2_params.yaml'),
            description='Full path to the ROS2 parameters file to use'),
        DeclareLaunchArgument(
            'default_bt_xml_filename',
            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(
            'map_subscribe_transient_local',
            default_value='false',
            description=
            'Whether to set the map subscriber QoS to transient local'),
        Node(package='nav2_controller',
             executable='controller_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_planner',
             executable='planner_server',
             name='planner_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_recoveries',
             executable='recoveries_server',
             name='recoveries_server',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_bt_navigator',
             executable='bt_navigator',
             name='bt_navigator',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_waypoint_follower',
             executable='waypoint_follower',
             name='waypoint_follower',
             output='screen',
             parameters=[configured_params],
             remappings=remappings),
        Node(package='nav2_lifecycle_manager',
             executable='lifecycle_manager',
             name='lifecycle_manager_navigation',
             output='screen',
             parameters=[{
                 'use_sim_time': use_sim_time
             }, {
                 'autostart': autostart
             }, {
                 'node_names': lifecycle_nodes
             }]),
    ])
def generate_launch_description():
    use_sim_time = launch.substitutions.LaunchConfiguration('use_sim_time',
                                                            default='false')
    autostart = launch.substitutions.LaunchConfiguration('autostart')
    params_file = launch.substitutions.LaunchConfiguration('params')
    bt_xml_file = launch.substitutions.LaunchConfiguration('bt_xml_file')

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

    configured_params = RewrittenYaml(source_file=params_file,
                                      rewrites=param_substitutions,
                                      convert_types=True)

    return LaunchDescription([
        # Set env var to print messages to stdout immediately
        launch.actions.SetEnvironmentVariable(
            'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        launch.actions.DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),
        launch.actions.DeclareLaunchArgument(
            'autostart',
            default_value='true',
            description='Automatically startup the nav2 stack'),
        launch.actions.DeclareLaunchArgument(
            'params',
            default_value=[
                launch.substitutions.ThisLaunchFileDir(), '/nav2_params.yaml'
            ],
            description='Full path to the ROS2 parameters file to use'),
        launch.actions.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'),
        launch_ros.actions.Node(package='nav2_world_model',
                                node_executable='world_model',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='dwb_controller',
                                node_executable='dwb_controller',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='nav2_navfn_planner',
                                node_executable='navfn_planner',
                                node_name='navfn_planner',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='nav2_motion_primitives',
                                node_executable='motion_primitives_node',
                                node_name='motion_primitives',
                                output='screen',
                                parameters=[{
                                    'use_sim_time': use_sim_time
                                }]),
        launch_ros.actions.Node(package='nav2_bt_navigator',
                                node_executable='bt_navigator',
                                node_name='bt_navigator',
                                output='screen',
                                parameters=[configured_params]),
        launch_ros.actions.Node(package='nav2_lifecycle_manager',
                                node_executable='lifecycle_manager',
                                node_name='lifecycle_manager_control',
                                output='screen',
                                parameters=[{
                                    'use_sim_time': use_sim_time
                                }, {
                                    'autostart': autostart
                                }, {
                                    'node_names': [
                                        'world_model', 'dwb_controller',
                                        'navfn_planner', 'bt_navigator'
                                    ]
                                }]),
    ])