MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / main

Function main

examples/t02_basic_ports.cpp:66–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64};
65
66int main()
67{
68 using namespace DummyNodes;
69
70 BehaviorTreeFactory factory;
71
72 // The class SaySomething has a method called providedPorts() that define the INPUTS.
73 // In this case, it requires an input called "message"
74 factory.registerNodeType<SaySomething>("SaySomething");
75
76 // Similarly to SaySomething, ThinkWhatToSay has an OUTPUT port called "text"
77 // Both these ports are std::string, therefore they can connect to each other
78 factory.registerNodeType<ThinkWhatToSay>("ThinkWhatToSay");
79
80 // SimpleActionNodes can not define their own method providedPorts(), therefore
81 // we have to pass the PortsList explicitly if we want the Action to use getInput()
82 // or setOutput();
83 PortsList say_something_ports = { InputPort<std::string>("message") };
84 factory.registerSimpleAction("SaySomething2", SaySomethingSimple, say_something_ports);
85
86 /* An INPUT can be either a string, for instance:
87 *
88 * <SaySomething message="hello" />
89 *
90 * or contain a "pointer" to a type erased entry in the Blackboard,
91 * using this syntax: {name_of_entry}. Example:
92 *
93 * <SaySomething message="{the_answer}" />
94 */
95
96 auto tree = factory.createTreeFromText(xml_text);
97
98 tree.tickWhileRunning();
99
100 /* Expected output:
101 *
102 Robot says: hello
103 Robot says: this works too
104 Robot says: The answer is 42
105 *
106 * The way we "connect" output ports to input ports is to "point" to the same
107 * Blackboard entry.
108 *
109 * This means that ThinkSomething will write into the entry with key "the_answer";
110 * SaySomething and SaySomething will read the message from the same entry.
111 *
112 */
113 return 0;
114}

Callers

nothing calls this directly

Calls 3

registerSimpleActionMethod · 0.80
createTreeFromTextMethod · 0.80
tickWhileRunningMethod · 0.80

Tested by

no test coverage detected