t06_subtree_port_remapping.cpp
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 // clang-format off
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 // clang-format on
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     // Keep on ticking until you get either a SUCCESS or FAILURE state
00068     while( status == NodeStatus::RUNNING)
00069     {
00070         status = tree.root_node->executeTick();
00071         SleepMS(1);   // optional sleep to avoid "busy loops"
00072     }
00073 
00074     // let's visualize some information about the current state of the blackboards.
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 /* Expected output:
00085 
00086     [ MoveBase: STARTED ]. goal: x=1 y=2.0 theta=3.00
00087     [ MoveBase: FINISHED ]
00088     Robot says: mission accomplished
00089     --------------
00090     move_result (std::string) -> full
00091     move_goal (Pose2D) -> full
00092     --------------
00093     output (std::string) -> remapped to parent [move_result]
00094     target (Pose2D) -> remapped to parent [move_goal]
00095     --------------
00096 
00097 */


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15