Nav2, or the Navigation 2 Stack, is a powerful and flexible navigation framework for robots in the Robot Operating System 2 (ROS 2). It provides a modular set of tools and algorithms for autonomous robot navigation in complex environments.
Starting Nav2 from the Terminal
Here are the terminal commands for launching the Nav2 toolkit.
# Start robot or robot simulator in this case I wil use the turtlebot3ros2launchturtlebot3_gazeboturtlebot3_world.launch.py
ros2launchnav2_bringupbringup_launch.pyuse_sim_time:=truemap:=Desktop/maps/my_map.yaml
# Launch rviz2 and add the TF visualization and the map visualizationros2runrviz2rviz2
fromlaunchimportLaunchDescriptionimportosfromament_index_pythonimportget_package_share_directoryfromlaunch_ros.parameter_descriptionsimportParameterValuefromlaunch.substitutionsimportLaunchConfigurationfromlaunch_ros.actionsimportNodefromlaunch.actionsimportDeclareLaunchArgument,IncludeLaunchDescriptiondefgenerate_launch_description():# Declare the argumentsuse_sim_time=LaunchConfiguration('use_sim_time',default='False')map=LaunchConfiguration('map')# Define RViz config pathrviz_config_path=os.path.join(get_package_share_directory('locker98_tools_bringup'),'rviz','nav2_config.rviz')# Include the bringup launch filebringup_launch_file=os.path.join(get_package_share_directory('nav2_bringup'),'launch','bringup_launch.py')# Include the bringup launch file and pass argumentsinclude_bringup=IncludeLaunchDescription(bringup_launch_file,launch_arguments={'use_sim_time':use_sim_time,'map':map}.items())# RViz noderviz2_node=Node(package='rviz2',executable='rviz2',output='screen',arguments=['-d',rviz_config_path])# Return LaunchDescriptionreturnLaunchDescription([DeclareLaunchArgument('use_sim_time',default_value='False',description='Use simulation time'),DeclareLaunchArgument('map',default_value='',description='Map input'),include_bringup,rviz2_node])