00001 // Copyright (C) 2010-2011 Institut de Robotica i Informatica Industrial, CSIC-UPC. 00002 // Author 00003 // All rights reserved. 00004 // 00005 // This file is part of iri-ros-pkg 00006 // iri-ros-pkg is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 // IMPORTANT NOTE: This code has been generated through a script from the 00020 // iri_ros_scripts. Please do NOT delete any comments to guarantee the correctness 00021 // of the scripts. ROS topics can be easly add by using those scripts. Please 00022 // refer to the IRI wiki page for more information: 00023 // http://wikiri.upc.es/index.php/Robotics_Lab 00024 00025 #ifndef _people_tracking_rai_alg_node_h_ 00026 #define _people_tracking_rai_alg_node_h_ 00027 00028 //std 00029 #include <sstream> 00030 #include <string> 00031 #include <fstream> 00032 00033 //library 00034 //#include "position3d.h" 00035 #include "peopleTracker.h" 00036 00037 //iri-ros 00038 #include <iri_base_algorithm/iri_base_algorithm.h> 00039 #include "people_tracking_rai_alg.h" 00040 00041 //required headers for image I/O 00042 #include <image_transport/image_transport.h> 00043 #include <cv_bridge/cv_bridge.h> 00044 #include <sensor_msgs/image_encodings.h> 00045 #include <opencv2/imgproc/imgproc.hpp> 00046 #include <opencv2/highgui/highgui.hpp> 00047 00048 // [publisher subscriber headers] 00049 #include <std_msgs/Int32.h> 00050 #include <tld_msgs/BoundingBox.h> 00051 #include <tld_msgs/Target.h> 00052 #include <pal_vision_msgs/FaceDetections.h> 00053 #include <pal_vision_msgs/HogDetections.h> 00054 #include <nav_msgs/Odometry.h> 00055 #include <visualization_msgs/MarkerArray.h> 00056 #include <iri_perception_msgs/peopleTrackingArray.h> 00057 #include <pal_vision_msgs/LegDetections.h> 00058 #include <tf/transform_broadcaster.h> 00059 #include <tf/transform_listener.h> 00060 00061 // [service client headers] 00062 00063 // [action server client headers] 00064 00065 //visualization constants 00066 const double MARKER_SIZE = 0.5; 00067 const double MARKER_Z = 0.2; 00068 const double MARKER_DURATION = 0.1; 00069 const double MARKER_TEXT_SIZE = 0.3; 00070 const double MARKER_TRANSPARENCY = 0.9; 00071 00072 //node execution mode 00073 enum executionModes {MULTI_TRACKING=0, SHOOT_TLD, FOLLOW_ME}; 00074 00079 class PeopleTrackingRaiAlgNode : public algorithm_base::IriBaseAlgorithm<PeopleTrackingRaiAlgorithm> 00080 { 00081 private: 00082 //execution mode 00083 unsigned int exeMode; 00084 00085 // initialize tf from base_link to camera, and get camera matrix 00086 void initCamera(); 00087 00088 //indicates when the TLD request message has been filled 00089 bool tldMessageFilled; 00090 00091 //useful to initialize base_link to camera transform 00092 //tf::TransformListener tfListener; 00093 00094 // image transport 00095 image_transport::ImageTransport it_; 00096 cv_bridge::CvImagePtr cv_ptr; 00097 00098 // [publisher attributes] 00099 ros::Publisher tldBB_publisher_; 00100 tld_msgs::Target tldBB_msg_; 00101 ros::Publisher particleSet_publisher_; 00102 visualization_msgs::MarkerArray MarkerArray_msg_; 00103 ros::Publisher peopleSet_publisher_; 00104 iri_perception_msgs::peopleTrackingArray peopleTrackingArray_msg_; 00105 image_transport::Publisher image_pub_; 00106 00107 // [subscriber attributes] 00108 ros::Subscriber followMe_subscriber_; 00109 void followMe_callback(const std_msgs::Int32::ConstPtr& msg); 00110 CMutex followMe_mutex_; 00111 ros::Subscriber tldDetections_subscriber_; 00112 void tldDetections_callback(const tld_msgs::BoundingBox::ConstPtr& msg); 00113 CMutex tldDetections_mutex_; 00114 ros::Subscriber faceDetections_subscriber_; 00115 void faceDetections_callback(const pal_vision_msgs::FaceDetections::ConstPtr& msg); 00116 CMutex faceDetections_mutex_; 00117 ros::Subscriber bodyDetections_subscriber_; 00118 void bodyDetections_callback(const pal_vision_msgs::HogDetections::ConstPtr& msg); 00119 CMutex bodyDetections_mutex_; 00120 ros::Subscriber odometry_subscriber_; 00121 void odometry_callback(const nav_msgs::Odometry::ConstPtr& msg); 00122 CMutex odometry_mutex_; 00123 ros::Subscriber legDetections_subscriber_; 00124 void legDetections_callback(const pal_vision_msgs::LegDetections::ConstPtr& msg); 00125 CMutex legDetections_mutex_; 00126 image_transport::Subscriber image_sub_; 00127 void image_callback(const sensor_msgs::ImageConstPtr& msg); 00128 CMutex image_mutex_; 00129 00130 //dynamic reconfigure mutex 00131 CMutex config_mutex; 00132 00133 // [service attributes] 00134 00135 // [client attributes] 00136 00137 // [action server attributes] 00138 00139 // [action client attributes] 00140 00141 //library objects 00142 pFilterParameters filterParams; 00143 trackerParameters trackerParams; 00144 CpeopleTracker tracker; 00145 CodometryObservation platformOdometry; 00146 00147 //debugging 00148 std::ofstream hogFile; 00149 bool verboseMode; 00150 bool viewBodyDetections; 00151 double ratioParticlesDisplayed; 00152 unsigned int frameCount, hogDetCount; 00153 00154 public: 00161 PeopleTrackingRaiAlgNode(void); 00162 00169 ~PeopleTrackingRaiAlgNode(void); 00170 00176 void fillMessages(); 00177 00178 protected: 00191 void mainNodeThread(void); 00192 00205 void node_config_update(Config &config, uint32_t level); 00206 00213 void addNodeDiagnostics(void); 00214 00215 // [diagnostic functions] 00216 00217 // [test functions] 00218 }; 00219 00220 #endif