iri_oa_client_alg_node.cpp
Go to the documentation of this file.
00001 #include "iri_oa_client_alg_node.h"
00002 
00003 IriOAClientAlgNode::IriOAClientAlgNode(void) :
00004   MoveBase_client_("MoveBase", true)
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   // [init publishers]
00010   
00011   // [init subscribers]
00012   nav_goal_subscriber_  = public_node_handle_.subscribe("nav_goal", 100, &IriOAClientAlgNode::nav_goal_callback, this);
00013   
00014   // [init services]
00015   
00016   // [init clients]
00017   
00018   // [init action servers]
00019   
00020   // [init action clients]
00021 }
00022 
00023 IriOAClientAlgNode::~IriOAClientAlgNode(void)
00024 {
00025   // [free dynamic memory]
00026 }
00027 
00028 void IriOAClientAlgNode::mainNodeThread(void)
00029 {
00030   // [fill msg structures]
00031   
00032   // [fill srv structure and make request to the server]
00033   
00034   // [fill action structure and make request to the action server]
00035 
00036   // [publish messages]
00037 }
00038 
00039 /*  [subscriber callbacks] */
00040 void IriOAClientAlgNode::nav_goal_callback(const geometry_msgs::PoseStamped::ConstPtr& msg) 
00041 { 
00042   ROS_INFO("NoCollisionAlgNode::nav_goal_callback: New Message Received"); 
00043 
00044   //use appropiate mutex to shared variables if necessary 
00045   alg_.lock(); 
00046 
00047     ROS_INFO("goal_reqs_=%d frame_id=%s pose=(%f,%f,%f)",
00048              msg->header.seq, msg->header.frame_id.c_str(),
00049              msg->pose.position.x, msg->pose.position.y, msg->pose.position.z);
00050     
00051     MoveBaseMakeActionRequest(*msg);
00052 
00053   //unlock previously blocked shared variables 
00054   alg_.unlock();
00055 }
00056 
00057 /*  [service callbacks] */
00058 
00059 /*  [action callbacks] */
00060 void IriOAClientAlgNode::MoveBaseDone(const actionlib::SimpleClientGoalState& state,  const move_base_msgs::MoveBaseResultConstPtr& result) 
00061 { 
00062   ROS_INFO("IriOAClientAlgNode::MoveBaseDone: Goal Achieved!"); 
00063   ROS_INFO("IriOAClientAlgNode::MoveBaseDone: %s", state.toString().c_str()); 
00064 
00065   //copy & work with requested result 
00066 } 
00067 
00068 void IriOAClientAlgNode::MoveBaseActive(void) 
00069 { 
00070   ROS_INFO("IriOAClientAlgNode::MoveBaseActive: Goal just went active!"); 
00071 } 
00072 
00073 void IriOAClientAlgNode::MoveBaseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback) 
00074 { 
00075 //   ROS_INFO("IriOAClientAlgNode::MoveBaseFeedback: Got Feedback!"); 
00076 
00077   //analyze feedback 
00078   ROS_INFO("IriOAClientAlgNode::MoveBaseFeedback: pose=(%f, %f)", 
00079            feedback->base_position.pose.position.x, 
00080            feedback->base_position.pose.position.y);
00081 
00082   //if feedback is not what expected, cancel requested goal 
00083 //   if( !feedback_is_ok ) 
00084 //   { 
00085 //     MoveBase_client_.cancelGoal(); 
00086 //     ROS_INFO("HrengagementAlgNode::MoveBaseFeedback: Cancelling Action!"); 
00087 //   } 
00088 }
00089 
00090 /*  [action requests] */
00091 void IriOAClientAlgNode::MoveBaseMakeActionRequest(const geometry_msgs::PoseStamped & new_goal) 
00092 { 
00093   ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Starting New Request!"); 
00094 
00095   //wait for the action server to start 
00096   //will wait for infinite time 
00097   ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Waiting for Server..."); 
00098   MoveBase_client_.waitForServer();
00099   ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Server is Available!"); 
00100 
00101   //set goal
00102   move_base_msgs::MoveBaseGoal goal;
00103   
00104   goal.target_pose.header = new_goal.header;
00105   goal.target_pose.pose   = new_goal.pose;
00106 
00107   ROS_INFO("[%d] - NEW goal=(%f, %f, %f)", goal.target_pose.header.seq,
00108                                            goal.target_pose.pose.position.x,
00109                                            goal.target_pose.pose.position.y, 
00110                                            goal.target_pose.pose.position.z);
00111   
00112   //send a goal to the action 
00113   MoveBase_client_.sendGoal(goal, 
00114               boost::bind(&IriOAClientAlgNode::MoveBaseDone,     this, _1, _2), 
00115               boost::bind(&IriOAClientAlgNode::MoveBaseActive,   this), 
00116               boost::bind(&IriOAClientAlgNode::MoveBaseFeedback, this, _1)); 
00117   ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Goal Sent. Wait for Result!"); 
00118   
00119   // wait for the action to return 
00120 /*  float server_timeout = 100.f; //in [secs] 
00121   bool finished_before_timeout = MoveBase_client_.waitForResult(ros::Duration(server_timeout)); 
00122 
00123   //if server replies in time 
00124   if (finished_before_timeout) 
00125   { 
00126     actionlib::SimpleClientGoalState state = MoveBase_client_.getState(); 
00127     ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Action Succesfully Accomplished!"); 
00128     ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: %s", state.toString().c_str()); 
00129   } 
00130   else 
00131   { 
00132     MoveBase_client_.cancelGoal(); 
00133     ROS_INFO("IriOAClientAlgNode::MoveBaseMakeActionRequest: Action did NOT finish before Timeout."); 
00134   }*/ 
00135 }
00136 
00137 void IriOAClientAlgNode::node_config_update(Config &config, uint32_t level)
00138 {
00139   this->alg_.lock();
00140 
00141   this->alg_.unlock();
00142 }
00143 
00144 void IriOAClientAlgNode::addNodeDiagnostics(void)
00145 {
00146 }
00147 
00148 /* main function */
00149 int main(int argc,char *argv[])
00150 {
00151   return algorithm_base::main<IriOAClientAlgNode>(argc, argv, "iri_oa_client_alg_node");
00152 }


iri_oa_client
Author(s):
autogenerated on Fri Dec 6 2013 23:35:27