people_follower_client_alg.cpp
Go to the documentation of this file.
00001 #include "people_follower_client_alg.h"
00002 
00003 #include <vector>
00004 
00005 PeopleFollowerClientAlgorithm::PeopleFollowerClientAlgorithm(void)
00006 {
00007 }
00008 
00009 PeopleFollowerClientAlgorithm::~PeopleFollowerClientAlgorithm(void)
00010 {
00011 }
00012 
00013 void PeopleFollowerClientAlgorithm::config_update(Config& new_cfg, uint32_t level)
00014 {
00015   this->lock();
00016 
00017   // save the current configuration
00018   this->config_=new_cfg;
00019   
00020   this->unlock();
00021 }
00022 
00023 // PeopleFollowerClientAlgorithm Public API
00024 bool PeopleFollowerClientAlgorithm::isSomeoneStanding(const iri_people_tracking::peopleTrackingArray::ConstPtr& msg, 
00025                                                       unsigned int & target_index)
00026 {
00027   bool ret = false;
00028 
00029   ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: msg->peopleSet.size=%d", msg->peopleSet.size());
00030 
00031   this->lock();
00032   std::vector<TargetPeople> vCurrentTargets;
00033 
00034   //for all tracked persons
00035   for(unsigned int ii=0; ii<msg->peopleSet.size(); ii++)
00036   {
00037     unsigned int target_id = (unsigned int)abs(msg->peopleSet[ii].targetId);
00038 
00039     //compute current velocity
00040     float mod_vel = sqrt(msg->peopleSet[ii].vx*msg->peopleSet[ii].vx + 
00041                          msg->peopleSet[ii].vy*msg->peopleSet[ii].vy);
00042 
00043     //if current velocity is below threshold
00044     //person is stopped
00045     if( mod_vel < people_stand_max_vel_ )
00046     {
00047       //check if this person was already tracked
00048       bool found = false;
00049       unsigned int jj;
00050       for(jj=0; jj<vTargets_.size(); jj++)
00051       {
00052         if( target_id == vTargets_[jj].target_id )
00053         {
00054           ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: target_id=%d FOUND in jj=%d!", target_id, jj);
00055           found = true;
00056           break;
00057         }
00058       }
00059     
00060       ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: target_id=%d STANDING!", target_id);
00061 
00062       //if target was already tracked
00063       if(found)
00064         vCurrentTargets.push_back( TargetPeople(target_id, ++vTargets_[jj].stop_iter) );
00065       //if first time
00066       else
00067         vCurrentTargets.push_back( TargetPeople(target_id) );
00068 
00069       ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: [%d][%d] target_id=%d stop_iter=%d", ii, jj, target_id, vCurrentTargets[jj].stop_iter);
00070     }
00071     //person is moving
00072     else
00073       ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: targetId=%d MOVING", target_id);
00074   }
00075 
00076   //for all current tracked targets
00077   target_index = msg->peopleSet.size()+1;
00078   float min_dist = 1000000000.f;
00079   for(unsigned int ii=0; ii<vCurrentTargets.size(); ii++)
00080   {
00081     //if number of stopped iterations greater than threshold
00082     if( vCurrentTargets[ii].stop_iter > min_stopped_iters_)
00083     {
00084       float dist = sqrt(msg->peopleSet[ii].x*msg->peopleSet[ii].x + msg->peopleSet[ii].y*msg->peopleSet[ii].y);
00085       ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: \ttargetId=%d pose=(%f, %f) dist=%f", 
00086                msg->peopleSet[ii].targetId, msg->peopleSet[ii].x, msg->peopleSet[ii].y, dist);
00087       
00088       //check if it is the current minimum distance
00089       if( dist < min_dist )
00090       {
00091         target_index = ii;
00092         min_dist     = dist;
00093       }
00094     }
00095     else
00096       ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: \ttargetId=%d NOT stopped for enough time: %d", msg->peopleSet[ii].targetId, vCurrentTargets[ii].stop_iter);
00097   }
00098 
00099   //save current targets
00100   vTargets_ = vCurrentTargets;
00101   if(target_index != msg->peopleSet.size()+1)
00102   {
00103     ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: Final Candidate: target_id=%d", msg->peopleSet[target_index].targetId);
00104     ret = true;
00105   }
00106   else
00107     ROS_DEBUG("PeopleFollowerClientAlgorithm::isSomeoneStanding: NO Final Candidate");
00108   
00109   this->unlock();
00110 
00111   return ret;
00112 }


iri_people_follower_client
Author(s):
autogenerated on Fri Dec 6 2013 21:02:34