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