tibi_coop_alg_node.cpp
Go to the documentation of this file.
00001 #include "tibi_coop_alg_node.h"
00002 #include <wiimote/State.h>
00003 
00004 TibiCoopAlgNode::TibiCoopAlgNode(void) :
00005   algorithm_base::IriBaseAlgorithm<TibiCoopAlgorithm>(),
00006   move_guide_client_("move_guide", true),
00007   car_tibi_action_aserver_(public_node_handle_, "car_tibi_action"),
00008   dabo_tibi_action_aserver_(public_node_handle_, "dabo_tibi_action"),
00009   gui_action_aserver_(public_node_handle_, "gui_action"),
00010   tibi_car_action_client_("tibi_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, &TibiCoopAlgNode::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_tibi_action_aserver_.registerStartCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionStartCallback, this, _1)); 
00031   car_tibi_action_aserver_.registerStopCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionStopCallback, this)); 
00032   car_tibi_action_aserver_.registerIsFinishedCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionIsFinishedCallback, this)); 
00033   car_tibi_action_aserver_.registerHasSucceedCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionHasSucceedCallback, this)); 
00034   car_tibi_action_aserver_.registerGetResultCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionGetResultCallback, this, _1)); 
00035   car_tibi_action_aserver_.registerGetFeedbackCallback(boost::bind(&TibiCoopAlgNode::car_tibi_actionGetFeedbackCallback, this, _1)); 
00036   car_tibi_action_aserver_.start();
00037   this->new_car_cmd=false;
00038   this->car_cmd=tibi_none;
00039 
00040   dabo_tibi_action_aserver_.registerStartCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionStartCallback, this, _1)); 
00041   dabo_tibi_action_aserver_.registerStopCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionStopCallback, this)); 
00042   dabo_tibi_action_aserver_.registerIsFinishedCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionIsFinishedCallback, this)); 
00043   dabo_tibi_action_aserver_.registerHasSucceedCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionHasSucceedCallback, this)); 
00044   dabo_tibi_action_aserver_.registerGetResultCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionGetResultCallback, this, _1)); 
00045   dabo_tibi_action_aserver_.registerGetFeedbackCallback(boost::bind(&TibiCoopAlgNode::dabo_tibi_actionGetFeedbackCallback, this, _1)); 
00046   dabo_tibi_action_aserver_.start();
00047   this->new_dabo_cmd=false;
00048   this->dabo_cmd=tibi_none;
00049 
00050   gui_action_aserver_.registerStartCallback(boost::bind(&TibiCoopAlgNode::gui_actionStartCallback, this, _1)); 
00051   gui_action_aserver_.registerStopCallback(boost::bind(&TibiCoopAlgNode::gui_actionStopCallback, this)); 
00052   gui_action_aserver_.registerIsFinishedCallback(boost::bind(&TibiCoopAlgNode::gui_actionIsFinishedCallback, this)); 
00053   gui_action_aserver_.registerHasSucceedCallback(boost::bind(&TibiCoopAlgNode::gui_actionHasSucceedCallback, this)); 
00054   gui_action_aserver_.registerGetResultCallback(boost::bind(&TibiCoopAlgNode::gui_actionGetResultCallback, this, _1)); 
00055   gui_action_aserver_.registerGetFeedbackCallback(boost::bind(&TibiCoopAlgNode::gui_actionGetFeedbackCallback, this, _1)); 
00056   gui_action_aserver_.start();
00057   this->new_gui_cmd=false;
00058   this->gui_cmd=gui_none;
00059 
00060   this->tibi_car_action_done=true;
00061   
00062   // [init action clients]
00063   this->hri_client_done=true;
00064   this->move_base_done=true;
00065   this->move_guide_done=true;
00066 
00067   this->hri_client_goal_.sequence_file.resize(5); 
00068 
00069   this->current_state=tibi_idle;
00070 
00071   this->hri_client_goal_.sequence_file.resize(5);
00072   this->loadSentences();
00073 }
00074 
00075 TibiCoopAlgNode::~TibiCoopAlgNode(void)
00076 {
00077   // [free dynamic memory]
00078 }
00079 
00080 void TibiCoopAlgNode::mainNodeThread(void)
00081 {
00082   static tibi_states state=tibi_idle;
00083   static int timeout=0;
00084 
00085   alg_.lock(); 
00086   switch(state)
00087   {
00088     case tibi_idle: if(this->new_gui_cmd)
00089                     {
00090                       // start HRI action
00091                       if(this->gui_cmd==gui_set_goal)
00092                       {
00093                         this->hri_client_goal_.sequence_file[0] = "Destination chosen. Follow me, please.";
00094                         this->hri_client_goal_.sequence_file[1] = "";
00095                         this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00096                         this->hri_client_goal_.sequence_file[4] = "";
00097                         this->hri_client_goal_.sequence_file[3] = "";
00098                         if(hri_clientMakeActionRequest())
00099                         {
00100                           this->new_gui_cmd=false;
00101                           state=tibi_wait_intro;
00102                         }
00103                         else
00104                           state=tibi_idle;
00105                       }
00106                       else
00107                         state=tibi_idle;
00108                     }
00109                     else if(timeout>25)
00110                     {
00111                       // start HRI action
00112                       this->hri_client_goal_.sequence_file[0] = "Where do you want to go?";
00113                       this->hri_client_goal_.sequence_file[1] = "";
00114                       this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00115                       this->hri_client_goal_.sequence_file[4] = "";
00116                       this->hri_client_goal_.sequence_file[3] = "";
00117                       if(hri_clientMakeActionRequest())
00118                         state=tibi_wait_bored;
00119                       else
00120                         state=tibi_idle;
00121                     }
00122                     else
00123                     {
00124                       state=tibi_idle;
00125                       timeout+=this->loop_rate_.expectedCycleTime().toSec();
00126                     }
00127                     ROS_INFO("TibiCoopAlgNode: state tibi_idle!");
00128                     break;
00129     case tibi_wait_bored: if(this->hri_client_done)
00130                           {
00131                             timeout=0;
00132                             state=tibi_idle;
00133                           }
00134                           else
00135                             state=tibi_wait_bored;
00136                           ROS_INFO("TibiCoopAlgNode: state tibi_wait_bored!");
00137                           break;
00138     case tibi_wait_intro: if(this->hri_client_done)
00139                           {
00140                             move_guide_goal_.location_id="taxi_stop";
00141                             move_guide_goal_.robot_id="tibi";
00142                             move_guide_goal_.target_id=0;
00143                             // start moving to the goal
00144                             move_guideMakeActionRequest();
00145                             state=tibi_set_car_goal;
00146                           }
00147                           else
00148                             state=tibi_wait_intro;
00149                           ROS_INFO("TibiCoopAlgNode: state tibi_wait_intro!");
00150                           break;
00151     case tibi_set_car_goal: // make the car move to the goal
00152                             tibi_car_action_goal_.cmd_id=car_set_goal;
00153                             tibi_car_action_goal_.num_params.clear();
00154                             tibi_car_action_goal_.string_params.resize(1);
00155                             tibi_car_action_goal_.string_params[0]="taxi_stop";
00156                             if(tibi_car_actionMakeActionRequest())
00157                               state=tibi_wait_guiding;
00158                             else
00159                               state=tibi_set_car_goal;
00160                             ROS_INFO("TibiCoopAlgNode: state tibi_set_car_goal!");
00161                             break;
00162     case tibi_wait_guiding: if(this->move_guide_done)
00163                             {
00164                               if(this->hri_client_done)
00165                               {
00166                                 if(this->tibi_car_action_done)
00167                                 {
00168                                   // start HRI
00169                                   this->hri_client_goal_.sequence_file[0] = "Get in the car and press the screen button when you are ready.";
00170                                   this->hri_client_goal_.sequence_file[1] = "";
00171                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00172                                   this->hri_client_goal_.sequence_file[4] = "";
00173                                   this->hri_client_goal_.sequence_file[3] = "";
00174                                   hri_clientMakeActionRequest();
00175                                   state=tibi_wait_done;
00176                                 }
00177                                 else 
00178                                 {
00179                                   // start HRI
00180                                   this->hri_client_goal_.sequence_file[0] = "Wait for the car";
00181                                   this->hri_client_goal_.sequence_file[1] = "";
00182                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00183                                   this->hri_client_goal_.sequence_file[4] = "";
00184                                   this->hri_client_goal_.sequence_file[3] = "";
00185                                   hri_clientMakeActionRequest();
00186                                   state=tibi_wait_no_car;
00187                                 }
00188                               }
00189                               else
00190                                 state=tibi_wait_guiding;
00191                             }
00192                             else if(this->new_joy_cmd)
00193                             {
00194                               if(this->joy_cmd==joy_cancel_goal)
00195                               {
00196                                 this->move_base_client_.cancelGoal();
00197                                 if(this->tibi_car_action_done)
00198                                 {
00199                                   // start HRI
00200                                   this->hri_client_goal_.sequence_file[0] = "Get in the car and press the screen button when you are ready.";
00201                                   this->hri_client_goal_.sequence_file[1] = "";
00202                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00203                                   this->hri_client_goal_.sequence_file[4] = "";
00204                                   this->hri_client_goal_.sequence_file[3] = "";
00205                                   hri_clientMakeActionRequest();
00206                                   state=tibi_wait_done;
00207                                 }
00208                                 else 
00209                                 {
00210                                   // start HRI
00211                                   this->hri_client_goal_.sequence_file[0] = "Wait for the car";
00212                                   this->hri_client_goal_.sequence_file[1] = "";
00213                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00214                                   this->hri_client_goal_.sequence_file[4] = "";
00215                                   this->hri_client_goal_.sequence_file[3] = "";
00216                                   hri_clientMakeActionRequest();
00217                                   state=tibi_wait_no_car;
00218                                 }
00219                                 this->new_joy_cmd=false;
00220                               }
00221                               else if(this->joy_cmd==joy_replan_goal)
00222                               {
00223                                 move_base_goal_.target_pose.header.stamp=ros::Time::now();
00224                                 // start moving to the goal
00225                                 move_baseMakeActionRequest();
00226                                 state=tibi_wait_guiding;
00227                                 this->new_joy_cmd=false;
00228                               }
00229                               else
00230                               {
00231                                 state=tibi_wait_guiding;
00232                                 this->new_joy_cmd=false;
00233                               }
00234                             }
00235                             else
00236                               state=tibi_wait_guiding;
00237                             ROS_INFO("TibiCoopAlgNode: state tibi_wait_guiding!");
00238                             break;
00239     case tibi_wait_no_car: if(this->hri_client_done)
00240                            {
00241                              if(this->tibi_car_action_done)
00242                              {
00243                                // start HRI
00244                                this->hri_client_goal_.sequence_file[0] = "Here it is. Get in the car and press the screen button when you are ready.";
00245                                this->hri_client_goal_.sequence_file[1] = "";
00246                                this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00247                                this->hri_client_goal_.sequence_file[4] = "";
00248                                this->hri_client_goal_.sequence_file[3] = "";
00249                                if(hri_clientMakeActionRequest())
00250                                  state=tibi_wait_done;
00251                                else
00252                                  state=tibi_wait_no_car;
00253                              }
00254                              else
00255                              {
00256                                timeout=0;
00257                                state=tibi_delay;
00258                              }
00259                            }
00260                            else
00261                              state=tibi_wait_no_car;
00262                            ROS_INFO("TibiCoopAlgNode: state tibi_wait_no_car!");
00263                            break;
00264     case tibi_delay: if(this->hri_client_done)
00265                      {
00266                        if(this->tibi_car_action_done)
00267                        {
00268                          // start HRI
00269                          this->hri_client_goal_.sequence_file[0] = "Here it is. Get in the car and press the screen button when you are ready.";
00270                          this->hri_client_goal_.sequence_file[1] = "";
00271                          this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00272                          this->hri_client_goal_.sequence_file[4] = "";
00273                          this->hri_client_goal_.sequence_file[3] = "";
00274                          if(hri_clientMakeActionRequest())
00275                            state=tibi_wait_done;
00276                          else
00277                            state=tibi_delay;
00278                        }
00279                        else if(timeout>5)
00280                        {
00281                          this->hri_client_goal_.sequence_file[0] = "The car is about to arrive";
00282                          this->hri_client_goal_.sequence_file[1] = "";
00283                          this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00284                          this->hri_client_goal_.sequence_file[4] = "";
00285                          this->hri_client_goal_.sequence_file[3] = "";
00286                          if(hri_clientMakeActionRequest())
00287                            state=tibi_delay;
00288                          else
00289                            state=tibi_delay;
00290                          timeout=0;
00291                        }
00292                        else
00293                        {
00294                          state=tibi_delay;
00295                          timeout+=this->loop_rate_.expectedCycleTime().toSec();
00296                        }
00297                      }
00298                      else
00299                        state=tibi_delay;
00300                      ROS_INFO("TibiCoopAlgNode: state tibi_delay!");
00301                      break;
00302     case tibi_wait_done: if(this->hri_client_done)
00303                          {
00304                            if(this->tibi_car_action_done)
00305                            {
00306                              // send the user goal to the car
00307                              tibi_car_action_goal_.cmd_id=car_set_goal;
00308                              tibi_car_action_goal_.num_params.clear();
00309                              tibi_car_action_goal_.string_params.resize(1);
00310                              tibi_car_action_goal_.string_params[0]=this->gui_location_id;
00311                              if(tibi_car_actionMakeActionRequest())
00312                                state=tibi_wait_car;
00313                              else
00314                                state=tibi_wait_done;
00315                            }
00316                            else
00317                              state=tibi_wait_done;
00318                          }
00319                          else
00320                            state=tibi_wait_done;
00321                          ROS_INFO("TibiCoopAlgNode: state tibi_wait_done!");
00322                          break;
00323     case tibi_wait_car: if(this->tibi_car_action_done)
00324                           state=tibi_wait_dabo;
00325                         else
00326                           state=tibi_wait_car;
00327                         ROS_INFO("TibiCoopAlgNode: state tibi_wait_car!");
00328                         break;
00329     case tibi_wait_dabo: if(this->new_dabo_cmd)
00330                          {
00331                            if(this->dabo_cmd==tibi_set_goal)
00332                            {
00333                              // get the goal position from the database (gui_cmd)
00334                              get_goal_srv_.request.location_id=this->dabo_location_id;
00335                              get_goal_srv_.request.robot_id="tibi";
00336                              if (get_goal_client_.call(get_goal_srv_))
00337                              {
00338                                move_base_goal_.target_pose.header.stamp=ros::Time::now();
00339                                move_base_goal_.target_pose.header.frame_id="/map";
00340                                move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00341                                move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00342                                // start moving to the goal
00343                                if(move_baseMakeActionRequest())
00344                                {
00345                                  this->new_dabo_cmd=false;
00346                                  state=tibi_wait_home;
00347                                }
00348                                else
00349                                  state=tibi_wait_dabo;
00350                              }
00351                              else
00352                              {
00353                                ROS_INFO("TibiCoopAlgNode:: Failed to Call Server on topic get_goal ");
00354                                state=tibi_wait_dabo;
00355                              }
00356                            }
00357                            else
00358                              state=tibi_wait_dabo;
00359                          }
00360                          else
00361                            state=tibi_wait_dabo;
00362                          ROS_INFO("TibiCoopAlgNode: state tibi_wait_dabo!");
00363                          break;
00364     case tibi_wait_home: if(this->move_base_done)
00365                            state=tibi_wait_car_home;
00366                          else if(this->new_joy_cmd)
00367                          {
00368                            if(this->joy_cmd==joy_cancel_goal)
00369                            {
00370                              this->move_base_client_.cancelGoal();
00371                              state=tibi_wait_car_home;
00372                              this->new_joy_cmd=false;
00373                            }
00374                            else if(this->joy_cmd==joy_replan_goal)
00375                            {
00376                              move_base_goal_.target_pose.header.stamp=ros::Time::now();
00377                              // start moving to the goal
00378                              move_baseMakeActionRequest();
00379                              state=tibi_wait_home;
00380                              this->new_joy_cmd=false;
00381                            }
00382                            else
00383                            {
00384                              state=tibi_wait_home;
00385                              this->new_joy_cmd=false;
00386                            }
00387                          }
00388                          else
00389                            state=tibi_wait_home;
00390                          ROS_INFO("TibiCoopAlgNode: state tibi_wait_home!");
00391                          break;
00392     case tibi_wait_car_home: if(this->new_car_cmd)
00393                              {
00394                                this->new_car_cmd=false;
00395                                if(this->car_cmd==tibi_car_done)
00396                                  state=tibi_idle;
00397                                else
00398                                  state=tibi_wait_car_home;
00399                              }
00400                              else
00401                                state=tibi_wait_car_home;
00402                              ROS_INFO("TibiCoopAlgNode: state tibi_wait_car_home!");
00403                              break;
00404   }
00405   this->current_state=state;
00406   alg_.unlock(); 
00407 
00408   // [fill msg structures]
00409   
00410   // [fill srv structure and make request to the server]
00411   
00412   // [fill action structure and make request to the action server]
00413 
00414   // [publish messages]
00415 }
00416 
00417 /*  [subscriber callbacks] */
00418 void TibiCoopAlgNode::supervisor_callback(const sensor_msgs::Joy::ConstPtr& msg) 
00419 { 
00420 //  ROS_INFO("TibiCoopAlgNode::supervisor_callback: New Message Received"); 
00421   static std::vector<int> prev_buttons(msg->buttons);
00422 
00423   this->alg_.lock(); 
00424 
00425   if(msg->buttons[wiimote::State::MSG_BTN_PLUS]==1 && prev_buttons[wiimote::State::MSG_BTN_PLUS]==0)//replan
00426   {
00427     ROS_INFO("Replan"); 
00428     this->joy_cmd=joy_replan_goal;
00429     this->new_joy_cmd=true;
00430   }
00431   else if(msg->buttons[wiimote::State::MSG_BTN_MINUS]==1 && prev_buttons[wiimote::State::MSG_BTN_MINUS]==0)// cancel goal
00432   {
00433   ROS_INFO("Cancel"); 
00434     this->joy_cmd=joy_cancel_goal;
00435     this->new_joy_cmd=true;
00436   }
00437   else if(msg->buttons[wiimote::State::MSG_BTN_HOME]==1 && prev_buttons[wiimote::State::MSG_BTN_HOME]==0)// teleop
00438   {
00439   ROS_INFO("Teleop"); 
00440     this->joy_cmd=joy_teleop;
00441     this->new_joy_cmd=true;
00442   }
00443 
00444   prev_buttons=msg->buttons;
00445 
00446   //unlock previously blocked shared variables 
00447   this->alg_.unlock(); 
00448   //this->supervisor_mutex_.exit(); 
00449 }
00450 
00451 /*  [service callbacks] */
00452 
00453 /*  [action callbacks] */
00454 void TibiCoopAlgNode::move_guideDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::guideGoalResultConstPtr& result) 
00455 { 
00456   if( state.toString().compare("SUCCEEDED") == 0 ) 
00457     ROS_INFO("TibiCoopAlgNode::move_guideDone: Goal Achieved!"); 
00458   else 
00459     ROS_INFO("TibiCoopAlgNode::move_guideDone: %s", state.toString().c_str()); 
00460   this->move_guide_done=true;
00461 
00462   //copy & work with requested result 
00463 } 
00464 
00465 void TibiCoopAlgNode::move_guideActive() 
00466 { 
00467   //ROS_INFO("TibiCoopAlgNode::move_guideActive: Goal just went active!"); 
00468 } 
00469 
00470 void TibiCoopAlgNode::move_guideFeedback(const tibi_dabo_msgs::guideGoalFeedbackConstPtr& feedback) 
00471 { 
00472   //ROS_INFO("TibiCoopAlgNode::move_guideFeedback: Got Feedback!"); 
00473 
00474   bool feedback_is_ok = true; 
00475 
00476   //analyze feedback 
00477   //my_var = feedback->var; 
00478 
00479   //if feedback is not what expected, cancel requested goal 
00480   if( !feedback_is_ok ) 
00481   { 
00482     move_guide_client_.cancelGoal(); 
00483     //ROS_INFO("TibiCoopAlgNode::move_guideFeedback: Cancelling Action!"); 
00484   } 
00485 }
00486 void TibiCoopAlgNode::car_tibi_actionStartCallback(const tibi_dabo_msgs::guiGoalConstPtr& goal)
00487 {
00488   ROS_INFO("TibiCoopAlgNode::car_tibi_actionStartCallback!"); 
00489   alg_.lock(); 
00490     //check goal 
00491   this->car_cmd=(tibi_cmds)goal->cmd_id;
00492   switch(this->car_cmd)
00493   {
00494     case tibi_set_goal: this->new_car_cmd=false;
00495                         break;
00496     case tibi_car_done: this->new_car_cmd=true;
00497                         break;
00498     default: this->new_car_cmd=false;
00499              break;
00500   }
00501     //execute goal 
00502   alg_.unlock(); 
00503 } 
00504 
00505 void TibiCoopAlgNode::car_tibi_actionStopCallback(void) 
00506 { 
00507   alg_.lock(); 
00508     //stop action 
00509   alg_.unlock(); 
00510 } 
00511 
00512 bool TibiCoopAlgNode::car_tibi_actionIsFinishedCallback(void) 
00513 { 
00514   bool ret = false; 
00515 
00516   alg_.lock(); 
00517     //if action has finish for any reason 
00518   if(this->current_state==tibi_idle)
00519     ret=true;
00520   else
00521     ret=false;
00522     //ret = true; 
00523   alg_.unlock(); 
00524 
00525   return ret; 
00526 } 
00527 
00528 bool TibiCoopAlgNode::car_tibi_actionHasSucceedCallback(void) 
00529 { 
00530   bool ret = false; 
00531 
00532   alg_.lock(); 
00533     //if goal was accomplished 
00534     ret = true; 
00535   alg_.unlock(); 
00536 
00537   return ret; 
00538 } 
00539 
00540 void TibiCoopAlgNode::car_tibi_actionGetResultCallback(tibi_dabo_msgs::guiResultPtr& result) 
00541 { 
00542   alg_.lock(); 
00543     //update result data to be sent to client 
00544     //result->data = data; 
00545   alg_.unlock(); 
00546 } 
00547 
00548 void TibiCoopAlgNode::car_tibi_actionGetFeedbackCallback(tibi_dabo_msgs::guiFeedbackPtr& feedback) 
00549 { 
00550   alg_.lock(); 
00551     //keep track of feedback 
00552     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00553   alg_.unlock(); 
00554 }
00555 void TibiCoopAlgNode::dabo_tibi_actionStartCallback(const tibi_dabo_msgs::guiGoalConstPtr& goal)
00556 { 
00557   ROS_INFO("TibiCoopAlgNode::dabo_tibi_actionStartCallback");
00558   alg_.lock(); 
00559     //check goal 
00560   this->dabo_cmd=(tibi_cmds)goal->cmd_id;
00561   switch(this->dabo_cmd)
00562   {
00563     case tibi_set_goal: if(goal->string_params.size()==1)
00564                         {
00565                           this->dabo_location_id=goal->string_params[0];
00566                           this->new_dabo_cmd=true;
00567                         }
00568                         else
00569                           this->new_dabo_cmd=false;
00570                         break;
00571     case tibi_car_done: this->new_dabo_cmd=false;
00572                         break;
00573     default: this->new_dabo_cmd=false;
00574              break;
00575   }
00576 
00577     //execute goal 
00578   alg_.unlock(); 
00579 } 
00580 
00581 void TibiCoopAlgNode::dabo_tibi_actionStopCallback(void) 
00582 { 
00583   alg_.lock(); 
00584     //stop action 
00585   // cancel the move base goal
00586   move_base_client_.cancelGoal();
00587   alg_.unlock(); 
00588 } 
00589 
00590 bool TibiCoopAlgNode::dabo_tibi_actionIsFinishedCallback(void) 
00591 { 
00592   bool ret = false; 
00593 
00594   alg_.lock(); 
00595     //if action has finish for any reason 
00596   if(this->current_state==tibi_idle)
00597     ret=true;
00598   else
00599     ret=false;
00600     //ret = true; 
00601   alg_.unlock(); 
00602 
00603   return ret; 
00604 } 
00605 
00606 bool TibiCoopAlgNode::dabo_tibi_actionHasSucceedCallback(void) 
00607 { 
00608   bool ret = false; 
00609 
00610   alg_.lock(); 
00611     //if goal was accomplished 
00612     ret = true; 
00613   alg_.unlock(); 
00614 
00615   return ret; 
00616 } 
00617 
00618 void TibiCoopAlgNode::dabo_tibi_actionGetResultCallback(tibi_dabo_msgs::guiResultPtr& result) 
00619 { 
00620   alg_.lock(); 
00621     //update result data to be sent to client 
00622     //result->data = data; 
00623   alg_.unlock(); 
00624 } 
00625 
00626 void TibiCoopAlgNode::dabo_tibi_actionGetFeedbackCallback(tibi_dabo_msgs::guiFeedbackPtr& feedback) 
00627 { 
00628   alg_.lock(); 
00629     //keep track of feedback 
00630     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00631   alg_.unlock(); 
00632 }
00633 void TibiCoopAlgNode::tibi_car_actionDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::guiResultConstPtr& result) 
00634 {
00635   this->alg_.lock(); 
00636   if( state.toString().compare("SUCCEEDED") == 0 ) 
00637     ROS_INFO("TibiCoopAlgNode::tibi_car_actionDone: Goal Achieved!"); 
00638   else 
00639     ROS_INFO("TibiCoopAlgNode::tibi_car_actionDone: %s", state.toString().c_str()); 
00640   this->tibi_car_action_done=true;
00641 
00642   //copy & work with requested result 
00643   this->alg_.unlock(); 
00644 } 
00645 
00646 void TibiCoopAlgNode::tibi_car_actionActive() 
00647 { 
00648   //ROS_INFO("TibiCoopAlgNode::tibi_car_actionActive: Goal just went active!"); 
00649 } 
00650 
00651 void TibiCoopAlgNode::tibi_car_actionFeedback(const tibi_dabo_msgs::guiFeedbackConstPtr& feedback) 
00652 { 
00653   //ROS_INFO("TibiCoopAlgNode::tibi_car_actionFeedback: Got Feedback!"); 
00654 
00655   bool feedback_is_ok = true; 
00656 
00657   //analyze feedback 
00658   //my_var = feedback->var; 
00659 
00660   //if feedback is not what expected, cancel requested goal 
00661   if( !feedback_is_ok ) 
00662   { 
00663     tibi_car_action_client_.cancelGoal(); 
00664     //ROS_INFO("TibiCoopAlgNode::tibi_car_actionFeedback: Cancelling Action!"); 
00665   } 
00666 }
00667 void TibiCoopAlgNode::gui_actionStartCallback(const tibi_dabo_msgs::guiGoalConstPtr& goal)
00668 {
00669   ROS_INFO("TibiCoopAlgNode::gui_actionStartCallback"); 
00670   alg_.lock(); 
00671     //check goal 
00672   this->gui_cmd=(gui_cmds)goal->cmd_id;
00673   switch(this->gui_cmd)
00674   {
00675     case gui_set_goal: if(goal->string_params.size()==1)
00676                        {
00677                          this->gui_location_id=goal->string_params[0];
00678                          this->new_gui_cmd=true;
00679                        }
00680                        else
00681                          this->new_gui_cmd=false;
00682                        break;
00683     case gui_cancel_goal: this->new_gui_cmd=false;
00684                           break;
00685     default: this->new_gui_cmd=false; 
00686              break;
00687   }
00688     //execute goal 
00689   alg_.unlock(); 
00690 } 
00691 
00692 void TibiCoopAlgNode::gui_actionStopCallback(void) 
00693 { 
00694   alg_.lock(); 
00695     //stop action 
00696   // cancel the move base goal
00697   move_base_client_.cancelGoal();
00698   alg_.unlock(); 
00699 } 
00700 
00701 bool TibiCoopAlgNode::gui_actionIsFinishedCallback(void) 
00702 { 
00703   bool ret = false; 
00704 
00705   alg_.lock(); 
00706     //if action has finish for any reason 
00707   if(this->current_state==tibi_wait_car_home)
00708     ret=true;
00709   else
00710     ret=false;
00711     //ret = true; 
00712   alg_.unlock(); 
00713 
00714   return ret; 
00715 } 
00716 
00717 bool TibiCoopAlgNode::gui_actionHasSucceedCallback(void) 
00718 { 
00719   bool ret = false; 
00720 
00721   alg_.lock(); 
00722     //if goal was accomplished 
00723   ret=true;
00724     //ret = true; 
00725   alg_.unlock(); 
00726 
00727   return ret; 
00728 } 
00729 
00730 void TibiCoopAlgNode::gui_actionGetResultCallback(tibi_dabo_msgs::guiResultPtr& result) 
00731 { 
00732   alg_.lock(); 
00733     //update result data to be sent to client 
00734     //result->data = data; 
00735   alg_.unlock(); 
00736 } 
00737 
00738 void TibiCoopAlgNode::gui_actionGetFeedbackCallback(tibi_dabo_msgs::guiFeedbackPtr& feedback) 
00739 { 
00740   alg_.lock(); 
00741     //keep track of feedback
00742     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00743   alg_.unlock(); 
00744 }
00745 
00746 void TibiCoopAlgNode::move_baseDone(const actionlib::SimpleClientGoalState& state,  const move_base_msgs::MoveBaseResultConstPtr& result) 
00747 { 
00748   this->alg_.lock(); 
00749   if( state.toString().compare("SUCCEEDED") == 0 ) 
00750     ROS_INFO("TibiCoopAlgNode::move_baseDone: Goal Achieved!"); 
00751   else 
00752     ROS_INFO("TibiCoopAlgNode::move_baseDone: %s", state.toString().c_str()); 
00753   this->move_base_done=true;
00754   //copy & work with requested result 
00755   this->alg_.unlock(); 
00756 } 
00757 
00758 void TibiCoopAlgNode::move_baseActive() 
00759 { 
00760   //ROS_INFO("TibiCoopAlgNode::move_baseActive: Goal just went active!"); 
00761 } 
00762 
00763 void TibiCoopAlgNode::move_baseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback) 
00764 { 
00765   //ROS_INFO("TibiCoopAlgNode::move_baseFeedback: Got Feedback!"); 
00766 
00767   bool feedback_is_ok = true; 
00768 
00769   //analyze feedback 
00770   //my_var = feedback->var; 
00771 
00772   //if feedback is not what expected, cancel requested goal 
00773   if( !feedback_is_ok ) 
00774   { 
00775     move_base_client_.cancelGoal(); 
00776     //ROS_INFO("TibiCoopAlgNode::move_baseFeedback: Cancelling Action!"); 
00777   } 
00778 }
00779 
00780 void TibiCoopAlgNode::hri_clientDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::sequenceResultConstPtr& result) 
00781 {
00782   this->alg_.lock(); 
00783   if( state.toString().compare("SUCCEEDED") == 0 ) 
00784     ROS_INFO("TibiCoopAlgNode::hri_clientDone: Goal Achieved!"); 
00785   else 
00786     ROS_INFO("TibiCoopAlgNode::hri_clientDone: %s", state.toString().c_str()); 
00787 
00788   this->hri_client_done=true;
00789   //copy & work with requested result 
00790   this->alg_.unlock(); 
00791 } 
00792 
00793 void TibiCoopAlgNode::hri_clientActive() 
00794 { 
00795   //ROS_INFO("TibiCoopAlgNode::hri_clientActive: Goal just went active!"); 
00796 } 
00797 
00798 void TibiCoopAlgNode::hri_clientFeedback(const tibi_dabo_msgs::sequenceFeedbackConstPtr& feedback) 
00799 { 
00800   //ROS_INFO("TibiCoopAlgNode::hri_clientFeedback: Got Feedback!"); 
00801 
00802   bool feedback_is_ok = true; 
00803 
00804   //analyze feedback 
00805   //my_var = feedback->var; 
00806 
00807   //if feedback is not what expected, cancel requested goal 
00808   if( !feedback_is_ok ) 
00809   { 
00810     hri_client_client_.cancelGoal(); 
00811     //ROS_INFO("TibiCoopAlgNode::hri_clientFeedback: Cancelling Action!"); 
00812   } 
00813 }
00814 
00815 /*  [action requests] */
00816 void TibiCoopAlgNode::move_guideMakeActionRequest() 
00817 { 
00818   ROS_INFO("TibiCoopAlgNode::move_guideMakeActionRequest: Starting New Request!"); 
00819 
00820   //wait for the action server to start 
00821   //will wait for infinite time 
00822   move_guide_client_.waitForServer();  
00823   ROS_INFO("TibiCoopAlgNode::move_guideMakeActionRequest: Server is Available!"); 
00824 
00825   //send a goal to the action 
00826   //move_guide_goal_.data = my_desired_goal; 
00827   move_guide_client_.sendGoal(move_guide_goal_, 
00828               boost::bind(&TibiCoopAlgNode::move_guideDone,     this, _1, _2), 
00829               boost::bind(&TibiCoopAlgNode::move_guideActive,   this), 
00830               boost::bind(&TibiCoopAlgNode::move_guideFeedback, this, _1)); 
00831   this->move_guide_done=false;
00832   ROS_INFO("TibiCoopAlgNode::move_guideMakeActionRequest: Goal Sent. Wait for Result!"); 
00833 }
00834 bool TibiCoopAlgNode::tibi_car_actionMakeActionRequest() 
00835 { 
00836   ROS_INFO("TibiCoopAlgNode::tibi_car_actionMakeActionRequest: Starting New Request!"); 
00837 
00838   //wait for the action server to start 
00839   //will wait for infinite time 
00840   if(!tibi_car_action_client_.waitForServer(ros::Duration(2.0)))  
00841     return false;
00842   ROS_INFO("TibiCoopAlgNode::tibi_car_actionMakeActionRequest: Server is Available!"); 
00843 
00844   //send a goal to the action 
00845   //tibi_car_action_goal_.data = my_desired_goal; 
00846   tibi_car_action_client_.sendGoal(tibi_car_action_goal_, 
00847               boost::bind(&TibiCoopAlgNode::tibi_car_actionDone,     this, _1, _2), 
00848               boost::bind(&TibiCoopAlgNode::tibi_car_actionActive,   this), 
00849               boost::bind(&TibiCoopAlgNode::tibi_car_actionFeedback, this, _1)); 
00850   this->tibi_car_action_done=false;
00851   ROS_INFO("TibiCoopAlgNode::tibi_car_actionMakeActionRequest: Goal Sent. Wait for Result!"); 
00852 
00853   return true;
00854 }
00855 
00856 bool TibiCoopAlgNode::move_baseMakeActionRequest() 
00857 { 
00858   ROS_INFO("TibiCoopAlgNode::move_baseMakeActionRequest: Starting New Request!"); 
00859 
00860   //wait for the action server to start 
00861   //will wait for infinite time 
00862   if(!move_base_client_.waitForServer(ros::Duration(2.0)))
00863     return false;  
00864   ROS_INFO("TibiCoopAlgNode::move_baseMakeActionRequest: Server is Available!"); 
00865 
00866   //send a goal to the action 
00867   //move_base_goal_.data = my_desired_goal; 
00868   move_base_client_.sendGoal(move_base_goal_, 
00869               boost::bind(&TibiCoopAlgNode::move_baseDone,     this, _1, _2), 
00870               boost::bind(&TibiCoopAlgNode::move_baseActive,   this), 
00871               boost::bind(&TibiCoopAlgNode::move_baseFeedback, this, _1)); 
00872   this->move_base_done=false;
00873   ROS_INFO("TibiCoopAlgNode::move_baseMakeActionRequest: Goal Sent. Wait for Result!"); 
00874 
00875   return true;
00876 }
00877 
00878 bool TibiCoopAlgNode::hri_clientMakeActionRequest() 
00879 { 
00880   ROS_INFO("TibiCoopAlgNode::hri_clientMakeActionRequest: Starting New Request!"); 
00881 
00882   //wait for the action server to start 
00883   //will wait for infinite time 
00884   if(!hri_client_client_.waitForServer(ros::Duration(2.0)))
00885     return false;  
00886   ROS_INFO("TibiCoopAlgNode::hri_clientMakeActionRequest: Server is Available!"); 
00887 
00888   //send a goal to the action 
00889   //hri_client_goal_.data = my_desired_goal; 
00890   hri_client_client_.sendGoal(hri_client_goal_, 
00891               boost::bind(&TibiCoopAlgNode::hri_clientDone,     this, _1, _2), 
00892               boost::bind(&TibiCoopAlgNode::hri_clientActive,   this), 
00893               boost::bind(&TibiCoopAlgNode::hri_clientFeedback, this, _1)); 
00894   this->hri_client_done=false;
00895   ROS_INFO("TibiCoopAlgNode::hri_clientMakeActionRequest: Goal Sent. Wait for Result!"); 
00896   ROS_INFO("TibiCoopAlgNode::hri_clientMakeActionRequest: Goal tts: %s",this->hri_client_goal_.sequence_file[0].c_str()); 
00897 
00898   return true;
00899 }
00900 
00901 void TibiCoopAlgNode::loadSentences()
00902 {
00903   std::vector<std::string> sentence;
00904   sentence.push_back("Destinació seleccionada. Segueix-me si us plau.");
00905   sentence.push_back("Destination selected. Follow me, please.");
00906   sentence.push_back("Destinación seleccionada. Sígueme por favor");
00907   sentences.push_back(sentence);
00908   sentence.clear();
00909   sentence.push_back("Where do you want to go?");
00910   sentence.push_back("A on vols anar?");
00911   sentence.push_back("¿A dónde quieres ir?");
00912   sentences.push_back(sentence);
00913   sentence.clear();
00914   sentence.push_back("Puja al vehicle i prem el botó de la pantalla quan estiguis llest.");
00915   sentence.push_back("Get in the vehicle and press the screen button when you are ready");
00916   sentence.push_back("Sube al vehículo y pulta el botón de la pantalla cuando estés listo.");
00917   sentences.push_back(sentence);
00918   sentence.clear();
00919   sentence.push_back("Espera al vehicle.");
00920   sentence.push_back("Wait for the vehicle.");
00921   sentence.push_back("Espera al vehículo.");
00922   sentences.push_back(sentence);
00923   sentence.clear();
00924   sentence.push_back("El vehicle està a punt d'arribar.");
00925   sentence.push_back("The vehicle is about to arrive.");
00926   sentence.push_back("El vehículo está a punto de llegar.");
00927   sentences.push_back(sentence);
00928   sentence.clear();
00929 }
00930 
00931 void TibiCoopAlgNode::node_config_update(Config &config, uint32_t level)
00932 {
00933   this->alg_.lock();
00934 
00935   this->alg_.unlock();
00936 }
00937 
00938 void TibiCoopAlgNode::addNodeDiagnostics(void)
00939 {
00940 }
00941 
00942 /* main function */
00943 int main(int argc,char *argv[])
00944 {
00945   return algorithm_base::main<TibiCoopAlgNode>(argc, argv, "tibi_coop_alg_node");
00946 }
00947 


tibi_coop
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 21:28:54