00001 /* 00002 * FeatureTrackerNode.h 00003 * 00004 * Author: roberto 00005 * 00006 * This is a modified implementation of the method for online estimation of kinematic structures described in our paper 00007 * "Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors" 00008 * (Martín-Martín and Brock, 2014). 00009 * This implementation can be used to reproduce the results of the paper and to be applied to new research. 00010 * The implementation allows also to be extended to perceive different information/models or to use additional sources of information. 00011 * A detail explanation of the method and the system can be found in our paper. 00012 * 00013 * If you are using this implementation in your research, please consider citing our work: 00014 * 00015 @inproceedings{martinmartin_ip_iros_2014, 00016 Title = {Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors}, 00017 Author = {Roberto {Mart\'in-Mart\'in} and Oliver Brock}, 00018 Booktitle = {Proceedings of the IEEE/RSJ International Conference on Intelligent Robots and Systems}, 00019 Pages = {2494-2501}, 00020 Year = {2014}, 00021 Location = {Chicago, Illinois, USA}, 00022 Note = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf}, 00023 Url = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf}, 00024 Projectname = {Interactive Perception} 00025 } 00026 * If you have questions or suggestions, contact us: 00027 * roberto.martinmartin@tu-berlin.de 00028 * 00029 * Enjoy! 00030 */ 00031 00032 #ifndef FEATURE_TRACKER_NODE_H_ 00033 #define FEATURE_TRACKER_NODE_H_ 00034 00035 #include <ros/ros.h> 00036 #include <ros/callback_queue.h> 00037 #include <image_transport/image_transport.h> 00038 #include <message_filters/subscriber.h> 00039 #include <message_filters/time_synchronizer.h> 00040 #include <message_filters/sync_policies/approximate_time.h> 00041 #include <sensor_msgs/PointCloud2.h> 00042 #include <sensor_msgs/Image.h> 00043 00044 #include <tf/tf.h> 00045 00046 #include "feature_tracker/FeatureTracker.h" 00047 00048 #include <boost/thread.hpp> 00049 00050 #include <omip_common/RecursiveEstimatorNodeInterface.h> 00051 00052 // Dynamic reconfigure includes. 00053 #include <dynamic_reconfigure/server.h> 00054 #include <feature_tracker/FeatureTrackerDynReconfConfig.h> 00055 00056 #include <std_msgs/Bool.h> 00057 #include "omip_msgs/ShapeTrackerStates.h" 00058 00059 namespace omip 00060 { 00067 template<class M> 00068 class BagSubscriber : public message_filters::SimpleFilter<M> 00069 { 00070 public: 00071 void newMessage(const boost::shared_ptr<M const> &msg) 00072 { 00073 this->signalMessage(msg); 00074 } 00075 }; 00076 00084 class FeatureTrackerNode : 00085 public RecursiveEstimatorNodeInterface<ft_measurement_ros_t, ft_state_ros_t, FeatureTracker> 00086 { 00087 // Policies to synchorize point clouds, depth and RGB images from the sensor 00088 typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, sensor_msgs::Image, sensor_msgs::Image> FTrackerSyncPolicy; 00089 typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> FTrackerLightSyncPolicy; 00090 00091 public: 00092 00096 FeatureTrackerNode(); 00097 00098 virtual void AdvanceBagCallbackFromShapeReconstruction(const boost::shared_ptr<std_msgs::Bool const> &flag); 00099 00100 virtual void AdvanceBagCallbackFromShapeTracker(const boost::shared_ptr<omip_msgs::ShapeTrackerStates const> &st_states); 00101 00105 virtual ~FeatureTrackerNode(); 00106 00114 virtual void measurementCallback(const sensor_msgs::PointCloud2ConstPtr &pc_msg, 00115 const sensor_msgs::ImageConstPtr &depth_image_msg, 00116 const sensor_msgs::ImageConstPtr &rgb_image_msg); 00117 00124 virtual void measurementCallback(const sensor_msgs::ImageConstPtr &depth_image_msg, 00125 const sensor_msgs::ImageConstPtr &rgb_image_msg); 00126 00132 virtual void measurementCallback(const boost::shared_ptr<ft_measurement_ros_t const> &ft_measurement_ros){} 00133 00139 virtual void statePredictionCallback(const boost::shared_ptr<ft_state_ros_t const> &predicted_next_state); 00140 00147 virtual void DynamicReconfigureCallback(feature_tracker::FeatureTrackerDynReconfConfig &config, uint32_t level); 00148 00154 virtual void ReadRosBag(); 00155 00161 virtual void OcclusionMaskImgCallback(const sensor_msgs::ImageConstPtr &occlusion_mask_img); 00162 00167 virtual void PublishTrackedFeaturesImg(); 00168 00173 virtual void PublishTrackedFeaturesWithPredictionMaskImg(); 00174 00179 virtual void PublishDepthEdgesImg(); 00180 00185 virtual void PublishPredictionMaskImg(); 00186 00191 virtual void PublishTrackingMaskImg(); 00192 00197 virtual void PublishDetectingMaskImg(); 00198 00203 virtual void PublishFullRGBDPC(); 00204 00205 virtual void PublishRGBImg(); 00206 00207 virtual void PublishDepthImg(); 00208 00213 virtual void PublishPredictedAndLastFeaturesImg(); 00214 00215 virtual void RepublishPredictedFeatLocation(); 00216 00217 virtual void run(); 00218 00219 protected: 00220 00225 virtual void _publishState() const; 00226 00231 virtual void _publishPredictedMeasurement() const; 00232 00236 virtual void _ReadParameters(); 00237 00241 virtual void _InitializeVariables(); 00242 00246 virtual void _SubscribeAndAdvertiseTopics(); 00247 00248 image_transport::ImageTransport _image_transport; 00249 00250 // Subscribers and synchronizer 00251 message_filters::Subscriber<sensor_msgs::PointCloud2> _full_rgbd_pc_sub; 00252 message_filters::Subscriber<sensor_msgs::Image> _depth_img_sub; 00253 message_filters::Subscriber<sensor_msgs::Image> _rgb_img_sub; 00254 message_filters::Synchronizer<FTrackerSyncPolicy> *_synchronizer; 00255 message_filters::Synchronizer<FTrackerLightSyncPolicy> *_light_synchronizer; 00256 ros::Subscriber _occlusion_mask_img_sub; 00257 00258 // Fake subscribers to capture images 00259 BagSubscriber<sensor_msgs::Image> _bag_rgb_img_sub; 00260 BagSubscriber<sensor_msgs::Image> _bag_depth_img_sub; 00261 BagSubscriber<sensor_msgs::PointCloud2> _bag_full_rgbd_pc_sub; 00262 ros::Publisher _shutdown_publisher; 00263 00264 // Publishers 00265 ros::Publisher _full_rgbd_pc_repub; 00266 ros::Publisher _camera_info_pub; 00267 ros::Publisher _camera_info_pub2; 00268 ros::Publisher _tf_repub; 00269 00270 ros::Publisher _time_repub; 00271 00272 ros::Publisher _pred_feat_locs_repub; 00273 00274 00275 image_transport::Publisher _depth_img_pub; 00276 image_transport::Publisher _rgb_img_pub; 00277 image_transport::Publisher _tracked_feats_img_pub; 00278 image_transport::Publisher _tracked_feats_with_pm_img_pub; 00279 image_transport::Publisher _depth_edges_img_pub; 00280 image_transport::Publisher _prediction_mask_img_pub; 00281 image_transport::Publisher _tracking_mask_img_pub; 00282 image_transport::Publisher _detecting_mask_img_pub; 00283 image_transport::Publisher _predicted_and_past_feats_img_pub; 00284 00285 sensor_msgs::CameraInfo _camera_info_msg; 00286 00287 // PCL variables 00288 PointCloudPCL::ConstPtr _full_rgbd_pc; 00289 FeatureCloudPCLwc::Ptr _predicted_locations_pc; 00290 00291 // OpenCV variables 00292 cv_bridge::CvImagePtr _cv_ptr_depth; 00293 cv_bridge::CvImagePtr _cv_ptr_rgb; 00294 cv_bridge::CvImagePtr _cv_ptr_occlusion_msk; 00295 00296 // Flags 00297 bool _data_from_bag; 00298 bool _subscribe_to_pc; 00299 bool _ci_initialized; 00300 bool _publishing_depth_edges_img; 00301 bool _publishing_rgb_img; 00302 bool _publishing_depth_img; 00303 bool _publishing_tracked_feats_img; 00304 bool _publishing_tracked_feats_with_pred_msk_img; 00305 bool _publishing_full_pc; 00306 bool _publishing_predicting_msk_img; 00307 bool _publishing_tracking_msk_img; 00308 bool _publishing_detecting_msk_img; 00309 bool _publishing_predicted_and_past_feats_img; 00310 bool _republishing_predicted_feat_locs; 00311 00312 bool _occlusion_mask_positive; 00313 00314 bool _attention_to_motion; 00315 00316 double _sensor_fps; 00317 double _loop_period_ns; 00318 int _processing_factor; 00319 00320 std::string _ft_ns; 00321 00322 std::string _tracker_type; 00323 std::string _bag_file_name; 00324 std::string _full_rgbd_pc_topic; 00325 std::string _depth_img_topic; 00326 std::string _rgb_img_topic; 00327 std::string _occlusion_mask_img_topic; 00328 std::string _ci_topic; 00329 std::string _predicted_locations_pc_topic; 00330 00331 tf::Transform _initial_ee_tf; 00332 00333 // Set up a dynamic reconfigure server. 00334 // This should be done before reading parameter server values. 00335 dynamic_reconfigure::Server<feature_tracker::FeatureTrackerDynReconfConfig> _dr_srv; 00336 dynamic_reconfigure::Server<feature_tracker::FeatureTrackerDynReconfConfig>::CallbackType _dr_callback; 00337 00338 double _advance_frame_min_wait_time; 00339 double _advance_frame_max_wait_time; 00340 00341 ros::Subscriber _advance_sub; 00342 bool _advance_sub_returned_true; 00343 00344 int _advance_frame_mechanism; 00345 }; 00346 } 00347 00348 #endif /* FEATURE_TRACKER_NODE_H_ */