17#include "auto_apms_behavior_tree/build_handler/build_handler_loader.hpp"
18#include "auto_apms_behavior_tree/executor/executor_base.hpp"
19#include "auto_apms_behavior_tree/executor/options.hpp"
20#include "auto_apms_behavior_tree/executor_params.hpp"
21#include "auto_apms_behavior_tree_core/builder.hpp"
22#include "auto_apms_behavior_tree_core/node/node_registration_loader.hpp"
23#include "auto_apms_interfaces/action/command_tree_executor.hpp"
24#include "auto_apms_util/action_context.hpp"
25#include "rclcpp/rclcpp.hpp"
26#include "std_srvs/srv/trigger.hpp"
31static const std::vector<std::string> TREE_EXECUTOR_EXPLICITLY_ALLOWED_PARAMETERS{
32 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_ALLOW_OTHER_BUILD_HANDLERS,
33 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_ALLOW_DYNAMIC_BLACKBOARD,
34 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_ALLOW_DYNAMIC_SCRIPTING_ENUMS,
35 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_EXCLUDE_PACKAGES_NODE,
36 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_EXCLUDE_PACKAGES_BUILD_HANDLER,
37 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_BUILD_HANDLER,
38 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_TICK_RATE,
39 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_GROOT2_PORT,
40 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_STATE_CHANGE_LOGGER};
42static const std::vector<std::string> TREE_EXECUTOR_EXPLICITLY_ALLOWED_PARAMETERS_WHILE_BUSY{
43 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_ALLOW_DYNAMIC_BLACKBOARD,
44 _AUTO_APMS_BEHAVIOR_TREE__EXECUTOR_PARAM_STATE_CHANGE_LOGGER};
63 using ExecutorParameters = executor_params::Params;
64 using ExecutorParameterListener = executor_params::ParamListener;
67 inline static const std::string SCRIPTING_ENUM_PARAM_PREFIX =
"enum";
68 inline static const std::string BLACKBOARD_PARAM_PREFIX =
"bb";
98 const std::string & build_request,
const std::string & entry_point =
"",
117 core::TreeBuilder & builder,
const std::string & build_request,
const std::string & entry_point,
161 const std::map<std::string, rclcpp::ParameterValue> & value_map,
bool simulate =
false);
170 const std::map<std::string, rclcpp::ParameterValue> & value_map,
bool simulate =
false);
188 const std::string & build_request,
const std::string & entry_point =
"",
203 bool onTick()
override;
205 bool afterTick()
override;
210 rcl_interfaces::msg::SetParametersResult on_set_parameters_callback_(
211 const std::vector<rclcpp::Parameter> & parameters);
213 void parameter_event_callback_(
const rcl_interfaces::msg::ParameterEvent & event);
215 rclcpp_action::GoalResponse handle_command_goal_(
216 const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const CommandActionContext::Goal> goal_ptr);
217 rclcpp_action::CancelResponse handle_command_cancel_(
218 std::shared_ptr<CommandActionContext::GoalHandle> goal_handle_ptr);
219 void handle_command_accept_(std::shared_ptr<CommandActionContext::GoalHandle> goal_handle_ptr);
222 const Options executor_options_;
223 ExecutorParameterListener executor_param_listener_;
225 core::NodeRegistrationLoader::SharedPtr tree_node_loader_ptr_;
226 TreeBuildHandlerLoader::UniquePtr build_handler_loader_ptr_;
227 core::TreeBuilder::UniquePtr builder_ptr_;
228 TreeBuildHandler::UniquePtr build_handler_ptr_;
229 std::string current_build_handler_name_;
230 std::map<std::string, int> scripting_enums_;
231 std::map<std::string, rclcpp::ParameterValue> translated_global_blackboard_entries_;
234 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_handle_ptr_;
235 std::shared_ptr<rclcpp::ParameterEventHandler> parameter_event_handler_ptr_;
236 rclcpp::ParameterEventCallbackHandle::SharedPtr parameter_event_callback_handle_ptr_;
239 rclcpp_action::Server<CommandActionContext::Type>::SharedPtr command_action_ptr_;
240 rclcpp::TimerBase::SharedPtr command_timer_ptr_;
243 rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr clear_blackboard_service_ptr_;
bool updateGlobalBlackboardWithParameterValues(const std::map< std::string, rclcpp::ParameterValue > &value_map, bool simulate=false)
Update the global blackboard using parameter values.
static const std::string PARAM_VALUE_NO_BUILD_HANDLER
Value indicating that no build handler is loaded.
GenericTreeExecutorNode(const std::string &name, Options options)
Constructor.
static std::string stripPrefixFromParameterName(const std::string &prefix, const std::string ¶m_name)
Get the name of a parameter without its prefix.
virtual bool clearGlobalBlackboard() override
Reset the global blackboard and clear all entries.
core::TreeBuilder::SharedPtr createTreeBuilder()
Create a tree builder for building the behavior tree.
std::map< std::string, rclcpp::ParameterValue > getParameterValuesWithPrefix(const std::string &prefix)
Assemble all parameters of this node that have a specific prefix.
bool updateScriptingEnumsWithParameterValues(const std::map< std::string, rclcpp::ParameterValue > &value_map, bool simulate=false)
Update the internal buffer of scripting enums.
ExecutorParameters getExecutorParameters() const
Get a copy of the current executor parameters.
std::shared_future< ExecutionResult > startExecution(const std::string &build_request, const std::string &entry_point="", const core::NodeManifest &node_manifest={})
Start the behavior tree specified by a particular build request.
virtual void postBuild(Tree &tree)
Callback invoked after the behavior tree has been instantiated.
virtual void preBuild(core::TreeBuilder &builder, const std::string &build_request, const std::string &entry_point, const core::NodeManifest &node_manifest, TreeBlackboard &bb)
Callback invoked before building the behavior tree.
void loadBuildHandler(const std::string &name)
Load a particular behavior tree build handler plugin.
TreeConstructor makeTreeConstructor(const std::string &build_request, const std::string &entry_point="", const core::NodeManifest &node_manifest={})
Create a callback that builds a behavior tree according to a specific request.
std::shared_future< ExecutionResult > startExecution(TreeConstructor make_tree, double tick_rate_sec=0.1, int groot2_port=-1)
Start a behavior tree that is built using a callback.
TreeExecutorBase(rclcpp::Node::SharedPtr node_ptr, rclcpp::CallbackGroup::SharedPtr tree_node_callback_group_ptr=nullptr)
Constructor.
Configuration options for GenericTreeExecutorNode.
Data structure for information about which behavior tree node plugin to load and how to configure the...
Class for configuring and instantiating behavior trees.
Helper class that stores contextual information related to a ROS 2 action.
Powerful tooling for incorporating behavior trees for task development.