bt_observer.h
Go to the documentation of this file.
1 #ifndef BT_OBSERVER_H
2 #define BT_OBSERVER_H
3 
4 #include <cstring>
6 
7 namespace BT
8 {
9 
18 {
19 public:
20  TreeObserver(const BT::Tree& tree);
21  ~TreeObserver() override;
22 
23  virtual void flush() override
24  {}
25 
26  void resetStatistics();
27 
29  {
30  // Last __valid__ result, either SUCCESS or FAILURE
32  // Last status. Can be any status, including IDLE or SKIPPED
34 
35  // count status transitions, excluding transition to IDLE
36  unsigned transitions_count = 0;
37  // count number of transitions to SUCCESS
38  unsigned success_count = 0;
39  // count number of transitions to FAILURE
40  unsigned failure_count = 0;
41  // count number of transitions to SKIPPED
42  unsigned skip_count = 0;
43 
45  };
46 
47  // find the statistics of a node, based on its path
48  const NodeStatistics& getStatistics(const std::string& path) const;
49 
50  // find the statistics of a node, based on its TreeNode::UID()
51  const NodeStatistics& getStatistics(uint16_t uid) const;
52 
53  // all statistics
54  const std::unordered_map<uint16_t, NodeStatistics>& statistics() const;
55 
56  // path to UID map
57  const std::unordered_map<std::string, uint16_t>& pathToUID() const;
58 
59  const std::map<uint16_t, std::string>& uidToPath() const;
60 
61 private:
62  std::unordered_map<uint16_t, NodeStatistics> _statistics;
63  std::unordered_map<std::string, uint16_t> _path_to_uid;
64  std::map<uint16_t, std::string> _uid_to_path;
65 
66  virtual void callback(Duration timestamp, const TreeNode& node, NodeStatus prev_status,
67  NodeStatus status) override;
68 };
69 
70 } // namespace BT
71 
72 #endif // BT_OBSERVER_H
BT
Definition: ex01_wrap_legacy.cpp:29
BT::TreeObserver::flush
virtual void flush() override
Definition: bt_observer.h:23
BT::TreeObserver::getStatistics
const NodeStatistics & getStatistics(const std::string &path) const
Definition: bt_observer.cpp:80
BT::TreeObserver::resetStatistics
void resetStatistics()
BT::TreeObserver::callback
virtual void callback(Duration timestamp, const TreeNode &node, NodeStatus prev_status, NodeStatus status) override
Definition: bt_observer.cpp:49
BT::TreeNode
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:118
BT::Tree
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Definition: bt_factory.h:91
BT::TreeObserver::NodeStatistics::transitions_count
unsigned transitions_count
Definition: bt_observer.h:36
BT::StatusChangeLogger
Definition: abstract_logger.h:15
BT::Duration
std::chrono::high_resolution_clock::duration Duration
Definition: basic_types.h:628
BT::TreeObserver::NodeStatistics
Definition: bt_observer.h:28
BT::TreeObserver::NodeStatistics::failure_count
unsigned failure_count
Definition: bt_observer.h:40
BT::TreeObserver::_path_to_uid
std::unordered_map< std::string, uint16_t > _path_to_uid
Definition: bt_observer.h:63
BT::TreeObserver::NodeStatistics::current_status
NodeStatus current_status
Definition: bt_observer.h:33
BT::TreeObserver::_statistics
std::unordered_map< uint16_t, NodeStatistics > _statistics
Definition: bt_observer.h:62
BT::TreeObserver::pathToUID
const std::unordered_map< std::string, uint16_t > & pathToUID() const
Definition: bt_observer.cpp:106
BT::TreeObserver
The TreeObserver is used to collect statistics about which nodes are executed and their returned stat...
Definition: bt_observer.h:17
BT::TreeObserver::TreeObserver
TreeObserver(const BT::Tree &tree)
Definition: bt_observer.cpp:7
BT::TreeObserver::NodeStatistics::success_count
unsigned success_count
Definition: bt_observer.h:38
BT::TreeObserver::NodeStatistics::skip_count
unsigned skip_count
Definition: bt_observer.h:42
BT::NodeStatus::IDLE
@ IDLE
BT::TreeObserver::uidToPath
const std::map< uint16_t, std::string > & uidToPath() const
Definition: bt_observer.cpp:111
BT::TreeObserver::~TreeObserver
~TreeObserver() override
Definition: bt_observer.cpp:46
BT::TreeObserver::NodeStatistics::last_result
NodeStatus last_result
Definition: bt_observer.h:31
BT::TreeObserver::statistics
const std::unordered_map< uint16_t, NodeStatistics > & statistics() const
Definition: bt_observer.cpp:101
BT::TreeObserver::NodeStatistics::last_timestamp
Duration last_timestamp
Definition: bt_observer.h:44
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
abstract_logger.h
BT::TreeObserver::_uid_to_path
std::map< uint16_t, std::string > _uid_to_path
Definition: bt_observer.h:64


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16