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
00038
00039
00040
00041 #ifndef _H_TRACKER_NODE_H_
00042 #define _H_TRACKER_NODE_H_
00043
00044 #include <ros/ros.h>
00045 #include <opencv2/core/core.hpp>
00046 #include <ros/duration.h>
00047 #include <ros/time.h>
00048
00049 #include <image_transport/image_transport.h>
00050 #include <image_transport/subscriber_filter.h>
00051 #include <message_filters/time_synchronizer.h>
00052 #include <cv_bridge/cv_bridge.h>
00053 #include <sensor_msgs/image_encodings.h>
00054 #include <geometry_msgs/Pose.h>
00055 #include <dynamic_reconfigure/server.h>
00056 #include <actionlib/server/action_server.h>
00057
00058 #include <blort_ros/TrackerConfig.h>
00059 #include <blort_msgs/TrackerResults.h>
00060 #include <blort_msgs/TrackerCommand.h>
00061 #include <blort_msgs/TrackerConfidences.h>
00062 #include <blort_msgs/RecoveryCall.h>
00063 #include <blort_msgs/EstimatePose.h>
00064 #include <blort_msgs/SetCameraInfo.h>
00065 #include <blort_msgs/RecognizeAction.h>
00066 #include <blort/GLWindow/glxhidingwindow.h>
00067 #include <blort/blort/pal_util.h>
00068 #include <blort_ros/gltracker.h>
00069 #include <boost/noncopyable.hpp>
00070 #include <boost/thread.hpp>
00071
00072
00073 class TrackerNode : boost::noncopyable
00074 {
00075 private:
00076 class Mode;
00077 class TrackingMode;
00078 class SingleShotMode;
00079
00080 private:
00081 ros::NodeHandle nh_;
00082 image_transport::ImageTransport it_;
00083 image_transport::Publisher image_pub;
00084 image_transport::Publisher image_debug_pub;
00085 ros::Publisher detection_result;
00086 ros::Publisher confidences_pub;
00087
00088
00089 unsigned int pose_seq;
00090 std::string camera_frame_id;
00091
00092 const std::string root_;
00093 ros::ServiceServer control_service;
00094 std::auto_ptr<dynamic_reconfigure::Server<blort_ros::TrackerConfig> > server_;
00095 dynamic_reconfigure::Server<blort_ros::TrackerConfig>::CallbackType f_;
00096 ros::ServiceClient recovery_client;
00097 blort_ros::GLTracker* tracker;
00098 std::string launch_mode;
00099
00100 boost::mutex recovery_mutex;
00101 boost::thread recovery_th;
00102 std::map<std::string, geometry_msgs::Pose> recovery_answers;
00103
00104 Mode* mode;
00105 public:
00106
00107 TrackerNode(std::string root = ".");
00108
00109 ~TrackerNode();
00110
00111 void setCameraFrameID(const std::string & id);
00112
00113 void imageCb(const sensor_msgs::ImageConstPtr& detectorImgMsg,
00114 const sensor_msgs::ImageConstPtr& trackerImgMsg );
00115
00116 bool trackerControlServiceCb(blort_msgs::TrackerCommand::Request &req,
00117 blort_msgs::TrackerCommand::Response &);
00118
00119 private:
00120
00121 void recovery(blort_msgs::RecoveryCall srv);
00122
00123
00124
00125 private:
00126 class Mode
00127 {
00128 public:
00129 virtual void reconf_callback(blort_ros::TrackerConfig &config, uint32_t level) = 0;
00130 virtual blort_msgs::RecoveryCall getRecoveryCall(std::vector<std::string> & i,
00131 const sensor_msgs::ImageConstPtr& msg) = 0;
00132 };
00133
00134 class TrackingMode : public Mode
00135 {
00136 private:
00137 ros::Subscriber cam_info_sub;
00138 boost::shared_ptr<image_transport::SubscriberFilter> detector_image_sub, tracker_image_sub;
00139 boost::shared_ptr< message_filters::TimeSynchronizer<sensor_msgs::Image, sensor_msgs::Image > > imageSynchronizer;
00140 TrackerNode* parent_;
00141 public:
00142 TrackingMode(TrackerNode* parent);
00143
00144 virtual void reconf_callback(blort_ros::TrackerConfig &config, uint32_t level);
00145
00146 virtual blort_msgs::RecoveryCall getRecoveryCall(std::vector<std::string> & i,
00147 const sensor_msgs::ImageConstPtr& msg);
00148
00149
00150 void cam_info_callback(const sensor_msgs::CameraInfo &msg);
00151 };
00152
00153 class SingleShotMode : public Mode
00154 {
00155 typedef actionlib::ActionServer<blort_msgs::RecognizeAction> AcServer;
00156 private:
00157 ros::ServiceServer singleshot_service;
00158 AcServer as_;
00159 double time_to_run_singleshot;
00160 ros::ServiceClient detector_set_caminfo_service;
00161 bool inServiceCall;
00162 double conf_treshold_;
00163 TrackerNode* parent_;
00164 std::vector<geometry_msgs::Pose> results_list;
00165
00166 sensor_msgs::ImageConstPtr lastImage;
00167 sensor_msgs::CameraInfoConstPtr lastCameraInfo;
00168
00169 blort_msgs::RecognizeFeedback feedback_;
00170 blort_msgs::RecognizeResult result_;
00171
00172 double getDistance(const sensor_msgs::ImageConstPtr& img, double x, double y, double z);
00173
00174 public:
00175 SingleShotMode(TrackerNode* parent);
00176
00177 void imageCallback(const sensor_msgs::ImageConstPtr &image);
00178
00179 void cameraCallback(const sensor_msgs::CameraInfoConstPtr &camera_info);
00180
00181 virtual void reconf_callback(blort_ros::TrackerConfig &config, uint32_t level);
00182
00183 virtual blort_msgs::RecoveryCall getRecoveryCall(std::vector<std::string> & i,
00184 const sensor_msgs::ImageConstPtr& msg);
00185
00186
00187
00188 bool singleShotService(blort_msgs::EstimatePose::Request &req,
00189 blort_msgs::EstimatePose::Response &resp);
00190
00191 void goalCb(AcServer::GoalHandle gh);
00192 };
00193 };
00194
00195 #endif // ifndef _H_TRACKER_NODE_H_
00196