BehaviorTree / BehaviorTree.CPP

Behavior Trees Library in C++. Batteries included.
https://www.behaviortree.dev
MIT License
3.03k stars 665 forks source link

Unable to use nodes as plugins in behavior tree v4.5 #842

Closed nilutpol-k closed 4 months ago

nilutpol-k commented 4 months ago

Hi, I am trying to use behavior tree nodes as plugins in ROS 2 code.

My tree has just 1 node

<?xml version="1.0"?>
<root BTCPP_format="4" >
    <BehaviorTree ID="BehaviorTree">
        <ReactiveSequence>
        <Action ID="Node1"/>
        </ReactiveSequence>
    </BehaviorTree>
    <TreeNodesModel>
        <Action ID="Node1"/>
    </TreeNodesModel>
</root>

Here is the code I added to my CMakelists.txt to use the nodes as plugins

add_library(bt_plugin1 SHARED src/behavior_tree_plugins/Node1.cpp)

list(APPEND plugin_libs
  bt_plugin1
)

foreach(bt_plugin ${plugin_libs})
  ament_target_dependencies(${bt_plugin} ${dependencies})
  target_compile_definitions(${bt_plugin} PRIVATE BT_PLUGIN_EXPORT)
endforeach()

...
...

install(TARGETS
  ${plugin_libs}
  bt_plugins_main
  DESTINATION lib/${PROJECT_NAME})

My ROS 2 package structure

behavior_tree_plugins/
├── package.xml
├── CMakeLists.txt
├── src/
      ├── behavior_tree_plugins/
              └── Node1.cpp
      └── bt_plugins_main.cpp
└── xml/
      └── tree1.xml

My main behavior tree code for loading the plugins (partial code)

    ....
    BT::SharedLibrary loader;

    factory.registerFromPlugin(loader.getOSName("bt_plugin1"));
    ....

The error

My code compiles successfully but my main behavior tree code is not able to load the Node1 library successfully as it is not able to find it.

I get the error as

terminate called after throwing an instance of 'BT::RuntimeError'
  what():  Could not load library: libbt_plugin1.so: cannot open shared object file: No such file or directory

Screenshot from 2024-07-01 12-15-11

System Details: OS: Ubuntu 22.04 ROS 2: Humble Behavior tree version: 4.5

facontidavide commented 4 months ago

The path where the file is will not be found magically. You need to specify the actual path. This may help: https://index.ros.org/p/ament_index_cpp/

nilutpol-k commented 4 months ago

Hi @facontidavide

specify the actual path

where do I mention the actual file paths?