Go to the documentation of this file.00001 #include "behaviortree_cpp/bt_factory.h"
00002
00003 #include "dummy_nodes.h"
00004 #include "movebase_node.h"
00005
00006 using namespace BT;
00007
00028
00029 static const char* xml_text = R"(
00030
00031 <root main_tree_to_execute = "MainTree" >
00032
00033 <BehaviorTree ID="MainTree">
00034 <Sequence name="root">
00035 <SaySomething message="start thinking..." />
00036 <ThinkWhatToSay text="{the_answer}"/>
00037 <SaySomething message="{the_answer}" />
00038 <SaySomething2 message="SaySomething2 works too..." />
00039 <SaySomething2 message="{the_answer}" />
00040 </Sequence>
00041 </BehaviorTree>
00042
00043 </root>
00044 )";
00045
00046
00047
00048 class ThinkWhatToSay : public BT::SyncActionNode
00049 {
00050 public:
00051 ThinkWhatToSay(const std::string& name, const BT::NodeConfiguration& config)
00052 : BT::SyncActionNode(name, config)
00053 {
00054 }
00055
00056
00057 BT::NodeStatus tick() override
00058 {
00059 setOutput("text", "The answer is 42" );
00060 return BT::NodeStatus::SUCCESS;
00061 }
00062
00063
00064 static BT::PortsList providedPorts()
00065 {
00066 return { BT::OutputPort<std::string>("text") };
00067 }
00068 };
00069
00070
00071 int main()
00072 {
00073 using namespace DummyNodes;
00074
00075 BehaviorTreeFactory factory;
00076
00077
00078
00079 factory.registerNodeType<SaySomething>("SaySomething");
00080
00081
00082
00083
00084 factory.registerNodeType<ThinkWhatToSay>("ThinkWhatToSay");
00085
00086
00087
00088
00089 PortsList say_something_ports = { InputPort<std::string>("message") };
00090 factory.registerSimpleAction("SaySomething2", SaySomethingSimple, say_something_ports );
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 auto tree = factory.createTreeFromText(xml_text);
00103
00104 tree.root_node->executeTick();
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 return 0;
00121 }
00122
00123