Nav2 - ROS 2 Navigation Stack¶
Nav2 is the navigation stack for mobile robots designed for ROS 2. This package is considered both in research and as well as in industrial applications because of the modularity and the wide range of algorithms that it provides to the user. Nav2 is still considered as an evolving project and new features can be expected every fortnight.
In this tutorial, we just explain on how Nav2 is used in our robots. We encourage the users to check out the detailed official Nav2 documentation page for understanding the concepts surronding it.
In this tutorial for the sake of generality, we will be using neo_m(?)_(?)00. Please fill in with your own robot. For the case of simulation use neo_simulation.
Map is one of the essential component representing the environment based on which the planning algorithm will be able to plan the path for the robot.
For creating a map, we use the slam_toolbox.
Depending on your requirement you can also change the parameters for the mapping under
- Start creating the map, use the following command
ros2 launch neo_m(?)_(?)00 mapping.launch.py parameters:=~/$your_workspace/src/neo_m(?)_(?)00/configs/navigation/mapping.yaml
ros2 launch neo_m(?)_(?)00 mapping.launch.py parameters:=~/$your_workspace/src/neo_m(?)_(?)00/configs/navigation/namespaced_mapping.yaml robot_namespace:=robot1
Do not close the launch until saving the map.
The namespacing support for mapping is currently only available in MP-400.
- After starting the mapping, you can see the stripes of the maps as shown in the image below.
- Move the robot along your map using teleoperation package.
- After you done creating the map, it will be something like as shown below
To save the map, use the following command
ros2 run nav2_map_server map_saver_cli -f ~/to_your_workspace/src/neo_m(?)_(?)00/configs/navigation/maps/your_map_name
- In the map folder, you can see two files created
Once the files are created, go back to ~/to_your_workspace and rebuild your workspace so that the new map can be found by the map_server for navigation.
In order for the robot to autonomously navigate, we require three important components:
We have a single launch file and a single config file that brings up all the above necessary components.
Before starting the navigation, it is essential to utilize the newly created map for navigation. For this there are 2 ways to go about.
- A default map for the robots’ environment can be set. For this, please go to ~/to_your_workspace/src/neo_m(?)_(?)00/launch/navigation.launch.py and change the default value under the map_dir variable. Once done, the navigation can be initiated from the commandline by running:
ros2 launch neo_m(?)_(?)00 navigation.launch.py
ros2 launch neo_mpo_700-2 navigation.launch.py namespace:="robot1" use_multi_robots:=True head_robot:=True params_file:=install/neo_mpo_700-2/share/neo_mpo_700-2/configs/navigation/multi_robot_navigation.yaml
- Also the map can be chosen from the commandline terminal:
ros2 launch neo_m(?)_(?)00 navigation.launch.py map:=to_your_map_file.yaml
ros2 launch neo_nav2_bringup rviz_launch.py
ros2 launch neo_nav2_bringup rviz_launch.py use_namespace:=True namespace:="robot1"
Localize the robot¶
By default we use neo_localization for localization. In order to localize the robot press the “2D Pose Estimate” button and select the robot location on the map.
Sending goal(s) for the robot¶
In order the robot to start navigating autonomous a goal position needs to be defined. Assuming the goal position is given, Nav2 uses the planner to find an optimal path for the robot to the goal location. A controller is deployed by Nav2 for the robot to follow the path.
There are different ways to give the goals for the robot, here we will just explain some of them to get started:
Sending a single goal¶
In order to send just a single goal, press the “Nav2 goal” button and select the desired goal location on the map, as shown in the GIF below:
Sending multiple goals¶
For the people who are interested in sending multiple goals to the robot, No problem! Navigation2 provides a waypoint-following plugin, which would allow us to select multiple goals. For the ease of the user, we have already configured this plugin and ready for use.
In order to select the multiple goals. First, press the “Waypoint / Nav Through Poses Mode” button. The again as same as selecting a single goal, press the “Nav2 goal” button to select your goal location.
Note that, before selecting each goal, it is required to press the “Nav2 goal” button.
Waypoint follower plug-in is a direct replacement for the neo_goal_sequence driver, which our ROS-1 users are familiar with.
More about Navigation launch¶
Navigation launch is equipped with bunch of arguments, allowing the users to enable multi robot navigation, changing parameter set and enable docking for autonomous charging.
The argument list are as follows:
|use_multi_robots||False (Format: Bool)||Enables namespacing to the nodes related to Nav2|
|head_robot||False (Format: Bool)||Enables the map server|
|enable_docking||False (Format: Bool)||Enables docking and sets the corresponding nav2 parameters|
|use_amcl||False (Format: Bool)||Enabled if user wants to use amcl for localization|
|autostart||True (Format: Bool)||Disabled if user wants to trigger the lifecycle nodes|
|namespace||“” (Format: String)||Used in multi-robot scenario|
|param_file_name||“navigation.yaml” (Format: String)||Path to the Nav2 param file for each robots|
|docking_param_file_name||“docking_navigation.yaml” (Format: String)||Path to the Nav2 param file for each robots during docking|
|map||“test.yaml” (Format: String)||Path to the map file that robot uses for navigation|
Change parameters and algorithms¶
There are different algorithms and corresponding parameters as part of the Navigation2 stack. These parameters can be found under
|Controller||neo_local_planner||TEB and DWB local planner|
All the home-brewed algorithms are explained in the section packages.
Behavior tree is one of the key core concepts that have been adapted into the Navigation 2 stack. Behavior trees in the Nav2 stack provides the user to easily develop and customize various behaviors that the robot should exhibit. Each behaviors are developed as an individual component and then is integrated into the behavior tree. Thus the behavior tree, provides us with a flexible development environment for solving a particular problem at hand.
By default, all our robot packages carry behavior trees, that you can customize upon your need and application. In order to customize it, you simply need to navigate to
~/your_workspace/src/neo_mp(?)_(?)00/config/navigation/behavior_trees. There you can find behavior trees for
navigating_through_poses . Depending on your application, you can bring about different functionality changes for the task that you want to achieve with your robot.