MotionPlanningTask.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 
25 #include "MotionPlanningTask.h"
26 #include "../util/PlanningUtil.h"
27 
28 namespace armarx
29 {
30  bool MotionPlanningTask::setTaskStatus(TaskStatus::Status newTaskStatus, const Ice::Current&)
31  {
32  //loop for compare and swap
33  //since states form a DAG and staying on the same state returns from this function,
34  //this loop will terminate
35  while (true)
36  {
37  auto currentTaskStatus = taskStatus.load();
38 
39  bool invalidTransition = false;
40  switch (newTaskStatus)
41  {
42  case TaskStatus::eNew:
43  case TaskStatus::eTaskStatusSize:
44  invalidTransition = true;
45  [[fallthrough]];
46 
47  case TaskStatus::eQueued:
48  if (currentTaskStatus != TaskStatus::eNew)
49  {
50  invalidTransition = true;
51  }
52  break;
53  case TaskStatus::ePlanning:
54  if (currentTaskStatus != TaskStatus::eQueued)
55  {
56  invalidTransition = true;
57  }
58  break;
59  case TaskStatus::eRefining:
60  if (currentTaskStatus != TaskStatus::ePlanning)
61  {
62  invalidTransition = true;
63  }
64  break;
65  case TaskStatus::ePlanningAborted:
66  if (
67  (currentTaskStatus != TaskStatus::eNew) &&
68  (currentTaskStatus != TaskStatus::eQueued) &&
69  (currentTaskStatus != TaskStatus::ePlanning)
70  )
71  {
72  invalidTransition = true;
73  }
74  break;
75  case TaskStatus::ePlanningFailed:
76  if (currentTaskStatus != TaskStatus::ePlanning)
77  {
78  invalidTransition = true;
79  }
80  break;
81  case TaskStatus::eRefinementAborted:
82  if (currentTaskStatus != TaskStatus::eRefining)
83  {
84  invalidTransition = true;
85  }
86  break;
87  case TaskStatus::eDone:
88  if (
89  (currentTaskStatus != TaskStatus::eRefining) &&
90  (currentTaskStatus != TaskStatus::ePlanning)
91  )
92  {
93  invalidTransition = true;
94  }
95  break;
96  case TaskStatus::eException:
97  break;
98  default:
99  invalidTransition = true;
100  }
101  if (invalidTransition)
102  {
103  if (currentTaskStatus != newTaskStatus)
104  {
105  ARMARX_WARNING_S << "Tried invalid transition from "
106  << TaskStatus::toString(currentTaskStatus)
107  << " to "
108  << TaskStatus::toString(newTaskStatus);
109  }
110  return false;
111  }
112 
113  if (taskStatus.compare_exchange_strong(currentTaskStatus, newTaskStatus))
114  {
115  if (TaskStatus::finishedRunning(newTaskStatus))
116  {
119  }
120  else
121  {
122  if (newTaskStatus == TaskStatus::eRefining)
123  {
125  }
126  }
127  for (auto& cb : taskStatusCallbacks)
128  {
129  cb(newTaskStatus);
130  }
131  return true;
132  }
133  }
134  }
135 }
armarx::MotionPlanningTaskCI::waitForFinishedRunning
AMDCallbackCollection waitForFinishedRunning
Definition: MotionPlanningTaskControlInterface.h:61
armarx::TaskStatus::toString
std::string toString(Status status)
Returns the given task status as a string.
Definition: PlanningUtil.cpp:30
armarx::TaskStatus::finishedRunning
bool finishedRunning(Status status)
Returns whether the given task status describes a state where planning is done (may be failed).
Definition: PlanningUtil.cpp:94
MotionPlanningTask.h
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::MotionPlanningTask::setTaskStatus
bool setTaskStatus(TaskStatus::Status newTaskStatus, const Ice::Current &=Ice::emptyCurrent) override
Definition: MotionPlanningTask.cpp:30
armarx::AMDCallbackCollection::setAutoResponse
void setAutoResponse(bool doAutoResponse=true)
setAutoResponse
Definition: AMDCallbackCollection.h:169
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MotionPlanningTaskCI::waitForFinishedPlanning
AMDCallbackCollection waitForFinishedPlanning
Definition: MotionPlanningTaskControlInterface.h:60