zyonz_chlorophyll_meter_client_alg_node.cpp
Go to the documentation of this file.
00001 #include "zyonz_chlorophyll_meter_client_alg_node.h"
00002 
00003 ZyonzChlorophyllMeterClientAlgNode::ZyonzChlorophyllMeterClientAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<ZyonzChlorophyllMeterClientAlgorithm>(),
00005   take_sample_client_("take_sample", true)
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009 
00010   // [init publishers]
00011   
00012   // [init subscribers]
00013   
00014   // [init services]
00015   
00016   // [init clients]
00017   
00018   // [init action servers]
00019   
00020   // [init action clients]
00021 
00022   this->action_done=true;
00023 }
00024 
00025 ZyonzChlorophyllMeterClientAlgNode::~ZyonzChlorophyllMeterClientAlgNode(void)
00026 {
00027   // [free dynamic memory]
00028 }
00029 
00030 void ZyonzChlorophyllMeterClientAlgNode::mainNodeThread(void)
00031 {
00032   static bool close=false;
00033 
00034   // [fill msg structures]
00035   
00036   // [fill srv structure and make request to the server]
00037   
00038   // [fill action structure and make request to the action server]
00039   if(action_done)
00040   {
00041     if(close)
00042     {
00043       this->take_sample_goal_.close=true;
00044       close=false;
00045     }
00046     else
00047     {
00048       this->take_sample_goal_.close=false;
00049       close=true;
00050     }
00051     take_sampleMakeActionRequest();  
00052   }
00053 
00054   // [publish messages]
00055 }
00056 
00057 /*  [subscriber callbacks] */
00058 
00059 /*  [service callbacks] */
00060 
00061 /*  [action callbacks] */
00062 void ZyonzChlorophyllMeterClientAlgNode::take_sampleDone(const actionlib::SimpleClientGoalState& state,  const zyonz_msgs::chlorophyll_sampleResultConstPtr& result) 
00063 { 
00064   if( state.toString().compare("SUCCEEDED") == 0 ) 
00065     ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleDone: Goal Achieved!"); 
00066   else 
00067     ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleDone: %s", state.toString().c_str()); 
00068   this->action_done=true;
00069   //copy & work with requested result 
00070 } 
00071 
00072 void ZyonzChlorophyllMeterClientAlgNode::take_sampleActive() 
00073 { 
00074   //ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleActive: Goal just went active!"); 
00075 } 
00076 
00077 void ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback(const zyonz_msgs::chlorophyll_sampleFeedbackConstPtr& feedback) 
00078 { 
00079   //ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback: Got Feedback!"); 
00080 
00081   bool feedback_is_ok = true; 
00082 
00083   //analyze feedback 
00084   //my_var = feedback->var; 
00085   std::cout << "Current meter angle: " << feedback->angle << std::endl;
00086   std::cout << "Current meter effort: " << feedback->effort << std::endl;
00087 
00088   //if feedback is not what expected, cancel requested goal 
00089   if( !feedback_is_ok ) 
00090   { 
00091     take_sample_client_.cancelGoal(); 
00092     //ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback: Cancelling Action!"); 
00093   } 
00094 }
00095 
00096 /*  [action requests] */
00097 void ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest() 
00098 { 
00099   ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Starting New Request!"); 
00100 
00101   //wait for the action server to start 
00102   //will wait for infinite time 
00103   take_sample_client_.waitForServer();  
00104   ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Server is Available!"); 
00105 
00106   //send a goal to the action 
00107   //take_sample_goal_.data = my_desired_goal; 
00108   sleep(1);
00109   take_sample_client_.sendGoal(take_sample_goal_, 
00110               boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleDone,     this, _1, _2), 
00111               boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleActive,   this), 
00112               boost::bind(&ZyonzChlorophyllMeterClientAlgNode::take_sampleFeedback, this, _1)); 
00113   this->action_done=false;
00114   ROS_INFO("ZyonzChlorophyllMeterClientAlgNode::take_sampleMakeActionRequest: Goal Sent. Wait for Result!"); 
00115 }
00116 
00117 void ZyonzChlorophyllMeterClientAlgNode::node_config_update(Config &config, uint32_t level)
00118 {
00119   this->alg_.lock();
00120 
00121   this->alg_.unlock();
00122 }
00123 
00124 void ZyonzChlorophyllMeterClientAlgNode::addNodeDiagnostics(void)
00125 {
00126 }
00127 
00128 /* main function */
00129 int main(int argc,char *argv[])
00130 {
00131   return algorithm_base::main<ZyonzChlorophyllMeterClientAlgNode>(argc, argv, "zyonz_chlorophyll_meter_client_alg_node");
00132 }


zyonz_chlorophyll_meter_client
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 19:57:02