mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
Task: Add ability to set timeout (#213)
Task::setTimeout will allow setting an overall timeout.
This commit is contained in:
parent
d3b878a31c
commit
be270cb574
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user