| 87 | // clang-format on |
| 88 | |
| 89 | int main() |
| 90 | { |
| 91 | BT::BehaviorTreeFactory factory; |
| 92 | |
| 93 | // Nodes registration, as usual |
| 94 | factory.registerNodeType<DummyNodes::SaySomething>("SaySomething"); |
| 95 | factory.registerNodeType<SetTask>("SetTask"); |
| 96 | |
| 97 | // Groot2 editor requires a model of your registered Nodes. |
| 98 | // You don't need to write that by hand, it can be automatically |
| 99 | // generated using the following command. |
| 100 | std::string xml_models = BT::writeTreeNodesModelXML(factory); |
| 101 | |
| 102 | factory.registerBehaviorTreeFromText(xml_text); |
| 103 | |
| 104 | auto tree = factory.createTree("MainTree"); |
| 105 | |
| 106 | std::cout << "----------- XML file ----------\n" |
| 107 | << BT::WriteTreeToXML(tree, false, false) |
| 108 | << "--------------------------------\n"; |
| 109 | |
| 110 | BT::SqliteLogger sqlite_logger(tree, "ex08_sqlitelog.db3", false); |
| 111 | |
| 112 | //------------------------------------------------------------------------ |
| 113 | // Write some data (from the blackboard) and write into the |
| 114 | // extra column called "extra_data". We will use JSON serialization |
| 115 | |
| 116 | auto meta_callback = [&](BT::Duration timestamp, const BT::TreeNode& node, |
| 117 | BT::NodeStatus prev_status, |
| 118 | BT::NodeStatus status) -> std::string { |
| 119 | if(prev_status == BT::NodeStatus::RUNNING && BT::isStatusCompleted(status)) |
| 120 | { |
| 121 | if(node.name() == "ExecuteTaskA") |
| 122 | { |
| 123 | auto task = node.config().blackboard->get<Command>("task"); |
| 124 | auto taskA = std::get<TaskA>(task); |
| 125 | nlohmann::json json; |
| 126 | json["taskA"] = { { "name", taskA.name }, { "type", taskA.type } }; |
| 127 | return json.dump(); |
| 128 | } |
| 129 | if(node.name() == "ExecuteTaskB") |
| 130 | { |
| 131 | auto task = node.config().blackboard->get<Command>("task"); |
| 132 | auto taskB = std::get<TaskB>(task); |
| 133 | nlohmann::json json; |
| 134 | json["taskB"] = { { "name", taskB.name }, { "value", taskB.value } }; |
| 135 | return json.dump(); |
| 136 | } |
| 137 | } |
| 138 | return {}; |
| 139 | }; |
| 140 | sqlite_logger.setAdditionalCallback(meta_callback); |
| 141 | //------------------------------------------------------------------------ |
| 142 | while(1) |
| 143 | { |
| 144 | std::cout << "Start" << std::endl; |
| 145 | tree.tickWhileRunning(); |
| 146 | std::this_thread::sleep_for(std::chrono::milliseconds(2000)); |
nothing calls this directly
no test coverage detected