Go to the documentation of this file.00001 #include "behaviortree_cpp/loggers/bt_cout_logger.h"
00002 #include "behaviortree_cpp/bt_factory.h"
00003
00004 #include "movebase_node.h"
00005 #include "dummy_nodes.h"
00006
00021
00022
00023 static const char* xml_text = R"(
00024 <root main_tree_to_execute = "MainTree">
00025
00026 <BehaviorTree ID="MainTree">
00027
00028 <Sequence name="main_sequence">
00029 <SetBlackboard output_key="move_goal" value="1;2;3" />
00030 <SubTree ID="MoveRobot" target="move_goal" output="move_result" />
00031 <SaySomething message="{move_result}"/>
00032 </Sequence>
00033
00034 </BehaviorTree>
00035
00036 <BehaviorTree ID="MoveRobot">
00037 <Fallback name="move_robot_main">
00038 <SequenceStar>
00039 <MoveBase goal="{target}"/>
00040 <SetBlackboard output_key="output" value="mission accomplished" />
00041 </SequenceStar>
00042 <ForceFailure>
00043 <SetBlackboard output_key="output" value="mission failed" />
00044 </ForceFailure>
00045 </Fallback>
00046 </BehaviorTree>
00047
00048 </root>
00049 )";
00050
00051
00052
00053
00054 using namespace BT;
00055 using namespace DummyNodes;
00056
00057 int main()
00058 {
00059 BehaviorTreeFactory factory;
00060
00061 factory.registerNodeType<SaySomething>("SaySomething");
00062 factory.registerNodeType<MoveBaseAction>("MoveBase");
00063
00064 auto tree = factory.createTreeFromText(xml_text);
00065
00066 NodeStatus status = NodeStatus::RUNNING;
00067
00068 while( status == NodeStatus::RUNNING)
00069 {
00070 status = tree.root_node->executeTick();
00071 SleepMS(1);
00072 }
00073
00074
00075 std::cout << "--------------" << std::endl;
00076 tree.blackboard_stack[0]->debugMessage();
00077 std::cout << "--------------" << std::endl;
00078 tree.blackboard_stack[1]->debugMessage();
00079 std::cout << "--------------" << std::endl;
00080
00081 return 0;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097