voice_recognition_alg_node.cpp
Go to the documentation of this file.
00001 #include "voice_recognition_alg_node.h"
00002 
00003 VoiceRecognitionAlgNode::VoiceRecognitionAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<VoiceRecognitionAlgorithm>(),
00005   voice_recognition_aserver_(public_node_handle_, "voice_recognition")
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009   ros::NodeHandle private_node_handle("~");
00010   private_node_handle.param<std::string>("filePath", filePath_, "");
00011   this->alg_.setFilePath(filePath_);
00012   this->start_=false;
00013   this->done_=false;
00014   this->alg_.initialize();
00015 
00016   // [init publishers]
00017   
00018   // [init subscribers]
00019   
00020   // [init services]
00021   
00022   // [init clients]
00023   
00024   // [init action servers]
00025   voice_recognition_aserver_.registerStartCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionStartCallback, this, _1)); 
00026   voice_recognition_aserver_.registerStopCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionStopCallback, this)); 
00027   voice_recognition_aserver_.registerIsFinishedCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionIsFinishedCallback, this)); 
00028   voice_recognition_aserver_.registerHasSucceedCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionHasSucceedCallback, this)); 
00029   voice_recognition_aserver_.registerGetResultCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionGetResultCallback, this, _1)); 
00030   voice_recognition_aserver_.registerGetFeedbackCallback(boost::bind(&VoiceRecognitionAlgNode::voice_recognitionGetFeedbackCallback, this, _1)); 
00031   voice_recognition_aserver_.start();
00032   
00033   // [init action clients]
00034 }
00035 
00036 VoiceRecognitionAlgNode::~VoiceRecognitionAlgNode(void)
00037 {
00038   // [free dynamic memory]
00039   this->alg_.finalize();
00040 }
00041 
00042 void VoiceRecognitionAlgNode::mainNodeThread(void)
00043 {
00044   if(this->start_)
00045   {
00046     this->answer_ = this->alg_.iteration();
00047     this->done_=true;
00048     this->start_=false;
00049   }
00050   // [fill msg structures]
00051   
00052   // [fill srv structure and make request to the server]
00053   
00054   // [fill action structure and make request to the action server]
00055 
00056   // [publish messages]
00057 }
00058 
00059 /*  [subscriber callbacks] */
00060 
00061 /*  [service callbacks] */
00062 
00063 /*  [action callbacks] */
00064 void VoiceRecognitionAlgNode::voice_recognitionStartCallback(const iri_perception_msgs::voiceRecognitionGoalConstPtr& goal)
00065 { 
00066   ROS_INFO("voice_recognitionStartCallback");
00067   alg_.lock(); 
00068     //check goal 
00069     //execute goal
00070     startTask();
00071     this->start_=true;
00072   alg_.unlock(); 
00073 } 
00074 
00075 void VoiceRecognitionAlgNode::voice_recognitionStopCallback(void) 
00076 {
00077   ROS_INFO("voice_recognitionStopCallback");
00078   alg_.lock(); 
00079     //stop action
00080     stopTask();
00081     this->start_=false;
00082   alg_.unlock(); 
00083 } 
00084 
00085 bool VoiceRecognitionAlgNode::voice_recognitionIsFinishedCallback(void) 
00086 {
00087   //ROS_INFO("voice_recognitionIsFinishedCallback");
00088   bool ret = false; 
00089 
00090   alg_.lock(); 
00091     //if action has finish for any reason
00092      if( this->done_ || !this->start_)
00093      {
00094        ret = true;
00095      }
00096   alg_.unlock(); 
00097 
00098   return ret; 
00099 } 
00100 
00101 bool VoiceRecognitionAlgNode::voice_recognitionHasSucceedCallback(void) 
00102 { 
00103   ROS_INFO("voice_recognitionHasSucceedCallback");
00104   bool ret = false; 
00105 
00106   alg_.lock(); 
00107     //if goal was accomplished
00108     //if( (this->alg_.answerCode_ != 0 ) && this->status_==0)
00109     if(this->done_)
00110     {
00111       ret = true;
00112       this->done_=false;
00113     }
00114   alg_.unlock(); 
00115 
00116   return ret; 
00117 } 
00118 
00119 void VoiceRecognitionAlgNode::voice_recognitionGetResultCallback(iri_perception_msgs::voiceRecognitionResultPtr& result) 
00120 {
00121   ROS_INFO("voice_recognitionGetResultCallback");
00122   alg_.lock(); 
00123     //update result data to be sent to client 
00124     //result->data = data;
00125     //Return answer string and related int code
00126     result->answer = this->answer_;
00127     this->answer_.clear();
00128     result->code   = this->alg_.answerCode_;
00129     this->alg_.answerCode_ = 0;
00130     this->start_=false;
00131   alg_.unlock(); 
00132 } 
00133 
00134 void VoiceRecognitionAlgNode::voice_recognitionGetFeedbackCallback(iri_perception_msgs::voiceRecognitionFeedbackPtr& feedback) 
00135 {
00136   //ROS_INFO("voice_recognitionGetFeedbackCallback");
00137   alg_.lock(); 
00138     //keep track of feedback 
00139     //ROS_INFO("feedback: %s", feedback->data.c_str());
00140     //Track status int
00141     this->status_ = getStatus();
00142     feedback->status = this->status_;
00143     //feedback->noise  = getNoise();
00144   alg_.unlock(); 
00145 }
00146 
00147 /*  [action requests] */
00148 
00149 void VoiceRecognitionAlgNode::node_config_update(Config &config, uint32_t level)
00150 {
00151   this->alg_.lock();
00152 
00153   this->alg_.unlock();
00154 }
00155 
00156 void VoiceRecognitionAlgNode::addNodeDiagnostics(void)
00157 {
00158 }
00159 
00160 /* main function */
00161 int main(int argc,char *argv[])
00162 {
00163   return algorithm_base::main<VoiceRecognitionAlgNode>(argc, argv, "voice_recognition_alg_node");
00164 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


iri_voice_recognition
Author(s): fherrero
autogenerated on Mon Jan 14 2013 13:02:57