dabo_coop_alg_node.cpp
Go to the documentation of this file.
00001 #include "dabo_coop_alg_node.h"
00002 #include <wiimote/State.h>
00003 
00004 DaboCoopAlgNode::DaboCoopAlgNode(void) :
00005   algorithm_base::IriBaseAlgorithm<DaboCoopAlgorithm>(),
00006   car_dabo_action_aserver_(public_node_handle_, "car_dabo_action"),
00007   gui_action_aserver_(public_node_handle_, "gui_action"),
00008   gui_action_client_client_("gui_action_client", true),
00009   dabo_tibi_action_client_("dabo_tibi_action", true),
00010   dabo_car_action_client_("dabo_car_action", true),
00011   move_base_client_("move_base", true),
00012   hri_client_client_("hri_client", true)
00013 {
00014   //init class attributes if necessary
00015   this->loop_rate_ = 1;//in [Hz]
00016 
00017   // [init publishers]
00018   
00019   // [init subscribers]
00020   this->supervisor_subscriber_ = this->public_node_handle_.subscribe("supervisor", 10, &DaboCoopAlgNode::supervisor_callback, this);
00021   this->new_joy_cmd=false;
00022   this->joy_cmd=joy_none;
00023   
00024   // [init services]
00025   
00026   // [init clients]
00027   get_goal_client_ = this->public_node_handle_.serviceClient<iri_goal_database::get_goal>("get_goal");
00028   
00029   // [init action servers]
00030   car_dabo_action_aserver_.registerStartCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionStartCallback, this, _1)); 
00031   car_dabo_action_aserver_.registerStopCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionStopCallback, this)); 
00032   car_dabo_action_aserver_.registerIsFinishedCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionIsFinishedCallback, this)); 
00033   car_dabo_action_aserver_.registerHasSucceedCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionHasSucceedCallback, this)); 
00034   car_dabo_action_aserver_.registerGetResultCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionGetResultCallback, this, _1)); 
00035   car_dabo_action_aserver_.registerGetFeedbackCallback(boost::bind(&DaboCoopAlgNode::car_dabo_actionGetFeedbackCallback, this, _1)); 
00036   car_dabo_action_aserver_.start();
00037   this->new_car_cmd=false;
00038   this->car_cmd=dabo_none;
00039   this->car_done=false;
00040 
00041   gui_action_aserver_.registerStartCallback(boost::bind(&DaboCoopAlgNode::gui_actionStartCallback, this, _1)); 
00042   gui_action_aserver_.registerStopCallback(boost::bind(&DaboCoopAlgNode::gui_actionStopCallback, this)); 
00043   gui_action_aserver_.registerIsFinishedCallback(boost::bind(&DaboCoopAlgNode::gui_actionIsFinishedCallback, this)); 
00044   gui_action_aserver_.registerHasSucceedCallback(boost::bind(&DaboCoopAlgNode::gui_actionHasSucceedCallback, this)); 
00045   gui_action_aserver_.registerGetResultCallback(boost::bind(&DaboCoopAlgNode::gui_actionGetResultCallback, this, _1)); 
00046   gui_action_aserver_.registerGetFeedbackCallback(boost::bind(&DaboCoopAlgNode::gui_actionGetFeedbackCallback, this, _1)); 
00047   gui_action_aserver_.start();
00048   this->new_gui_cmd=false;
00049   this->gui_cmd=gui_none;
00050   
00051   // [init action clients]
00052 
00053   this->move_base_done=true;
00054   this->hri_client_done=true;
00055   this->dabo_tibi_action_done=true;
00056   this->dabo_car_action_done=true;
00057   this->current_state=dabo_idle;
00058 
00059   this->hri_client_goal_.sequence_file.resize(5);
00060 }
00061 
00062 DaboCoopAlgNode::~DaboCoopAlgNode(void)
00063 {
00064   // [free dynamic memory]
00065 }
00066 
00067 void DaboCoopAlgNode::mainNodeThread(void)
00068 {
00069   static dabo_states state;
00070   static int timeout=0;
00071 
00072   this->alg_.lock();
00073   switch(state)
00074   {
00075     case dabo_idle: if(this->new_car_cmd)
00076                     {
00077                       if(this->car_cmd==dabo_set_goal)
00078                       {
00079                         // get the goal pose from the database
00080                         get_goal_srv_.request.location_id=this->car_location_id;
00081                         get_goal_srv_.request.robot_id="dabo";
00082                         if (get_goal_client_.call(get_goal_srv_))
00083                         {
00084                           //send goal to be shown on gui
00085                           gui_action_client_goal_.cmd_id=gui_set_goal;
00086                           gui_action_client_goal_.num_params.clear();
00087                           gui_action_client_goal_.string_params.resize(1);
00088                           gui_action_client_goal_.string_params[0]=this->car_location_id;
00089                           gui_action_clientMakeActionRequest();
00090 
00091                           move_base_goal_.target_pose.header.stamp=ros::Time::now();
00092                           move_base_goal_.target_pose.header.frame_id="/map";
00093                           move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00094                           move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00095                           // start moving to the goal
00096                           if(move_baseMakeActionRequest())
00097                           {
00098                             state=dabo_wait_car_goal;
00099                             this->new_car_cmd=false;
00100                           }
00101                           else
00102                             state=dabo_idle;
00103                         }
00104                         else
00105                         {
00106                           ROS_INFO("TibiCoopAlgNode:: Failed to Call Server on topic get_goal ");
00107                           state=dabo_idle;
00108                         }
00109                       }
00110                       else
00111                         state=dabo_idle;
00112                     }
00113                     else
00114                       state=dabo_idle;
00115                     ROS_INFO("State: DABO_IDLE");
00116                     break;
00117     case dabo_wait_car_goal: if(this->move_base_done)
00118                                state=dabo_wait_car_done;
00119                              else if(this->new_joy_cmd)
00120                              {
00121                                if(this->joy_cmd==joy_cancel_goal)
00122                                {
00123                                  this->move_base_client_.cancelGoal();
00124                                  state=dabo_wait_car_done;
00125                                  this->new_joy_cmd=false;
00126                                }
00127                                else if(this->joy_cmd==joy_replan_goal)
00128                                {
00129                                  move_base_goal_.target_pose.header.stamp=ros::Time::now();
00130                                  move_baseMakeActionRequest();
00131                                  state=dabo_wait_car_goal;
00132                                  this->new_joy_cmd=false;
00133                                }
00134                                else
00135                                {
00136                                  state=dabo_wait_car_goal;
00137                                  this->new_joy_cmd=false;
00138                                }
00139                              }
00140                              else
00141                                state=dabo_wait_car_goal;
00142                              ROS_INFO("State: DABO_WAIT_CAR_GOAL");   
00143                              break;
00144     case dabo_wait_car_done: if(this->new_car_cmd)
00145                              {
00146                                if(this->car_cmd==dabo_car_done)
00147                                {
00148                                  //start HRI action
00149                                  this->hri_client_goal_.sequence_file[0] = "Hello. Welcome to your destination. You can get out of the vehicle.";
00150                                  this->hri_client_goal_.sequence_file[1] = "";
00151                                  this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00152                                  this->hri_client_goal_.sequence_file[4] = "";
00153                                  this->hri_client_goal_.sequence_file[3] = "";
00154                                  if(hri_clientMakeActionRequest())
00155                                  {
00156                                    state=dabo_wait_speech;
00157                                    this->new_car_cmd=false;
00158                                  }
00159                                  else
00160                                    state=dabo_wait_car_done;
00161                                }
00162                                else
00163                                  state=dabo_wait_car_done;
00164                              }
00165                              else
00166                                state=dabo_wait_car_done;
00167                              ROS_INFO("State: DABO_WAIT_CAR_DONE");
00168                              break;
00169     case dabo_wait_speech: if(this->hri_client_done)
00170                            {
00171                              timeout=0;
00172                              state=dabo_wait_user_input;
00173                            }
00174                            else
00175                              state=dabo_wait_speech;
00176                            ROS_INFO("State: DABO_WAIT_SPEECH");
00177                            break;
00178     case dabo_wait_user_input: if(this->new_gui_cmd)
00179                                {
00180                                  this->new_gui_cmd=false;
00181                                  if(this->gui_cmd==gui_done)
00182                                  {
00183                                    // start HRI action
00184                                    this->hri_client_goal_.sequence_file[0] = "Please, follow me to the exit";
00185                                    this->hri_client_goal_.sequence_file[1] = "";
00186                                    this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00187                                    this->hri_client_goal_.sequence_file[4] = "";
00188                                    this->hri_client_goal_.sequence_file[3] = "";
00189                                    hri_clientMakeActionRequest();
00190 
00191                                    // start move base
00192                                    // get the goal pose from the database
00193                                    get_goal_srv_.request.location_id="home";
00194                                    get_goal_srv_.request.robot_id="dabo";
00195                                    if (get_goal_client_.call(get_goal_srv_))
00196                                    {
00197                                      move_base_goal_.target_pose.header.stamp=ros::Time::now();
00198                                      move_base_goal_.target_pose.header.frame_id="/map";
00199                                      move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00200                                      move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00201                                      // start moving to the goal
00202                                      move_baseMakeActionRequest();
00203                                      state=dabo_wait_home;
00204                                      this->new_gui_cmd=false;
00205                                    }
00206                                    else
00207                                    {
00208                                      ROS_INFO("TibiCoopAlgNode:: Failed to Call Server on topic get_goal ");
00209                                      state=dabo_wait_user_input;
00210                                    }
00211                                  }
00212                                  else
00213                                    state=dabo_wait_user_input;
00214                                }
00215                                else if(timeout>5)
00216                                {
00217                                  // start HRI action
00218                                  this->hri_client_goal_.sequence_file[0] = "When you are ready to leave, please press the Exit button.";
00219                                  this->hri_client_goal_.sequence_file[1] = "";
00220                                  this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00221                                  this->hri_client_goal_.sequence_file[4] = "";
00222                                  this->hri_client_goal_.sequence_file[3] = "";
00223                                  if(hri_clientMakeActionRequest())
00224                                    state=dabo_wait_reminder;
00225                                  else
00226                                    state=dabo_wait_user_input;
00227                                }
00228                                else
00229                                {
00230                                  state=dabo_wait_user_input;
00231                                  timeout+=this->loop_rate_.expectedCycleTime().toSec();
00232                                }
00233                                ROS_INFO("State: DABO_WAIT_USER_INPUT");
00234                                break;
00235     case dabo_wait_reminder: if(this->hri_client_done)
00236                              {
00237                                timeout=0;
00238                                state=dabo_wait_user_input;
00239                              }
00240                              else
00241                                state=dabo_wait_reminder;
00242                              ROS_INFO("State: DABO_WAIT_REMINDER");
00243                              break;
00244     case dabo_wait_home: if(this->move_base_done && this->hri_client_done)
00245                          {
00246                            // start HRI action
00247                            this->hri_client_goal_.sequence_file[0] = "Thank you for your participation. Good bye!";
00248                            this->hri_client_goal_.sequence_file[1] = "";
00249                            this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00250                            this->hri_client_goal_.sequence_file[4] = "";
00251                            this->hri_client_goal_.sequence_file[3] = "";
00252                            if(hri_clientMakeActionRequest())
00253                              state=dabo_wait_goodbye;
00254                            else
00255                              state=dabo_wait_home;
00256                          }
00257                          else if(this->new_joy_cmd)
00258                          {
00259                            if(this->joy_cmd==joy_cancel_goal)
00260                            {
00261                              this->move_base_client_.cancelGoal();
00262                              state=dabo_wait_car_done;
00263                              this->new_joy_cmd=false;
00264                            }
00265                            else if(this->joy_cmd==joy_replan_goal)
00266                            {
00267                              move_base_goal_.target_pose.header.stamp=ros::Time::now();
00268                              move_baseMakeActionRequest();
00269                              state=dabo_wait_car_goal;
00270                              this->new_joy_cmd=false;
00271                            }
00272                            else
00273                            {
00274                              state=dabo_wait_car_goal;
00275                              this->new_joy_cmd=false;
00276                            }
00277                          }
00278                          else
00279                            state=dabo_wait_home;
00280                          ROS_INFO("State: DABO_WAIT_HOME");
00281                          break;
00282     case dabo_wait_goodbye: if(this->hri_client_done)
00283                             {
00284                               // send the car home
00285                               dabo_car_action_goal_.cmd_id=dabo_set_goal;
00286                               dabo_car_action_goal_.num_params.clear();
00287                               dabo_car_action_goal_.string_params.resize(1);
00288                               dabo_car_action_goal_.string_params[0]="home";
00289                               if(dabo_car_actionMakeActionRequest())
00290                                 state=dabo_set_goal_tibi;
00291                               else
00292                                 state=dabo_wait_goodbye;
00293                             }
00294                             else
00295                               state=dabo_wait_goodbye;
00296                             ROS_INFO("State: DABO_WAIT_GOODBye");
00297                             break;
00298     case dabo_set_goal_tibi: // send the tibi home
00299                              dabo_tibi_action_goal_.cmd_id=dabo_set_goal;
00300                              dabo_tibi_action_goal_.num_params.clear();
00301                              dabo_tibi_action_goal_.string_params.resize(1);
00302                              dabo_tibi_action_goal_.string_params[0]="home";
00303                              if(dabo_tibi_actionMakeActionRequest())
00304                                state=dabo_wait_car_tibi_home;
00305                              else
00306                                state=dabo_set_goal_tibi;
00307                             ROS_INFO("State: DABO_SET_GOAL_TIBI");
00308                             break;
00309     case dabo_wait_car_tibi_home: if(this->dabo_tibi_action_done && this->dabo_car_action_done)
00310                                     state=dabo_idle;
00311                                   else
00312                                     state=dabo_wait_car_tibi_home;
00313                                   ROS_INFO("State: DABO_WAIT_CAR_TIBI_HOME");
00314                                   break;
00315   }
00316   this->current_state=state;
00317   this->alg_.unlock();
00318   // [fill msg structures]
00319   
00320   // [fill srv structure and make request to the server]
00321   
00322   // [fill action structure and make request to the action server]
00323 
00324   // [publish messages]
00325 }
00326 
00327 /*  [subscriber callbacks] */
00328 void DaboCoopAlgNode::supervisor_callback(const sensor_msgs::Joy::ConstPtr& msg) 
00329 { 
00330   static std::vector<int> prev_buttons(msg->buttons);
00331 
00332   this->alg_.lock();
00333 
00334   if(msg->buttons[wiimote::State::MSG_BTN_PLUS]==1 && prev_buttons[wiimote::State::MSG_BTN_PLUS]==0)//replan
00335   {
00336     ROS_INFO("Replan"); 
00337     this->new_joy_cmd=true;
00338     this->joy_cmd=joy_replan_goal;
00339   }
00340   else if(msg->buttons[wiimote::State::MSG_BTN_MINUS]==1 && prev_buttons[wiimote::State::MSG_BTN_MINUS]==0)// cancel goal
00341   {
00342     ROS_INFO("Cancel"); 
00343     this->new_joy_cmd=true;
00344     this->joy_cmd=joy_cancel_goal;
00345   }
00346   else if(msg->buttons[wiimote::State::MSG_BTN_HOME]==1 && prev_buttons[wiimote::State::MSG_BTN_HOME]==0)// teleop
00347   {
00348     ROS_INFO("Teleop"); 
00349     this->new_joy_cmd=true;
00350     this->joy_cmd=joy_teleop;
00351   }
00352 
00353   //unlock previously blocked shared variables 
00354   this->alg_.unlock();
00355 }
00356 
00357 /*  [service callbacks] */
00358 
00359 /*  [action callbacks] */
00360 void DaboCoopAlgNode::gui_action_clientDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::guiResultConstPtr& result) 
00361 { 
00362   if( state.toString().compare("SUCCEEDED") == 0 ) 
00363     ROS_INFO("DaboCoopAlgNode::gui_action_clientDone: Goal Achieved!"); 
00364   else 
00365     ROS_INFO("DaboCoopAlgNode::gui_action_clientDone: %s", state.toString().c_str()); 
00366 
00367   //copy & work with requested result 
00368 } 
00369 
00370 void DaboCoopAlgNode::gui_action_clientActive() 
00371 { 
00372   //ROS_INFO("DaboCoopAlgNode::gui_action_clientActive: Goal just went active!"); 
00373 } 
00374 
00375 void DaboCoopAlgNode::gui_action_clientFeedback(const tibi_dabo_msgs::guiFeedbackConstPtr& feedback) 
00376 { 
00377   //ROS_INFO("DaboCoopAlgNode::gui_action_clientFeedback: Got Feedback!"); 
00378 
00379   bool feedback_is_ok = true; 
00380 
00381   //analyze feedback 
00382   //my_var = feedback->var; 
00383 
00384   //if feedback is not what expected, cancel requested goal 
00385   if( !feedback_is_ok ) 
00386   { 
00387     gui_action_client_client_.cancelGoal(); 
00388     //ROS_INFO("DaboCoopAlgNode::gui_action_clientFeedback: Cancelling Action!"); 
00389   } 
00390 }
00391 void DaboCoopAlgNode::dabo_tibi_actionDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::guiResultConstPtr& result) 
00392 { 
00393   this->alg_.lock();
00394   if( state.toString().compare("SUCCEEDED") == 0 ) 
00395     ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionDone: Goal Achieved!"); 
00396   else 
00397     ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionDone: %s", state.toString().c_str()); 
00398   this->dabo_tibi_action_done=true;
00399   this->alg_.unlock();
00400   //copy & work with requested result 
00401 } 
00402 
00403 void DaboCoopAlgNode::dabo_tibi_actionActive() 
00404 { 
00405   //ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionActive: Goal just went active!"); 
00406 } 
00407 
00408 void DaboCoopAlgNode::dabo_tibi_actionFeedback(const tibi_dabo_msgs::guiFeedbackConstPtr& feedback) 
00409 { 
00410   //ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionFeedback: Got Feedback!"); 
00411 
00412   bool feedback_is_ok = true; 
00413 
00414   //analyze feedback 
00415   //my_var = feedback->var; 
00416 
00417   //if feedback is not what expected, cancel requested goal 
00418   if( !feedback_is_ok ) 
00419   { 
00420     dabo_tibi_action_client_.cancelGoal(); 
00421     //ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionFeedback: Cancelling Action!"); 
00422   } 
00423 }
00424 void DaboCoopAlgNode::dabo_car_actionDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::guiResultConstPtr& result) 
00425 { 
00426   this->alg_.lock();
00427   if( state.toString().compare("SUCCEEDED") == 0 ) 
00428     ROS_INFO("DaboCoopAlgNode::dabo_car_actionDone: Goal Achieved!"); 
00429   else 
00430     ROS_INFO("DaboCoopAlgNode::dabo_car_actionDone: %s", state.toString().c_str()); 
00431   this->dabo_car_action_done=true;
00432   this->alg_.unlock();
00433   //copy & work with requested result 
00434 } 
00435 
00436 void DaboCoopAlgNode::dabo_car_actionActive() 
00437 { 
00438   //ROS_INFO("DaboCoopAlgNode::dabo_car_actionActive: Goal just went active!"); 
00439 } 
00440 
00441 void DaboCoopAlgNode::dabo_car_actionFeedback(const tibi_dabo_msgs::guiFeedbackConstPtr& feedback) 
00442 { 
00443   //ROS_INFO("DaboCoopAlgNode::dabo_car_actionFeedback: Got Feedback!"); 
00444 
00445   bool feedback_is_ok = true; 
00446 
00447   //analyze feedback 
00448   //my_var = feedback->var; 
00449 
00450   //if feedback is not what expected, cancel requested goal 
00451   if( !feedback_is_ok ) 
00452   { 
00453     dabo_car_action_client_.cancelGoal(); 
00454     //ROS_INFO("DaboCoopAlgNode::dabo_car_actionFeedback: Cancelling Action!"); 
00455   } 
00456 }
00457 void DaboCoopAlgNode::car_dabo_actionStartCallback(const tibi_dabo_msgs::guiGoalConstPtr& goal)
00458 { 
00459   alg_.lock(); 
00460     //check goal
00461   ROS_INFO("Cmd: %d",goal->cmd_id);//goal->cmd_id,goal->string_params[0].c_str()); 
00462   this->car_cmd=(dabo_cmds)goal->cmd_id;
00463   switch(this->car_cmd)
00464   {
00465     case dabo_set_goal: if(goal->string_params.size()==1)
00466                         {
00467                           this->car_location_id=goal->string_params[0];
00468                           this->new_car_cmd=true;
00469                         }
00470                         else
00471                           this->new_car_cmd=false;
00472                         break;
00473     case dabo_car_done: this->car_done=true;
00474                         this->new_car_cmd=true;
00475                         break;
00476     default: this->new_car_cmd=false;
00477              break;
00478   }
00479     //execute goal 
00480   alg_.unlock(); 
00481 } 
00482 
00483 void DaboCoopAlgNode::car_dabo_actionStopCallback(void) 
00484 { 
00485   alg_.lock(); 
00486     //stop action 
00487   // cancel the move base goal
00488   move_base_client_.cancelGoal();
00489   alg_.unlock(); 
00490 } 
00491 
00492 bool DaboCoopAlgNode::car_dabo_actionIsFinishedCallback(void) 
00493 { 
00494   bool ret = false; 
00495 
00496   alg_.lock(); 
00497     //if action has finish for any reason 
00498   if(this->current_state==dabo_wait_car_done && this->move_base_done)
00499     ret=true;
00500   else if(this->current_state==dabo_wait_speech)
00501     ret=true;
00502   else
00503     ret=false;
00504 
00505     //ret = true; 
00506   alg_.unlock(); 
00507 
00508   return ret; 
00509 } 
00510 
00511 bool DaboCoopAlgNode::car_dabo_actionHasSucceedCallback(void) 
00512 { 
00513   bool ret = false; 
00514 
00515   alg_.lock(); 
00516     //if goal was accomplished 
00517     ret = true; 
00518   alg_.unlock(); 
00519 
00520   return ret; 
00521 } 
00522 
00523 void DaboCoopAlgNode::car_dabo_actionGetResultCallback(tibi_dabo_msgs::guiResultPtr& result) 
00524 { 
00525   alg_.lock(); 
00526     //update result data to be sent to client 
00527     //result->data = data; 
00528   alg_.unlock(); 
00529 } 
00530 
00531 void DaboCoopAlgNode::car_dabo_actionGetFeedbackCallback(tibi_dabo_msgs::guiFeedbackPtr& feedback) 
00532 { 
00533   alg_.lock(); 
00534     //keep track of feedback 
00535     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00536   alg_.unlock(); 
00537 }
00538 void DaboCoopAlgNode::gui_actionStartCallback(const tibi_dabo_msgs::guiGoalConstPtr& goal)
00539 { 
00540   alg_.lock(); 
00541     //check goal 
00542   this->gui_cmd=(gui_cmds)goal->cmd_id;
00543   this->new_gui_cmd=true;
00544     //execute goal 
00545   alg_.unlock(); 
00546 } 
00547 
00548 void DaboCoopAlgNode::gui_actionStopCallback(void) 
00549 { 
00550   alg_.lock(); 
00551     //stop action 
00552   alg_.unlock(); 
00553 } 
00554 
00555 bool DaboCoopAlgNode::gui_actionIsFinishedCallback(void) 
00556 { 
00557   bool ret = false; 
00558 
00559   alg_.lock(); 
00560     //if action has finish for any reason
00561   if(this->current_state==dabo_wait_home)
00562     ret=true;
00563   else
00564     ret=false;
00565     //ret = true; 
00566   alg_.unlock(); 
00567 
00568   return ret; 
00569 } 
00570 
00571 bool DaboCoopAlgNode::gui_actionHasSucceedCallback(void) 
00572 { 
00573   bool ret = false; 
00574 
00575   alg_.lock(); 
00576     //if goal was accomplished 
00577     //ret = true; 
00578   alg_.unlock(); 
00579 
00580   return ret; 
00581 } 
00582 
00583 void DaboCoopAlgNode::gui_actionGetResultCallback(tibi_dabo_msgs::guiResultPtr& result) 
00584 { 
00585   alg_.lock(); 
00586     //update result data to be sent to client 
00587     //result->data = data; 
00588   alg_.unlock(); 
00589 } 
00590 
00591 void DaboCoopAlgNode::gui_actionGetFeedbackCallback(tibi_dabo_msgs::guiFeedbackPtr& feedback) 
00592 { 
00593   alg_.lock(); 
00594     //keep track of feedback 
00595     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00596   alg_.unlock(); 
00597 }
00598 void DaboCoopAlgNode::move_baseDone(const actionlib::SimpleClientGoalState& state,  const move_base_msgs::MoveBaseResultConstPtr& result) 
00599 { 
00600   this->alg_.lock();
00601   if( state.toString().compare("SUCCEEDED") == 0 ) 
00602     ROS_INFO("DaboCoopAlgNode::move_baseDone: Goal Achieved!"); 
00603   else 
00604     ROS_INFO("DaboCoopAlgNode::move_baseDone: %s", state.toString().c_str()); 
00605   this->move_base_done=true;
00606   this->alg_.unlock();
00607   //copy & work with requested result 
00608 } 
00609 
00610 void DaboCoopAlgNode::move_baseActive() 
00611 { 
00612   //ROS_INFO("DaboCoopAlgNode::move_baseActive: Goal just went active!"); 
00613 } 
00614 
00615 void DaboCoopAlgNode::move_baseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback) 
00616 { 
00617   //ROS_INFO("DaboCoopAlgNode::move_baseFeedback: Got Feedback!"); 
00618 
00619   bool feedback_is_ok = true; 
00620 
00621   //analyze feedback 
00622   //my_var = feedback->var; 
00623 
00624   //if feedback is not what expected, cancel requested goal 
00625   if( !feedback_is_ok ) 
00626   { 
00627     move_base_client_.cancelGoal(); 
00628     //ROS_INFO("DaboCoopAlgNode::move_baseFeedback: Cancelling Action!"); 
00629   } 
00630 }
00631 void DaboCoopAlgNode::hri_clientDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::sequenceResultConstPtr& result) 
00632 { 
00633   this->alg_.lock();
00634   if( state.toString().compare("SUCCEEDED") == 0 ) 
00635     ROS_INFO("DaboCoopAlgNode::hri_clientDone: Goal Achieved!"); 
00636   else 
00637     ROS_INFO("DaboCoopAlgNode::hri_clientDone: %s", state.toString().c_str()); 
00638   this->hri_client_done=true;
00639   this->alg_.unlock();
00640  
00641   //copy & work with requested result 
00642 } 
00643 
00644 void DaboCoopAlgNode::hri_clientActive() 
00645 { 
00646   //ROS_INFO("DaboCoopAlgNode::hri_clientActive: Goal just went active!"); 
00647 } 
00648 
00649 void DaboCoopAlgNode::hri_clientFeedback(const tibi_dabo_msgs::sequenceFeedbackConstPtr& feedback) 
00650 { 
00651   //ROS_INFO("DaboCoopAlgNode::hri_clientFeedback: Got Feedback!"); 
00652 
00653   bool feedback_is_ok = true; 
00654 
00655   //analyze feedback 
00656   //my_var = feedback->var; 
00657 
00658   //if feedback is not what expected, cancel requested goal 
00659   if( !feedback_is_ok ) 
00660   { 
00661     hri_client_client_.cancelGoal(); 
00662     //ROS_INFO("DaboCoopAlgNode::hri_clientFeedback: Cancelling Action!"); 
00663   } 
00664 }
00665 
00666 /*  [action requests] */
00667 void DaboCoopAlgNode::gui_action_clientMakeActionRequest() 
00668 { 
00669   ROS_INFO("DaboCoopAlgNode::gui_action_clientMakeActionRequest: Starting New Request!"); 
00670 
00671   //wait for the action server to start 
00672   //will wait for infinite time 
00673   gui_action_client_client_.waitForServer();  
00674   ROS_INFO("DaboCoopAlgNode::gui_action_clientMakeActionRequest: Server is Available!"); 
00675 
00676   //send a goal to the action 
00677   //gui_action_client_goal_.data = my_desired_goal; 
00678   gui_action_client_client_.sendGoal(gui_action_client_goal_, 
00679               boost::bind(&DaboCoopAlgNode::gui_action_clientDone,     this, _1, _2), 
00680               boost::bind(&DaboCoopAlgNode::gui_action_clientActive,   this), 
00681               boost::bind(&DaboCoopAlgNode::gui_action_clientFeedback, this, _1)); 
00682   ROS_INFO("DaboCoopAlgNode::gui_action_clientMakeActionRequest: Goal Sent. Wait for Result!"); 
00683 }
00684 bool DaboCoopAlgNode::dabo_tibi_actionMakeActionRequest() 
00685 { 
00686   ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionMakeActionRequest: Starting New Request!"); 
00687 
00688   //wait for the action server to start 
00689   //will wait for infinite time 
00690   if(!dabo_tibi_action_client_.waitForServer(ros::Duration(2.0)))
00691     return false;
00692   ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionMakeActionRequest: Server is Available!"); 
00693 
00694   //send a goal to the action 
00695   //dabo_tibi_action_goal_.data = my_desired_goal; 
00696   dabo_tibi_action_client_.sendGoal(dabo_tibi_action_goal_, 
00697               boost::bind(&DaboCoopAlgNode::dabo_tibi_actionDone,     this, _1, _2), 
00698               boost::bind(&DaboCoopAlgNode::dabo_tibi_actionActive,   this), 
00699               boost::bind(&DaboCoopAlgNode::dabo_tibi_actionFeedback, this, _1)); 
00700   this->dabo_tibi_action_done=false;
00701   ROS_INFO("DaboCoopAlgNode::dabo_tibi_actionMakeActionRequest: Goal Sent. Wait for Result!"); 
00702   
00703   return true;
00704 }
00705 
00706 bool DaboCoopAlgNode::dabo_car_actionMakeActionRequest() 
00707 { 
00708   ROS_INFO("DaboCoopAlgNode::dabo_car_actionMakeActionRequest: Starting New Request!"); 
00709 
00710   //wait for the action server to start 
00711   //will wait for infinite time 
00712   if(!dabo_car_action_client_.waitForServer(ros::Duration(2.0)))
00713     return false;
00714   ROS_INFO("DaboCoopAlgNode::dabo_car_actionMakeActionRequest: Server is Available!"); 
00715 
00716   //send a goal to the action 
00717   //dabo_car_action_goal_.data = my_desired_goal; 
00718   dabo_car_action_client_.sendGoal(dabo_car_action_goal_, 
00719               boost::bind(&DaboCoopAlgNode::dabo_car_actionDone,     this, _1, _2), 
00720               boost::bind(&DaboCoopAlgNode::dabo_car_actionActive,   this), 
00721               boost::bind(&DaboCoopAlgNode::dabo_car_actionFeedback, this, _1)); 
00722   dabo_car_action_done=false;
00723   ROS_INFO("DaboCoopAlgNode::dabo_car_actionMakeActionRequest: Goal Sent. Wait for Result!"); 
00724 
00725   return true;
00726 }
00727 
00728 bool DaboCoopAlgNode::move_baseMakeActionRequest() 
00729 { 
00730   ROS_INFO("DaboCoopAlgNode::move_baseMakeActionRequest: Starting New Request!"); 
00731 
00732   //wait for the action server to start 
00733   //will wait for infinite time 
00734   if(!move_base_client_.waitForServer(ros::Duration(2.0)))
00735     return false;
00736   ROS_INFO("DaboCoopAlgNode::move_baseMakeActionRequest: Server is Available!"); 
00737 
00738   //send a goal to the action 
00739   //move_base_goal_.data = my_desired_goal; 
00740   move_base_client_.sendGoal(move_base_goal_, 
00741               boost::bind(&DaboCoopAlgNode::move_baseDone,     this, _1, _2), 
00742               boost::bind(&DaboCoopAlgNode::move_baseActive,   this), 
00743               boost::bind(&DaboCoopAlgNode::move_baseFeedback, this, _1)); 
00744   this->move_base_done=false;
00745   ROS_INFO("DaboCoopAlgNode::move_baseMakeActionRequest: Goal Sent. Wait for Result!"); 
00746 
00747   return true;
00748 }
00749 
00750 bool DaboCoopAlgNode::hri_clientMakeActionRequest() 
00751 { 
00752   ROS_INFO("DaboCoopAlgNode::hri_clientMakeActionRequest: Starting New Request!"); 
00753 
00754   //wait for the action server to start 
00755   //will wait for infinite time 
00756   if(!hri_client_client_.waitForServer(ros::Duration(2.0)))
00757     return false;
00758   ROS_INFO("DaboCoopAlgNode::hri_clientMakeActionRequest: Server is Available!"); 
00759 
00760   //send a goal to the action 
00761   //hri_client_goal_.data = my_desired_goal; 
00762   hri_client_client_.sendGoal(hri_client_goal_, 
00763               boost::bind(&DaboCoopAlgNode::hri_clientDone,     this, _1, _2), 
00764               boost::bind(&DaboCoopAlgNode::hri_clientActive,   this), 
00765               boost::bind(&DaboCoopAlgNode::hri_clientFeedback, this, _1)); 
00766   this->hri_client_done=false;
00767   ROS_INFO("DaboCoopAlgNode::hri_clientMakeActionRequest: Goal Sent. Wait for Result!"); 
00768   ROS_INFO("DaboCoopAlgNode::hri_clientMakeActionRequest: Goal tts: %s",this->hri_client_goal_.sequence_file[0].c_str()); 
00769 
00770   return true;
00771 }
00772 
00773 void DaboCoopAlgNode::node_config_update(Config &config, uint32_t level)
00774 {
00775   this->alg_.lock();
00776 
00777   this->alg_.unlock();
00778 }
00779 
00780 void DaboCoopAlgNode::addNodeDiagnostics(void)
00781 {
00782 }
00783 
00784 /* main function */
00785 int main(int argc,char *argv[])
00786 {
00787   return algorithm_base::main<DaboCoopAlgNode>(argc, argv, "dabo_coop_alg_node");
00788 }


dabo_coop
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 22:14:38