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
00008
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
00017
00018
00019
00020
00021
00022
00023
00024
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
00034 }
00035
00036 VoiceRecognitionAlgNode::~VoiceRecognitionAlgNode(void)
00037 {
00038
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
00051
00052
00053
00054
00055
00056
00057 }
00058
00059
00060
00061
00062
00063
00064 void VoiceRecognitionAlgNode::voice_recognitionStartCallback(const iri_perception_msgs::voiceRecognitionGoalConstPtr& goal)
00065 {
00066 ROS_INFO("voice_recognitionStartCallback");
00067 alg_.lock();
00068
00069
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
00080 stopTask();
00081 this->start_=false;
00082 alg_.unlock();
00083 }
00084
00085 bool VoiceRecognitionAlgNode::voice_recognitionIsFinishedCallback(void)
00086 {
00087
00088 bool ret = false;
00089
00090 alg_.lock();
00091
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
00108
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
00124
00125
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
00137 alg_.lock();
00138
00139
00140
00141 this->status_ = getStatus();
00142 feedback->status = this->status_;
00143
00144 alg_.unlock();
00145 }
00146
00147
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
00161 int main(int argc,char *argv[])
00162 {
00163 return algorithm_base::main<VoiceRecognitionAlgNode>(argc, argv, "voice_recognition_alg_node");
00164 }