moveit2
The MoveIt Motion Planning Framework for ROS 2.
moveit_error_code.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2021, PickNik Inc.
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 OWNER 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 
35 #pragma once
36 
37 #include <moveit_msgs/msg/move_it_error_codes.hpp>
38 #include <string>
39 
40 namespace moveit
41 {
42 namespace core
43 {
47 class MoveItErrorCode : public moveit_msgs::msg::MoveItErrorCodes
48 {
49 public:
50  MoveItErrorCode(int code = 0)
51  {
52  val = code;
53  }
54  MoveItErrorCode(const moveit_msgs::msg::MoveItErrorCodes& code)
55  {
56  val = code.val;
57  }
58  explicit operator bool() const
59  {
60  return val == moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
61  }
62  bool operator==(const int c) const
63  {
64  return val == c;
65  }
66  bool operator!=(const int c) const
67  {
68  return val != c;
69  }
70 };
71 
77 inline std::string error_code_to_string(MoveItErrorCode error_code)
78 {
79  switch (error_code.val)
80  {
81  case moveit::core::MoveItErrorCode::SUCCESS:
82  return std::string("SUCCESS");
83  case moveit::core::MoveItErrorCode::FAILURE:
84  return std::string("FAILURE");
85  case moveit::core::MoveItErrorCode::PLANNING_FAILED:
86  return std::string("PLANNING_FAILED");
87  case moveit::core::MoveItErrorCode::INVALID_MOTION_PLAN:
88  return std::string("INVALID_MOTION_PLAN");
89  case moveit::core::MoveItErrorCode::MOTION_PLAN_INVALIDATED_BY_ENVIRONMENT_CHANGE:
90  return std::string("MOTION_PLAN_INVALIDATED_BY_ENVIRONMENT_CHANGE");
91  case moveit::core::MoveItErrorCode::CONTROL_FAILED:
92  return std::string("CONTROL_FAILED");
93  case moveit::core::MoveItErrorCode::UNABLE_TO_AQUIRE_SENSOR_DATA:
94  return std::string("UNABLE_TO_AQUIRE_SENSOR_DATA");
95  case moveit::core::MoveItErrorCode::TIMED_OUT:
96  return std::string("TIMED_OUT");
97  case moveit::core::MoveItErrorCode::PREEMPTED:
98  return std::string("PREEMPTED");
99  case moveit::core::MoveItErrorCode::START_STATE_IN_COLLISION:
100  return std::string("START_STATE_IN_COLLISION");
101  case moveit::core::MoveItErrorCode::START_STATE_VIOLATES_PATH_CONSTRAINTS:
102  return std::string("START_STATE_VIOLATES_PATH_CONSTRAINTS");
103  case moveit::core::MoveItErrorCode::START_STATE_INVALID:
104  return std::string("START_STATE_INVALID");
105  case moveit::core::MoveItErrorCode::GOAL_IN_COLLISION:
106  return std::string("GOAL_IN_COLLISION");
107  case moveit::core::MoveItErrorCode::GOAL_VIOLATES_PATH_CONSTRAINTS:
108  return std::string("GOAL_VIOLATES_PATH_CONSTRAINTS");
109  case moveit::core::MoveItErrorCode::GOAL_CONSTRAINTS_VIOLATED:
110  return std::string("GOAL_CONSTRAINTS_VIOLATED");
111  case moveit::core::MoveItErrorCode::GOAL_STATE_INVALID:
112  return std::string("GOAL_STATE_INVALID");
113  case moveit::core::MoveItErrorCode::UNRECOGNIZED_GOAL_TYPE:
114  return std::string("UNRECOGNIZED_GOAL_TYPE");
115  case moveit::core::MoveItErrorCode::INVALID_GROUP_NAME:
116  return std::string("INVALID_GROUP_NAME");
117  case moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS:
118  return std::string("INVALID_GOAL_CONSTRAINTS");
119  case moveit::core::MoveItErrorCode::INVALID_ROBOT_STATE:
120  return std::string("INVALID_ROBOT_STATE");
121  case moveit::core::MoveItErrorCode::INVALID_LINK_NAME:
122  return std::string("INVALID_LINK_NAME");
123  case moveit::core::MoveItErrorCode::INVALID_OBJECT_NAME:
124  return std::string("INVALID_OBJECT_NAME");
125  case moveit::core::MoveItErrorCode::FRAME_TRANSFORM_FAILURE:
126  return std::string("FRAME_TRANSFORM_FAILURE");
127  case moveit::core::MoveItErrorCode::COLLISION_CHECKING_UNAVAILABLE:
128  return std::string("COLLISION_CHECKING_UNAVAILABLE");
129  case moveit::core::MoveItErrorCode::ROBOT_STATE_STALE:
130  return std::string("ROBOT_STATE_STALE");
131  case moveit::core::MoveItErrorCode::SENSOR_INFO_STALE:
132  return std::string("SENSOR_INFO_STALE");
133  case moveit::core::MoveItErrorCode::COMMUNICATION_FAILURE:
134  return std::string("COMMUNICATION_FAILURE");
135  case moveit::core::MoveItErrorCode::CRASH:
136  return std::string("CRASH");
137  case moveit::core::MoveItErrorCode::ABORT:
138  return std::string("ABORT");
139  case moveit::core::MoveItErrorCode::NO_IK_SOLUTION:
140  return std::string("NO_IK_SOLUTION");
141  }
142  return std::string("Unrecognized MoveItErrorCode. This should never happen!");
143 }
144 
145 } // namespace core
146 } // namespace moveit
a wrapper around moveit_msgs::MoveItErrorCodes to make it easier to return an error code message from...
bool operator!=(const int c) const
MoveItErrorCode(const moveit_msgs::msg::MoveItErrorCodes &code)
bool operator==(const int c) const
std::string error_code_to_string(MoveItErrorCode error_code)
Convenience function to translated error message into string.
Main namespace for MoveIt.
Definition: exceptions.h:43