Go to the documentation of this file.00001 #include "behaviortree_cpp/xml_parsing.h"
00002
00003 #include "dummy_nodes.h"
00004 #include "movebase_node.h"
00005
00006 using namespace BT;
00007
00016
00017
00018 const std::string xml_text_sequence = R"(
00019
00020 <root main_tree_to_execute = "MainTree" >
00021
00022 <BehaviorTree ID="MainTree">
00023 <Sequence name="root">
00024 <BatteryOK/>
00025 <TemperatureOK />
00026 <SaySomething message="mission started..." />
00027 <MoveBase goal="1;2;3"/>
00028 <SaySomething message="mission completed!" />
00029 </Sequence>
00030 </BehaviorTree>
00031
00032 </root>
00033 )";
00034
00035 const std::string xml_text_sequence_star = R"(
00036
00037 <root main_tree_to_execute = "MainTree" >
00038
00039 <BehaviorTree ID="MainTree">
00040 <SequenceStar name="root">
00041 <BatteryOK/>
00042 <TemperatureOK />
00043 <SaySomething message="mission started..." />
00044 <MoveBase goal="1;2;3"/>
00045 <SaySomething message="mission completed!" />
00046 </SequenceStar>
00047 </BehaviorTree>
00048
00049 </root>
00050 )";
00051
00052
00053
00054 void Assert(bool condition)
00055 {
00056 if (!condition)
00057 throw std::runtime_error("this is not what I expected");
00058 }
00059
00060 int main()
00061 {
00062 using namespace DummyNodes;
00063
00064 BehaviorTreeFactory factory;
00065 factory.registerSimpleCondition("TemperatureOK", std::bind(CheckBattery));
00066 factory.registerSimpleCondition("BatteryOK", std::bind(CheckTemperature));
00067 factory.registerNodeType<MoveBaseAction>("MoveBase");
00068 factory.registerNodeType<SaySomething>("SaySomething");
00069
00070
00071
00072
00073
00074
00075
00076
00077 for (auto& xml_text : {xml_text_sequence, xml_text_sequence_star})
00078 {
00079 std::cout << "\n------------ BUILDING A NEW TREE ------------" << std::endl;
00080
00081 auto tree = buildTreeFromText(factory, xml_text);
00082
00083 NodeStatus status;
00084
00085 std::cout << "\n--- 1st executeTick() ---" << std::endl;
00086 status = tree.root_node->executeTick();
00087 Assert(status == NodeStatus::RUNNING);
00088
00089 SleepMS(150);
00090 std::cout << "\n--- 2nd executeTick() ---" << std::endl;
00091 status = tree.root_node->executeTick();
00092 Assert(status == NodeStatus::RUNNING);
00093
00094 SleepMS(150);
00095 std::cout << "\n--- 3rd executeTick() ---" << std::endl;
00096 status = tree.root_node->executeTick();
00097 Assert(status == NodeStatus::SUCCESS);
00098
00099 std::cout << std::endl;
00100 }
00101 return 0;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140