Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00047
00048 #include <ros/ros.h>
00049 #include <pcl/common/angles.h>
00050
00051 #include <tf/transform_listener.h>
00052 #include <kinect_cleanup/GrabObject.h>
00053 #include <kinect_cleanup/ReleaseObject.h>
00054
00055 using namespace std;
00056
00057 class HumanTracker
00058 {
00059 protected:
00060 ros::NodeHandle nh_;
00061
00062 public:
00063 tf::TransformListener tf_;
00064 std::string gesture_arm_, pointing_arm_;
00065 std::string neck_frame_, world_;
00066 double tf_buffer_time_;
00067 bool start_, stop_;
00068 ros::ServiceClient client_grab, client_release;
00070 HumanTracker (ros::NodeHandle &n) : nh_(n)
00071 {
00072 nh_.param("world", world_, std::string("openni_rgb_optical_frame"));
00073 nh_.param("neck_frame", neck_frame_, std::string("neck"));
00074 nh_.param("gesture_arm", gesture_arm_, std::string("left"));
00075 nh_.param("pointing_arm", pointing_arm_, std::string("right"));
00076
00077 nh_.param("tf_buffer_time", tf_buffer_time_, 1.0);
00078 start_ = stop_ = false;
00079 client_grab = nh_.serviceClient<kinect_cleanup::GrabObject>("/grab_object");
00080 client_release = nh_.serviceClient<kinect_cleanup::ReleaseObject>("/release_object");
00081 }
00082
00084
00085 void spin ()
00086 {
00087 ros::Rate loop_rate(20);
00088 while (ros::ok())
00089 {
00090
00091 ros::Time time = ros::Time::now();
00092 bool found_transform1 = tf_.waitForTransform(neck_frame_, gesture_arm_ + "_elbow",
00093 time, ros::Duration(tf_buffer_time_));
00094 bool found_transform2 = tf_.waitForTransform(neck_frame_, gesture_arm_ + "_hand",
00095 time, ros::Duration(tf_buffer_time_));
00096 if (found_transform1 && found_transform2)
00097 {
00098 tf::StampedTransform transform1, transform2;
00099 tf_.lookupTransform(neck_frame_, gesture_arm_ + "_elbow", time, transform1);
00100 tf_.lookupTransform(neck_frame_, gesture_arm_ + "_hand", time, transform2);
00101
00102
00103
00104
00105
00106 if (fabs(transform2.getOrigin().x()) > 0.6)
00107 {
00108 ROS_INFO("Stop");
00109 stop_ = true;
00110 kinect_cleanup::ReleaseObject srv_release;
00111 srv_release.request.release = stop_;
00112 if (client_release.call (srv_release))
00113 {
00114 ROS_INFO ("Service call /release_object successful");
00115 }
00116 else
00117 {
00118 ROS_ERROR ("Failed to call service /release_object");
00119 }
00120 }
00121
00122
00123
00124
00125
00126 else if (-0.3 > transform2.getOrigin().z())
00127 {
00128 ROS_INFO("Start");
00129 start_ = true;
00130 }
00131 else
00132 {
00133
00134 }
00135 }
00136
00137
00138 if (start_)
00139 {
00140
00141 time = ros::Time::now();
00142 bool found_transform3 = tf_.waitForTransform(world_, pointing_arm_ + "_elbow",
00143 time, ros::Duration(tf_buffer_time_));
00144
00145 bool found_transform4 = tf_.waitForTransform(world_, pointing_arm_ + "_hand",
00146 time, ros::Duration(tf_buffer_time_));
00147
00148 if (found_transform3 && found_transform4)
00149 {
00150 tf::StampedTransform transform3, transform4;
00151 tf_.lookupTransform(world_, pointing_arm_ + "_elbow", time, transform3);
00152 tf_.lookupTransform(world_, pointing_arm_ + "_hand", time, transform4);
00153 btVector3 direction = transform4.getOrigin() - transform3.getOrigin();
00154 std::vector <float> point_axis (6, 0.0);
00155 point_axis[0] = transform4.getOrigin().x();
00156 point_axis[1] = transform4.getOrigin().y();
00157 point_axis[2] = transform4.getOrigin().z();
00158 point_axis[3] = direction.normalize().x();
00159 point_axis[4] = direction.normalize().y();
00160 point_axis[5] = direction.normalize().z();
00161
00162
00163 kinect_cleanup::GrabObject srv_grab;
00164
00165 for (unsigned long i=0; i < point_axis.size(); i++)
00166 {
00167 srv_grab.request.point_line[i] = point_axis[i];
00168
00169 }
00170
00171 if (client_grab.call (srv_grab))
00172 {
00173 ROS_INFO ("Service call /grab_object successful");
00174 }
00175 else
00176 {
00177 ROS_ERROR ("Failed to call service /grab_object");
00178 }
00179 start_ = false;
00180 }
00181 }
00182 ros::spinOnce();
00183 loop_rate.sleep();
00184 }
00185 }
00186 };
00187
00188 int main (int argc, char** argv)
00189 {
00190 ros::init (argc, argv, "human_tracker_node");
00191 ros::NodeHandle n("~");
00192 HumanTracker ht(n);
00193
00194 ht.spin();
00195 return (0);
00196 }
00197
00198