wam_move_arm_alg_node.cpp
Go to the documentation of this file.
00001 #include "wam_move_arm_alg_node.h"
00002 
00003 WamMoveArmAlgNode::WamMoveArmAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<WamMoveArmAlgorithm>(),
00005   has_move_arm_feedback(false),
00006   move_arm_aserver_(public_node_handle_, "move_arm"),
00007   syn_move_arm_client_("syn_move_arm", true)
00008 {
00009   //init class attributes if necessary
00010   //this->loop_rate_ = 2;//in [Hz]
00011 
00012   // [init publishers]
00013   
00014   // [init subscribers]
00015   
00016   // [init services]
00017   
00018   // [init clients]
00019   
00020   // [init action servers]
00021   move_arm_aserver_.registerStartCallback(boost::bind(&WamMoveArmAlgNode::move_armStartCallback, this, _1)); 
00022   move_arm_aserver_.registerStopCallback(boost::bind(&WamMoveArmAlgNode::move_armStopCallback, this)); 
00023   move_arm_aserver_.registerIsFinishedCallback(boost::bind(&WamMoveArmAlgNode::move_armIsFinishedCallback, this)); 
00024   move_arm_aserver_.registerHasSucceedCallback(boost::bind(&WamMoveArmAlgNode::move_armHasSucceedCallback, this)); 
00025   move_arm_aserver_.registerGetResultCallback(boost::bind(&WamMoveArmAlgNode::move_armGetResultCallback, this, _1)); 
00026   move_arm_aserver_.registerGetFeedbackCallback(boost::bind(&WamMoveArmAlgNode::move_armGetFeedbackCallback, this, _1)); 
00027   move_arm_aserver_.start();
00028 
00029   private_node_handle_.param<double>("tool_x", this->alg_.tool_x, 0.0);
00030   private_node_handle_.param<double>("tool_y", this->alg_.tool_y, 0.0);
00031   private_node_handle_.param<double>("tool_z", this->alg_.tool_z, 0.0);
00032 
00033   // [init action clients]
00034 }
00035 
00036 WamMoveArmAlgNode::~WamMoveArmAlgNode(void)
00037 {
00038   // [free dynamic memory]
00039 }
00040 
00041 void WamMoveArmAlgNode::mainNodeThread(void)
00042 {
00043   // [fill msg structures]
00044   
00045   // [fill srv structure and make request to the server]
00046   
00047   // [fill action structure and make request to the action server]
00048   //syn_move_armMakeActionRequest();
00049   //clienteMakeActionRequest();
00050 
00051   // [publish messages]
00052 }
00053 
00054 /*  [subscriber callbacks] */
00055 
00056 /*  [service callbacks] */
00057 
00058 /*  [action callbacks] */
00059 
00060 void WamMoveArmAlgNode::syn_move_armDone(const actionlib::SimpleClientGoalState& state,  const arm_navigation_msgs::MoveArmResultConstPtr& result) 
00061 { 
00062   ROS_INFO("WamMoveArmAlgNode::syn_move_armDone: %s", state.toString().c_str()); 
00063 
00064   error_code_move_arm=result->error_code;
00065   contact_information_move_arm=result->contacts;
00066   state_move_arm_goal=state.toString();
00067   //copy & work with requested result 
00068 } 
00069 
00070 void WamMoveArmAlgNode::syn_move_armActive() 
00071 { 
00072   //ROS_INFO("WamMoveArmAlgNode::syn_move_armActive: Goal just went active!"); 
00073 } 
00074 
00075 void WamMoveArmAlgNode::syn_move_armFeedback(const arm_navigation_msgs::MoveArmFeedbackConstPtr& feedback) 
00076 { 
00077   //ROS_INFO_STREAM("WamMoveArmAlgNode::syn_move_armFeedback: Got Feedback!"<<feedback->state); 
00078   bool feedback_is_ok = true; 
00079 
00080   //analyze feedback 
00081   //my_var = feedback->var; 
00082   has_move_arm_feedback = true;
00083   state_move_arm_feedback = feedback->state;
00084   time_move_arm_feedback = feedback->time_to_completion;
00085   //if feedback is not what expected, cancel requested goal 
00086   if( !feedback_is_ok ) 
00087   { 
00088     syn_move_arm_client_.cancelGoal(); 
00089     ROS_INFO("WamMoveArmAlgNode::syn_move_armFeedback: Cancelling Action!"); 
00090   } 
00091   else 
00092     move_feedback.time_to_completion = feedback->time_to_completion;
00093 }
00094 void WamMoveArmAlgNode::syn_move_armMakeActionRequest(const arm_navigation_msgs::MoveArmGoal& goal) 
00095 { 
00096   ROS_INFO("WamMoveArmAlgNode::syn_move_armMakeActionRequest: Starting New Request!"); 
00097 
00098   //wait for the action server to start 
00099   //will wait for infinite time 
00100   syn_move_arm_client_.waitForServer();  
00101   ROS_INFO("WamMoveArmAlgNode::syn_move_armMakeActionRequest: Server is Available!"); 
00102         
00103   //send a goal to the action 
00104   syn_move_arm_goal_ = goal; 
00105   syn_move_arm_client_.sendGoal(syn_move_arm_goal_, 
00106               boost::bind(&WamMoveArmAlgNode::syn_move_armDone,     this, _1, _2), 
00107               boost::bind(&WamMoveArmAlgNode::syn_move_armActive,   this), 
00108               boost::bind(&WamMoveArmAlgNode::syn_move_armFeedback, this, _1)); 
00109   ROS_INFO("WamMoveArmAlgNode::syn_move_armMakeActionRequest: Goal Sent. Wait for Result!"); 
00110 }
00111 void WamMoveArmAlgNode::move_armStartCallback(const arm_navigation_msgs::MoveArmGoalConstPtr& goal)
00112 {   
00113         move_feedback.state="PENDING";
00114     alg_.lock(); 
00115     arm_navigation_msgs::MoveArmGoal mov = *goal;
00116     this->alg_.reconfigure(mov);
00117     syn_move_armMakeActionRequest(mov);    
00118     alg_.unlock(); 
00119 } 
00120 void WamMoveArmAlgNode::move_armStopCallback(void) 
00121 { 
00122   alg_.lock(); 
00123     //stop action 
00124     arm_navigation_msgs::MoveArmGoal empty;
00125     syn_move_armMakeActionRequest(empty);
00126   alg_.unlock(); 
00127 } 
00128 bool WamMoveArmAlgNode::move_armIsFinishedCallback(void) 
00129 { 
00130   bool ret = false; 
00131 
00132   alg_.lock(); 
00133     //if action has finish for any reason 
00134    if ( (state_move_arm_goal.compare("SUCCEEDED") == 0) ||
00135                 (state_move_arm_goal.compare("LOST") == 0) ||
00136                 (state_move_arm_goal.compare("ABORTED")== 0))
00137                 {
00138                         ret = true; 
00139                         has_move_arm_feedback=false;
00140                 }
00141   alg_.unlock(); 
00142 
00143   return ret; 
00144 } 
00145 
00146 bool WamMoveArmAlgNode::move_armHasSucceedCallback(void) 
00147 { 
00148   bool ret = false; 
00149 
00150   alg_.lock(); 
00151     //if goal was accomplished 
00152     if( state_move_arm_goal.compare("SUCCEEDED") == 0) ret=true;
00153   alg_.unlock(); 
00154 
00155   return ret; 
00156 } 
00157 
00158 void WamMoveArmAlgNode::move_armGetResultCallback(arm_navigation_msgs::MoveArmResultPtr& result) 
00159 { 
00160   alg_.lock(); 
00161     //update result data to be sent to client 
00162     (*result).error_code=error_code_move_arm;
00163     (*result).contacts=contact_information_move_arm;
00164     //result->data = data; 
00165   alg_.unlock(); 
00166 } 
00167 
00168 void WamMoveArmAlgNode::move_armGetFeedbackCallback(arm_navigation_msgs::MoveArmFeedbackPtr& feedback) 
00169 { 
00170   alg_.lock(); 
00171     //keep track of feedback 
00172     if(has_move_arm_feedback)
00173     {
00174                 (*feedback).state=state_move_arm_feedback;
00175                 (*feedback).time_to_completion=time_move_arm_feedback;          
00176         }
00177         else
00178         {
00179                 (*feedback).state="WAIT FOR RESULT";
00180         }
00181     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00182   alg_.unlock(); 
00183 }
00184 
00185 void WamMoveArmAlgNode::node_config_update(Config &config, uint32_t level)
00186 {
00187   this->alg_.lock();
00188 
00189   this->alg_.unlock();
00190 }
00191 
00192 void WamMoveArmAlgNode::addNodeDiagnostics(void)
00193 {
00194 }
00195 /* main function */
00196 int main(int argc,char *argv[])
00197 {
00198   return algorithm_base::main<WamMoveArmAlgNode>(argc, argv, "wam_move_arm_alg_node");
00199 }


iri_wam_move_arm
Author(s): Ivan Rojas (ivan.rojas.j@gmail.com)
autogenerated on Fri Dec 6 2013 20:42:05