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";
108 const std::string & build_request,
const std::string & entry_point =
"",
127 core::TreeBuilder & builder,
const std::string & build_request,
const std::string & entry_point,
140 virtual bool onTick()
override;
142 virtual bool afterTick()
override;
175 const std::map<std::string, rclcpp::ParameterValue> & value_map,
bool simulate =
false);
184 const std::map<std::string, rclcpp::ParameterValue> & value_map,
bool simulate =
false);
202 const std::string & build_request,
const std::string & entry_point =
"",
220 rcl_interfaces::msg::SetParametersResult on_set_parameters_callback_(
221 const std::vector<rclcpp::Parameter> & parameters);
223 void parameter_event_callback_(
const rcl_interfaces::msg::ParameterEvent & event);
225 rclcpp_action::GoalResponse handle_command_goal_(
226 const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const CommandActionContext::Goal> goal_ptr);
227 rclcpp_action::CancelResponse handle_command_cancel_(
228 std::shared_ptr<CommandActionContext::GoalHandle> goal_handle_ptr);
229 void handle_command_accept_(std::shared_ptr<CommandActionContext::GoalHandle> goal_handle_ptr);
232 const Options executor_options_;
233 ExecutorParameterListener executor_param_listener_;
235 core::NodeRegistrationLoader::SharedPtr tree_node_loader_ptr_;
236 TreeBuildHandlerLoader::UniquePtr build_handler_loader_ptr_;
237 core::TreeBuilder::UniquePtr builder_ptr_;
238 TreeBuildHandler::UniquePtr build_handler_ptr_;
239 std::string current_build_handler_name_;
240 std::map<std::string, int> scripting_enums_;
241 std::map<std::string, rclcpp::ParameterValue> translated_global_blackboard_entries_;
244 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_handle_ptr_;
245 std::shared_ptr<rclcpp::ParameterEventHandler> parameter_event_handler_ptr_;
246 rclcpp::ParameterEventCallbackHandle::SharedPtr parameter_event_callback_handle_ptr_;
249 rclcpp_action::Server<CommandActionContext::Type>::SharedPtr command_action_ptr_;
250 rclcpp::TimerBase::SharedPtr command_timer_ptr_;
253 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.
static std::string stripPrefixFromParameterName(const std::string &prefix, const std::string ¶m_name)
Get the name of a parameter without its prefix.
GenericTreeExecutorNode(rclcpp::Node::SharedPtr node_ptr, Options options)
Constructor using an existing ROS 2 node.
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.