| 158 | // clang-format on |
| 159 | |
| 160 | int 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 | } |
nothing calls this directly
no test coverage detected