Skip to content

Commit a0fa19d

Browse files
Added documentation for Groot 2 (#672)
* Doc for Groot2 Signed-off-by: Alberto Tudela <ajtudela@gmail.com> * Minor fixes Signed-off-by: Alberto Tudela <ajtudela@gmail.com> * Minor fixes Signed-off-by: Alberto Tudela <ajtudela@gmail.com> * Update plugin_tutorials/docs/writing_new_bt_plugin.rst Signed-off-by: Alberto Tudela <ajtudela@gmail.com> Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> Signed-off-by: Alberto Tudela <ajtudela@gmail.com> --------- Signed-off-by: Alberto Tudela <ajtudela@gmail.com> Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
1 parent bd5a99e commit a0fa19d

3 files changed

Lines changed: 147 additions & 2 deletions

File tree

configuration/packages/configuring-bt-navigator.rst

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ Parameters
249249
Description
250250
Use time provided by simulation.
251251

252-
:error_code_name_prefixes
252+
:error_code_name_prefixes:
253+
253254
============== ===========================
254255
Type Default
255256
-------------- ---------------------------
@@ -270,7 +271,7 @@ Parameters
270271
Description
271272
For Kilted and newer: List of of error code name prefixes to be appended with '_error_code' and '_error_msg' and searched for during aborted navigator error processing.
272273

273-
:error_code_names
274+
:error_code_names:
274275

275276
============== ===========================
276277
Type Default
@@ -293,6 +294,57 @@ Parameters
293294
Description
294295
The lifecycle node bond mechanism publishing period (on the /bond topic). Disabled if inferior or equal to 0.0.
295296

297+
298+
NavigateToPose Parameters
299+
*************************
300+
301+
:``<navigate_to_pose_name>``.enable_groot_monitoring:
302+
303+
============== =======
304+
Type Default
305+
-------------- -------
306+
bool False
307+
============== =======
308+
309+
Description
310+
Whether to enable Groot2 monitoring for this navigator.
311+
312+
:``<navigate_to_pose_name>``.groot_server_port:
313+
314+
==== =======
315+
Type Default
316+
---- -------
317+
int 1667
318+
==== =======
319+
320+
Description
321+
The port number for the Groot2 server. Note: In Groot2, you only need to specify the server port value, not the publisher port, as it is always the server port +1. Therefore, in this case, to use another navigator, the next available port would be 1669.
322+
323+
NavigateThroughPoses Parameters
324+
*******************************
325+
326+
:``<navigate_through_poses>``.enable_groot_monitoring:
327+
328+
============== =======
329+
Type Default
330+
-------------- -------
331+
bool False
332+
============== =======
333+
334+
Description
335+
Whether to enable Groot2 monitoring for this navigator.
336+
337+
:``<navigate_through_poses>``.groot_server_port:
338+
339+
==== =======
340+
Type Default
341+
---- -------
342+
int 1669
343+
==== =======
344+
345+
Description
346+
The port number for the Groot2 server. Note: In Groot2, you only need to specify the server port value, not the publisher port, as it is always the server port +1. Therefore, in this case, to use another navigator, the next available port would be 1671.
347+
296348
Example
297349
*******
298350
.. code-block:: yaml
@@ -315,8 +367,12 @@ Example
315367
navigators: ['navigate_to_pose', 'navigate_through_poses']
316368
navigate_to_pose:
317369
plugin: "nav2_bt_navigator::NavigateToPoseNavigator" # In Iron and older versions, "/" was used instead of "::"
370+
enable_groot_monitoring: false
371+
groot_server_port: 1667
318372
navigate_through_poses:
319373
plugin: "nav2_bt_navigator::NavigateThroughPosesNavigator" # In Iron and older versions, "/" was used instead of "::"
374+
enable_groot_monitoring: false
375+
groot_server_port: 1669
320376
plugin_lib_names:
321377
- nav2_compute_path_to_pose_action_bt_node
322378
- nav2_follow_path_action_bt_node

migration/Jazzy.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,9 @@ Modified statuses should then be propagated through output ports for downstream
429429

430430
The ``NavigateThroughPoses`` navigator retrieves the ``waypoint_statuses`` instance from the blackboard in its ``onLoop`` callback and writes it into the feedback message.
431431
During the ``goalCompleted`` callback, it fetches the ``waypoint_statuses`` instance and, based on the BT's final execution status (``final_bt_status``), updates any waypoints still in the ``PENDING`` state to either ``COMPLETED`` (if ``final_bt_status`` is ``SUCCEEDED``) or ``FAILED`` (otherwise).
432+
433+
Groot 2 Support
434+
***************
435+
In `PR #5065 <https://github.com/ros-navigation/navigation2/pull/5065>`_ , BT navigators: ``navigate_to_pose`` and ``navigate_through_poses`` now support live monitoring and visualization of the behavior tree using Groot 2. JSON conversions are also available to see the content of the Blackboard, allowing the introspection of the BT nodes. Switching bt-xmls on the fly through a new goal request is also included.
436+
437+
Because live monitoring of Behavior Tree with more than 20 nodes and visualizing the content of the blackboard is a PRO (paid) feature of Groot 2. This feature is disabled by default.

plugin_tutorials/docs/writing_new_bt_plugin.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Writing a New Behavior Tree Plugin
66
- `Overview`_
77
- `Requirements`_
88
- `Tutorial Steps`_
9+
- `Using custom types for Input/Output ports`_
10+
- `Visualize the content of the blackboard in Groot 2 (PRO)`_
911

1012
Overview
1113
========
@@ -235,3 +237,84 @@ Select this BT XML file in your specific navigation request in ``NavigateToPose`
235237
</RecoveryNode>
236238
</BehaviorTree>
237239
</root>
240+
241+
Using custom types for Input/Output ports
242+
=========================================
243+
244+
In addition to standard types, custom types such as those from ``nav2_msgs`` or ``geometry_msgs`` can also be used for input/output ports.
245+
246+
For example, you can define custom types for ports in the ``providedPorts`` function as follows:
247+
248+
.. code-block:: cpp
249+
250+
static PortsList providedPorts()
251+
{
252+
return providedBasicPorts(
253+
BT::OutputPort<geometry_msgs::msg::Point>("position", "Position of the robot")
254+
});
255+
}
256+
257+
To use custom types for input/output ports in the behavior tree XML, it is necessary to convert them from a string. This is because ports in the XML are represented as strings and must be transformed into the corresponding data type in the code.
258+
259+
For example, if you have a custom type ``geometry_msgs::msg::Point``, you can perform the conversion as follows:
260+
261+
.. code-block:: cpp
262+
263+
namespace BT
264+
{
265+
template<>
266+
inline geometry_msgs::msg::Point convertFromString(const StringView key)
267+
{
268+
// three real numbers separated by semicolons
269+
auto parts = BT::splitString(key, ';');
270+
if (parts.size() != 3) {
271+
throw std::runtime_error("invalid number of fields for point attribute)");
272+
} else {
273+
geometry_msgs::msg::Point position;
274+
position.x = BT::convertFromString<double>(parts[0]);
275+
position.y = BT::convertFromString<double>(parts[1]);
276+
position.z = BT::convertFromString<double>(parts[2]);
277+
return position;
278+
}
279+
}
280+
} // namespace BT
281+
282+
For more information on custom type conversion, you can refer to the `bt_utils.hpp <https://github.com/ros-navigation/navigation2/blob/main/nav2_behavior_tree/include/nav2_behavior_tree/bt_utils.hpp>`_ or the BT.CPP documentation: `Parsing a string <https://www.behaviortree.dev/docs/tutorial-basics/tutorial_03_generic_ports#parsing-a-string>`_.
283+
284+
Visualize the content of the blackboard in Groot 2 (PRO)
285+
========================================================
286+
287+
If you are using the paid version of Groot 2 Pro, you can view the content of the blackboard of the BT nodes. To achieve this, you need to perform a conversion of the custom input/output type to JSON format. Below is an example of such a conversion:
288+
289+
.. code-block:: cpp
290+
291+
namespace geometry_msgs::msg
292+
{
293+
BT_JSON_CONVERTER(geometry_msgs::msg::Point, msg)
294+
{
295+
add_field("x", &msg.x);
296+
add_field("y", &msg.y);
297+
add_field("z", &msg.z);
298+
}
299+
} // namespace geometry_msgs::msg
300+
301+
The macro ``BT_JSON_CONVERTER`` must be placed within the namespace of the custom type to be converted. Additionally, if the custom type is composed of other custom types, those types must be converted first before converting the parent type.
302+
303+
After defining the conversion, you need to register the custom type in the `providedPorts` function. Below is an example of how to register it:
304+
305+
.. code-block:: cpp
306+
307+
static PortsList providedPorts()
308+
{
309+
// Register JSON definitions for the types used in the ports
310+
BT::RegisterJsonDefinition<geometry_msgs::msg::Point>();
311+
return providedBasicPorts(
312+
BT::OutputPort<geometry_msgs::msg::Point>("position", "Position of the robot")
313+
});
314+
}
315+
316+
For more information on custom type conversion, you can refer to the `json_utils.hpp <https://github.com/ros-navigation/navigation2/blob/main/nav2_behavior_tree/include/nav2_behavior_tree/json_utils.hpp>`_ or the BT.CPP documentation: `Visualize custom types in the Blackboard <https://www.behaviortree.dev/docs/tutorial-basics/tutorial_11_groot2/#visualize-custom-types-in-the-blackboard>`_
317+
318+
.. note::
319+
320+
All custom types used in Nav2 are already registered in the `json_utils.hpp` file. You can use them directly without the need to register them again.

0 commit comments

Comments
 (0)