tibi_dabo_guide_nav_alg_node.cpp
Go to the documentation of this file.
00001 #include "tibi_dabo_guide_nav_alg_node.h"
00002 #include <limits>
00003 
00004 TibiDaboGuideNavAlgNode::TibiDaboGuideNavAlgNode(void) :
00005   algorithm_base::IriBaseAlgorithm<TibiDaboGuideNavAlgorithm>(),
00006   move_guide_aserver_(public_node_handle_, "move_guide"),
00007   hri_client_client_("hri_client", true),
00008   move_base_client_("move_base", true),
00009   tf_listener_(ros::Duration(10.f))
00010 {
00011   //init class attributes if necessary
00012   this->loop_rate_ = 1;//in [Hz]
00013 
00014   this->move_base_done        = true;
00015   this->distanceThresholdFar  = -1;
00016   this->distanceThresholdNear = -1;
00017   this->current_state         = guide_idle;
00018   this->public_node_handle_.getParam("robot_frame",this->robot_frame);
00019   this->person_distance       = -1.0;
00020   this->person_lost           = true;
00021   this->hri_client_done       = true;
00022   this->success               = false;
00023 
00024   // [init publishers]
00025   
00026   // [init subscribers]
00027 
00028   this->peopleSet_subscriber_ = this->public_node_handle_.subscribe("peopleSet", 100, &TibiDaboGuideNavAlgNode::peopleSet_callback, this);
00029   
00030   // [init services]
00031   
00032   // [init clients]
00033   change_speed_client_ = this->public_node_handle_.serviceClient<iri_diff_local_planner::change_max_vel>("change_max_vel");
00034   get_goal_client_ = this->public_node_handle_.serviceClient<iri_goal_database::get_goal>("get_goal");
00035   
00036   // [init action servers]
00037   move_guide_aserver_.registerStartCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideStartCallback, this, _1)); 
00038   move_guide_aserver_.registerStopCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideStopCallback, this)); 
00039   move_guide_aserver_.registerIsFinishedCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideIsFinishedCallback, this)); 
00040   move_guide_aserver_.registerHasSucceedCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideHasSucceedCallback, this)); 
00041   move_guide_aserver_.registerGetResultCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideGetResultCallback, this, _1)); 
00042   move_guide_aserver_.registerGetFeedbackCallback(boost::bind(&TibiDaboGuideNavAlgNode::move_guideGetFeedbackCallback, this, _1)); 
00043   move_guide_aserver_.start();  
00044   this->new_guide_request = false;
00045   this->target_id = -1;
00046   // [init action clients]
00047 
00048   this->hri_client_goal_.sequence_file.resize(5);
00049 }
00050 
00051 TibiDaboGuideNavAlgNode::~TibiDaboGuideNavAlgNode(void)
00052 {
00053   // [free dynamic memory]
00054 }
00055 
00056 void TibiDaboGuideNavAlgNode::mainNodeThread(void)
00057 {
00058   static guiding_states state=guide_idle;
00059   static int timeout=0, num_lost=0,num_wait=0;
00060 
00061   this->alg_.lock();
00062   switch(state)
00063   {
00064     case guide_idle: if(this->new_guide_request)
00065                      {
00066                        change_speed_srv_.request.new_max_vel = 0.2;
00067                        ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!"); 
00068                        if (change_speed_client_.call(change_speed_srv_))
00069                        {
00070                          get_goal_srv_.request.location_id = this->location_id;
00071                          get_goal_srv_.request.robot_id = this->robot_id;
00072                          ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!");
00073                          if (get_goal_client_.call(get_goal_srv_))
00074                          {
00075                            //ROS_INFO("TibiDaboGuideNavAlgNode:: Response: %s", get_goal_srv_.response.result); 
00076                            //move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00077                            //move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00078                            //move_base_goal_.target_pose.header.stamp=ros::Time::now();
00079                            //move_base_goal_.target_pose.header.frame_id="/map";
00080                            //move_baseMakeActionRequest();
00081                            move_base_goal_.target_pose.pose.position.x=-1.0;
00082                            move_base_goal_.target_pose.pose.position.y=0.0;
00083                            move_base_goal_.target_pose.pose.position.z=0.0;
00084                            move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(3.14159);
00085                            move_base_goal_.target_pose.header.stamp=ros::Time::now();
00086                            move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00087                            move_baseMakeActionRequest();
00088                            state=guide_wait_goal;
00089                            this->new_guide_request=false;
00090                            num_lost=0;
00091                            num_wait=0;
00092                            timeout=0;
00093                          }
00094                          else
00095                          {
00096                            ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic get_goal "); 
00097                            state=guide_idle;
00098                          }
00099                        }
00100                        else
00101                        {
00102                          ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic change_max_vel "); 
00103                          state=guide_idle;
00104                        }
00105                      }
00106                      else
00107                        state=guide_idle;
00108                      ROS_INFO("State: GUIDE_IDLE");  
00109                      break;
00110     case guide_wait_goal: if(move_base_done)
00111                           {
00112                             move_base_goal_.target_pose.header.stamp=ros::Time::now();
00113                             move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00114                             move_base_goal_.target_pose.pose.position.x=0.0;
00115                             move_base_goal_.target_pose.pose.position.y=0.0;
00116                             move_base_goal_.target_pose.pose.position.z=0.0;
00117                             move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(atan2(this->person_pose.pose.position.y,this->person_pose.pose.position.x));
00118                             move_baseMakeActionRequest();
00119                             state=guide_face_person;
00120                           }
00121                           else
00122                           {
00123                             if(person_lost) 
00124                             {
00125                               // stop the robot
00126                               this->move_base_client_.cancelGoal(); 
00127                               state=guide_person_lost_hri;;
00128                             }
00129                             else
00130                             {
00131                               if(this->person_distance>this->distanceThresholdFar)
00132                               {
00133                                 // stop and turn arround
00134                                 state=guide_cancel_goal;
00135                               }
00136                               else if(this->person_distance>this->distanceThresholdNear)
00137                               {
00138                                 // slow down
00139                                 state=guide_slow_down;
00140                               }
00141                               else
00142                               {
00143                                 state=guide_wait_goal;
00144                               }
00145                             }
00146                           }
00147                           ROS_INFO("State: GUIDE_WAIT_GOAL");  
00148                           break;
00149     case guide_slow_down: // change the planner max speed with a service     
00150                           change_speed_srv_.request.new_max_vel = 0.1;
00151                           //ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!"); 
00152                           if (change_speed_client_.call(change_speed_srv_)) 
00153                           {  
00154                             //ROS_INFO("TibiDaboGuideNavAlgNode:: Response: %s", change_speed_srv_.response.result); 
00155                             if(move_base_done)
00156                             {
00157                               move_base_goal_.target_pose.header.stamp=ros::Time::now();
00158                               move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00159                               move_base_goal_.target_pose.pose.position.x=0.0;
00160                               move_base_goal_.target_pose.pose.position.y=0.0;
00161                               move_base_goal_.target_pose.pose.position.z=0.0;
00162                               move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(atan2(this->person_pose.pose.position.y,this->person_pose.pose.position.x));
00163                               move_baseMakeActionRequest();
00164                               state=guide_face_person;
00165                             }
00166                             else
00167                             {
00168                               if(person_lost)
00169                               {
00170                                 // stop the robot
00171                                 this->move_base_client_.cancelGoal();
00172                                 state=guide_person_lost_hri;;
00173                               }
00174                               else
00175                               {
00176                                 if(this->person_distance>this->distanceThresholdFar)
00177                                 {
00178                                   // stop and turn arround
00179                                   state=guide_cancel_goal;
00180                                 }
00181                                 else if(this->person_distance<this->distanceThresholdNear)
00182                                 {
00183                                   change_speed_srv_.request.new_max_vel = 0.2;
00184                                   //ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!"); 
00185                                   if (change_speed_client_.call(change_speed_srv_))
00186                                   {
00187                                     state=guide_wait_goal;
00188                                   }
00189                                   else
00190                                   {
00191                                     //ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic change_speed "); 
00192                                     state=guide_slow_down;
00193                                   }
00194                                 }
00195                                 else
00196                                 {
00197                                   state=guide_slow_down;
00198                                 }
00199                               }
00200                             }
00201                           }  
00202                           else 
00203                           {  
00204                             //ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic change_speed "); 
00205                             state=guide_slow_down;
00206                           }
00207                           ROS_INFO("State: GUIDE_SLOW_DOWN");  
00208                           break;
00209     case guide_cancel_goal: // cancel the current goal
00210                             this->move_base_client_.cancelGoal(); 
00211                             state=guide_turn_arround;
00212                             ROS_INFO("State: GUIDE_CANCEL_GOAL");  
00213                             break;
00214     case guide_turn_arround: if(this->move_base_done)
00215                              {
00216                                move_base_goal_.target_pose.header.stamp=ros::Time::now();
00217                                move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00218                                move_base_goal_.target_pose.pose.position.x=0.0;
00219                                move_base_goal_.target_pose.pose.position.y=0.0;
00220                                move_base_goal_.target_pose.pose.position.z=0.0;
00221                                move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(atan2(this->person_pose.pose.position.y,this->person_pose.pose.position.x));
00222                                move_baseMakeActionRequest();
00223                                state=guide_wait_person_hri;                       
00224                              }
00225                              else
00226                                state=guide_turn_arround;
00227                              ROS_INFO("State: GUIDE_TURN_ARROUND");  
00228                              break;
00229     case guide_wait_person_hri: if(this->move_base_done)
00230                                 {
00231                                   // start HRI action
00232                                   this->hri_client_goal_.sequence_file[0] = "Your are quite far, please come closer to me!";
00233                                   this->hri_client_goal_.sequence_file[1] = "";
00234                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00235                                   this->hri_client_goal_.sequence_file[4] = "";
00236                                   this->hri_client_goal_.sequence_file[3] = "";
00237                                   hri_clientMakeActionRequest();
00238                                   state=guide_wait_person;
00239                                   timeout=0;
00240                                   num_wait++;
00241                                 }
00242                                 else
00243                                   state=guide_wait_person_hri;
00244                                 ROS_INFO("State: GUIDE_WAIT_PERSON_HRI");  
00245                                 break;
00246     case guide_wait_person: if(this->hri_client_done)
00247                             {
00248                               if(person_lost)
00249                                 state=guide_person_lost_hri;
00250                               else
00251                               {
00252                                 if(this->person_distance<this->distanceThresholdNear)
00253                                 {
00254                                   // continue with the goal
00255                                   get_goal_srv_.request.location_id = this->location_id;
00256                                   get_goal_srv_.request.robot_id = this->robot_id;
00257                                   ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!");
00258                                   if (get_goal_client_.call(get_goal_srv_))
00259                                   {
00260                                     //ROS_INFO("TibiDaboGuideNavAlgNode:: Response: %s", get_goal_srv_.response.result); 
00261                                     //move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00262                                     //move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00263                                     //move_base_goal_.target_pose.header.stamp=ros::Time::now();
00264                                     //move_base_goal_.target_pose.header.frame_id="/map";
00265                                     //move_baseMakeActionRequest();
00266                                     move_base_goal_.target_pose.pose.position.x=-1.0;
00267                                     move_base_goal_.target_pose.pose.position.y=0.0;
00268                                     move_base_goal_.target_pose.pose.position.z=0.0;
00269                                     move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(3.14159);
00270                                     move_base_goal_.target_pose.header.stamp=ros::Time::now();
00271                                     move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00272                                     move_baseMakeActionRequest();
00273                                     state=guide_wait_goal;
00274                                   }
00275                                   else
00276                                   {
00277                                     ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic get_goal "); 
00278                                     state=guide_wait_person;
00279                                   }
00280                                 }
00281                                 else if(timeout>5)
00282                                 {
00283                                   if(num_wait>1)
00284                                   {
00285                                     // start HRI
00286                                     this->hri_client_goal_.sequence_file[0] = "If you will not come closer, I will look for another person.";
00287                                     this->hri_client_goal_.sequence_file[1] = "";
00288                                     this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00289                                     this->hri_client_goal_.sequence_file[4] = "";
00290                                     this->hri_client_goal_.sequence_file[3] = "";
00291                                     hri_clientMakeActionRequest();
00292                                     state=guide_ignored;
00293                                   }
00294                                   else
00295                                     state=guide_wait_person_hri;
00296                                 }
00297                                 else
00298                                 {
00299                                   state=guide_wait_person;
00300                                   timeout+=this->loop_rate_.expectedCycleTime().toSec();
00301                                 }
00302                               }
00303                             }
00304                             else
00305                               state=guide_wait_person;
00306                             ROS_INFO("State: GUIDE_WAIT_PERSON");  
00307                             break;
00308     case guide_person_lost_hri: if(num_lost<3)
00309                                 {
00310                                   if(this->person_lost)
00311                                   {
00312                                     // start HRI action
00313                                     this->hri_client_goal_.sequence_file[0] = "I have lost you, please come closer!";
00314                                     this->hri_client_goal_.sequence_file[1] = "";
00315                                     this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00316                                     this->hri_client_goal_.sequence_file[4] = "";
00317                                     this->hri_client_goal_.sequence_file[3] = "";
00318                                     hri_clientMakeActionRequest();
00319                                     state=guide_person_lost;
00320                                     timeout=0;
00321                                   }
00322                                   else
00323                                   {
00324                                     // continue with the goal
00325                                     get_goal_srv_.request.location_id = this->location_id;
00326                                     get_goal_srv_.request.robot_id = this->robot_id;
00327                                     ROS_INFO("TibiDaboGuideNavAlgNode:: Sending New Request!");
00328                                     if (get_goal_client_.call(get_goal_srv_))
00329                                     {
00330                                       //ROS_INFO("TibiDaboGuideNavAlgNode:: Response: %s", get_goal_srv_.response.result); 
00331                                       //move_base_goal_.target_pose.pose.position=get_goal_srv_.response.goal_pose.position;
00332                                       //move_base_goal_.target_pose.pose.orientation=get_goal_srv_.response.goal_pose.orientation;
00333                                       //move_base_goal_.target_pose.header.stamp=ros::Time::now();
00334                                       //move_base_goal_.target_pose.header.frame_id="/map";
00335                                       //move_baseMakeActionRequest();
00336                                       move_base_goal_.target_pose.pose.position.x=-1.0;
00337                                       move_base_goal_.target_pose.pose.position.y=0.0;
00338                                       move_base_goal_.target_pose.pose.position.z=0.0;
00339                                       move_base_goal_.target_pose.pose.orientation=tf::createQuaternionMsgFromYaw(3.14159);
00340                                       move_base_goal_.target_pose.header.stamp=ros::Time::now();
00341                                       move_base_goal_.target_pose.header.frame_id=this->robot_frame;
00342                                       move_baseMakeActionRequest();
00343                                       state=guide_wait_goal;
00344                                     }
00345                                     else
00346                                     {
00347                                       ROS_INFO("TibiDaboGuideNavAlgNode:: Failed to Call Server on topic get_goal "); 
00348                                       state=guide_wait_person_hri;
00349                                     }
00350                                   }
00351                                   num_lost++;
00352                                 }
00353                                 else
00354                                 {
00355                                   this->hri_client_goal_.sequence_file[0] = "You are ignoring me, I will look for another person!";
00356                                   this->hri_client_goal_.sequence_file[1] = "";
00357                                   this->hri_client_goal_.sequence_file[2] = "head_home.xml";
00358                                   this->hri_client_goal_.sequence_file[4] = "";
00359                                   this->hri_client_goal_.sequence_file[3] = "";
00360                                   hri_clientMakeActionRequest();
00361                                   state=guide_ignored;
00362                                 }
00363                                 ROS_INFO("State: GUIDE_PERSON_LOST_HRI");  
00364                                 break;
00365     case guide_ignored: if(this->hri_client_done)
00366                         {
00367                           state=guide_idle;
00368                           this->success=false;
00369                         }
00370                         else
00371                           state=guide_ignored;
00372                         ROS_INFO("State: GUIDE_IGNORED");  
00373                         break;
00374     case guide_person_lost: if(this->hri_client_done)
00375                             {
00376                               if(timeout>5)
00377                                 state=guide_person_lost_hri;
00378                               else
00379                               {
00380                                 state=guide_person_lost;
00381                                 timeout+=this->loop_rate_.expectedCycleTime().toSec();
00382                               }
00383                             }
00384                             else
00385                               state=guide_person_lost;
00386                             ROS_INFO("State: GUIDE_PERSON_LOST");  
00387                             break;
00388     case guide_face_person: if(this->move_base_done)
00389                             {
00390                               state=guide_idle;
00391                               this->success=true;
00392                             }
00393                             else
00394                               state=guide_face_person; 
00395                             ROS_INFO("State: GUIDE_FACE_PERSON");  
00396                             break;
00397   }
00398   this->current_state=state;
00399   this->alg_.unlock();
00400   
00401   // [fill msg structures]
00402   
00403   // [fill srv structure and make request to the server]
00404   
00405   // [fill action structure and make request to the action server]
00406 
00407   // [publish messages]
00408 }
00409 
00410 /*  [subscriber callbacks] */
00411 
00412 void TibiDaboGuideNavAlgNode::peopleSet_callback(const iri_perception_msgs::peopleTrackingArray::ConstPtr& msg) 
00413 { 
00414   ROS_DEBUG("TibiDaboGuideNavAlgNode::peopleSet_callback: New Message Received"); 
00415   geometry_msgs::PoseStamped closest_pose;
00416   unsigned int i,closest_id=this->target_id;
00417   double closest_dist=std::numeric_limits<double>::max(),x0,y0;
00418   geometry_msgs::PoseStamped poseOut;
00419 
00420   //use appropiate mutex to shared variables if necessary 
00421   this->alg_.lock(); 
00422     if(this->target_id!=-1 && this->current_state!=guide_idle)
00423     {
00424       if(msg->peopleSet.size()==0)
00425         this->person_lost=true;
00426       else
00427       {
00428         for(i=0; i<msg->peopleSet.size(); i++)
00429         {
00430           // found target_id
00431           double x = msg->peopleSet[i].x;
00432           double y = msg->peopleSet[i].y;
00433           if(msg->header.frame_id != this->robot_frame)
00434           {
00435             // transform target pose to target_frame (base_link)
00436             try
00437             {
00438               std::string source_frame = msg->header.frame_id;
00439               std::string target_frame = this->robot_frame;
00440               ros::Time   target_time  = msg->header.stamp;
00441               bool tf_exists = tf_listener_.waitForTransform(target_frame, source_frame, target_time, ros::Duration(5), ros::Duration(0.01));
00442               if(tf_exists)
00443               {
00444                 geometry_msgs::PoseStamped poseIn;
00445                 poseIn.header = msg->header;
00446                 poseIn.pose.position.x   = msg->peopleSet[i].x;
00447                 poseIn.pose.position.y   = msg->peopleSet[i].y;
00448                 poseIn.pose.orientation=tf::createQuaternionMsgFromYaw(0);
00449                 tf_listener_.transformPose( target_frame, poseIn, poseOut);
00450                 // update transformed x,y coordinates
00451                 x = poseOut.pose.position.x;
00452                 y = poseOut.pose.position.y;
00453               }
00454               else
00455               {
00456                 ROS_INFO("TibiDaboGuideNavAlgNode::No transform: %s-->%s", source_frame.c_str(), target_frame.c_str());
00457                 break;
00458               }
00459             }
00460             catch (tf::TransformException &ex)
00461             {
00462               ROS_INFO("TibiDaboGuideNavAlgNode:: %s",ex.what());
00463               break;
00464             }
00465           }
00466           if(msg->peopleSet[i].targetId == this->target_id)
00467           {
00468             //distance to target
00469             this->person_distance = sqrt(x*x+y*y);
00470             this->person_lost=false;
00471             this->person_pose=poseOut;
00472             ROS_INFO("Target id: %d at %f meters",this->target_id,this->person_distance);
00473             break;
00474           }
00475           else
00476           {
00477             x0=this->person_pose.pose.position.x;
00478             y0=this->person_pose.pose.position.y;
00479             if(sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0))<closest_dist)
00480             {
00481               closest_dist=sqrt(x*x+y*y);
00482               closest_pose=this->person_pose;
00483               closest_id=msg->peopleSet[i].targetId;
00484             }
00485           }
00486         }
00487         if(i>=msg->peopleSet.size())
00488         {
00489           ROS_INFO("Target id: %d not prenset, switching to target id %d at %f meters", this->target_id,closest_id, closest_dist);
00490           this->person_distance=closest_dist;
00491           this->person_pose=closest_pose;
00492           this->person_lost=false;
00493           this->target_id=closest_id;
00494         }
00495       }
00496     }
00497     //unlock previously blocked shared variables 
00498   this->alg_.unlock(); 
00499   //this->peopleSet_mutex_.exit(); 
00500 }
00501 
00502 /*  [service callbacks] */
00503 
00504 /*  [action callbacks] */
00505 void TibiDaboGuideNavAlgNode::hri_clientDone(const actionlib::SimpleClientGoalState& state,  const tibi_dabo_msgs::sequenceResultConstPtr& result) 
00506 { 
00507   if( state.toString().compare("SUCCEEDED") == 0 ) 
00508     ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientDone: Goal Achieved!"); 
00509   else 
00510     ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientDone: %s", state.toString().c_str()); 
00511   this->hri_client_done=true;
00512 
00513   //copy & work with requested result 
00514 } 
00515 
00516 void TibiDaboGuideNavAlgNode::hri_clientActive() 
00517 { 
00518   //ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientActive: Goal just went active!"); 
00519 } 
00520 
00521 void TibiDaboGuideNavAlgNode::hri_clientFeedback(const tibi_dabo_msgs::sequenceFeedbackConstPtr& feedback) 
00522 { 
00523   //ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientFeedback: Got Feedback!"); 
00524 
00525   bool feedback_is_ok = true; 
00526 
00527   //analyze feedback 
00528   //my_var = feedback->var; 
00529 
00530   //if feedback is not what expected, cancel requested goal 
00531   if( !feedback_is_ok ) 
00532   { 
00533     hri_client_client_.cancelGoal(); 
00534     //ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientFeedback: Cancelling Action!"); 
00535   } 
00536 }
00537 void TibiDaboGuideNavAlgNode::move_guideStartCallback(const tibi_dabo_msgs::guideGoalGoalConstPtr& goal)
00538 { 
00539   alg_.lock(); 
00540   ROS_INFO("TibiDaboGuideNavAlgNode::New guide request"); 
00541   this->location_id=goal->location_id;
00542   this->robot_id=goal->robot_id;
00543   this->target_id = goal->target_id;
00544   this->new_guide_request=true;
00545   alg_.unlock(); 
00546 } 
00547 
00548 void TibiDaboGuideNavAlgNode::move_guideStopCallback(void) 
00549 { 
00550   alg_.lock(); 
00551     //stop action
00552     //move_base_client_.cancelGoal();
00553   alg_.unlock(); 
00554 } 
00555 
00556 bool TibiDaboGuideNavAlgNode::move_guideIsFinishedCallback(void) 
00557 { 
00558   bool ret = false; 
00559 
00560   alg_.lock(); 
00561     //if action has finish for any reason 
00562   if(this->current_state==guide_face_person)
00563     ret=true;
00564     //ret = true; 
00565   alg_.unlock(); 
00566 
00567   return ret; 
00568 } 
00569 
00570 bool TibiDaboGuideNavAlgNode::move_guideHasSucceedCallback(void) 
00571 { 
00572   bool ret = false; 
00573 
00574   alg_.lock(); 
00575     //if goal was accomplished 
00576     ret = this->success;
00577   alg_.unlock(); 
00578 
00579   return ret; 
00580 } 
00581 
00582 void TibiDaboGuideNavAlgNode::move_guideGetResultCallback(tibi_dabo_msgs::guideGoalResultPtr& result) 
00583 { 
00584   alg_.lock(); 
00585     //update result data to be sent to client 
00586     //result->data = data; 
00587   alg_.unlock(); 
00588 } 
00589 
00590 void TibiDaboGuideNavAlgNode::move_guideGetFeedbackCallback(tibi_dabo_msgs::guideGoalFeedbackPtr& feedback) 
00591 { 
00592   alg_.lock(); 
00593     //keep track of feedback 
00594     //ROS_INFO("feedback: %s", feedback->data.c_str()); 
00595   alg_.unlock(); 
00596 }
00597 
00598 void TibiDaboGuideNavAlgNode::move_baseDone(const actionlib::SimpleClientGoalState& state,  const move_base_msgs::MoveBaseResultConstPtr& result) 
00599 { 
00600   if( state.toString().compare("SUCCEEDED") == 0 )
00601     ROS_INFO("TibiDaboGuideNavAlgNode::move_baseDone: Goal Achieved!");
00602   else 
00603     ROS_INFO("TibiDaboGuideNavAlgNode::move_baseDone: %s", state.toString().c_str()); 
00604 
00605   //copy & work with requested result 
00606   this->move_base_done=true;
00607 } 
00608 
00609 void TibiDaboGuideNavAlgNode::move_baseActive() 
00610 { 
00611   //ROS_INFO("TibiDaboGuideNavAlgNode::move_baseActive: Goal just went active!"); 
00612 } 
00613 
00614 void TibiDaboGuideNavAlgNode::move_baseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback) 
00615 { 
00616   //ROS_INFO("TibiDaboGuideNavAlgNode::move_baseFeedback: Got Feedback!"); 
00617 
00618   bool feedback_is_ok = true; 
00619 
00620   //analyze feedback 
00621   //my_var = feedback->var; 
00622 
00623   //if feedback is not what expected, cancel requested goal 
00624   if( !feedback_is_ok ) 
00625   { 
00626     move_base_client_.cancelGoal(); 
00627     //ROS_INFO("TibiDaboGuideNavAlgNode::move_baseFeedback: Cancelling Action!"); 
00628   } 
00629 }
00630 
00631 /*  [action requests] */
00632 void TibiDaboGuideNavAlgNode::hri_clientMakeActionRequest() 
00633 { 
00634   ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientMakeActionRequest: Starting New Request!"); 
00635 
00636   //wait for the action server to start 
00637   //will wait for infinite time 
00638   hri_client_client_.waitForServer();  
00639   ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientMakeActionRequest: Server is Available!"); 
00640 
00641   //send a goal to the action 
00642   //hri_client_goal_.data = my_desired_goal; 
00643   hri_client_client_.sendGoal(hri_client_goal_, 
00644               boost::bind(&TibiDaboGuideNavAlgNode::hri_clientDone,     this, _1, _2), 
00645               boost::bind(&TibiDaboGuideNavAlgNode::hri_clientActive,   this), 
00646               boost::bind(&TibiDaboGuideNavAlgNode::hri_clientFeedback, this, _1)); 
00647   this->hri_client_done=false;
00648   ROS_INFO("TibiDaboGuideNavAlgNode::hri_clientMakeActionRequest: Goal Sent. Wait for Result!"); 
00649 }
00650 void TibiDaboGuideNavAlgNode::move_baseMakeActionRequest() 
00651 { 
00652   ROS_INFO("TibiDaboGuideNavAlgNode::move_baseMakeActionRequest: Starting New Request!"); 
00653 
00654   //wait for the action server to start 
00655   //will wait for infinite time 
00656   move_base_client_.waitForServer();  
00657   ROS_INFO("TibiDaboGuideNavAlgNode::move_baseMakeActionRequest: Server is Available!"); 
00658 
00659   //send a goal to the action 
00660   //move_base_goal_.data = my_desired_goal; 
00661   move_base_client_.sendGoal(move_base_goal_, 
00662               boost::bind(&TibiDaboGuideNavAlgNode::move_baseDone,     this, _1, _2), 
00663               boost::bind(&TibiDaboGuideNavAlgNode::move_baseActive,   this), 
00664               boost::bind(&TibiDaboGuideNavAlgNode::move_baseFeedback, this, _1)); 
00665   ROS_INFO("TibiDaboGuideNavAlgNode::move_baseMakeActionRequest: Goal Sent. Wait for Result!"); 
00666   this->move_base_done=false;
00667 }
00668 
00669 void TibiDaboGuideNavAlgNode::node_config_update(Config &config, uint32_t level)
00670 {
00671   this->alg_.lock();
00672     this->distanceThresholdFar  = config.distanceThresholdFar;
00673     this->distanceThresholdNear = config.distanceThresholdNear;
00674     this->robot_frame           = config.robot_frame;
00675     this->target_id             = config.target_id;
00676   this->alg_.unlock();
00677 }
00678 
00679 void TibiDaboGuideNavAlgNode::addNodeDiagnostics(void)
00680 {
00681 }
00682 
00683 /* main function */
00684 int main(int argc,char *argv[])
00685 {
00686   return algorithm_base::main<TibiDaboGuideNavAlgNode>(argc, argv, "tibi_dabo_guide_nav_alg_node");
00687 }


tibi_dabo_guide_nav
Author(s): fherrero
autogenerated on Fri Dec 6 2013 23:32:11