global_footstep_planner.cpp
Go to the documentation of this file.
2 
4 {
6  : footstep_planner(footstep_planner)
7  , step_plan(new StepPlan())
8 {
9 }
10 
12  : step_plan(new StepPlan())
13 {
14 }
15 
17 {
18 }
19 
21 {
22  if (!footstep_planner)
23  footstep_planner.reset(new FootstepPlanner(nh));
24 
25  // start service clients
26  generate_feet_pose_client = nh.serviceClient<msgs::GenerateFeetPoseService>("generate_feet_pose");
27 }
28 
29 msgs::ErrorStatus GlobalFootstepPlanner::setStepPlan(const msgs::StepPlan& step_plan)
30 {
31  return this->step_plan->fromMsg(step_plan);
32 }
33 
34 msgs::ErrorStatus GlobalFootstepPlanner::getStepPlan(msgs::StepPlan& step_plan) const
35 {
36  return this->step_plan->toMsg(step_plan);
37 }
38 
39 msgs::ErrorStatus GlobalFootstepPlanner::appendStepPlan(const std::vector<msgs::StepPlan>& step_plans, msgs::StepPlan& result) const
40 {
41  msgs::ErrorStatus status;
42  StepPlan temp_step_plan;
43 
44  // append all plans
45  for (std::vector<msgs::StepPlan>::const_iterator itr = step_plans.begin(); itr != step_plans.end() && status.error == msgs::ErrorStatus::NO_ERROR; itr++)
46  status += temp_step_plan.appendStepPlan(*itr);
47 
48  status += temp_step_plan.toMsg(result);
49  return status;
50 }
51 
52 msgs::ErrorStatus GlobalFootstepPlanner::stitchStepPlan(const std::vector<msgs::StepPlan>& step_plans, msgs::StepPlan &result) const
53 {
54  msgs::ErrorStatus status;
55  StepPlan temp_step_plan;
56 
57  // stitch all plans
58  for (std::vector<msgs::StepPlan>::const_iterator itr = step_plans.begin(); itr != step_plans.end() && status.error == msgs::ErrorStatus::NO_ERROR; itr++)
59  status += temp_step_plan.stitchStepPlan(*itr);
60 
61  status += temp_step_plan.toMsg(result);
62  return status;
63 }
64 
65 msgs::ErrorStatus GlobalFootstepPlanner::editStep(const msgs::EditStep& edit_step, const msgs::StepPlan& step_plan, std::vector<msgs::StepPlan>& result) const
66 {
67  result.clear();
68 
69  msgs::ErrorStatus status;
70  StepPlan temp_step_plan(step_plan);
71  msgs::StepPlan temp_step_plan_msg;
72 
73  // dispatch edit mode
74  msgs::UpdateMode update_mode;
75  switch (edit_step.plan_mode)
76  {
77  case msgs::EditStep::EDIT_MODE_REMOVE:
78  // remove step if found
79  if (!temp_step_plan.hasStep(edit_step.step.step_index))
80  status += ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "GlobalFootstepPlanner", "editStep: Step with index " + boost::lexical_cast<std::string>(edit_step.step.step_index) + " was not found!");
81  else
82  temp_step_plan.removeStep(edit_step.step.step_index);
83  break;
84  case msgs::EditStep::EDIT_MODE_2D:
85  update_mode.mode = msgs::UpdateMode::UPDATE_MODE_Z;
86  break;
87  case msgs::EditStep::EDIT_MODE_3D:
88  update_mode.mode = msgs::UpdateMode::UPDATE_MODE_3D;
89  break;
90  case msgs::EditStep::EDIT_MODE_FULL:
91  break;
92  default:
93  status += ErrorStatusError(msgs::ErrorStatus::ERR_UNKNOWN, "GlobalFootstepPlanner", "editStep: Invalid plan mode: " + boost::lexical_cast<std::string>(edit_step.plan_mode));
94  return status;
95  }
96 
97  // update step
98  if (edit_step.plan_mode != msgs::EditStep::EDIT_MODE_REMOVE)
99  {
100  // update foot
101  msgs::Step step = edit_step.step;
102  if (update_mode.mode)
103  status += footstep_planner->updateFoot(step.foot, update_mode.mode);
104 
105  // update plan
106  status += temp_step_plan.updateStep(step);
107  status += temp_step_plan.toMsg(temp_step_plan_msg);
108 
109  // check validity of entire plan
110  footstep_planner->updateStepPlan(temp_step_plan_msg, msgs::UpdateMode::UPDATE_MODE_CHECK_VALIDITY);
111  }
112  else
113  status += temp_step_plan.toMsg(temp_step_plan_msg);
114 
115  // split plan if needed
116  if (temp_step_plan_msg.steps.size() && status.warning == msgs::ErrorStatus::WARN_INCOMPLETE_STEP_PLAN)
117  {
118  msgs::StepPlan sub_step_plan;
119  sub_step_plan.header = temp_step_plan_msg.header;
120  sub_step_plan.data = temp_step_plan_msg.data;
121 
122  // search split points
123  unsigned int next_index = temp_step_plan_msg.steps.front().step_index;
124  for (unsigned int i = 0; i < temp_step_plan_msg.steps.size(); i++)
125  {
126  msgs::Step& step = temp_step_plan_msg.steps[i];
127 
128  if (step.step_index != static_cast<int>(next_index++) || i == temp_step_plan_msg.steps.size()-1)
129  {
130  result.push_back(sub_step_plan);
131  sub_step_plan.steps.clear();
132  next_index = step.step_index+1;
133  }
134 
135  sub_step_plan.steps.push_back(step);
136  }
137  }
138  else
139  result.push_back(temp_step_plan_msg);
140 
141  return status;
142 }
143 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
msgs::ErrorStatus getStepPlan(msgs::StepPlan &result) const
msgs::ErrorStatus appendStepPlan(const std::vector< msgs::StepPlan > &step_plans, msgs::StepPlan &result) const
unsigned int step
msgs::ErrorStatus setStepPlan(const msgs::StepPlan &result)
msgs::ErrorStatus editStep(const msgs::EditStep &edit_step, const msgs::StepPlan &step_plan, std::vector< msgs::StepPlan > &result) const
msgs::ErrorStatus stitchStepPlan(const std::vector< msgs::StepPlan > &step_plans, msgs::StepPlan &result) const


vigir_global_footstep_planner
Author(s): Alexander Stumpf
autogenerated on Sun Nov 17 2019 03:30:05