exceptions.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #ifndef NAV_CORE2_EXCEPTIONS_H
35 #define NAV_CORE2_EXCEPTIONS_H
36 
37 #include <nav_2d_msgs/Pose2DStamped.h>
38 #include <stdexcept>
39 #include <exception>
40 #include <string>
41 #include <memory>
42 
43 /**************************************************
44  * The nav_core2 Planning Exception Hierarchy!!
45  * (with arbitrary integer result codes)
46  **************************************************
47  * NavCore2Exception
48  * 0 CostmapException
49  * 1 CostmapSafetyException
50  * 2 CostmapDataLagException
51  * 3 PlannerException
52  * 4 GlobalPlannerException
53  * 5 InvalidStartPoseException
54  * 6 StartBoundsException
55  * 7 OccupiedStartException
56  * 8 InvalidGoalPoseException
57  * 9 GoalBoundsException
58  * 10 OccupiedGoalException
59  * 11 NoGlobalPathException
60  * 12 GlobalPlannerTimeoutException
61  * 13 LocalPlannerException
62  * 14 IllegalTrajectoryException
63  * 15 NoLegalTrajectoriesException
64  * 16 PlannerTFException
65  *
66  * -1 Unknown
67  **************************************************/
68 
69 namespace nav_core2
70 {
71 
72 inline std::string poseToString(const nav_2d_msgs::Pose2DStamped& pose)
73 {
74  return "(" + std::to_string(pose.pose.x) + ", " + std::to_string(pose.pose.y) + ", " + std::to_string(pose.pose.theta)
75  + " : " + pose.header.frame_id + ")";
76 }
77 
78 class NavCore2Exception: public std::runtime_error
79 {
80 public:
81  explicit NavCore2Exception(const std::string& description, int result_code)
82  : std::runtime_error(description), result_code_(result_code) {}
83  int getResultCode() const { return result_code_; }
84 protected:
86 };
87 
88 using NavCore2ExceptionPtr = std::exception_ptr;
89 
93 inline int getResultCode(const NavCore2ExceptionPtr& e_ptr)
94 {
95  if (e_ptr == nullptr)
96  {
97  return -1;
98  }
99  try
100  {
101  std::rethrow_exception(e_ptr);
102  }
103  catch (const NavCore2Exception& e)
104  {
105  return e.getResultCode();
106  }
107  catch (...)
108  {
109  // Will end up here if current_exception returned a non-NavCore2Exception
110  return -1;
111  }
112 }
113 
119 {
120 public:
121  explicit CostmapException(const std::string& description, int result_code = 0)
122  : NavCore2Exception(description, result_code) {}
123 };
124 
130 {
131 public:
132  explicit CostmapSafetyException(const std::string& description, int result_code = 1)
133  : CostmapException(description, result_code) {}
134 };
135 
143 {
144 public:
145  explicit CostmapDataLagException(const std::string& description, int result_code = 2)
146  : CostmapSafetyException(description, result_code) {}
147 };
148 
154 {
155 public:
156  explicit PlannerException(const std::string& description, int result_code = 3)
157  : NavCore2Exception(description, result_code) {}
158 };
159 
165 {
166 public:
167  explicit GlobalPlannerException(const std::string& description, int result_code = 4)
168  : PlannerException(description, result_code) {}
169 };
170 
176 {
177 public:
178  explicit LocalPlannerException(const std::string& description, int result_code = 13)
179  : PlannerException(description, result_code) {}
180 };
181 
187 {
188 public:
189  explicit PlannerTFException(const std::string& description, int result_code = 16)
190  : PlannerException(description, result_code) {}
191 };
192 
198 {
199 public:
200  explicit InvalidStartPoseException(const std::string& description, int result_code = 5)
201  : GlobalPlannerException(description, result_code) {}
202  InvalidStartPoseException(const nav_2d_msgs::Pose2DStamped& pose, const std::string& problem, int result_code = 5) :
203  InvalidStartPoseException("The starting pose " + poseToString(pose) + " is " + problem, result_code) {}
204 };
205 
211 {
212 public:
213  explicit StartBoundsException(const std::string& description, int result_code = 6)
214  : InvalidStartPoseException(description, result_code) {}
215  explicit StartBoundsException(const nav_2d_msgs::Pose2DStamped& pose) :
216  InvalidStartPoseException(pose, "out of bounds", 6) {}
217 };
218 
224 {
225 public:
226  explicit OccupiedStartException(const std::string& description, int result_code = 7)
227  : InvalidStartPoseException(description, result_code) {}
228  explicit OccupiedStartException(const nav_2d_msgs::Pose2DStamped& pose) :
229  InvalidStartPoseException(pose, "occupied", 7) {}
230 };
231 
237 {
238 public:
239  explicit InvalidGoalPoseException(const std::string& description, int result_code = 8)
240  : GlobalPlannerException(description, result_code) {}
241  InvalidGoalPoseException(const nav_2d_msgs::Pose2DStamped& pose, const std::string& problem, int result_code = 8) :
242  GlobalPlannerException("The goal pose " + poseToString(pose) + " is " + problem, result_code) {}
243 };
244 
250 {
251 public:
252  explicit GoalBoundsException(const std::string& description, int result_code = 9)
253  : InvalidGoalPoseException(description, result_code) {}
254  explicit GoalBoundsException(const nav_2d_msgs::Pose2DStamped& pose) :
255  InvalidGoalPoseException(pose, "out of bounds", 9) {}
256 };
257 
263 {
264 public:
265  explicit OccupiedGoalException(const std::string& description, int result_code = 10)
266  : InvalidGoalPoseException(description, result_code) {}
267  explicit OccupiedGoalException(const nav_2d_msgs::Pose2DStamped& pose) :
268  InvalidGoalPoseException(pose, "occupied", 10) {}
269 };
270 
276 {
277 public:
278  explicit NoGlobalPathException(const std::string& description, int result_code = 11)
279  : GlobalPlannerException(description, result_code) {}
280  NoGlobalPathException() : GlobalPlannerException("No global path found.") {}
281 };
282 
288 {
289 public:
290  explicit GlobalPlannerTimeoutException(const std::string& description, int result_code = 12)
291  : GlobalPlannerException(description, result_code) {}
292 };
293 
299 {
300 public:
301  IllegalTrajectoryException(const std::string& critic_name, const std::string& description, int result_code = 14)
302  : LocalPlannerException(description, result_code), critic_name_(critic_name) {}
303  std::string getCriticName() const { return critic_name_; }
304 protected:
305  std::string critic_name_;
306 };
307 
313 {
314 public:
315  explicit NoLegalTrajectoriesException(const std::string& description, int result_code = 15)
316  : LocalPlannerException(description, result_code) {}
317 };
318 
319 } // namespace nav_core2
320 
321 #endif // NAV_CORE2_EXCEPTIONS_H
LocalPlannerException(const std::string &description, int result_code=13)
Definition: exceptions.h:178
CostmapException(const std::string &description, int result_code=0)
Definition: exceptions.h:121
GlobalPlannerTimeoutException(const std::string &description, int result_code=12)
Definition: exceptions.h:290
Thrown when one of the critics encountered a fatal error.
Definition: exceptions.h:298
InvalidGoalPoseException(const nav_2d_msgs::Pose2DStamped &pose, const std::string &problem, int result_code=8)
Definition: exceptions.h:241
OccupiedGoalException(const nav_2d_msgs::Pose2DStamped &pose)
Definition: exceptions.h:267
NoLegalTrajectoriesException(const std::string &description, int result_code=15)
Definition: exceptions.h:315
Exception thrown when the start location of the global planner is out of the expected bounds...
Definition: exceptions.h:210
Exception thrown when the goal location of the global planner is out of the expected bounds...
Definition: exceptions.h:249
PlannerException(const std::string &description, int result_code=3)
Definition: exceptions.h:156
StartBoundsException(const std::string &description, int result_code=6)
Definition: exceptions.h:213
IllegalTrajectoryException(const std::string &critic_name, const std::string &description, int result_code=14)
Definition: exceptions.h:301
Exception thrown when the start location of the global planner is occupied in the costmap...
Definition: exceptions.h:223
NavCore2Exception(const std::string &description, int result_code)
Definition: exceptions.h:81
Parent type of all exceptions defined within.
Definition: exceptions.h:153
General container for exceptions thrown from the Global Planner.
Definition: exceptions.h:164
std::exception_ptr NavCore2ExceptionPtr
Definition: exceptions.h:88
Exception thrown when the global planner cannot find a path from the start to the goal...
Definition: exceptions.h:275
InvalidStartPoseException(const nav_2d_msgs::Pose2DStamped &pose, const std::string &problem, int result_code=5)
Definition: exceptions.h:202
Thrown when all the trajectories explored are illegal.
Definition: exceptions.h:312
StartBoundsException(const nav_2d_msgs::Pose2DStamped &pose)
Definition: exceptions.h:215
std::string poseToString(const nav_2d_msgs::Pose2DStamped &pose)
Definition: exceptions.h:72
PlannerTFException(const std::string &description, int result_code=16)
Definition: exceptions.h:189
Exception thrown when there is a problem at the goal location for the global planner.
Definition: exceptions.h:236
General container for exceptions thrown when the costmap thinks any movement would be unsafe...
Definition: exceptions.h:129
OccupiedGoalException(const std::string &description, int result_code=10)
Definition: exceptions.h:265
NoGlobalPathException(const std::string &description, int result_code=11)
Definition: exceptions.h:278
Exception thrown when the global planner has spent too long looking for a path.
Definition: exceptions.h:287
InvalidGoalPoseException(const std::string &description, int result_code=8)
Definition: exceptions.h:239
OccupiedStartException(const std::string &description, int result_code=7)
Definition: exceptions.h:226
CostmapSafetyException(const std::string &description, int result_code=1)
Definition: exceptions.h:132
General container for exceptions thrown from the Local Planner.
Definition: exceptions.h:175
Exception thrown when the goal location of the global planner is occupied in the costmap.
Definition: exceptions.h:262
Indicates costmap is out of date because data in not up to date.
Definition: exceptions.h:142
GlobalPlannerException(const std::string &description, int result_code=4)
Definition: exceptions.h:167
std::string getCriticName() const
Definition: exceptions.h:303
Extensible exception class for all costmap-related problems.
Definition: exceptions.h:118
Thrown when either the global or local planner cannot complete its operation due to TF errors...
Definition: exceptions.h:186
CostmapDataLagException(const std::string &description, int result_code=2)
Definition: exceptions.h:145
GoalBoundsException(const nav_2d_msgs::Pose2DStamped &pose)
Definition: exceptions.h:254
InvalidStartPoseException(const std::string &description, int result_code=5)
Definition: exceptions.h:200
Exception thrown when there is a problem at the start location for the global planner.
Definition: exceptions.h:197
GoalBoundsException(const std::string &description, int result_code=9)
Definition: exceptions.h:252
OccupiedStartException(const nav_2d_msgs::Pose2DStamped &pose)
Definition: exceptions.h:228


nav_core2
Author(s):
autogenerated on Sun Jan 10 2021 04:08:27