|
| 1 | +// Copyright 2024 Marq Rasmussen |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 4 | +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 5 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 6 | +// permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright |
| 7 | +// notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 8 | +// |
| 9 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 10 | +// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 11 | +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 12 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 13 | + |
| 14 | +#include <functional> |
| 15 | +#include <memory> |
| 16 | +#include <thread> |
| 17 | + |
| 18 | +// auto-generated header, created by generate_parameter_library |
| 19 | +#include "bt_executor_parameters.hpp" |
| 20 | + |
| 21 | +#include "btcpp_ros2_interfaces/msg/node_status.hpp" |
| 22 | + |
| 23 | +#include "behaviortree_cpp/bt_factory.h" |
| 24 | + |
| 25 | +#include "behaviortree_ros2/plugins.hpp" |
| 26 | +#include "behaviortree_ros2/ros_node_params.hpp" |
| 27 | + |
| 28 | +#include "rclcpp/rclcpp.hpp" |
| 29 | +#include <ament_index_cpp/get_package_share_directory.hpp> |
| 30 | + |
| 31 | +namespace BT |
| 32 | +{ |
| 33 | +/** |
| 34 | + * @brief Convert BT::NodeStatus into Action Server feedback message NodeStatus |
| 35 | + * |
| 36 | + * @param status Current status of the executing BehaviorTree |
| 37 | + * @return NodeStatus used to publish feedback to the Action Client |
| 38 | + */ |
| 39 | +btcpp_ros2_interfaces::msg::NodeStatus ConvertNodeStatus(BT::NodeStatus& status); |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief Function the uses ament_index_cpp to get the package path of the parameter specified by the user |
| 43 | + * |
| 44 | + * @param parameter_value String containing 'package_name/subfolder' for the directory path to look up |
| 45 | + * @return Full path to the directory specified by the parameter_value |
| 46 | + */ |
| 47 | +std::string GetDirectoryPath(const std::string& parameter_value); |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Function to load BehaviorTree xml files from a specific directory |
| 51 | + * |
| 52 | + * @param factory BehaviorTreeFactory to register the BehaviorTrees into |
| 53 | + * @param directory_path Full path to the directory to search for BehaviorTree definitions |
| 54 | + */ |
| 55 | +void LoadBehaviorTrees(BT::BehaviorTreeFactory& factory, |
| 56 | + const std::string& directory_path); |
| 57 | + |
| 58 | +/** |
| 59 | + * @brief Function to load BehaviorTree ROS plugins (or standard BT.CPP plugins) from a specific directory |
| 60 | + * |
| 61 | + * @param factory BehaviorTreeFactory to register the plugins into |
| 62 | + * @param directory_path Full path to the directory to search for BehaviorTree plugins |
| 63 | + * @param params parameters passed to the ROS plugins |
| 64 | + */ |
| 65 | +void LoadRosPlugins(BT::BehaviorTreeFactory& factory, const std::string& directory_path, |
| 66 | + BT::RosNodeParams params); |
| 67 | + |
| 68 | +/** |
| 69 | + * @brief Function to register all Behaviors and BehaviorTrees from user specified packages |
| 70 | + * |
| 71 | + * @param params ROS parameters that contain lists of packages to load |
| 72 | + * plugins, ros_plugins and BehaviorTrees from |
| 73 | + * @param factory BehaviorTreeFactory to register into |
| 74 | + * @param node node pointer that is shared with the ROS based Behavior plugins |
| 75 | + */ |
| 76 | +void RegisterBehaviorTrees(bt_server::Params& params, BT::BehaviorTreeFactory& factory, |
| 77 | + rclcpp::Node::SharedPtr node); |
| 78 | + |
| 79 | +} // namespace BT |
0 commit comments