footstep_planning_msgs.cpp
Go to the documentation of this file.
2 
4 {
5 // Extension to ErrorStatus message
6 msgs::ErrorStatus operator+(const msgs::ErrorStatus& lhs, const msgs::ErrorStatus& rhs)
7 {
8  msgs::ErrorStatus result;
9 
10  result.error = lhs.error | rhs.error;
11  result.error_msg = lhs.error_msg;
12  if (result.error_msg.size() && rhs.error_msg.size())
13  result.error_msg += "\n";
14  result.error_msg += rhs.error_msg;
15 
16  result.warning = lhs.warning | rhs.warning;
17  result.warning_msg = lhs.warning_msg;
18  if (result.warning_msg.size() && rhs.warning_msg.size())
19  result.warning_msg += "\n";
20  result.warning_msg += rhs.warning_msg;
21 
22  return result;
23 }
24 
25 msgs::ErrorStatus operator+=(msgs::ErrorStatus& lhs, const msgs::ErrorStatus& rhs)
26 {
27  lhs = operator+(lhs, rhs);
28  return lhs;
29 }
30 
31 msgs::ErrorStatus isConsistent(const msgs::StepPlan& step_plan)
32 {
33  // an empty plan is always consistent
34  if (step_plan.steps.empty())
35  return msgs::ErrorStatus();
36 
37  msgs::ErrorStatus status;
38 
39  // check if steps are ordered and closed
40  unsigned int step_index = step_plan.steps.front().step_index;
41  for (std::vector<msgs::Step>::const_iterator itr = step_plan.steps.begin(); itr != step_plan.steps.end(); itr++)
42  {
43  if (itr->header.frame_id != step_plan.header.frame_id)
44  status += ErrorStatusError(msgs::ErrorStatus::ERR_INCONSISTENT_STEP_PLAN, "isConsistent", "Frame id mismatch! Plan: " + step_plan.header.frame_id + " vs. step: " + itr->header.frame_id);
45 
46  if (itr->step_index != step_index++)
47  status += ErrorStatusWarning(msgs::ErrorStatus::WARN_INCOMPLETE_STEP_PLAN, "isConsistent", "Wrong step index order: Expected " + boost::lexical_cast<std::string>(step_index-1) + " but got " + boost::lexical_cast<std::string>(itr->step_index) + "!");
48 
49  if (!itr->valid)
50  status += ErrorStatusWarning(msgs::ErrorStatus::WARN_INVALID_STEP_PLAN, "isConsistent", "Step " + boost::lexical_cast<std::string>(itr->step_index) + " invalid!");
51  }
52 
53  return status;
54 }
55 
56 std::string ErrorStatusCodeToString(unsigned int error)
57 {
58  switch (error)
59  {
60  case msgs::ErrorStatus::NO_ERROR: return "NO_ERROR";
61  case msgs::ErrorStatus::ERR_UNKNOWN: return "ERR_UNKNOWN";
62  case msgs::ErrorStatus::ERR_NO_SOLUTION: return "ERR_NO_SOLUTION";
63  case msgs::ErrorStatus::ERR_INVALID_START: return "ERR_INVALID_START";
64  case msgs::ErrorStatus::ERR_INVALID_GOAL: return "ERR_INVALID_GOAL";
65  case msgs::ErrorStatus::ERR_INVALID_GRID_MAP: return "ERR_INVALID_GRID_MAP";
66  case msgs::ErrorStatus::ERR_INVALID_TERRAIN_MODEL: return "ERR_INVALID_TERRAIN_MODEL";
67  case msgs::ErrorStatus::ERR_INVALID_STEP: return "ERR_INVALID_STEP";
68  case msgs::ErrorStatus::ERR_INCONSISTENT_STEP_PLAN: return "ERR_INCONSISTENT_STEP_PLAN";
69  case msgs::ErrorStatus::ERR_INVALID_PARAMETERS: return "ERR_INVALID_PARAMETERS";
70  case msgs::ErrorStatus::ERR_NO_PLUGIN_AVAILABLE: return "ERR_NO_PLUGIN_AVAILABLE";
71  case msgs::ErrorStatus::ERR_INCONSISTENT_REQUEST: return "ERR_INCONSISTENT_REQUEST";
72  default: return "ERR_UNKNOWN";
73  }
74 }
75 
76 std::string WarningStatusCodeToString(unsigned int warning)
77 {
78  switch (warning)
79  {
80  case msgs::ErrorStatus::NO_WARNING: return "NO_WARNING";
81  case msgs::ErrorStatus::WARN_UNKNOWN: return "WARN_UNKNOWN";
82  case msgs::ErrorStatus::WARN_INCOMPLETE_STEP_PLAN: return "WARN_INCOMPLETE_STEP_PLAN";
83  case msgs::ErrorStatus::WARN_INVALID_STEP_PLAN: return "WARN_INVALID_STEP_PLAN";
84  default: return "WARN_UNKNOWN";
85  }
86 }
87 
88 msgs::ErrorStatus createErrorStatus(const std::string& context, unsigned int error, const std::string& error_msg, unsigned int warning, const std::string& warning_msg, bool output, double throttle_rate)
89 {
90  if (output)
91  {
92  if (throttle_rate > 0.0)
93  {
94  if (error)
95  ROS_ERROR_THROTTLE(throttle_rate, "[%s][%s] %s", ErrorStatusCodeToString(error).c_str(), context.c_str(), error_msg.c_str());
96  if (warning)
97  ROS_WARN_THROTTLE(throttle_rate, "[%s][%s] %s", WarningStatusCodeToString(warning).c_str(), context.c_str(), warning_msg.c_str());
98  }
99  else
100  {
101  if (error)
102  ROS_ERROR("[%s][%s] %s", ErrorStatusCodeToString(error).c_str(), context.c_str(), error_msg.c_str());
103  if (warning)
104  ROS_WARN("[%s][%s] %s", WarningStatusCodeToString(warning).c_str(), context.c_str(), warning_msg.c_str());
105  }
106  }
107 
108  msgs::ErrorStatus status;
109  status.error = error;
110  status.error_msg = error != msgs::ErrorStatus::NO_ERROR ? "[" + ErrorStatusCodeToString(error) + "][" + context + "] " + error_msg : error_msg;
111  status.warning = warning;
112  status.warning_msg = warning != msgs::ErrorStatus::NO_WARNING ? "[" + WarningStatusCodeToString(warning) + "][" + context + "] " + warning_msg : warning_msg;
113  return status;
114 }
115 
116 msgs::ErrorStatus ErrorStatusError(unsigned int error, const std::string& context, const std::string& error_msg, bool output, double throttle_rate)
117 {
118  return createErrorStatus(context, error, error_msg, msgs::ErrorStatus::NO_WARNING, "", output, throttle_rate);
119 }
120 
121 msgs::ErrorStatus ErrorStatusWarning(unsigned int warning, const std::string& context, const std::string& warning_msg, bool output, double throttle_rate)
122 {
123  return createErrorStatus(context, msgs::ErrorStatus::NO_ERROR, "", warning, warning_msg, output, throttle_rate);
124 }
125 
126 bool hasError(const msgs::ErrorStatus& status)
127 {
128  return status.error != msgs::ErrorStatus::NO_ERROR;
129 }
130 
131 bool hasWarning(const msgs::ErrorStatus& status)
132 {
133  return status.warning != msgs::ErrorStatus::NO_WARNING;
134 }
135 
136 bool isOk(const msgs::ErrorStatus& status)
137 {
138  return !hasError(status) && !hasWarning(status);
139 }
140 
141 std::string toString(const msgs::ErrorStatus& error_status)
142 {
143  std::string msg;
144 
145  if (error_status.error_msg.size())
146  msg = error_status.error_msg;
147 
148  if (error_status.warning_msg.size())
149  {
150  if (msg.size())
151  msg += "\n";
152  msg = error_status.warning_msg;
153  }
154 
155  return msg;
156 }
157 
158 std::string toString(const msgs::FootstepExecutionStatus& execution_status)
159 {
160  if (!execution_status.status)
161  return "NO_ERROR";
162 
163  std::string msg;
164 
165  if (execution_status.status & msgs::FootstepExecutionStatus::REACHED_GOAL)
166  msg += "REACHED_GOAL ";
167  if (execution_status.status & msgs::FootstepExecutionStatus::WAITING_FOR_ATLAS)
168  msg += "WAITING_FOR_ATLAS ";
169  if (execution_status.status & msgs::FootstepExecutionStatus::EXECUTING_STEP_PLAN)
170  msg += "EXECUTING_STEP_PLAN ";
171  if (execution_status.status & msgs::FootstepExecutionStatus::PREMATURE_HALT)
172  msg += "PREMATURE_HALT ";
173  if (execution_status.status & msgs::FootstepExecutionStatus::UPDATED_STEP_PLAN)
174  msg += "UPDATED_STEP_PLAN ";
175  if (execution_status.status & msgs::FootstepExecutionStatus::EMERGENCY_HALT)
176  msg += "EMERGENCY_HALT ";
177  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_UNKNOWN)
178  msg += "ERR_UNKNOWN ";
179  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_EMPTY_PLAN)
180  msg += "ERR_EMPTY_PLAN ";
181  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_INVALID_BEHAVIOR_MODE)
182  msg += "ERR_INVALID_BEHAVIOR_MODE ";
183  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_INVALID_PLAN)
184  msg += "ERR_INVALID_PLAN ";
185  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_INVALID_INCONSISTENT_INDICES)
186  msg += "ERR_INVALID_INCONSISTENT_INDICES ";
187  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_INCONSISTENT_STEP_PLAN)
188  msg += "ERR_INCONSISTENT_STEP_PLAN ";
189  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_CONTROLLER_NOT_READY)
190  msg += "ERR_CONTROLLER_NOT_READY ";
191  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_FALLEN)
192  msg += "ERR_FALLEN ";
193  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_NON_ZERO_INITIAL_STEP)
194  msg += "ERR_NON_ZERO_INITIAL_STEP ";
195  if (execution_status.status & msgs::FootstepExecutionStatus::ERR_NEXT_ERROR)
196  msg += "ERR_NEXT_ERROR ";
197 
198  return msg;
199 }
200 }
msgs::ErrorStatus ErrorStatusWarning(unsigned int warning, const std::string &context, const std::string &warning_msg, bool output=true, double throttle_rate=0.0)
#define ROS_WARN_THROTTLE(rate,...)
std::string WarningStatusCodeToString(unsigned int warning)
std::string ErrorStatusCodeToString(unsigned int error)
std::string toString(const msgs::ErrorStatus &error_status)
#define ROS_WARN(...)
#define ROS_ERROR_THROTTLE(rate,...)
msgs::ErrorStatus isConsistent(const msgs::StepPlan &result)
bool hasWarning(const msgs::ErrorStatus &status)
msgs::ErrorStatus createErrorStatus(const std::string &context, unsigned int error, const std::string &error_msg, unsigned int warning, const std::string &warning_msg, bool output=true, double throttle_rate=0.0)
msgs::ErrorStatus operator+(const msgs::ErrorStatus &lhs, const msgs::ErrorStatus &rhs)
bool isOk(const msgs::ErrorStatus &status)
msgs::ErrorStatus ErrorStatusError(unsigned int error, const std::string &context, const std::string &error_msg, bool output=true, double throttle_rate=0.0)
msgs::ErrorStatus operator+=(msgs::ErrorStatus &lhs, const msgs::ErrorStatus &rhs)
bool hasError(const msgs::ErrorStatus &status)
#define ROS_ERROR(...)


vigir_footstep_planning_msgs
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:45:25