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

Function main

examples/t11_groot_howto.cpp:160–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158// clang-format on
159
160int main()
161{
162 BT::BehaviorTreeFactory factory;
163
164 // Nodes registration, as usual
165 CrossDoor cross_door;
166 cross_door.registerNodes(factory);
167 factory.registerNodeType<UpdatePosition>("UpdatePosition");
168
169 // Groot2 editor requires a model of your registered Nodes.
170 // You don't need to write that by hand, it can be automatically
171 // generated using the following command.
172 [[maybe_unused]] const std::string xml_models = BT::writeTreeNodesModelXML(factory);
173
174 factory.registerBehaviorTreeFromText(xml_text);
175
176 // Add this to allow Groot2 to visualize your custom type
177 BT::RegisterJsonDefinition<Position2D>();
178 BT::RegisterJsonDefinition<Waypoint>();
179
180 auto tree = factory.createTree("MainTree");
181
182 std::cout << "----------- XML file ----------\n"
183 << BT::WriteTreeToXML(tree, false, false)
184 << "--------------------------------\n";
185
186 // Connect the Groot2Publisher. This will allow Groot2 to
187 // get the tree and poll status updates.
188 const unsigned port = 1667;
189 BT::Groot2Publisher publisher(tree, port);
190
191 // Add two more loggers, to save the transitions into a file.
192 // Both formats are compatible with Groot2
193
194 // Logging with lightweight serialization
195 BT::FileLogger2 logger2(tree, "t11_groot_howto.btlog");
196 BT::MinitraceLogger minilog(tree, "minitrace.json");
197
198 while(true)
199 {
200 std::cout << "Start" << std::endl;
201 cross_door.reset();
202 tree.tickWhileRunning();
203 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
204 }
205
206 return 0;
207}

Callers

nothing calls this directly

Calls 7

writeTreeNodesModelXMLFunction · 0.85
WriteTreeToXMLFunction · 0.85
registerNodesMethod · 0.80
createTreeMethod · 0.80
tickWhileRunningMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected