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
28
29namespace armarx
30{
31 bool
32 MotionPlanningTask::setTaskStatus(TaskStatus::Status newTaskStatus, const Ice::Current&)
33 {
34 //loop for compare and swap
35 //since states form a DAG and staying on the same state returns from this function,
36 //this loop will terminate
37 while (true)
38 {
39 auto currentTaskStatus = taskStatus.load();
40
41 bool invalidTransition = false;
42 switch (newTaskStatus)
43 {
44 case TaskStatus::eNew:
45 case TaskStatus::eTaskStatusSize:
46 invalidTransition = true;
47 [[fallthrough]];
48
49 case TaskStatus::eQueued:
50 if (currentTaskStatus != TaskStatus::eNew)
51 {
52 invalidTransition = true;
53 }
54 break;
55 case TaskStatus::ePlanning:
56 if (currentTaskStatus != TaskStatus::eQueued)
57 {
58 invalidTransition = true;
59 }
60 break;
61 case TaskStatus::eRefining:
62 if (currentTaskStatus != TaskStatus::ePlanning)
63 {
64 invalidTransition = true;
65 }
66 break;
67 case TaskStatus::ePlanningAborted:
68 if ((currentTaskStatus != TaskStatus::eNew) &&
69 (currentTaskStatus != TaskStatus::eQueued) &&
70 (currentTaskStatus != TaskStatus::ePlanning))
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 ((currentTaskStatus != TaskStatus::eRefining) &&
89 (currentTaskStatus != TaskStatus::ePlanning))
90 {
91 invalidTransition = true;
92 }
93 break;
94 case TaskStatus::eException:
95 break;
96 default:
97 invalidTransition = true;
98 }
99 if (invalidTransition)
100 {
101 if (currentTaskStatus != newTaskStatus)
102 {
103 ARMARX_WARNING_S << "Tried invalid transition from "
104 << TaskStatus::toString(currentTaskStatus) << " to "
105 << TaskStatus::toString(newTaskStatus);
106 }
107 return false;
108 }
109
110 if (taskStatus.compare_exchange_strong(currentTaskStatus, newTaskStatus))
111 {
112 if (TaskStatus::finishedRunning(newTaskStatus))
113 {
114 waitForFinishedPlanning.setAutoResponse();
115 waitForFinishedRunning.setAutoResponse();
116 }
117 else
118 {
119 if (newTaskStatus == TaskStatus::eRefining)
120 {
121 waitForFinishedPlanning.setAutoResponse();
122 }
123 }
124 for (auto& cb : taskStatusCallbacks)
125 {
126 cb(newTaskStatus);
127 }
128 return true;
129 }
130 }
131 }
132} // namespace armarx
bool setTaskStatus(TaskStatus::Status newTaskStatus, const Ice::Current &=Ice::emptyCurrent) override
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
bool finishedRunning(Status status)
Returns whether the given task status describes a state where planning is done (may be failed).
std::string toString(Status status)
Returns the given task status as a string.
This file offers overloads of toIce() and fromIce() functions for STL container types.