t01_programmatic_tree.cpp
Go to the documentation of this file.
2 #include "dummy_nodes.h"
3 
4 using namespace BT;
5 
14 int main()
15 {
16  using namespace DummyNodes;
17  GripperInterface gripper;
18 
19  // sequence_root will be the root of our tree
20  BT::SequenceNode sequence_root("sequence");
21 
22  // Function pointers can be wrapped inside ActionNodeBase
23  // using the SimpleActionNode
24  SimpleActionNode say_hello("action_hello", std::bind(SayHello));
25 
26  // SimpleActionNode works also with class methods, using std::bind
27  SimpleActionNode open_gripper("open_gripper", std::bind(&GripperInterface::open, &gripper));
28  SimpleActionNode close_gripper("close_gripper", std::bind(&GripperInterface::close, &gripper));
29 
30  // To be able to use ALL the functionalities of a TreeNode,
31  // your should create a class that inherits from either:
32  // - ConditionNode (synchronous execution)
33  // - ActionNodeBase (synchronous execution)
34  // - ActionNode (asynchronous execution in a separate thread).
35  ApproachObject approach_object("approach_object");
36 
37  // Add children to the sequence.
38  // they will be executed in the same order they are added.
39  sequence_root.addChild(&say_hello);
40  sequence_root.addChild(&open_gripper);
41  sequence_root.addChild(&approach_object);
42  sequence_root.addChild(&close_gripper);
43 
44  // The tick is propagated to all the children.
45  // until one of them returns FAILURE or RUNNING.
46  // In this case all of them return SUCCESS immediately
47  sequence_root.executeTick();
48 
49  // needed when you use ActionNodes with their own thread
50  haltAllActions(&sequence_root);
51 
52  return 0;
53 }
NodeStatus SayHello()
Definition: test_package.cpp:6
int main()
void haltAllActions(TreeNode *root_node)
The SimpleActionNode provides an easy to use ActionNode. The user should simply provide a callback wi...
Definition: action_node.h:77
void addChild(TreeNode *child)
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
The SequenceNode is used to execute a sequence of children. If any child returns RUNNING, previous children will be ticked again.
Definition: sequence_node.h:34


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53