Task: Add ability to set timeout (#213)

Task::setTimeout will allow setting an overall timeout.
This commit is contained in:
Jafar Abdi 2020-10-24 04:22:05 +03:00 committed by GitHub
parent d3b878a31c
commit be270cb574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -112,6 +112,9 @@ public:
using WrapperBase::removeSolutionCallback;
using WrapperBase::SolutionCallback;
using WrapperBase::setTimeout;
using WrapperBase::timeout;
/// reset all stages
void reset() final;
/// initialize all stages with given scene

View File

@ -109,6 +109,8 @@ Task::Task(const std::string& id, bool introspection, ContainerBase::pointer&& c
if (!id.empty())
stages()->setName(id);
setTimeout(std::numeric_limits<double>::max());
// monitor state on commandline
// addTaskCallback(std::bind(&Task::printState, this, std::ref(std::cout)));
// enable introspection by default, but only if ros::init() was called
@ -296,8 +298,11 @@ bool Task::plan(size_t max_solutions) {
init();
impl->preempt_requested_ = false;
const double available_time = timeout();
const auto start_time = std::chrono::steady_clock::now();
while (ros::ok() && !impl->preempt_requested_ && canCompute() &&
(max_solutions == 0 || numSolutions() < max_solutions)) {
(max_solutions == 0 || numSolutions() < max_solutions) &&
std::chrono::duration<double>(std::chrono::steady_clock::now() - start_time).count() < available_time) {
compute();
for (const auto& cb : impl->task_cbs_)
cb(*this);