PlanningUtil.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#include "PlanningUtil.h"
25
26#include <stdexcept>
27
29{
30 std::string
32 {
33 switch (status)
34 {
35 case eNew:
36 return "eNew";
37
38 case eQueued:
39 return "eQueued";
40
41 case ePlanning:
42 return "ePlanning";
43
44 case ePlanningAborted:
45 return "ePlanningAborted";
46
47 case ePlanningFailed:
48 return "ePlanningFailed";
49
50 case eRefining:
51 return "eRefining";
52
53 case eRefinementAborted:
54 return "eRefinementAborted";
55
56 case eDone:
57 return "eDone";
58
59 case eException:
60 return "eException";
61
62 default:
63 return "Unknown status: " + std::to_string(status);
64 }
65 }
66
67 //status information
68 bool
70 {
71 switch (status)
72 {
73 case ePlanning:
74 case eRefining:
75 return true;
76
77 case eNew:
78 case eQueued:
79 case ePlanningAborted:
80 case ePlanningFailed:
81 case eRefinementAborted:
82 case eDone:
83 case eException:
84 return false;
85
86 case eTaskStatusSize:
87 break;
88 //do not add a default case. a new status is either a planning step or it is not (but both is possible for a new status).
89 }
90
91 //this point should never be reached!
92 //if it is a new status was added without changing this function
93 throw std::logic_error{__FILE__ " in line " + std::to_string(__LINE__) + toString(status)};
94 }
95
96 bool
98 {
99 switch (status)
100 {
101 case eNew:
102 case eQueued:
103 case ePlanning:
104 case eRefining:
105 return false;
106
107 case ePlanningAborted:
108 case ePlanningFailed:
109 case eRefinementAborted:
110 case eDone:
111 case eException:
112 return true;
113
114 case eTaskStatusSize:
115 break;
116 //do not add a default case. a new status is either a finished status or it is not (but both is possible for a new status).
117 }
118
119 //this point should never be reached!
120 //if it is a new status was added without changing this function
121 throw std::logic_error{__FILE__ " in line " + std::to_string(__LINE__) + toString(status)};
122 }
123
124 //status transition
125 Status
127 {
128 switch (status)
129 {
130 case ePlanning:
131 return ePlanningAborted;
132 break;
133
134 case eRefining:
135 return eRefinementAborted;
136 break;
137
138 case ePlanningFailed:
139 case eDone:
140 case eNew:
141 case eQueued:
142 case ePlanningAborted:
143 case eRefinementAborted:
144 case eTaskStatusSize:
145 case eException:
146 break;
147 }
148
149 std::stringstream ss;
150 ss << "planningStatusTransitionAtKill: transition from " << toString(status)
151 << " is illegal";
152 throw std::invalid_argument{ss.str()};
153 }
154
155 Status
157 {
158 switch (status)
159 {
160 case ePlanning:
161 return ePlanningFailed;
162 break;
163
164 case eRefining:
165 return eDone;
166 break;
167
168 case ePlanningFailed:
169 case eDone:
170 case eNew:
171 case eQueued:
172 case ePlanningAborted:
173 case eRefinementAborted:
174 case eTaskStatusSize:
175 case eException:
176 break;
177 }
178
179 std::stringstream ss;
180 ss << "planningStatusTransitionAtOutoftime: transition from " << toString(status)
181 << " is illegal";
182 throw std::invalid_argument{ss.str()};
183 }
184
185 Status
187 {
188 switch (status)
189 {
190 case ePlanning:
191 return eDone;
192 break;
193
194 case eRefining:
195 return eDone;
196
197 case ePlanningFailed:
198 case eDone:
199 case eNew:
200 case eQueued:
201 case ePlanningAborted:
202 case eRefinementAborted:
203 case eTaskStatusSize:
204 case eException:
205 break;
206 }
207
208 std::stringstream ss;
209 ss << "planningStatusTransitionAtDone: transition from " << toString(status)
210 << " is illegal";
211 throw std::invalid_argument{ss.str()};
212 }
213} // namespace armarx::TaskStatus
Status transitionAtDone(Status status)
Performs a transition from the given to the appropiate following status in case the task is done.
bool finishedRunning(Status status)
Returns whether the given task status describes a state where planning is done (may be failed).
bool isRunning(Status status)
Returns whether the given task status describes a state where a path is planned.
std::string toString(Status status)
Returns the given task status as a string.
Status transitionAtOutoftime(Status status)
Performs a transition from the given to the appropiate following status in case of the task failing.
Status transitionAtKill(Status status)
Performs a transition from the given to the appropiate following status in case of a task kill.