AutoAPMS
Streamlining behaviors in ROS 2
Loading...
Searching...
No Matches
NodeRegistrationFromLibraryAdapter Class Referenceabstract

A node registration interface that is able to load and registers behavior tree nodes from a shared library using BT::BehaviorTreeFactory::registerFromPlugin. More...

#include <auto_apms_behavior_tree_core/node/node_registration_from_library_adapter.hpp>

Inheritance diagram for NodeRegistrationFromLibraryAdapter:

Private Member Functions

virtual std::string getPluginLibraryPath () const =0
 Get the library path that exports the node registration function associated with this class.
 

Detailed Description

A node registration interface that is able to load and registers behavior tree nodes from a shared library using BT::BehaviorTreeFactory::registerFromPlugin.

The libraries must export the BT_RegisterNodesFromPlugin(factory) symbol which is the ROS-agnostic approach for distributing behavior tree nodes through plugins in BehaviorTree.CPP.

You can find an example of how to implement the required plugin export macro in the official BehaviorTree.CPP repository: https://github.com/BehaviorTree/BehaviorTree.CPP/blob/3ff6a32ba0497a08519c77a1436e3b81eff1bcd6/examples/plugin_example/plugin_action.cpp

Usage:

  1. Create a subclass of this adapter for each plugin library you want to load nodes from. Implement the NodeRegistrationFromLibraryAdapter::getPluginLibraryPath() method to return the respective library path.
  2. Apply the pluginlib practices to register adapter subclasses as a node registration plugin using the PLUGINLIB_EXPORT_CLASS macro.

    #include "pluginlib/class_list_macros.hpp"
    #include "auto_apms_behavior_tree_core/node/node_registration_interface.hpp"
    PLUGINLIB_EXPORT_CLASS(
    my_namespace::MyNodeRegistrationType,
    Interface used for registering behavior tree node plugins.

    You also need to create a plugin manifest XML file and list the adapter subclasses as plugins in the manifest. Follow ROS 2's documentation for details on how to do this: https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Pluginlib.html

  3. Use the NODE_REGISTRATION_TYPE keyword in the auto_apms_behavior_tree_register_nodes macro in your CMakeLists.txt to specify the adapter subclass as the registration type for the nodes you want to register from the plugin library.

    auto_apms_behavior_tree_register_nodes(my_nodes
    my_package::MyNodeRegistrationType
    NODE_REGISTRATION_TYPE my_package::MyNodeRegistrationType
    )

    In this case, you need to specify my_package::MyNodeRegistrationType both under ARGN and NODE_REGISTRATION_TYPE. Supplying multiple args under ARGN would create ambiguity, because there would be multiple names for the same collection of nodes. The convention is to call this macro once for each node registration type (if it's not a template).

  4. In your node manifest YAML, specify the fully qualified name of the adapter subclass as the class name for the nodes you want to register from the plugin library. You can specify the same adapter subclass multiple times with different registration names to register multiple nodes from the same library.

    MyNodeName:
    class_name: my_package::MyNodeRegistrationType
    MyOtherNodeName:
    class_name: my_package::MyNodeRegistrationType

    As you see, it is also possible to register multiple nodes from the same plugin library using the same adapter subclass.

Definition at line 85 of file node_registration_from_library_adapter.hpp.

Member Function Documentation

◆ getPluginLibraryPath()

virtual std::string getPluginLibraryPath ( ) const
privatepure virtual

Get the library path that exports the node registration function associated with this class.

Returns
Library path.

The documentation for this class was generated from the following files: