Go to the documentation of this file.00001 #include <vigir_pattern_generator/pattern_generator_node.h>
00002
00003 namespace vigir_footstep_planning
00004 {
00005 PatternGeneratorNode::PatternGeneratorNode(ros::NodeHandle& nh)
00006 : pattern_generator(nh)
00007 {
00008 double update_rate;
00009 nh.param("pattern_generator/update_rate", update_rate, 10.0);
00010 nh.param("pattern_generator/republish_complete_step_plan", republish_complete_step_plan, false);
00011
00012
00013 set_params_sub = nh.subscribe("pattern_generator/set_params", 1, &PatternGeneratorNode::setParams, this);
00014
00015
00016 step_plan_pub = nh.advertise<msgs::StepPlan>("step_plan", 1);
00017 step_plan_vis_pub = nh.advertise<msgs::StepPlan>("vis/step_plan", 1);
00018
00019
00020 set_params_srv = nh.advertiseService("pattern_generator/set_params", &PatternGeneratorNode::setParamsService, this);
00021
00022
00023 execute_step_plan_ac = SimpleActionClient<msgs::ExecuteStepPlanAction>::create(nh, "execute_step_plan");
00024
00025
00026 update_intervall = ros::Duration(1.0/update_rate);
00027 timer = nh.createTimer(update_intervall, &PatternGeneratorNode::update, this);
00028 }
00029
00030 PatternGeneratorNode::~PatternGeneratorNode()
00031 {
00032 }
00033
00034 void PatternGeneratorNode::setParams(const msgs::PatternGeneratorParametersConstPtr& params)
00035 {
00036 pattern_generator.setParams(*params);
00037 }
00038
00039 bool PatternGeneratorNode::setParamsService(msgs::PatternGeneratorParametersService::Request& req, msgs::PatternGeneratorParametersService::Response& )
00040 {
00041 pattern_generator.setParams(req.params);
00042 return true;
00043 }
00044
00045 void PatternGeneratorNode::executeStepPlanFeedback(const msgs::ExecuteStepPlanFeedbackConstPtr& feedback)
00046 {
00047 pattern_generator.updateFirstChangeableStepIndex(feedback->first_changeable_step_index);
00048 }
00049
00050 void PatternGeneratorNode::update(const ros::TimerEvent& timer)
00051 {
00052 pattern_generator.update(timer);
00053
00054 if (!pattern_generator.hasNewSteps())
00055 return;
00056
00057
00058 msgs::StepPlan complete_step_plan;
00059 pattern_generator.getCompleteStepPlan(complete_step_plan);
00060 step_plan_vis_pub.publish(complete_step_plan);
00061
00062 msgs::ExecuteStepPlanGoal goal;
00063 pattern_generator.getLastStepSequence(goal.step_plan);
00064
00065 if (republish_complete_step_plan)
00066 goal.step_plan = complete_step_plan;
00067
00068
00069 if (!pattern_generator.isSimulationMode() && execute_step_plan_ac->waitForServer(update_intervall))
00070 {
00071 execute_step_plan_ac->sendGoal(goal,
00072 SimpleActionClient<msgs::ExecuteStepPlanAction>::SimpleDoneCallback(),
00073 SimpleActionClient<msgs::ExecuteStepPlanAction>::SimpleActiveCallback(),
00074 boost::bind(&PatternGeneratorNode::executeStepPlanFeedback, this, _1));
00075 }
00076 }
00077 }
00078
00079 int main(int argc, char **argv)
00080 {
00081 ros::init(argc, argv, "vigir_pattern_generator");
00082 ros::NodeHandle nh;
00083 vigir_footstep_planning::PatternGeneratorNode patternGeneratorNode(nh);
00084 ros::spin();
00085
00086 return 0;
00087 }