Go to the documentation of this file.00001 #include "people_follower_alg.h"
00002
00003 PeopleFollowerAlgorithm::PeopleFollowerAlgorithm(void) :
00004 tf_listener_()
00005 {
00006 }
00007
00008 PeopleFollowerAlgorithm::~PeopleFollowerAlgorithm(void)
00009 {
00010 }
00011
00012 void PeopleFollowerAlgorithm::config_update(Config& new_cfg, uint32_t level)
00013 {
00014 lock();
00015
00016 config_=new_cfg;
00017 unlock();
00018 }
00019
00020
00021
00022 bool PeopleFollowerAlgorithm::transformGoal(geometry_msgs::PoseStamped & pose,
00023 const std::string & target_frame,
00024 const std::string & fixed_frame) const
00025 {
00026 bool tf_exists = false;
00027
00028 try
00029 {
00030
00031 ros::Time request_time = pose.header.stamp;
00032 ROS_DEBUG("PeopleFollowerAlgorithm::transformGoal: now=%f", request_time.toSec());
00033 ROS_DEBUG("PeopleFollowerAlgorithm::transformGoal: header=%f", pose.header.stamp.toSec());
00034
00035
00036 tf_exists = tf_listener_.waitForTransform(target_frame, pose.header.frame_id, request_time, ros::Duration(100));
00037 ROS_DEBUG("PeopleFollowerAlgorithm::transformGoal: tf_exists=%d",tf_exists);
00038
00039 if(tf_exists)
00040 {
00041 ROS_DEBUG("PeopleFollowerAlgorithm::transformGoal: frame_id=%s\tpose=(%f, %f)",
00042 pose.header.frame_id.c_str(),
00043 pose.pose.position.x,
00044 pose.pose.position.y);
00045
00046
00047 tf_listener_.transformPose(target_frame, request_time, pose, fixed_frame, pose);
00048
00049 ROS_DEBUG("PeopleFollowerAlgorithm::transformGoal: frame_id=%s\tpose=(%f, %f)",
00050 pose.header.frame_id.c_str(),
00051 pose.pose.position.x,
00052 pose.pose.position.y);
00053
00054 }
00055 }
00056 catch(tf::TransformException e)
00057 {
00058 ROS_ERROR("PeopleFollowerAlgorithm::TF Error: %s", e.what());
00059 tf_exists = false;
00060 }
00061
00062 return tf_exists;
00063 }
00064
00065 bool PeopleFollowerAlgorithm::udpateGoal(geometry_msgs::PoseStamped & last_pose,
00066 const geometry_msgs::PoseStamped & current_pose,
00067 const float & threshold_dist) const
00068 {
00069 const float alpha = 0.2f;
00070
00071 float dx = last_pose.pose.position.x - current_pose.pose.position.x;
00072 float dy = last_pose.pose.position.y - current_pose.pose.position.y;
00073 float dist = sqrt(dx*dx + dy*dy);
00074
00075 ROS_DEBUG("PeopleFollowerAlgorithm::udpateGoal:: last(%f,%f) current(%f,%f) needs_update=%d (%f>%f)",
00076 last_pose.pose.position.x, last_pose.pose.position.y,
00077 current_pose.pose.position.x, current_pose.pose.position.y, (dist > alpha*threshold_dist),
00078 dist, alpha*threshold_dist);
00079
00080
00081 if( dist > alpha*threshold_dist )
00082 {
00083
00084 last_pose = current_pose;
00085 return true;
00086 }
00087
00088 else
00089 return false;
00090 }
00091
00092 geometry_msgs::Point
00093 PeopleFollowerAlgorithm::substractSafetyDistance(const geometry_msgs::Point & goal_pose,
00094 const float & min_safety_dist)
00095 {
00096 geometry_msgs::Point robot_pose;
00097
00098
00099 float safety_mod = sqrt(goal_pose.x*goal_pose.x + goal_pose.y*goal_pose.y) - min_safety_dist;
00100
00101
00102 robot_pose.x = safety_mod*goal_pose.x;
00103 robot_pose.y = safety_mod*goal_pose.y;
00104
00105 ROS_DEBUG("from goal_pose(%f,%f) to robot_pose(%f,%f)",goal_pose.x,goal_pose.y,robot_pose.x,robot_pose.y);
00106 return robot_pose;
00107 }