global_footstep_planner_node.cpp
Go to the documentation of this file.
2 
4 {
7 {
8 }
9 
11 {
12 }
13 
15 {
16  // init basics
18 
19  // init global footstep planner
21 
22  // subscribe topics
23  edit_step_sub = nh.subscribe("edit_step", 1, &GlobalFootstepPlannerNode::editStep, this);
26 
27  // start own services
32 
33  // init action servers
34  edit_step_as = SimpleActionServer<msgs::EditStepAction>::create(nh, "edit_step", true, boost::bind(&GlobalFootstepPlannerNode::editStepAction, this, boost::ref(edit_step_as)));
35  set_step_plan_as = SimpleActionServer<msgs::SetStepPlanAction>::create(nh, "set_step_plan", true, boost::bind(&GlobalFootstepPlannerNode::setStepPlanAction, this, boost::ref(set_step_plan_as)));
36  get_step_plan_as = SimpleActionServer<msgs::GetStepPlanAction>::create(nh, "get_step_plan", true, boost::bind(&GlobalFootstepPlannerNode::getStepPlanAction, this, boost::ref(get_step_plan_as)));
37  stitch_step_plan_as = SimpleActionServer<msgs::StitchStepPlanAction>::create(nh, "stitch_step_plan", true, boost::bind(&GlobalFootstepPlannerNode::stitchStepPlanAction, this, boost::ref(stitch_step_plan_as)));
38 }
39 
40 // --- Subscriber calls ---
41 
42 void GlobalFootstepPlannerNode::editStep(const msgs::EditStepConstPtr& edit_step)
43 {
44  std::vector<msgs::StepPlan> result;
45  msgs::StepPlan step_plan;
46  global_footstep_planner->getStepPlan(step_plan); // don't need to save status here
47  msgs::ErrorStatus error_status = global_footstep_planner->editStep(*edit_step, step_plan, result);
48 
49  //step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result)));
50  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(error_status)));
51 }
52 
53 void GlobalFootstepPlannerNode::setStepPlan(const msgs::StepPlanConstPtr& step_plan)
54 {
55  msgs::ErrorStatus error_status = global_footstep_planner->setStepPlan(*step_plan);
56  msgs::StepPlan result;
57  error_status += global_footstep_planner->getStepPlan(result);
58 
59  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(error_status)));
60 }
61 
62 void GlobalFootstepPlannerNode::stitchStepPlan(const std::vector<msgs::StepPlan>& step_plans)
63 {
64  msgs::StepPlan result;
65  msgs::ErrorStatus error_status = global_footstep_planner->stitchStepPlan(step_plans, result);
66 
67  step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result)));
68  step_plan_vis_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result)));
69  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(error_status)));
70 }
71 
72 void GlobalFootstepPlannerNode::stitchStepPlan(const msgs::StepPlanConstPtr& step_plan)
73 {
74  std::vector<msgs::StepPlan> step_plans;
75 
76  msgs::StepPlan current_step_plan;
77  global_footstep_planner->getStepPlan(current_step_plan);
78  step_plans.push_back(current_step_plan);
79  step_plans.push_back(*step_plan);
80 
81  stitchStepPlan(step_plans);
82 }
83 
84 // --- Service calls ---
85 
86 bool GlobalFootstepPlannerNode::editStepService(msgs::EditStepService::Request &req, msgs::EditStepService::Response &resp)
87 {
88  resp.status = global_footstep_planner->editStep(req.edit_step, req.step_plan, resp.step_plans);
89 
90  //temp_step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(resp.step_plans)));
91  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(resp.status)));
92 
93  return true; // return always true so the message is returned
94 }
95 
96 bool GlobalFootstepPlannerNode::setStepPlanService(msgs::SetStepPlanService::Request &req, msgs::SetStepPlanService::Response &resp)
97 {
98  resp.status = global_footstep_planner->setStepPlan(req.step_plan);
99  resp.status += global_footstep_planner->getStepPlan(resp.step_plan);
100 
101  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(resp.status)));
102 
103  return true; // return always true so the message is returned
104 }
105 
106 bool GlobalFootstepPlannerNode::getStepPlanService(msgs::GetStepPlanService::Request &req, msgs::GetStepPlanService::Response &resp)
107 {
108  resp.status = global_footstep_planner->getStepPlan(resp.step_plan);
109  return true; // return always true so the message is returned
110 }
111 
112 bool GlobalFootstepPlannerNode::stitchStepPlanService(msgs::StitchStepPlanService::Request &req, msgs::StitchStepPlanService::Response &resp)
113 {
114  resp.status = global_footstep_planner->stitchStepPlan(req.step_plans, resp.step_plan);
115 
116  temp_step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(resp.step_plan)));
117  step_plan_vis_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(resp.step_plan)));
118  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(resp.status)));
119 
120  return true; // return always true so the message is returned
121 }
122 
123 //--- action server calls ---
124 
125 void GlobalFootstepPlannerNode::editStepAction(SimpleActionServer<msgs::EditStepAction>::Ptr& as)
126 {
127  const msgs::EditStepGoalConstPtr& goal(as->acceptNewGoal());
128 
129  // check if new goal was preempted in the meantime
130  if (as->isPreemptRequested())
131  {
132  as->setPreempted();
133  return;
134  }
135 
136  msgs::EditStepResult result;
137  result.status = global_footstep_planner->editStep(goal->edit_step, goal->step_plan, result.step_plans);
138 
139  as->finish(result);
140  //if (result.status.error == msgs::ErrorStatus::NO_ERROR)
141  // temp_step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result.step_plan)));
142  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(result.status)));
143 }
144 
145 void GlobalFootstepPlannerNode::setStepPlanAction(SimpleActionServer<msgs::SetStepPlanAction>::Ptr& as)
146 {
147  const msgs::SetStepPlanGoalConstPtr& goal(as->acceptNewGoal());
148 
149  // check if new goal was preempted in the meantime
150  if (as->isPreemptRequested())
151  {
152  as->setPreempted();
153  return;
154  }
155 
156  msgs::SetStepPlanResult result;
157  result.status = global_footstep_planner->setStepPlan(goal->step_plan);
158  result.status += global_footstep_planner->getStepPlan(result.step_plan);
159 
160  as->finish(result);
161  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(result.status)));
162 }
163 
164 void GlobalFootstepPlannerNode::getStepPlanAction(SimpleActionServer<msgs::GetStepPlanAction>::Ptr& as)
165 {
166  as->acceptNewGoal();
167 
168  // check if new goal was preempted in the meantime
169  if (as->isPreemptRequested())
170  {
171  as->setPreempted();
172  return;
173  }
174 
175  msgs::GetStepPlanResult result;
176  result.status = global_footstep_planner->getStepPlan(result.step_plan);
177  as->setSucceeded(result, toString(result.status));
178 }
179 
180 void GlobalFootstepPlannerNode::stitchStepPlanAction(SimpleActionServer<msgs::StitchStepPlanAction>::Ptr& as)
181 {
182  const msgs::StitchStepPlanGoalConstPtr& goal(as->acceptNewGoal());
183 
184  // check if new goal was preempted in the meantime
185  if (as->isPreemptRequested())
186  {
187  as->setPreempted();
188  return;
189  }
190 
191  msgs::StitchStepPlanResult result;
192  result.status = global_footstep_planner->stitchStepPlan(goal->step_plans, result.step_plan);
193 
194  as->finish(result);
195  temp_step_plan_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result.step_plan)));
196  step_plan_vis_pub.publish(msgs::StepPlanConstPtr(new msgs::StepPlan(result.step_plan)));
197  error_status_pub.publish(msgs::ErrorStatusConstPtr(new msgs::ErrorStatus(result.status)));
198 }
199 }
200 
201 int main(int argc, char **argv)
202 {
203  ros::init(argc, argv, "vigir_global_footstep_planner");
204 
205  ros::NodeHandle nh;
206 
207  // ensure that node's services are set up in proper namespace
208  if (nh.getNamespace().size() <= 1)
209  nh = ros::NodeHandle("~");
210 
211  // init parameter and plugin manager
212  vigir_generic_params::ParameterManager::initialize(nh);
213  vigir_pluginlib::PluginManager::initialize(nh);
214 
216  globalPlannerNode.initialize(nh);
217 
218  ros::spin();
219 
220  return 0;
221 }
void setStepPlanAction(SimpleActionServer< msgs::SetStepPlanAction >::Ptr &as)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
SimpleActionServer< msgs::SetStepPlanAction >::Ptr set_step_plan_as
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
SimpleActionServer< msgs::StitchStepPlanAction >::Ptr stitch_step_plan_as
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ROSCPP_DECL void spin(Spinner &spinner)
bool stitchStepPlanService(msgs::StitchStepPlanService::Request &req, msgs::StitchStepPlanService::Response &resp)
const std::string & getNamespace() const
void editStep(const msgs::EditStepConstPtr &edit_step)
void getStepPlanAction(SimpleActionServer< msgs::GetStepPlanAction >::Ptr &as)
bool editStepService(msgs::EditStepService::Request &req, msgs::EditStepService::Response &resp)
int main(int argc, char **argv)
bool getStepPlanService(msgs::GetStepPlanService::Request &req, msgs::GetStepPlanService::Response &resp)
bool setStepPlanService(msgs::SetStepPlanService::Request &req, msgs::SetStepPlanService::Response &resp)
SimpleActionServer< msgs::EditStepAction >::Ptr edit_step_as
void setStepPlan(const msgs::StepPlanConstPtr &step_plan)
void stitchStepPlanAction(SimpleActionServer< msgs::StitchStepPlanAction >::Ptr &as)
SimpleActionServer< msgs::GetStepPlanAction >::Ptr get_step_plan_as
goal
void editStepAction(SimpleActionServer< msgs::EditStepAction >::Ptr &as)
void stitchStepPlan(const std::vector< msgs::StepPlan > &step_plans)
virtual void initialize(ros::NodeHandle &nh)


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