Skip to content

Commit 2703efe

Browse files
authored
Add groot2 tutorial (#645)
* Add groot2 tutorial Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Fix build warnings Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Fix as suggested Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Revert Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Formatting Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Fix Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Revert, remove sections Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> * Add exporting behavior trees Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com> --------- Signed-off-by: Maurice-1235 <mauricepurnawan@gmail.com>
1 parent 8e02bf6 commit 2703efe

19 files changed

Lines changed: 210 additions & 103 deletions

behavior_trees/trees/nav_through_poses_recovery.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ While this behavior tree does not make use of it, the ``PlannerSelector``, ``Con
7575
<ClearEntireCostmap name="ClearLocalCostmap-Subtree" service_name="local_costmap/clear_entirely_local_costmap"/>
7676
<ClearEntireCostmap name="ClearGlobalCostmap-Subtree" service_name="global_costmap/clear_entirely_global_costmap"/>
7777
</Sequence>
78-
<Spin spin_dist="1.57" error_code_id="{spin_error_code} error_msg="{spin_error_msg}"/>
78+
<Spin spin_dist="1.57" error_code_id="{spin_error_code}" error_msg="{spin_error_msg}"/>
7979
<Wait wait_duration="5.0"/>
8080
<BackUp backup_dist="0.30" backup_speed="0.05" error_code_id="{backup_error_code}" error_msg="{backup_error_msg}"/>
8181
</RoundRobin>

configuration/packages/configuring-bt-navigator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The BT Navigator (Behavior Tree Navigator) module implements the NavigateToPose,
1111
It is a Behavior Tree-based implementation of navigation that is intended to allow for flexibility
1212
in the navigation task and provide a way to easily specify complex robot behaviors, including recovery.
1313

14-
Consider checking out the :ref:`groot_introduction` tutorial for using Groot to visualize and modify behavior trees.
14+
Consider checking out the :ref:`using_groot` tutorial for using Groot to visualize and modify behavior trees.
1515

1616
Make sure to review all parameters for non-default navigator plugins not discussed on this page (e.g. ``CoverageNavigator`` or custom additions).
1717

configuration/packages/configuring-bt-xml.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Check this introduction_ to learn how behavior trees work and the difference bet
1111

1212
.. _introduction: https://www.behaviortree.dev/bt_basics/
1313

14-
Consider checking out the :ref:`groot_introduction` tutorial for using Groot to visualize and modify behavior trees.
14+
Consider checking out the :ref:`using_groot` tutorial for using Groot to visualize and modify behavior trees.
1515

1616
Action Plugins
1717
**************

migration/Iron.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ New features ``allow_primitive_interpolation`` which allows for more primitives
172172
New node in nav2_collision_monitor: Collision Detector
173173
******************************************************
174174

175-
In this `PR #3693 <https://github.com/ros-navigation/navigation2/pull/3500>`_ A new node was introduced in the nav2_collision_monitor: Collision Detector.
175+
In this `PR #3500 <https://github.com/ros-navigation/navigation2/pull/3500>`_ A new node was introduced in the nav2_collision_monitor: Collision Detector.
176176
It works similarly to the Collision Monitor, but does not affect the robot's velocity. It will only inform that data from the configured sources has been detected within the configured polygons via message to the ``collision_detector_state`` topic that might be used by any external module (e.g. switching LED or sound alarm in case of collision).
177177

178178
Dynamic enabling/disabling of sources/polygons in Collision Monitor/Detector
@@ -331,7 +331,7 @@ New graceful cancellation API for Controllers
331331
Standardization of Plugin Naming with Double Colons (::)
332332
********************************************************
333333

334-
`PR #4220`_ standardizes plugin naming across the Navigation2 package to use double colons (::), replacing the previous mixed use of slashes (/) and double colons. Affected plugins include:
334+
`PR #4220 <https://github.com/ros-planning/navigation2/pull/4220>`_ standardizes plugin naming across the Navigation2 package to use double colons (::), replacing the previous mixed use of slashes (/) and double colons. Affected plugins include:
335335

336336
- Behavior Server: ``nav2_behaviors::Spin``, ``nav2_behaviors::BackUp``, ``nav2_behaviors::DriveOnHeading``, ``nav2_behaviors::Wait``, ``nav2_behaviors::AssistedTeleop``
337337
- Planner Server: ``nav2_navfn_planner::NavfnPlanner``, ``nav2_smac_planner::SmacPlanner2D``, ``nav2_smac_planner::SmacPlannerHybrid``, ``nav2_theta_star_planner::ThetaStarPlanner``

migration/Jazzy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The following provides examples of modifications that should be made to behavior
5252

5353
.. code-block:: xml
5454
55-
<ComputePathToPose goal="{goal}" path="{path}" planner_id="{selected_planner}" error_code_id="{compute_path_error_code} error_msg="{compute_path_error_msg}"/>
55+
<ComputePathToPose goal="{goal}" path="{path}" planner_id="{selected_planner}" error_code_id="{compute_path_error_code}" error_msg="{compute_path_error_msg}"/>
5656
<FollowPath path="{path}" controller_id="{selected_controller}" error_code_id="{follow_path_error_code}" error_msg="{follow_path_error_msg}"/>
5757
<Spin spin_dist="1.57" error_code_id="{spin_error_code}" error_msg="{spin_error_msg}"/>
5858
<Wait wait_duration="5.0" error_code_id="{wait_error_code}" error_msg="{wait_error_msg}"/>

tutorials/docs/adding_a_nav2_task_server.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ The table below shows the current servers along with the expected error code str
162162
.. _Smoother Server: https://github.com/ros-navigation/navigation2/blob/main/nav2_smoother/src/nav2_smoother.cpp
163163
.. _Waypoint Follower Server: https://github.com/ros-navigation/navigation2/blob/main/nav2_waypoint_follower/src/waypoint_follower.cpp
164164
.. _Behavior Server: https://github.com/ros-navigation/navigation2/blob/main/nav2_behaviors/src/behavior_server.cpp
165+
.. _Navigator: https://github.com/ros-navigation/navigation2/blob/main/nav2_bt_navigator/
165166

166167
Error codes and messages are attached to the response of the action message. An example can be seen below for the route server. Note it is necessary to set the error code field within the message result definition to ``error_code`` and the error message field to ``error_msg``.
167168

tutorials/docs/groot.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.. _groot_introduction:
2+
3+
Groot - Interacting with Behavior Trees
4+
***************************************
5+
6+
- `Visualize Behavior Trees`_
7+
- `Edit Behavior Trees`_
8+
- `Adding A Custom Node`_
9+
10+
11+
Visualize Behavior Trees
12+
========================
13+
14+
To display a Behavior Tree like that in :numref:`groot_nav2_default_bt`, we will first start the Groot executable.
15+
Out of the box, Groot can only display Behavior Trees and nodes that are from the defaults in BT.CPP, since it does not know anything about Nav2 or your other projects.
16+
Therefore, we must point Groot to our palette, or index of Nav2 / custom behavior tree nodes:
17+
18+
1. Open Groot in editor mode. Now, Groot should look like in :numref:`groot_bt_editor`.
19+
2. Select the `Load palette from file` option either via the context menu or the import icon in the top middle of the menu bar.
20+
3. Open the file `/path/to/navigation2/nav2_behavior_tree/nav2_tree_nodes.xml` to import all the custom behavior tree nodes used for navigation. This is the palette of Nav2 custom behavior tree nodes. Now, Groot should look like in :numref:`groot_bt_editor_with_nodes`.
21+
4. Select `Load tree` option near the top left corner
22+
5. Browse the tree you want to visualize, then select `OK`. The Nav2 BTs exist in `/path/to/navigation2/nav2_bt_navigator/behavior_trees/`
23+
24+
+-----------------------------------------------------------+-----------------------------------------------------------+
25+
| .. figure:: images/Groot/groot_bt_editor.png | .. figure:: images/Groot/groot_with_nav2_custom_nodes.png |
26+
| :name: groot_bt_editor | :name: groot_bt_editor_with_nodes |
27+
| | |
28+
| Default Editor View | Editor with Custom Nodes loaded in blue |
29+
+-----------------------------------------------------------+-----------------------------------------------------------+
30+
31+
If you select the default tree `navigate_w_replanning_and_recovery.xml`, then a Groot editor should look like :numref:`groot_nav2_default_bt`.
32+
33+
+-----------------------------------------------------------+
34+
| .. figure:: images/Groot/bt_w_replanning_and_recovery.png |
35+
| :name: groot_nav2_default_bt |
36+
| |
37+
| Full Nav2 Default BehaviorTree |
38+
+-----------------------------------------------------------+
39+
40+
.. note::
41+
If a tree cannot be visualized because some nodes are missing in the palette, you might need to add it to your palette. While we try to keep Nav2's BT nodes and palettes in sync, if you notice one is missing, please file a ticket or pull request and we should have that updated quickly.
42+
43+
44+
Edit Behavior Trees
45+
===================
46+
47+
Now that you have a Nav2 BT open in Groot in editor mode, you should be able to trivially modify it using the GUI.
48+
Starting from a screen like that shown in :numref:`groot_nav2_default_bt`, you can pull in new nodes from the side panel to add them to the workspace.
49+
You may then connect the nodes using a "drag and drop" motion between the node's input and output ports to assemble the new nodes into the tree.
50+
51+
If you select a given node, you can change metadata about it such as its name or values of parameterizable ports. When you're done modifying, simply save the new configuration file and use that on your robot the next time!
52+
53+
Adding A Custom Node
54+
====================
55+
56+
Each node in the behavior tree holds a specialized function.
57+
Sometimes, its useful to create new nodes and add them to your palette during the design process - perhaps before the implementations themselves exist.
58+
This helps designers abstract away the implementation specifics of the nodes from the higher level logic of the tree itself and how they'd like to interact with a given node (e.g. type, ports, etc).
59+
Within Groot, you may create new custom nodes to add to your tree and export these new nodes back to your palette.
60+
Implementing the node itself needs to be done separately from Groot, which is described in :ref:`writing_new_nbt_plugin`.
61+
62+
+-----------------------------------------------------------+
63+
| .. figure:: images/Groot/groot_create_custom_node.png |
64+
| :name: groot_create_custom_node |
65+
| |
66+
| Create a new Custom Node |
67+
+-----------------------------------------------------------+
68+
69+
Creating a new custom node can be started by clicking the orange marked icon in :numref:`groot_create_custom_node`, while Groot is in Editor mode.
70+
This should load a new window, similar to :numref:`groot_interactive_node_creation`.
71+
In this new window, it asks you to fill in the metadata about this new node, in order to create it.
72+
It will ask you for standard information such as name (green box), type of node (orange box), and any optional ports for parameterization or access to blackboard variables (blue box).
73+
74+
After completing, select `OK` in :numref:`groot_interactive_node_creation`, the new custom node should appear in blue in the `TreeNode Palette` as in :numref:`groot_export_new_node`.
75+
76+
+--------------------------------------------------------------+--------------------------------------------------------------+
77+
| .. figure:: images/Groot/groot_interactive_node_creation.png | .. figure:: images/Groot/groot_export_new_node.png |
78+
| :name: groot_interactive_node_creation | :name: groot_export_new_node |
79+
| | :width: 180% |
80+
| | |
81+
| UI to describing new Nodes | Exporting the new Custom Node |
82+
+--------------------------------------------------------------+--------------------------------------------------------------+
83+
84+
Before starting to create a new BT based on the new custom nodes, it is recommend to export the newly created nodes to save in case of Groot crashing.
85+
This can be performed with the icon highlighted in green from :numref:`groot_export_new_node`.
86+
The resulting XML output from the node created in :numref:`groot_interactive_node_creation` can be seen below.
87+
You can see more examples in `Nav2's BT Node Palette XML <https://github.com/ros-navigation/navigation2/blob/main/nav2_behavior_tree/nav2_tree_nodes.xml>`_.
88+
89+
90+
.. code-block:: xml
91+
92+
<root>
93+
<TreeNodesModel>
94+
<Action ID="MyAwesomeNewNode">
95+
<input_port name="key_name" default="false">coffee</input_port>
96+
<output_port name="key_name2" default="42">Sense of life</output_port>
97+
<inout_port name="next_target" default="pancakes">rolling target</inout_port>
98+
</Action>
99+
</TreeNodesModel>
100+
</root>

tutorials/docs/groot2.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.. _groot2_introduction:
2+
3+
Groot2 - Interacting with Behavior Trees
4+
****************************************
5+
6+
- `Visualize Behavior Trees`_
7+
- `Edit Behavior Trees`_
8+
- `Adding A Custom Node`_
9+
10+
11+
Visualize Behavior Trees
12+
========================
13+
14+
To display the default editor view, we will first start the Groot2 executable.
15+
Out of the box, Groot2 can only display Behavior Trees and nodes that are from the defaults in BT.CPP, since it does not know anything about Nav2 or your other projects.
16+
Therefore, we must point Groot2 to our palette, or index of Nav2 / custom behavior tree nodes:
17+
18+
1. Open Groot2 in editor mode. The interface should now look like the example shown in the first image below.
19+
2. Click the red icon as shown in the second image, open the file `/path/to/navigation2/nav2_behavior_tree/nav2_tree_nodes.xml` to import all the custom behavior tree nodes used for navigation. Once loaded, you should see the full palette of Nav2's custom nodes.
20+
3. Click the blue icon as shown in the second image, browse the tree you want to visualize, then select `Open`. The Nav2 BTs exist in `/path/to/navigation2/nav2_bt_navigator/behavior_trees/`.
21+
22+
.. image:: images/Groot2/groot_bt_editor.png
23+
:width: 46%
24+
.. image:: images/Groot2/groot_with_nav2_custom_nodes.png
25+
:width: 45%
26+
27+
If you select the default tree `navigate_w_replanning_and_recovery.xml`, the Groot2 editor should now display the full behavior tree structure, as shown in the image below.
28+
29+
.. image:: images/Groot2/bt_w_replanning_and_recovery.png
30+
:width: 80%
31+
32+
You can also check/uncheck the Nodes visualization part in the preferences to better visualize the tree.
33+
34+
.. image:: images/Groot2/groot_preferences.png
35+
:width: 80%
36+
37+
.. note::
38+
If a tree cannot be visualized because some nodes are missing in the palette, you might need to add it to your palette. While we try to keep Nav2's BT nodes and palettes in sync, if you notice one is missing, please file a ticket or pull request and we should have that updated quickly.
39+
40+
Edit Behavior Trees
41+
===================
42+
43+
Now that you have a Nav2 BT open in Groot2 in editor mode, you should be able to trivially modify it using the GUI.
44+
You can pull in new nodes from the side panel to add them to the workspace.
45+
You may then connect the nodes using a "drag and drop" motion between the node's input and output ports to assemble the new nodes into the tree.
46+
47+
If you select a given node, you can change metadata about it such as its name or values of parameterizable ports. When you're done modifying, simply save the new configuration file and use that on your robot the next time!
48+
49+
.. image:: images/Groot2/editing_bt.png
50+
:width: 80%
51+
52+
53+
Adding A Custom Node
54+
====================
55+
56+
Each node in the behavior tree holds a specialized function.
57+
Sometimes, its useful to create new nodes and add them to your palette during the design process - perhaps before the implementations themselves exist.
58+
This helps designers abstract away the implementation specifics of the nodes from the higher level logic of the tree itself and how they'd like to interact with a given node (e.g. type, ports, etc).
59+
Within Groot2, you may create new custom nodes to add to your tree and export these new nodes back to your palette.
60+
Implementing the node itself needs to be done separately from Groot2, which is described in :ref:`writing_new_nbt_plugin`.
61+
62+
63+
64+
Creating a new custom node can be started by clicking the red marked icon, while Groot2 is in Editor mode.
65+
66+
.. image:: images/Groot2/groot_create_custom_node.png
67+
:width: 40%
68+
69+
This should load a new window, as shown in the next image.
70+
71+
.. image:: images/Groot2/groot_interactive_node_creation.png
72+
:width: 50%
73+
74+
In this new window, it asks you to fill in the metadata about this new node, in order to create it.
75+
It will ask you for standard information such as port name, type of node, and any optional ports for parameterization or access to blackboard variables.
76+
After completing, select `OK`, the new custom node should now appear in the `TreeNode Palette`.
77+
78+
.. image:: images/Groot2/groot_new_node.png
79+
:width: 35%
80+
81+
Exporting Behavior Trees
82+
========================
83+
84+
Once you have finished editing or creating your behavior tree in Groot2, you may want to export it for use in your application.
85+
To do this, you can either use the Export Project button shown in the image below, or use the Save Current Project As button next to it.
86+
87+
.. image:: images/Groot2/groot_export_button.png
88+
:width: 50%
89+
.. image:: images/Groot2/groot_export_page.png
90+
:width: 40%
91+
92+
Your behavior tree has been successfully exported! You can reload it the next time you open Groot2.
299 KB
Loading
393 KB
Loading

0 commit comments

Comments
 (0)