60 return steps.begin()->second.step_index;
70 return steps.rbegin()->second.step_index;
85 bool StepPlan::getStep(msgs::Step& step,
const msgs::StepPlan& step_plan,
unsigned int step_index)
87 for (std::vector<msgs::Step>::const_iterator itr = step_plan.steps.begin(); itr != step_plan.steps.end(); itr++)
89 const msgs::Step&
s = *itr;
90 if (s.step_index == step_index)
107 std::map<unsigned int, msgs::Step>::const_iterator itr =
steps.begin();
108 std::advance(itr, position);
122 step =
steps.begin()->second;
135 step =
steps.rbegin()->second;
148 step =
steps.begin()->second;
163 steps.erase(step_index);
179 from_step_index = std::max(from_step_index,
steps.begin()->first);
180 if (from_step_index > to_step_index)
183 std::map<unsigned int, msgs::Step>::iterator start_itr =
steps.find(from_step_index);
184 std::map<unsigned int, msgs::Step>::iterator end_itr = to_step_index >= 0 ?
steps.find(to_step_index+1) :
steps.end();
185 steps.erase(start_itr, end_itr);
194 if (status.error != msgs::ErrorStatus::NO_ERROR)
196 else if (step_plan.steps.empty())
197 return ErrorStatusWarning(msgs::ErrorStatus::WARN_INVALID_STEP_PLAN,
"appendStepPlan",
"Got empty plan!");
201 if (step_plan.header.frame_id !=
header.frame_id)
202 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"appendStepPlan",
"Frame id mismatch of plans: " +
header.frame_id +
" vs. " + step_plan.header.frame_id);
203 else if (
mode != step_plan.mode)
204 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"appendStepPlan",
"Plans have different modes!");
215 if (step_plan.steps.empty())
216 return ErrorStatusWarning(msgs::ErrorStatus::WARN_INVALID_STEP_PLAN,
"updateStepPlan",
"Got empty plan!");
220 if (step_plan.header.frame_id !=
header.frame_id)
221 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"updateStepPlan",
"Frame id mismatch of plans: " +
header.frame_id +
" vs. " + step_plan.header.frame_id);
222 else if (
mode != step_plan.mode)
223 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"updateStepPlan",
"Plans have different modes!");
236 if (status.error != msgs::ErrorStatus::NO_ERROR)
238 else if (step_plan.steps.empty())
239 return ErrorStatusWarning(msgs::ErrorStatus::WARN_INVALID_STEP_PLAN,
"stitchStepPlan",
"Got empty plan!");
243 if (step_plan.header.frame_id !=
header.frame_id)
244 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"stitchStepPlan",
"Frame id mismatch of plans: " +
header.frame_id +
" vs. " + step_plan.header.frame_id);
245 else if (
mode != step_plan.mode)
246 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"stitchStepPlan",
"Plans have different modes!");
247 else if (step_index > 0 && (
steps.empty() || step_index >
steps.rbegin()->second.step_index))
248 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"stitchStepPlan",
"Can't stitch as requested step index is not in current step plan!");
266 return ref_target * ref_current.
inverse();
275 pose = transform * pose;
279 pose = transform * pose;
284 pose = transform * pose;
288 pose = transform * pose;
292 for (std::vector<msgs::Step>::iterator itr = step_plan.steps.begin(); itr != step_plan.steps.end(); itr++)
294 msgs::Step&
step = *itr;
297 pose = transform * pose;
304 header = std_msgs::Header();
305 start = msgs::Feet();
314 return steps.empty();
329 std::map<unsigned int, msgs::Step>::const_iterator itr =
steps.find(step_index);
330 if (itr !=
steps.end())
343 else if (step.header.frame_id !=
header.frame_id)
344 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"insertStep",
"Frame id mismatch! Plan: " +
header.frame_id +
" vs. step: " + step.header.frame_id);
347 steps[step.step_index] = step;
349 return msgs::ErrorStatus();
357 else if (step.header.frame_id !=
header.frame_id)
358 return ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN,
"updateStep",
"Frame id mismatch! Plan: " +
header.frame_id +
" vs. step: " + step.header.frame_id);
361 bool modified(
_hasStep(step.step_index));
364 steps[step.step_index] = step;
365 steps[step.step_index].modified = modified;
367 return msgs::ErrorStatus();
377 header = step_plan.header;
378 mode = step_plan.mode;
379 data = step_plan.data;
382 step_index =
steps.rbegin()->second.step_index + 1;
385 msgs::ErrorStatus status;
386 for (msgs::Step
step : step_plan.steps)
388 step.step_index = step_index++;
391 if (status.error != msgs::ErrorStatus::NO_ERROR)
403 header = step_plan.header;
404 mode = step_plan.mode;
405 data = step_plan.data;
409 msgs::ErrorStatus status;
410 for (std::vector<msgs::Step>::const_iterator itr = step_plan.steps.begin(); itr != step_plan.steps.end(); itr++)
414 if (status.error != msgs::ErrorStatus::NO_ERROR)
423 if (step_plan.steps.empty())
424 return msgs::ErrorStatus();
430 msgs::Step last_current_step;
431 msgs::Step first_new_step;
435 last_current_step =
steps.rbegin()->second;
436 first_new_step = step_plan.steps.front();
440 if (!
_getStep(last_current_step, step_index))
441 return ErrorStatusError(msgs::ErrorStatus::ERR_INVALID_STEP,
"stitchStepPlan",
"Current step plan doesn't contain step index " + boost::lexical_cast<std::string>(step_index) +
"!");
443 if (!
getStep(first_new_step, step_plan, step_index))
444 return ErrorStatusError(msgs::ErrorStatus::ERR_INVALID_STEP,
"stitchStepPlan",
"Input step plan doesn't contain step index " + boost::lexical_cast<std::string>(step_index) +
"!");
448 if (last_current_step.foot.foot_index != first_new_step.foot.foot_index)
449 return ErrorStatusError(msgs::ErrorStatus::ERR_INCONSISTENT_STEP_PLAN,
"stitchStepPlan", std::string(
"First foot ") +
450 (first_new_step.foot.foot_index == msgs::Foot::RIGHT ? std::string(
"(RIGHT)") : std::string(
"(LEFT)")) + std::string(
" of input step plan doesn't match ") +
451 (last_current_step.foot.foot_index == msgs::Foot::RIGHT ? std::string(
"(RIGHT)") : std::string(
"(LEFT)")) + std::string(
" last foot of current step plan."));
454 msgs::StepPlan step_plan_transformed = step_plan;
455 step_plan_transformed.steps.clear();
457 for (msgs::Step
step : step_plan.steps)
459 if (step.step_index >= step_index)
460 step_plan_transformed.steps.push_back(step);
468 unsigned int max_step_index = step_plan_transformed.steps.back().step_index;
469 for (std::map<unsigned int, msgs::Step>::iterator itr =
steps.begin(); itr !=
steps.end();)
471 if (itr->second.step_index > max_step_index)
478 step_plan_transformed.steps.erase(step_plan_transformed.steps.begin());
490 if (status.error != msgs::ErrorStatus::NO_ERROR)
496 header = step_plan.header;
498 start = step_plan.start;
499 goal = step_plan.goal;
501 mode = step_plan.mode;
502 data = step_plan.data;
506 for (
unsigned int i = 0u; i < step_plan.steps.size(); i++)
510 if (status.error != msgs::ErrorStatus::NO_ERROR)
521 msgs::ErrorStatus status;
524 step_plan.header =
header;
526 step_plan.start =
start;
527 step_plan.goal =
goal;
529 step_plan.steps.clear();
530 for (std::map<unsigned int, msgs::Step>::const_iterator itr =
steps.begin(); itr !=
steps.end(); itr++)
531 step_plan.steps.push_back(itr->second);
533 step_plan.mode =
mode;
534 step_plan.data =
data;
static void poseMsgToTF(const geometry_msgs::Pose &msg, Pose &bt)
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)