Skip to content

Commit 94352c9

Browse files
committed
add more informative IDLE status
1 parent 3dca763 commit 94352c9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

include/behaviortree_cpp/loggers/groot2_publisher.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ class Groot2Publisher : public StatusChangeLogger
5858

5959
std::mutex status_mutex_;
6060

61-
std::unordered_map<uint16_t, char*> buffer_ptr_;
6261
std::string status_buffer_;
62+
// each element of this map points to a character in status_buffer_
63+
std::unordered_map<uint16_t, char*> status_buffer_map_;
6364

6465
// weak reference to the tree.
6566
std::unordered_map<std::string, std::weak_ptr<BT::Tree::Subtree>> subtrees_;
@@ -73,6 +74,12 @@ class Groot2Publisher : public StatusChangeLogger
7374

7475
std::thread heartbeat_thread_;
7576

77+
enum {
78+
IDLE_FROM_SUCCESS = 10 + static_cast<int>(NodeStatus::SUCCESS),
79+
IDLE_FROM_FAILURE = 10 + static_cast<int>(NodeStatus::FAILURE),
80+
IDLE_FROM_RUNNING = 10 + static_cast<int>(NodeStatus::RUNNING)
81+
};
82+
7683
struct Pimpl;
7784
Pimpl* zmq_;
7885
void enableAllHooks(bool enable);

src/loggers/groot2_publisher.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Groot2Publisher::Groot2Publisher(const BT::Tree& tree,
9898

9999
ptr_offset += Monitor::Serialize(buffer_ptr, ptr_offset,
100100
node->UID());
101-
buffer_ptr_.insert( {node->UID(), buffer_ptr + ptr_offset} );
101+
status_buffer_map_.insert( {node->UID(), buffer_ptr + ptr_offset} );
102102
ptr_offset += Monitor::Serialize(buffer_ptr, ptr_offset,
103103
uint8_t(NodeStatus::IDLE));
104104
}
@@ -139,10 +139,15 @@ Groot2Publisher::~Groot2Publisher()
139139
}
140140

141141
void Groot2Publisher::callback(Duration, const TreeNode& node,
142-
NodeStatus, NodeStatus status)
142+
NodeStatus prev_status, NodeStatus new_status)
143143
{
144144
std::unique_lock<std::mutex> lk(status_mutex_);
145-
*(buffer_ptr_.at(node.UID())) = static_cast<char>(status);
145+
auto status = static_cast<char>(new_status);
146+
147+
if( new_status == NodeStatus::IDLE) {
148+
status = 10 + static_cast<char>(prev_status);
149+
}
150+
*(status_buffer_map_.at(node.UID())) = status;
146151
}
147152

148153
void Groot2Publisher::flush()

0 commit comments

Comments
 (0)