BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
bt_file_logger_v2.h
1#pragma once
2#include "behaviortree_cpp/loggers/abstract_logger.h"
3
4#include <filesystem>
5#include <memory>
6
7namespace BT
8{
9
10/**
11 * @brief The FileLogger2 is a logger that saves the tree as
12 * XML and all the transitions.
13 * Data is written to file in a separate thread, to minimize latency.
14 *
15 * Format:
16 *
17 * - first 4 bytes: size of the XML string (N)
18 * - next N bytes: string containing the XML representing the tree.
19 * - next 8 bytes: first timestamp (microseconds since epoch)
20 * - next: each 9 bytes is a FileLogger2::Transition. See definition.
21 *
22 */
24{
25public:
26 /**
27 * @brief To correctly read this log with Groot2, you must use the suffix ".btlog".
28 * Constructor will throw otherwise.
29 *
30 * @param tree the tree to log
31 * @param filepath path of the file where info will be stored
32 */
33 FileLogger2(const Tree& tree, std::filesystem::path const& filepath);
34
35 FileLogger2(const FileLogger2& other) = delete;
36 FileLogger2& operator=(const FileLogger2& other) = delete;
37
38 FileLogger2(FileLogger2&& other) = delete;
39 FileLogger2& operator=(FileLogger2&& other) = delete;
40
41 virtual ~FileLogger2() override;
42
43 void callback(Duration timestamp, const TreeNode& node, NodeStatus prev_status,
44 NodeStatus status) override;
45
46 struct Transition
47 {
48 // when serializing, we will remove the initial time and serialize only
49 // 6 bytes, instead of 8
50 uint64_t timestamp_usec;
51 // if you have more than 64.000 nodes, you are doing something wrong :)
52 uint16_t node_uid;
53 // enough bits to contain NodeStatus
54 uint8_t status;
55 };
56
57 void flush() override;
58
59private:
60 struct Pimpl;
61 std::unique_ptr<Pimpl> _p;
62
63 void writerLoop();
64};
65
66} // namespace BT
The FileLogger2 is a logger that saves the tree as XML and all the transitions. Data is written to fi...
Definition: bt_file_logger_v2.h:24
FileLogger2(const Tree &tree, std::filesystem::path const &filepath)
To correctly read this log with Groot2, you must use the suffix ".btlog". Constructor will throw othe...
Definition: abstract_logger.h:16
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:96
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:154
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34
Definition: bt_file_logger_v2.h:47