🌳 Goal Navigation BT#
As mentioned earlier, the Goal Navigation uses of Behavior Trees to define the logic used in the navigation tasks. In this section, you will learn about the available Behavior Trees, their characteristics, and how to create new ones with new custom logic.
Behavior Tree Navigator#
The bt_navigator is a Behavior Tree-based implementation for navigation, designed to provide flexibility in navigation tasks and to allow for the easy specification of complex robot behaviors, including recovery actions.
It implements different task interfaces, one of this is the Nav2 NavigateToPose .
Navigate To Pose#
The NavigateToPose task interface is responsible for loading and executing a certain navigation logic defined in a Behavior Tree.
Note
By default, the NavigateToPose task interface uses the Behavior Tree defined in the navigate_to_pose_w_replanning_and_recovery.xml.
This BT allows to navigate from a Start pose to a Goal pose in freespace. It contains both use of custom recovery behaviors in specific sub-contexts as well as a global recovery subtree for system-level failures. It also provides the opportunity for users to retry tasks multiple times before returning a failed state.
Apart from this Behavior Three, Nav2 offers different alternative navigation logics. For more information, please check Nav2 Behavior Trees.
Note
You can list the available Nav2 Behavior Trees with
ls /opt/ros/$ROS_DISTRO/share/nav2_bt_navigator/behavior_trees/
And the available PAL Behavior Trees with
ls /opt/pal/$PAL_DISTRO/share/pal_navigation_cfg/templates/nav2_bt_navigator/behavior_trees/
How to create your Goal Navigation Behavior Tree#
In addition to the PAL Behavior Trees and the Nav2 Behavior Trees, you can create a new Behavior Tree with custom logic, by creating a new XML file.
You can create it in the directory you prefer, though it is recommended to create it in the .pal
folder of your robot.
mkdir -p ~/.pal/behavior_trees
And then, within this folder, you can create a new XML file for your custom Behavior Tree.
touch ~/.pal/behavior_trees/my_custom_bt.xml
To do so, you can refer to the BT Official Documentation and configure it by adding your nodes to the XML file as indicated in the Official Configuration Guide.
Configuration#
In order to start using your custom Behavior Tree, you can :
Use the /navigate_to_pose by providing the full path to your custom XML file as shown in the previous section 🥅 Goal Navigation.
ros2 action send_goal /navigate_to_pose nav2_msgs/action/NavigateToPose "pose:
header:
stamp:
sec: 0
nanosec: 0
frame_id: 'map' # The frame in which the pose is expressed
pose:
position:
x: 0.0
y: 0.0
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
behavior_tree: '/home/pal/.pal/behavior_trees/my_custom_bt.xml'"
Create your custom configuration for the bt_navigator and update the default
default_nav_to_pose_bt_xml
parameter to the full path of your custom XML file.
If you want to go with the second option, you first need to create a new directory in the .pal
folder of your robot.
mkdir -p ~/.pal/config
And then, within this folder, you can create a new bt_navigator
configuration file.
touch ~/.pal/config/99_my_bt_navigator_config.yaml
Attention
The name of the file should start with a number to ensure that it is loaded last and overrides the default PAL configurations.
Within the newly created 99_my_bt_navigator_config.yaml
file, you can insert your bt_navigator
parameters.
For the list of available parameters, their meaning and how they affect the SLAM algorithm, you can refer to the
bt_navigator configuration guide.
When creating a new Navigation configuration file, you need to specify the node name it refers to, in this case,
bt_navigator
.
/bt_navigator:
ros__parameters:
# Your bt_navigator parameters
default_nav_to_pose_bt_xml: "/home/pal/.pal/behavior_trees/my_custom_bt.xml"
Once created, to start using your custom bt_navigator
configuration, you need to restart the
navigation
module with the command:
pal module restart navigation
Note
This change is is persistent and will be loaded every time you start the navigation
module.
If you want to revert to the default PAL configuration, you can simply delete the custom configuration file
you created in the ~/.pal/config
folder.
See also#
To continue learning about the Behavior Trees used in Nav2, and specific nodes used in the BTs you can check Nav2 Behavior Trees