Files
Main/99 Work/0 OneSec/OneSecNotes/10 Projects/OsdAutopilot/How to add a Behavior Tree Node.md
2024-12-02 15:11:30 +01:00

1.4 KiB

Since the entire autopilot is heavily inspired by the ROS2 - NAV2 Library we also use Behaviour Trees to implement the autopilot.

All of our simple behaviors are located in the nav3_behavior_tree package under the plugins folder. There are four types of plugins that form the base of behavior trees as basic building blocks.: action, condition, control and decorators.

  1. Decide what kind of node you will be adding: we're assuming a control node for the sake of the example
  2. write your h-file in nav3_behavior_tree/include/nav3_behavior_tree/plugins/control.
    1. As an example
    2. Inherit from BT::ControlNode. (See round_robin_node.hpp as an example)
  3. Write the cpp-file in nav3_behavior_tree/plugins/control/round_robin_node.cpp 4. Make sure you use the BT_REGISTER_NODES() macro to register the node in the behavior tree factory.
  4. Add the plugin to the CMakeLists.txt: nav3_behavior_tree/CMakeLists.txt
  5. Write a test in the following file: nav3_behavior_tree/test/plugins/control/test_round_robin_node.cpp
  6. Register the test in the following file: nav3_behavior_tree/test/plugins/control/CMakeLists.txt
    1. Make sure you test all cases that the node uses.
  7. Add the new tree node to the library file: nav3_behavior_tree/nav3_tree_nodes.xml