global_footstep_planner.cpp
Go to the documentation of this file.
00001 #include <vigir_global_footstep_planner/global_footstep_planner.h>
00002 
00003 namespace vigir_footstep_planning
00004 {
00005 GlobalFootstepPlanner::GlobalFootstepPlanner(FootstepPlanner::Ptr& footstep_planner)
00006   : footstep_planner(footstep_planner)
00007   , step_plan(new StepPlan())
00008 {
00009 }
00010 
00011 GlobalFootstepPlanner::GlobalFootstepPlanner()
00012   : step_plan(new StepPlan())
00013 {
00014 }
00015 
00016 GlobalFootstepPlanner::~GlobalFootstepPlanner()
00017 {
00018 }
00019 
00020 void GlobalFootstepPlanner::init(ros::NodeHandle& nh)
00021 {
00022   if (!footstep_planner)
00023     footstep_planner.reset(new FootstepPlanner(nh));
00024 
00025   // start service clients
00026   generate_feet_pose_client = nh.serviceClient<msgs::GenerateFeetPoseService>("generate_feet_pose");
00027 }
00028 
00029 msgs::ErrorStatus GlobalFootstepPlanner::setStepPlan(const msgs::StepPlan& step_plan)
00030 {
00031   return this->step_plan->fromMsg(step_plan);
00032 }
00033 
00034 msgs::ErrorStatus GlobalFootstepPlanner::getStepPlan(msgs::StepPlan& step_plan) const
00035 {
00036   return this->step_plan->toMsg(step_plan);
00037 }
00038 
00039 msgs::ErrorStatus GlobalFootstepPlanner::appendStepPlan(const std::vector<msgs::StepPlan>& step_plans, msgs::StepPlan& result) const
00040 {
00041   msgs::ErrorStatus status;
00042   StepPlan temp_step_plan;
00043 
00044   // append all plans
00045   for (std::vector<msgs::StepPlan>::const_iterator itr = step_plans.begin(); itr != step_plans.end() && status.error == msgs::ErrorStatus::NO_ERROR; itr++)
00046     status += temp_step_plan.appendStepPlan(*itr);
00047 
00048   status += temp_step_plan.toMsg(result);
00049   return status;
00050 }
00051 
00052 msgs::ErrorStatus GlobalFootstepPlanner::stitchStepPlan(const std::vector<msgs::StepPlan>& step_plans, msgs::StepPlan &result) const
00053 {
00054   msgs::ErrorStatus status;
00055   StepPlan temp_step_plan;
00056 
00057   // stitch all plans
00058   for (std::vector<msgs::StepPlan>::const_iterator itr = step_plans.begin(); itr != step_plans.end() && status.error == msgs::ErrorStatus::NO_ERROR; itr++)
00059     status += temp_step_plan.stitchStepPlan(*itr);
00060 
00061   status += temp_step_plan.toMsg(result);
00062   return status;
00063 }
00064 
00065 msgs::ErrorStatus GlobalFootstepPlanner::editStep(const msgs::EditStep& edit_step, const msgs::StepPlan& step_plan, std::vector<msgs::StepPlan>& result) const
00066 {
00067   result.clear();
00068 
00069   msgs::ErrorStatus status;
00070   StepPlan temp_step_plan(step_plan);
00071   msgs::StepPlan temp_step_plan_msg;
00072 
00073   // dispatch edit mode
00074   msgs::UpdateMode update_mode;
00075   switch (edit_step.plan_mode)
00076   {
00077     case msgs::EditStep::EDIT_MODE_REMOVE:
00078       // remove step if found
00079       if (!temp_step_plan.hasStep(edit_step.step.step_index))
00080         status += ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "GlobalFootstepPlanner", "editStep: Step with index " + boost::lexical_cast<std::string>(edit_step.step.step_index) + " was not found!");
00081       else
00082         temp_step_plan.removeStep(edit_step.step.step_index);
00083       break;
00084     case msgs::EditStep::EDIT_MODE_2D:
00085       update_mode.mode = msgs::UpdateMode::UPDATE_MODE_Z;
00086       break;
00087     case msgs::EditStep::EDIT_MODE_3D:
00088       update_mode.mode = msgs::UpdateMode::UPDATE_MODE_3D;
00089       break;
00090     case msgs::EditStep::EDIT_MODE_FULL:
00091       break;
00092     default:
00093       status += ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "GlobalFootstepPlanner", "editStep: Invalid plan mode: " + boost::lexical_cast<std::string>(edit_step.plan_mode));
00094       return status;
00095   }
00096 
00097   // update step
00098   if (edit_step.plan_mode != msgs::EditStep::EDIT_MODE_REMOVE)
00099   {
00100     // update foot
00101     msgs::Step step = edit_step.step;
00102     if (update_mode.mode)
00103       status += footstep_planner->updateFoot(step.foot, update_mode.mode);
00104 
00105     // update plan
00106     status += temp_step_plan.updateStep(step);
00107     status += temp_step_plan.toMsg(temp_step_plan_msg);
00108 
00109     // check validity of entire plan
00110     footstep_planner->updateStepPlan(temp_step_plan_msg, msgs::UpdateMode::UPDATE_MODE_CHECK_VALIDITY);
00111   }
00112   else
00113     status += temp_step_plan.toMsg(temp_step_plan_msg);
00114 
00115   // split plan if needed
00116   if (temp_step_plan_msg.steps.size() && status.warning == msgs::ErrorStatus::WARN_INCOMPLETE_STEP_PLAN)
00117   {
00118     msgs::StepPlan sub_step_plan;
00119     sub_step_plan.header = temp_step_plan_msg.header;
00120     sub_step_plan.data = temp_step_plan_msg.data;
00121 
00122     // search split points
00123     unsigned int next_index = temp_step_plan_msg.steps.front().step_index;
00124     for (unsigned int i = 0; i < temp_step_plan_msg.steps.size(); i++)
00125     {
00126       msgs::Step& step = temp_step_plan_msg.steps[i];
00127 
00128       if (step.step_index != static_cast<int>(next_index++) || i == temp_step_plan_msg.steps.size()-1)
00129       {
00130         result.push_back(sub_step_plan);
00131         sub_step_plan.steps.clear();
00132         next_index = step.step_index+1;
00133       }
00134 
00135       sub_step_plan.steps.push_back(step);
00136     }
00137   }
00138   else
00139     result.push_back(temp_step_plan_msg);
00140 
00141   return status;
00142 }
00143 }


vigir_global_footstep_planner
Author(s): Alexander Stumpf
autogenerated on Fri Apr 7 2017 02:59:49