Skip to content

Commit 36e0e72

Browse files
committed
make max heartbeat delay configurable
1 parent ae9f5fa commit 36e0e72

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

examples/t12_groot_howto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main()
7373
BT::FileLogger2 logger2(tree, "t12_logger2.btlog");
7474
// SQLite logger can save multiple sessions into the same database
7575
bool append_to_database = true;
76-
BT::SqliteLogger sqlite_logger(tree, "t12_sqlitelog.btsql", append_to_database);
76+
BT::SqliteLogger sqlite_logger(tree, "t12_sqlitelog.db3", append_to_database);
7777

7878
while(1)
7979
{

include/behaviortree_cpp/loggers/groot2_publisher.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class Groot2Publisher : public StatusChangeLogger
3434
Groot2Publisher(Groot2Publisher&& other) = default;
3535
Groot2Publisher& operator=(Groot2Publisher&& other) = default;
3636

37+
/**
38+
* @brief setMaxHeartbeatDelay is used to tell the publisher
39+
* when a connection with Groot2 should be cancelled, if no
40+
* hearbeat is received.
41+
*
42+
* Default is 5000 ms
43+
*/
44+
void setMaxHeartbeatDelay( std::chrono::milliseconds delay);
45+
46+
std::chrono::milliseconds maxHeartbeatDelay() const;
47+
3748
private:
3849

3950
void callback(Duration timestamp,

src/loggers/bt_sqlite_logger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ SqliteLogger::SqliteLogger(const Tree &tree,
99
bool append):
1010
StatusChangeLogger(tree.rootNode())
1111
{
12-
if(filepath.filename().extension() != ".db3")
12+
const auto extension = filepath.filename().extension();
13+
if( extension!= ".db3" && extension != ".btdb")
1314
{
14-
throw RuntimeError("SqliteLogger: the file extension must be [.db3]");
15+
throw RuntimeError("SqliteLogger: the file extension must be [.db3] or [.btdb]");
1516
}
1617

1718
enableTransitionToIdle(true);

src/loggers/groot2_publisher.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct Groot2Publisher::PImpl
8080
std::unordered_map<uint16_t, Monitor::Hook::Ptr> post_hooks;
8181

8282
std::chrono::system_clock::time_point last_heartbeat;
83+
std::chrono::milliseconds max_heartbeat_delay = std::chrono::milliseconds(5000);
8384

8485
std::thread heartbeat_thread;
8586

@@ -149,6 +150,16 @@ Groot2Publisher::Groot2Publisher(const BT::Tree& tree,
149150
_p->heartbeat_thread = std::thread(&Groot2Publisher::heartbeatLoop, this);
150151
}
151152

153+
void Groot2Publisher::setMaxHeartbeatDelay(std::chrono::milliseconds delay)
154+
{
155+
_p->max_heartbeat_delay = delay;
156+
}
157+
158+
std::chrono::milliseconds Groot2Publisher::maxHeartbeatDelay() const
159+
{
160+
return _p->max_heartbeat_delay;
161+
}
162+
152163
Groot2Publisher::~Groot2Publisher()
153164
{
154165
removeAllHooks();
@@ -404,12 +415,12 @@ void Groot2Publisher::heartbeatLoop()
404415

405416
while (_p->active_server)
406417
{
407-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
418+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
408419

409420
auto now = std::chrono::system_clock::now();
410421
bool prev_heartbeat = has_heartbeat;
411422

412-
has_heartbeat = ( now - _p->last_heartbeat < std::chrono::milliseconds(5000));
423+
has_heartbeat = ( now - _p->last_heartbeat < _p->max_heartbeat_delay);
413424

414425
// if we loose or gain heartbeat, disable/enable all breakpoints
415426
if(has_heartbeat != prev_heartbeat)

0 commit comments

Comments
 (0)