15#include "auto_apms_mission/mission_builder_base.hpp"
16#include "auto_apms_util/container.hpp"
24 using MissionBuildHandlerBase::MissionBuildHandlerBase;
30 sub_tree.removeChildren();
31 for (
const TreeResource::Identity & r : trees) {
32 sub_tree.insertTreeFromResource(r);
40 using MissionBuildHandlerBase::MissionBuildHandlerBase;
49 for (
const TreeResource::Identity & r : trees) {
50 mission_sequence.insertTreeFromResource(r);
57 .set_clear_blackboard(
true)
58 .set_executor(MISSION_EXECUTOR_NAME);
61 void buildEventMonitor(
63 const std::vector<std::pair<TreeResource::Identity, TreeResource::Identity>> & contingencies,
64 const std::vector<std::pair<TreeResource::Identity, TreeResource::Identity>> & emergencies)
override final
68 MissionBuildHandlerBase::buildEventMonitor(event_monitor_tree, contingencies, emergencies);
69 event_monitor_tree.getFirstNode()
70 .setName(event_monitor_tree.getName())
71 .setConditionalScript(BT::PostCond::ON_SUCCESS,
"@event_id = event_id")
72 .setConditionalScript(BT::PostCond::ON_FAILURE,
"@event_id = ''");
74 main_tree.
insertNode<model::KeepRunningUntilFailure>().insertNode<model::ForceSuccess>().
insertTree(
79 model::Sequence run_once_seq = seq.
insertNode<model::RunOnce>().insertNode<model::Sequence>();
80 run_once_seq.insertNode<model::SetParameterString>()
81 .set_node(EVENT_MONITOR_EXECUTOR_NAME)
82 .set_parameter(
"bb.event_id")
85 .setName(
"StartDetachedEventMonitor")
87 .set_clear_blackboard(
false)
88 .set_executor(EVENT_MONITOR_EXECUTOR_NAME);
89 seq.insertNode<model::GetParameterString>()
90 .set_node(EVENT_MONITOR_EXECUTOR_NAME)
91 .set_parameter(
"bb.event_id")
92 .set_value(
"{event_id}");
95 void buildContingencyHandling(
97 const std::vector<std::pair<TreeResource::Identity, TreeResource::Identity>> & contingencies)
override final
101 model::Parallel parallel = handler_tree.
insertNode<model::Parallel>().set_success_count(1).set_failure_count(1);
102 parallel.
insertNode<model::KeepRunningUntilFailure>()
103 .insertNode<model::GetParameterString>()
104 .set_node(EVENT_MONITOR_EXECUTOR_NAME)
105 .set_parameter(
"bb.event_id")
106 .set_value(
"{event_id}");
108 MissionBuildHandlerBase::buildContingencyHandling(base_tree, contingencies);
109 parallel.insertNode<model::WaitValueUpdate>().set_entry(
"{event_id}").insertTree(base_tree);
112 .setName(handler_tree.getName())
114 .set_clear_blackboard(
true)
115 .set_executor(EVENT_HANDLER_EXECUTOR_NAME);
118 void buildEmergencyHandling(
120 const std::vector<std::pair<TreeResource::Identity, TreeResource::Identity>> & emergencies)
override final
124 model::Parallel parallel = handler_tree.
insertNode<model::Parallel>().set_success_count(1).set_failure_count(1);
125 parallel.
insertNode<model::KeepRunningUntilFailure>()
126 .insertNode<model::GetParameterString>()
127 .set_node(EVENT_MONITOR_EXECUTOR_NAME)
128 .set_parameter(
"bb.event_id")
129 .set_value(
"{event_id}");
131 MissionBuildHandlerBase::buildEmergencyHandling(base_tree, emergencies);
132 parallel.insertNode<model::WaitValueUpdate>().set_entry(
"{event_id}").insertTree(base_tree);
135 .setName(handler_tree.getName())
137 .set_clear_blackboard(
true)
138 .set_executor(EVENT_HANDLER_EXECUTOR_NAME);
144 model::SequenceWithMemory seq = sub_tree.removeChildren().insertNode<model::SequenceWithMemory>();
145 seq.insertNode<model::TerminateExecutor>().set_executor(EVENT_MONITOR_EXECUTOR_NAME);
150 MissionBuildHandlerBase::buildShutDown(temp, trees);
151 seq.insertTree(temp);
Handle for a single node of a TreeDocument.
virtual NodeElement & setName(const std::string &instance_name)
Assign a name for this specific node instance.
NodeElement insertTree(const TreeElement &tree, const NodeElement *before_this=nullptr)
Concatenate a tree and add its first child node to the children of this node.
NodeElement insertNode(const std::string &name, const NodeElement *before_this=nullptr)
Add a new node to the children of this node.
NodeElement & removeChildren()
Recursively remove all children of this node element.
Handle for a single behavior tree of a TreeDocument.
Base class for behavior tree build handlers that are used to configure missions including fallback me...
#define AUTO_APMS_BEHAVIOR_TREE_DECLARE_BUILD_HANDLER(type)
Macro for registering a behavior tree build handler plugin which may be loaded at runtime to build a ...
model::StartExecutor insertStartExecutorFromString(core::TreeDocument::NodeElement &parent, const std::string &tree_str, const core::TreeDocument::NodeElement *before_this=nullptr)
Helper that extends the children of a given parent node by a StartExecutor node for a specific behavi...
Mission design utilities incorporating behavior trees to model the complexity of arbitrary operations...