def generate_launch_description(): ld = LaunchDescription([ DeclareLaunchArgument( 'gazebo_model_path_env_var', description='GAZEBO_MODEL_PATH environment variable'), DeclareLaunchArgument( 'gazebo_plugin_path_env_var', description='GAZEBO_PLUGIN_PATH environment variable'), DeclareLaunchArgument( 'headless', default_value='False', description='Whether to execute gzclient'), DeclareLaunchArgument( 'world_model_file', description='Full path to world model file to load'), DeclareLaunchArgument( 'robot_gt_urdf_file', description='Full path to robot urdf model file to load'), DeclareLaunchArgument( 'robot_realistic_urdf_file', description='Full path to robot urdf model file to load'), SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'), SetEnvironmentVariable('GAZEBO_MODEL_PATH', LaunchConfiguration('gazebo_model_path_env_var')), SetEnvironmentVariable('GAZEBO_PLUGIN_PATH', LaunchConfiguration('gazebo_plugin_path_env_var')), ExecuteProcess( cmd=['gzserver', '--verbose', '-s', 'libgazebo_ros_init.so', LaunchConfiguration('world_model_file')], output='screen'), ExecuteProcess( condition=IfCondition(PythonExpression(['not ', LaunchConfiguration('headless')])), cmd=['gzclient'], output='log'), Node( package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher_gt', output='log', parameters=[{'use_sim_time': True}], arguments=[LaunchConfiguration('robot_gt_urdf_file')]), Node( package='tf2_ros', node_executable='static_transform_publisher', node_name='gt_odom_static_transform_publisher', output='log', parameters=[{'use_sim_time': True}], arguments=["0", "0", "0", "0", "0", "0", "map", "odom"]), # odom is actually the ground truth, because currently (Eloquent) odom and base_link are hardcoded in the navigation stack (recoveries and controller) >:C Node( package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher_realistic', output='log', parameters=[{'use_sim_time': True}], arguments=[LaunchConfiguration('robot_realistic_urdf_file')]), ]) return ld
def generate_launch_description(): declare_use_remappings_cmd = DeclareLaunchArgument( 'use_remappings', default_value='false', description='Arguments to pass to all nodes launched by the file') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config_file', description='Full path to the RVIZ config file to use') start_rviz_cmd = Node( package='rviz2', node_executable='rviz2', node_name='rviz2', arguments=['-d', LaunchConfiguration('rviz_config_file')], output='log', use_remappings=IfCondition(LaunchConfiguration('use_remappings')), remappings=[('/tf', 'tf'), ('/tf_static', 'tf_static'), ('goal_pose', 'goal_pose'), ('/clicked_point', 'clicked_point'), ('/initialpose', 'initialpose')]) # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_use_remappings_cmd) ld.add_action(declare_rviz_config_file_cmd) # Add any conditioned actions ld.add_action(start_rviz_cmd) return ld
def generate_launch_description(): namespace = LaunchConfiguration('namespace') declare_namespace_cmd = DeclareLaunchArgument( 'namespace', default_value='bla', description='Top-level namespace') print(declare_namespace_cmd.parse()) gamepad_parser_cmd = Node(package='gamepad_parser', namespace=namespace, executable='gamepad_parser_node', name='gamepad_parser_node', output='screen', emulate_tty=True) ld = LaunchDescription() ld.add_action(declare_namespace_cmd) ld.add_action(gamepad_parser_cmd) return ld
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'))), ])
def generate_launch_description(): # Get the launch directory bringup_dir = get_package_share_directory('nav2_bringup') launch_dir = os.path.join(bringup_dir, 'launch') # Create the launch configuration variables namespace = LaunchConfiguration('namespace') map_yaml_file = LaunchConfiguration('map') use_sim_time = LaunchConfiguration('use_sim_time') params_file = LaunchConfiguration('params_file') bt_xml_file = LaunchConfiguration('bt_xml_file') autostart = LaunchConfiguration('autostart') use_remappings = LaunchConfiguration('use_remappings') # Launch configuration variables specific to simulation rviz_config_file = LaunchConfiguration('rviz_config_file') use_simulator = LaunchConfiguration('use_simulator') use_robot_state_pub = LaunchConfiguration('use_robot_state_pub') use_rviz = LaunchConfiguration('use_rviz') simulator = LaunchConfiguration('simulator') world = LaunchConfiguration('world') # TODO(orduno) Remove once `PushNodeRemapping` is resolved # https://github.com/ros2/launch_ros/issues/56 remappings = [((namespace, '/tf'), '/tf'), ((namespace, '/tf_static'), '/tf_static'), ('/scan', 'scan'), ('/tf', 'tf'), ('/tf_static', 'tf_static'), ('/cmd_vel', 'cmd_vel'), ('/map', 'map')] # Declare the launch arguments declare_namespace_cmd = DeclareLaunchArgument( 'namespace', default_value='', description='Top-level namespace') declare_map_yaml_cmd = DeclareLaunchArgument( 'map', default_value=os.path.join(bringup_dir, 'maps', 'turtlebot3_world.yaml'), description='Full path to map file to load') declare_use_sim_time_cmd = DeclareLaunchArgument( 'use_sim_time', default_value='true', description='Use simulation (Gazebo) clock if true') declare_params_file_cmd = DeclareLaunchArgument( 'params_file', default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'), description= 'Full path to the ROS2 parameters file to use for all launched nodes') declare_bt_xml_cmd = DeclareLaunchArgument( 'bt_xml_file', default_value=os.path.join( get_package_share_directory('nav2_bt_navigator'), 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'), description='Full path to the behavior tree xml file to use') declare_autostart_cmd = DeclareLaunchArgument( 'autostart', default_value='false', description='Automatically startup the nav2 stack') declare_use_remappings_cmd = DeclareLaunchArgument( 'use_remappings', default_value='false', description='Arguments to pass to all nodes launched by the file') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config_file', default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'), description='Full path to the RVIZ config file to use') declare_use_simulator_cmd = DeclareLaunchArgument( 'use_simulator', default_value='True', description='Whether to start the simulator') declare_use_robot_state_pub_cmd = DeclareLaunchArgument( 'use_robot_state_pub', default_value='True', description='Whether to start the robot state publisher') declare_use_rviz_cmd = DeclareLaunchArgument( 'use_rviz', default_value='True', description='Whether to start RVIZ') declare_simulator_cmd = DeclareLaunchArgument( 'simulator', default_value='gazebo', description='The simulator to use (gazebo or gzserver)') declare_world_cmd = DeclareLaunchArgument( 'world', # TODO(orduno) Switch back once ROS argument passing has been fixed upstream # https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91 # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'), # 'worlds/turtlebot3_worlds/waffle.model'), default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'), description='Full path to world model file to load') # Specify the actions start_gazebo_cmd = ExecuteProcess( condition=IfCondition(use_simulator), cmd=[simulator, '-s', 'libgazebo_ros_init.so', world], cwd=[launch_dir], output='screen') urdf = os.path.join(get_package_share_directory('turtlebot3_description'), 'urdf', 'turtlebot3_waffle.urdf') start_robot_state_publisher_cmd = Node( condition=IfCondition(use_robot_state_pub), package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher', output='screen', parameters=[{ 'use_sim_time': use_sim_time }], use_remappings=IfCondition(use_remappings), remappings=remappings, arguments=[urdf]) start_rviz_cmd = Node(condition=IfCondition(use_rviz), package='rviz2', node_executable='rviz2', node_name='rviz2', arguments=['-d', rviz_config_file], output='screen', use_remappings=IfCondition(use_remappings), remappings=[('/tf', 'tf'), ('/tf_static', 'tf_static'), ('goal_pose', 'goal_pose'), ('/clicked_point', 'clicked_point'), ('/initialpose', 'initialpose')]) exit_event_handler = RegisterEventHandler( event_handler=OnProcessExit(target_action=start_rviz_cmd, on_exit=EmitEvent(event=Shutdown( reason='rviz exited')))) bringup_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(launch_dir, 'nav2_bringup_launch.py')), launch_arguments={ 'namespace': namespace, 'map': map_yaml_file, 'use_sim_time': use_sim_time, 'params_file': params_file, 'bt_xml_file': bt_xml_file, 'autostart': autostart, 'use_remappings': use_remappings }.items()) # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_namespace_cmd) ld.add_action(declare_map_yaml_cmd) ld.add_action(declare_use_sim_time_cmd) ld.add_action(declare_params_file_cmd) ld.add_action(declare_bt_xml_cmd) ld.add_action(declare_autostart_cmd) ld.add_action(declare_use_remappings_cmd) ld.add_action(declare_rviz_config_file_cmd) ld.add_action(declare_use_simulator_cmd) ld.add_action(declare_use_robot_state_pub_cmd) ld.add_action(declare_use_rviz_cmd) ld.add_action(declare_simulator_cmd) ld.add_action(declare_world_cmd) # Add any conditioned actions ld.add_action(start_gazebo_cmd) ld.add_action(start_rviz_cmd) # Add other nodes and processes we need ld.add_action(exit_event_handler) # Add the actions to launch all of the navigation nodes ld.add_action(start_robot_state_publisher_cmd) ld.add_action(bringup_cmd) return ld
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') map_yaml_file = LaunchConfiguration('map') use_sim_time = LaunchConfiguration('use_sim_time') params_file = LaunchConfiguration('params_file') bt_xml_file = LaunchConfiguration('bt_xml_file') autostart = LaunchConfiguration('autostart') use_remappings = LaunchConfiguration('use_remappings') stdout_linebuf_envvar = SetEnvironmentVariable( 'RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '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 the launch arguments 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_bt_xml_cmd = DeclareLaunchArgument( 'bt_xml_file', default_value=os.path.join( get_package_share_directory('nav2_bt_navigator'), 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'), description='Full path to the behavior tree xml file to use') declare_autostart_cmd = DeclareLaunchArgument( 'autostart', default_value='true', description='Automatically startup the nav2 stack') declare_use_remappings_cmd = DeclareLaunchArgument( 'use_remappings', default_value='false', description='Arguments to pass to all nodes launched by the file') # Specify the actions bringup_cmd_group = GroupAction([ PushRosNamespace(condition=IfCondition(use_namespace), namespace=namespace), IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(launch_dir, 'nav2_localization_launch.py')), launch_arguments={ 'namespace': namespace, 'map': map_yaml_file, 'use_sim_time': use_sim_time, 'autostart': autostart, 'params_file': params_file, 'use_lifecycle_mgr': 'false', 'use_remappings': use_remappings }.items()), IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(launch_dir, 'nav2_navigation_launch.py')), launch_arguments={ 'namespace': namespace, 'use_sim_time': use_sim_time, 'autostart': autostart, 'params_file': params_file, 'bt_xml_file': bt_xml_file, 'use_lifecycle_mgr': 'false', 'use_remappings': use_remappings, 'map_subscribe_transient_local': 'true' }.items()), Node(package='nav2_lifecycle_manager', node_executable='lifecycle_manager', node_name='lifecycle_manager', output='screen', parameters=[{ 'use_sim_time': use_sim_time }, { 'autostart': autostart }, { 'node_names': [ 'map_server', 'amcl', 'controller_server', 'planner_server', 'recoveries_server', 'bt_navigator', 'waypoint_follower' ] }]), ]) # 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_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) ld.add_action(declare_use_remappings_cmd) # Add the actions to launch all of the navigation nodes ld.add_action(bringup_cmd_group) return ld
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'] }]) ])
def generate_launch_description(): # Get the launch directory nav2_bringup_dir = get_package_share_directory('nav2_bringup') pilot_dir = get_package_share_directory('pilot_urjc_bringup') pilot_launch_dir = os.path.join(pilot_dir, 'launch') # Create the launch configuration variables namespace = LaunchConfiguration('namespace') use_namespace = LaunchConfiguration('use_namespace') map_yaml_file = LaunchConfiguration('map') use_sim_time = LaunchConfiguration('use_sim_time') params_file = LaunchConfiguration('params_file') bt_xml_file = LaunchConfiguration('bt_xml_file') autostart = LaunchConfiguration('autostart') cmd_vel_topic = LaunchConfiguration('cmd_vel_topic') # Launch configuration variables specific to simulation rviz_config_file = LaunchConfiguration('rviz_config_file') use_rviz = LaunchConfiguration('use_rviz') # TODO(orduno) Remove once `PushNodeRemapping` is resolved # https://github.com/ros2/launch_ros/issues/56 remappings = [((namespace, '/tf'), '/tf'), ((namespace, '/tf_static'), '/tf_static'), ('/tf', 'tf'), ('/tf_static', 'tf_static')] # Declare the launch arguments declare_namespace_cmd = DeclareLaunchArgument( 'namespace', default_value='', description='Top-level namespace') declare_use_namespace_cmd = DeclareLaunchArgument( 'use_namespace', default_value='false', description='Whether to apply a namespace to the navigation stack') declare_map_yaml_cmd = DeclareLaunchArgument( 'map', default_value=os.path.join(pilot_dir, 'maps/urjc/restaurant', 'map.yaml'), description='Full path to map file to load') declare_use_sim_time_cmd = DeclareLaunchArgument( 'use_sim_time', default_value='false', description='Use simulation (Gazebo) clock if true') declare_params_file_cmd = DeclareLaunchArgument( 'params_file', default_value=os.path.join(pilot_dir, 'params', 'nav2_tiago_params.yaml'), description= 'Full path to the ROS2 parameters file to use for all launched nodes') #declare_params_file_cmd = DeclareLaunchArgument( # 'params_file', # default_value=os.path.join(nav2_bringup_dir, 'params', 'nav2_params.yaml'), # description='Full path to the ROS2 parameters file to use for all launched nodes') declare_bt_xml_cmd = DeclareLaunchArgument( 'bt_xml_file', default_value=os.path.join( get_package_share_directory('nav2_bt_navigator'), 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'), description='Full path to the behavior tree xml file to use') declare_autostart_cmd = DeclareLaunchArgument( 'autostart', default_value='true', description='Automatically startup the nav2 stack') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config_file', default_value=os.path.join(nav2_bringup_dir, 'rviz', 'nav2_default_view.rviz'), description='Full path to the RVIZ config file to use') declare_use_rviz_cmd = DeclareLaunchArgument( 'use_rviz', default_value='True', description='Whether to start RVIZ') declare_cmd_vel_topic_cmd = DeclareLaunchArgument( 'cmd_vel_topic', default_value='cmd_vel_mux', description='Command velocity topic') start_rviz_cmd = Node(condition=IfCondition(use_rviz), package='rviz2', executable='rviz2', arguments=['-d', rviz_config_file], output='log', remappings=[('/tf', 'tf'), ('/tf_static', 'tf_static'), ('goal_pose', 'goal_pose'), ('/clicked_point', 'clicked_point'), ('/initialpose', 'initialpose')]) exit_event_handler = RegisterEventHandler( event_handler=OnProcessExit(target_action=start_rviz_cmd, on_exit=EmitEvent(event=Shutdown( reason='rviz exited')))) bringup_cmd = IncludeLaunchDescription(PythonLaunchDescriptionSource( os.path.join(pilot_launch_dir, 'nav2_bringup_launch.py')), launch_arguments={ 'namespace': namespace, 'use_namespace': use_namespace, 'map': map_yaml_file, 'use_sim_time': use_sim_time, 'params_file': params_file, 'bt_xml_file': bt_xml_file, 'autostart': autostart, 'cmd_vel_topic': cmd_vel_topic }.items()) shm_model_path = (get_package_share_directory('pilot_urjc_bringup') + '/params/pilot_modes.yaml') # Start as a normal node is currently not possible. # Path to SHM file should be passed as a ROS parameter. mode_manager_node = Node(package='system_modes', executable='mode_manager', parameters=[{ 'modelfile': shm_model_path }], output='screen') # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_namespace_cmd) ld.add_action(declare_use_namespace_cmd) ld.add_action(declare_map_yaml_cmd) ld.add_action(declare_use_sim_time_cmd) ld.add_action(declare_params_file_cmd) ld.add_action(declare_bt_xml_cmd) ld.add_action(declare_autostart_cmd) ld.add_action(declare_rviz_config_file_cmd) ld.add_action(declare_use_rviz_cmd) ld.add_action(declare_cmd_vel_topic_cmd) # Add any conditioned actions ld.add_action(start_rviz_cmd) # Add other nodes and processes we need ld.add_action(exit_event_handler) # Add the actions to launch all of the navigation nodes ld.add_action(bringup_cmd) # Add system modes manager ld.add_action(mode_manager_node) return ld
def generate_launch_description(): # Get the launch directory bringup_dir = get_package_share_directory('nav2_bringup') # Create the launch configuration variables namespace = LaunchConfiguration('namespace') use_namespace = LaunchConfiguration('use_namespace') rviz_config_file = LaunchConfiguration('rviz_config') # Declare the launch arguments declare_namespace_cmd = DeclareLaunchArgument( 'namespace', default_value='navigation', description=('Top-level namespace. The value will be used to replace the ' '<robot_namespace> keyword on the rviz config file.')) declare_use_namespace_cmd = DeclareLaunchArgument( 'use_namespace', default_value='false', description='Whether to apply a namespace to the navigation stack') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config', default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'), description='Full path to the RVIZ config file to use') # Launch rviz start_rviz_cmd = Node( condition=UnlessCondition(use_namespace), package='rviz2', node_executable='rviz2', node_name='rviz2', arguments=['-d', rviz_config_file], output='screen') namespaced_rviz_config_file = ReplaceString( source_file=rviz_config_file, replacements={'<robot_namespace>': ('/', namespace)}) start_namespaced_rviz_cmd = Node( condition=IfCondition(use_namespace), package='rviz2', node_executable='rviz2', node_name='rviz2', node_namespace=namespace, arguments=['-d', namespaced_rviz_config_file], output='screen', use_remappings=IfCondition('True'), remappings=[('/tf', 'tf'), ('/tf_static', 'tf_static'), ('/goal_pose', 'goal_pose'), ('/clicked_point', 'clicked_point'), ('/initialpose', 'initialpose')]) exit_event_handler = RegisterEventHandler( condition=UnlessCondition(use_namespace), event_handler=OnProcessExit( target_action=start_rviz_cmd, on_exit=EmitEvent(event=Shutdown(reason='rviz exited')))) exit_event_handler_namespaced = RegisterEventHandler( condition=IfCondition(use_namespace), event_handler=OnProcessExit( target_action=start_namespaced_rviz_cmd, on_exit=EmitEvent(event=Shutdown(reason='rviz exited')))) # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_namespace_cmd) ld.add_action(declare_use_namespace_cmd) ld.add_action(declare_rviz_config_file_cmd) # Add any conditioned actions ld.add_action(start_rviz_cmd) ld.add_action(start_namespaced_rviz_cmd) # Add other nodes and processes we need ld.add_action(exit_event_handler) ld.add_action(exit_event_handler_namespaced) return ld
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), ])
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') bt_xml_file = LaunchConfiguration('bt_xml_file') use_lifecycle_mgr = LaunchConfiguration('use_lifecycle_mgr') use_remappings = LaunchConfiguration('use_remappings') map_subscribe_transient_local = LaunchConfiguration('map_subscribe_transient_local') # 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 = [((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, '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_CONSOLE_STDOUT_LINE_BUFFERED', '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( '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_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'), DeclareLaunchArgument( 'map_subscribe_transient_local', default_value='false', description='Whether to set the map subscriber QoS to transient local'), Node( package='nav2_controller', node_executable='controller_server', output='screen', parameters=[configured_params], use_remappings=IfCondition(use_remappings), remappings=remappings), Node( package='nav2_planner', node_executable='planner_server', node_name='planner_server', output='screen', parameters=[configured_params], use_remappings=IfCondition(use_remappings), remappings=remappings), Node( package='nav2_recoveries', node_executable='recoveries_server', node_name='recoveries_server', output='screen', parameters=[{'use_sim_time': use_sim_time}], use_remappings=IfCondition(use_remappings), remappings=remappings), Node( package='nav2_bt_navigator', node_executable='bt_navigator', node_name='bt_navigator', output='screen', parameters=[configured_params], use_remappings=IfCondition(use_remappings), remappings=remappings), Node( package='nav2_waypoint_follower', node_executable='waypoint_follower', node_name='waypoint_follower', 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_navigation', output='screen', parameters=[{'use_sim_time': use_sim_time}, {'autostart': autostart}, {'node_names': ['controller_server', 'planner_server', 'recoveries_server', 'bt_navigator', 'waypoint_follower']}]), ])
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') map_yaml_file = LaunchConfiguration('map') use_sim_time = LaunchConfiguration('use_sim_time') params_file = LaunchConfiguration('params_file') bt_xml_file = LaunchConfiguration('bt_xml_file') autostart = LaunchConfiguration('autostart') use_remappings = LaunchConfiguration('use_remappings') # Launch configuration variables specific to simulation rviz_config_file = LaunchConfiguration('rviz_config_file') use_simulator = LaunchConfiguration('use_simulator') use_robot_state_pub = LaunchConfiguration('use_robot_state_pub') use_rviz = LaunchConfiguration('use_rviz') headless = LaunchConfiguration('headless') world = LaunchConfiguration('world') # Map fully qualified names to relative ones so the node's namespace can be prepended. # In case of the transforms (tf), currently, there doesn't seem to be a better alternative # https://github.com/ros/geometry2/issues/32 # https://github.com/ros/robot_state_publisher/pull/30 # TODO(orduno) Substitute with `PushNodeRemapping` # https://github.com/ros2/launch_ros/issues/56 remappings = [((namespace, '/tf'), '/tf'), ((namespace, '/tf_static'), '/tf_static'), ('/tf', 'tf'), ('/tf_static', 'tf_static')] # Declare the launch arguments declare_namespace_cmd = DeclareLaunchArgument( 'namespace', default_value='', description='Top-level namespace') declare_use_namespace_cmd = DeclareLaunchArgument( 'use_namespace', default_value='false', description='Whether to apply a namespace to the navigation stack') declare_map_yaml_cmd = DeclareLaunchArgument( 'map', default_value=os.path.join(bringup_dir, 'maps', 'turtlebot3_world.yaml'), description='Full path to map file to load') declare_use_sim_time_cmd = DeclareLaunchArgument( 'use_sim_time', default_value='true', description='Use simulation (Gazebo) clock if true') declare_params_file_cmd = DeclareLaunchArgument( 'params_file', default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'), description='Full path to the ROS2 parameters file to use for all launched nodes') declare_bt_xml_cmd = DeclareLaunchArgument( 'bt_xml_file', default_value=os.path.join( get_package_share_directory('nav2_bt_navigator'), 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'), description='Full path to the behavior tree xml file to use') declare_autostart_cmd = DeclareLaunchArgument( 'autostart', default_value='false', description='Automatically startup the nav2 stack') declare_use_remappings_cmd = DeclareLaunchArgument( 'use_remappings', default_value='false', description='Arguments to pass to all nodes launched by the file') declare_rviz_config_file_cmd = DeclareLaunchArgument( 'rviz_config_file', default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'), description='Full path to the RVIZ config file to use') declare_use_simulator_cmd = DeclareLaunchArgument( 'use_simulator', default_value='True', description='Whether to start the simulator') declare_use_robot_state_pub_cmd = DeclareLaunchArgument( 'use_robot_state_pub', default_value='True', description='Whether to start the robot state publisher') declare_use_rviz_cmd = DeclareLaunchArgument( 'use_rviz', default_value='True', description='Whether to start RVIZ') declare_simulator_cmd = DeclareLaunchArgument( 'headless', default_value='False', description='Whether to execute gzclient)') declare_world_cmd = DeclareLaunchArgument( 'world', # TODO(orduno) Switch back once ROS argument passing has been fixed upstream # https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91 # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'), # 'worlds/turtlebot3_worlds/waffle.model'), default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'), description='Full path to world model file to load') # Specify the actions start_gazebo_server_cmd = ExecuteProcess( condition=IfCondition(use_simulator), cmd=['gzserver', '-s', 'libgazebo_ros_init.so', world], cwd=[launch_dir], output='screen') start_gazebo_client_cmd = ExecuteProcess( condition=IfCondition(PythonExpression([use_simulator, ' and not ', headless])), cmd=['gzclient'], cwd=[launch_dir], output='screen') urdf = os.path.join(bringup_dir, 'urdf', 'turtlebot3_waffle.urdf') start_robot_state_publisher_cmd = Node( condition=IfCondition(use_robot_state_pub), package='robot_state_publisher', node_executable='robot_state_publisher', node_name='robot_state_publisher', node_namespace=namespace, output='screen', parameters=[{'use_sim_time': use_sim_time}], use_remappings=IfCondition(use_remappings), remappings=remappings, arguments=[urdf]) rviz_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'nav2_rviz_launch.py')), condition=IfCondition(use_rviz), launch_arguments={'namespace': '', 'use_namespace': 'False', 'rviz_config': rviz_config_file}.items()) bringup_cmd = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'nav2_bringup_launch.py')), launch_arguments={'namespace': namespace, 'use_namespace': use_namespace, 'map': map_yaml_file, 'use_sim_time': use_sim_time, 'params_file': params_file, 'bt_xml_file': bt_xml_file, 'autostart': autostart}.items()) # Create the launch description and populate ld = LaunchDescription() # Declare the launch options ld.add_action(declare_namespace_cmd) ld.add_action(declare_use_namespace_cmd) ld.add_action(declare_map_yaml_cmd) ld.add_action(declare_use_sim_time_cmd) ld.add_action(declare_params_file_cmd) ld.add_action(declare_bt_xml_cmd) ld.add_action(declare_autostart_cmd) ld.add_action(declare_use_remappings_cmd) ld.add_action(declare_rviz_config_file_cmd) ld.add_action(declare_use_simulator_cmd) ld.add_action(declare_use_robot_state_pub_cmd) ld.add_action(declare_use_rviz_cmd) ld.add_action(declare_simulator_cmd) ld.add_action(declare_world_cmd) # Add any conditioned actions ld.add_action(start_gazebo_server_cmd) ld.add_action(start_gazebo_client_cmd) # Add the actions to launch all of the navigation nodes ld.add_action(start_robot_state_publisher_cmd) ld.add_action(rviz_cmd) ld.add_action(bringup_cmd) return ld