Go to the documentation of this file.
18 using Command = std::variant<TaskA, TaskB>;
30 auto type = getInput<std::string>(
"type").value();
33 setOutput<Command>(
"task",
TaskA{ 43,
type });
37 setOutput<Command>(
"task",
TaskB{ 3.14,
type });
44 return { BT::InputPort<std::string>(
"type"), BT::OutputPort<Command>(
"task") };
53 <root BTCPP_format="4">
55 <BehaviorTree ID="MainTree">
58 <Script code="type:='A'" />
59 <SetTask type="{type}" task="{task}" />
60 <SubTree ID="ExecuteTaskA" task="{task}" _skipIf=" type!='A' " />
62 <Script code="type:='B'" />
63 <SetTask type="{type}" task="{task}" />
64 <SubTree ID="ExecuteTaskB" task="{task}" _skipIf=" type!='B' " />
69 <BehaviorTree ID="ExecuteTaskA">
72 <SaySomething message="executed command A" />
76 <BehaviorTree ID="ExecuteTaskB">
79 <SaySomething message="executed command B" />
105 std::cout <<
"----------- XML file ----------\n"
107 <<
"--------------------------------\n";
120 if(node.name() ==
"ExecuteTaskA")
122 auto task = node.config().blackboard->get<
Command>(
"task");
123 auto taskA = std::get<TaskA>(task);
125 json[
"taskA"] = { {
"name", taskA.name }, {
"type", taskA.
type } };
128 if(node.name() ==
"ExecuteTaskB")
130 auto task = node.config().blackboard->get<
Command>(
"task");
131 auto taskB = std::get<TaskB>(task);
133 json[
"taskB"] = { {
"name", taskB.name }, {
"value", taskB.
value } };
143 std::cout <<
"Start" << std::endl;
144 tree.tickWhileRunning();
145 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
SetTask(const std::string &name, const BT::NodeConfig &config)
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
const NodeConfig & config() const
virtual NodeType type() const override final
void setAdditionalCallback(ExtraCallback func)
The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite data...
Abstract base class for Behavior Tree Nodes.
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
namespace for Niels Lohmann
static const char * xml_text
std::chrono::high_resolution_clock::duration Duration
std::string WriteTreeToXML(const Tree &tree, bool add_metadata, bool add_builtin_models)
WriteTreeToXML create a string that contains the XML that corresponds to a given tree....
std::unordered_map< std::string, PortInfo > PortsList
void registerNodeType(const std::string &ID, const PortsList &ports, ExtraArgs... args)
static BT::PortsList providedPorts()
SyncActionNode(const std::string &name, const NodeConfig &config)
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
const std::string & name() const
Name of the instance, not the type.
bool isStatusCompleted(const NodeStatus &status)
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
basic_json<> json
default specialization
void registerBehaviorTreeFromText(const std::string &xml_text)
BT::NodeStatus tick() override
Method to be implemented by the user.
std::variant< TaskA, TaskB > Command
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
std::string writeTreeNodesModelXML(const BehaviorTreeFactory &factory, bool include_builtin=false)
writeTreeNodesModelXML generates an XMl that contains the manifests in the <TreeNodesModel>