Go to the documentation of this file.00001 #include "tibi_dabo_face_tracking_alg_node.h"
00002
00003 TibiDaboFaceTrackingAlgNode::TibiDaboFaceTrackingAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<TibiDaboFaceTrackingAlgorithm>(),
00005 follow_target_client_("follow_target", true)
00006 {
00007
00008 this->loop_rate_ = 20;
00009
00010
00011 this->target_joints_publisher_ = this->public_node_handle_.advertise<trajectory_msgs::JointTrajectoryPoint>("target_joints", 10);
00012
00013
00014 this->face_detections_subscriber_ = this->public_node_handle_.subscribe("face_detections", 100, &TibiDaboFaceTrackingAlgNode::face_detections_callback, this);
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 this->JointTrajectoryPoint_msg_.positions.resize(2);
00025 this->JointTrajectoryPoint_msg_.positions[0]=0;
00026 this->JointTrajectoryPoint_msg_.positions[1]=0;
00027 this->JointTrajectoryPoint_msg_.velocities.resize(2);
00028 this->JointTrajectoryPoint_msg_.velocities[0]=2.61;
00029 this->JointTrajectoryPoint_msg_.velocities[1]=2.61;
00030
00031
00032 this->image_width = 512;
00033 this->image_height = 384;
00034 this->focus_length_x = 833;
00035 this->focus_length_y = 835;
00036
00037 this->first=true;
00038 }
00039
00040 TibiDaboFaceTrackingAlgNode::~TibiDaboFaceTrackingAlgNode(void)
00041 {
00042
00043 }
00044
00045 void TibiDaboFaceTrackingAlgNode::mainNodeThread(void)
00046 {
00047
00048
00049
00050
00051
00052
00053 }
00054
00055
00056 void TibiDaboFaceTrackingAlgNode::face_detections_callback(const face_detector_mono::RectArray::ConstPtr& msg)
00057 {
00058
00059 double x_mm=0.0, pan_angle=0.0, y_mm=0.0, tilt_angle=0.0;
00060 ROS_INFO("TibiDaboFaceTrackingAlgNode::face_detections_callback: New Message Received");
00061
00062
00063
00064
00065
00066
00067
00068 if(msg->rects.size()!=0)
00069 {
00070 x_mm = 2*(msg->rects[0].x + msg->rects[0].width/2.0 - this->image_width/2.0);
00071 pan_angle = -atan2(x_mm, focus_length_x);
00072
00073 y_mm = 2*(msg->rects[0].y +msg->rects[0].height/2.0 - this->image_height/2.0);
00074 tilt_angle = -atan2(y_mm, focus_length_y);
00075
00076 this->JointTrajectoryPoint_msg_.positions[0]=pan_angle;
00077 this->JointTrajectoryPoint_msg_.positions[1]=tilt_angle;
00078
00079 ROS_INFO("TibiDaboFaceTrackingAlgNode::face_detections_callback: pan %f, tilt %f", pan_angle, tilt_angle);
00080
00081 if(this->first==true)
00082 {
00083 this->target_joints_publisher_.publish(this->JointTrajectoryPoint_msg_);
00084 this->first=false;
00085 follow_targetMakeActionRequest();
00086 }
00087 else
00088 {
00089 this->target_joints_publisher_.publish(this->JointTrajectoryPoint_msg_);
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 }
00129
00130
00131
00132
00133 void TibiDaboFaceTrackingAlgNode::follow_targetDone(const actionlib::SimpleClientGoalState& state, const iri_nav_msgs::followTargetResultConstPtr& result)
00134 {
00135 if( state.toString().compare("SUCCEEDED") == 0 )
00136 ROS_INFO("TibiDaboFaceTrackingAlgNode::follow_targetDone: Goal Achieved!");
00137 else
00138 ROS_INFO("TibiDaboFaceTrackingAlgNode::follow_targetDone: %s", state.toString().c_str());
00139
00140
00141 }
00142
00143 void TibiDaboFaceTrackingAlgNode::follow_targetActive()
00144 {
00145
00146 }
00147
00148 void TibiDaboFaceTrackingAlgNode::follow_targetFeedback(const iri_nav_msgs::followTargetFeedbackConstPtr& feedback)
00149 {
00150
00151
00152 bool feedback_is_ok = true;
00153
00154
00155
00156
00157
00158 if( !feedback_is_ok )
00159 {
00160 follow_target_client_.cancelGoal();
00161
00162 }
00163 }
00164
00165
00166 void TibiDaboFaceTrackingAlgNode::follow_targetMakeActionRequest()
00167 {
00168 ROS_INFO("TibiDaboFaceTrackingAlgNode::follow_targetMakeActionRequest: Starting New Request!");
00169
00170
00171
00172 follow_target_client_.waitForServer();
00173 ROS_INFO("TibiDaboFaceTrackingAlgNode::follow_targetMakeActionRequest: Server is Available!");
00174
00175
00176
00177 follow_target_client_.sendGoal(follow_target_goal_,
00178 boost::bind(&TibiDaboFaceTrackingAlgNode::follow_targetDone, this, _1, _2),
00179 boost::bind(&TibiDaboFaceTrackingAlgNode::follow_targetActive, this),
00180 boost::bind(&TibiDaboFaceTrackingAlgNode::follow_targetFeedback, this, _1));
00181 ROS_INFO("TibiDaboFaceTrackingAlgNode::follow_targetMakeActionRequest: Goal Sent. Wait for Result!");
00182 }
00183
00184 void TibiDaboFaceTrackingAlgNode::node_config_update(Config &config, uint32_t level)
00185 {
00186 this->alg_.lock();
00187
00188 this->alg_.unlock();
00189 }
00190
00191 void TibiDaboFaceTrackingAlgNode::addNodeDiagnostics(void)
00192 {
00193 }
00194
00195
00196 int main(int argc,char *argv[])
00197 {
00198 return algorithm_base::main<TibiDaboFaceTrackingAlgNode>(argc, argv, "tibi_dabo_face_tracking_alg_node");
00199 }