Skip to content

Commit 28085ab

Browse files
committed
Early wakeup should not advance loop deadline.
1 parent 6c6aa07 commit 28085ab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

behaviortree_ros2/src/tree_execution_server.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,20 @@ void TreeExecutionServer::execute(
251251
goal_handle->publish_feedback(feedback);
252252
}
253253

254-
const auto now = std::chrono::steady_clock::now();
254+
auto now = std::chrono::steady_clock::now();
255255
if(now < loop_deadline)
256256
{
257257
p_->tree.sleep(std::chrono::duration_cast<std::chrono::system_clock::duration>(
258258
loop_deadline - now));
259+
now = std::chrono::steady_clock::now();
260+
}
261+
// If sleep was woken early, it will still be before the next deadline
262+
// so it might still be necessary to wait for it. Only advance to the
263+
// next deadline if one has passed.
264+
if(now >= loop_deadline)
265+
{
266+
loop_deadline += period;
259267
}
260-
loop_deadline += period;
261268
}
262269
}
263270
catch(const std::exception& ex)

0 commit comments

Comments
 (0)