Go to the documentation of this file.00001 #include "tibi_dabo_hri_client_alg_node.h"
00002
00003 TibiDaboHriClientAlgNode::TibiDaboHriClientAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<TibiDaboHriClientAlgorithm>(),
00005
00006 hri_client_("hri", true),
00007 sequences(NUM_CLIENTS, std::string("")),
00008 hri_active(false),
00009 sendRequest(false),
00010 stopRequest(false)
00011 {
00012
00013
00014 hri_goal_.sequence_file = std::vector<std::string>(NUM_CLIENTS, std::string(""));
00015 hri_goal_.num_repetitions = std::vector<int>(NUM_CLIENTS, 0);
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 }
00029
00030 TibiDaboHriClientAlgNode::~TibiDaboHriClientAlgNode(void)
00031 {
00032
00033 }
00034
00035 void TibiDaboHriClientAlgNode::mainNodeThread(void)
00036 {
00037
00038
00039
00040
00041
00042 if(this->sendRequest && !this->hri_active )
00043 {
00044 hriMakeActionRequest(sequences);
00045 this->sendRequest = false;
00046 }
00047
00048 if(this->stopRequest && this->hri_active )
00049 {
00050 ROS_INFO("TibiDaboHriClientAlgNode::mainNodeThread: Cancelling Action!");
00051 this->hri_client_.cancelGoal();
00052 this->stopRequest = false;
00053 }
00054
00055
00056 }
00057
00058
00059
00060
00061
00062
00063 void TibiDaboHriClientAlgNode::hriDone(const actionlib::SimpleClientGoalState& state, const tibi_dabo_msgs::sequenceResultConstPtr& result)
00064 {
00065 if( state.toString().compare("SUCCEEDED") == 0 )
00066 ROS_INFO("TibiDaboHriClientAlgNode::hriDone: Goal Achieved!");
00067 else
00068 ROS_INFO("TibiDaboHriClientAlgNode::hriDone: %s", state.toString().c_str());
00069
00070
00071 this->hri_active = false;
00072 }
00073
00074 void TibiDaboHriClientAlgNode::hriActive()
00075 {
00076
00077 }
00078
00079 void TibiDaboHriClientAlgNode::hriFeedback(const tibi_dabo_msgs::sequenceFeedbackConstPtr& feedback)
00080 {
00081
00082
00083 bool feedback_is_ok = true;
00084
00085
00086
00087
00088
00089 if( !feedback_is_ok )
00090 {
00091 hri_client_.cancelGoal();
00092
00093 }
00094 }
00095
00096
00097 void TibiDaboHriClientAlgNode::hriMakeActionRequest(std::vector<std::string> &sequences)
00098 {
00099 ROS_INFO("TibiDaboHriClientAlgNode::hriMakeActionRequest: Starting New Request!");
00100
00101
00102
00103 hri_client_.waitForServer();
00104 ROS_INFO("TibiDaboHriClientAlgNode::hriMakeActionRequest: Server is Available!");
00105
00106
00107
00108 hri_goal_.sequence_file[TTS_] = sequences[TTS_];
00109 hri_goal_.sequence_file[LEDS_] = sequences[LEDS_];
00110 hri_goal_.sequence_file[HEAD_] = sequences[HEAD_];
00111 hri_goal_.sequence_file[RIGHT_ARM_] = sequences[RIGHT_ARM_];
00112 hri_goal_.sequence_file[LEFT_ARM_] = sequences[LEFT_ARM_];
00113
00114 hri_client_.sendGoal(hri_goal_,
00115 boost::bind(&TibiDaboHriClientAlgNode::hriDone, this, _1, _2),
00116 boost::bind(&TibiDaboHriClientAlgNode::hriActive, this),
00117 boost::bind(&TibiDaboHriClientAlgNode::hriFeedback, this, _1));
00118 ROS_INFO("TibiDaboHriClientAlgNode::hriMakeActionRequest: Goal Sent. Wait for Result!");
00119
00120 std::string goal_str("goal : {");
00121 for(unsigned int ii=0; ii<hri_goal_.sequence_file.size(); ii++)
00122 {
00123 goal_str += hri_goal_.sequence_file[ii] + ", ";
00124 }
00125 ROS_INFO("TibiDaboHriClientAlgNode::hriMakeActionRequest: %s}", goal_str.c_str());
00126
00127 this->hri_active = true;
00128
00129 }
00130
00131 void TibiDaboHriClientAlgNode::node_config_update(Config &config, uint32_t level)
00132 {
00133 this->alg_.lock();
00134 ROS_INFO("TibiDaboHriClientAlgNode::node_config_update!");
00135 if(config.Request)
00136 {
00137 if(!this->sendRequest)
00138 {
00139 ROS_INFO("TibiDaboHriClientAlgNode::node_config_update: new request!");
00140
00141 std::string voice;
00142 if(config.Genre == "Dabo")
00143 {
00144 if(config.Language == "English")
00145 voice="Simon";
00146 else if(config.Language == "Catalan")
00147 voice="Jordi";
00148 else if(config.Language == "Spanish")
00149 voice="Jorge";
00150 else
00151 voice="Simon";
00152 }
00153 else if(config.Genre == "Tibi")
00154 {
00155 if(config.Language == "English")
00156 voice="Kate";
00157 else if(config.Language == "Catalan")
00158 voice="Montserrat";
00159 else if(config.Language == "Spanish")
00160 voice="Leonor";
00161 else
00162 voice="Kate";
00163 }
00164 else
00165 voice="Kate";
00166
00167 sequences[TTS_] = "\\language="+config.Language + " \\voice=" + voice + " \\volume=" + boost::to_string(config.Volume) + " " + config.tts;
00168 sequences[LEDS_] = config.leds;
00169 sequences[HEAD_] = config.head;
00170 sequences[RIGHT_ARM_] = config.right_arm;
00171 sequences[LEFT_ARM_] = config.left_arm;
00172 this->sendRequest=true;
00173 }
00174 else
00175 {
00176 this->sendRequest=false;
00177 }
00178 }
00179 this->stopRequest = config.Stop;
00180 this->alg_.unlock();
00181 }
00182
00183 void TibiDaboHriClientAlgNode::addNodeDiagnostics(void)
00184 {
00185 }
00186
00187
00188 int main(int argc,char *argv[])
00189 {
00190 return algorithm_base::main<TibiDaboHriClientAlgNode>(argc, argv, "tibi_dabo_hri_client_alg_node");
00191 }