00001 // -*- mode: C++ -*- 00002 /********************************************************************* 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2013, JSK Lab 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/o2r other materials provided 00017 * with the distribution. 00018 * * Neither the name of the JSK Lab nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 *********************************************************************/ 00035 00036 #ifndef JSK_PCL_ROS_SNAPIT_H_ 00037 #define JSK_PCL_ROS_SNAPIT_H_ 00038 00039 #include <ros/ros.h> 00040 00041 #include <pcl/point_types.h> 00042 #include <pcl_ros/pcl_nodelet.h> 00043 #include <jsk_recognition_msgs/PolygonArray.h> 00044 #include <geometry_msgs/PolygonStamped.h> 00045 #include <geometry_msgs/PoseArray.h> 00046 #include <jsk_recognition_msgs/ModelCoefficientsArray.h> 00047 #include "jsk_pcl_ros/CallSnapIt.h" 00048 #include <tf/transform_listener.h> 00049 #include <jsk_topic_tools/diagnostic_nodelet.h> 00050 #include "jsk_pcl_ros/geo_util.h" 00051 #include <message_filters/subscriber.h> 00052 #include <message_filters/time_synchronizer.h> 00053 #include <message_filters/synchronizer.h> 00054 #include <jsk_pcl_ros/SnapFootstep.h> 00055 #include "jsk_pcl_ros/tf_listener_singleton.h" 00056 namespace jsk_pcl_ros 00057 { 00058 class SnapIt: public jsk_topic_tools::DiagnosticNodelet 00059 { 00060 public: 00061 typedef message_filters::sync_policies::ExactTime< 00062 jsk_recognition_msgs::PolygonArray, 00063 jsk_recognition_msgs::ModelCoefficientsArray> SyncPolygonPolicy; 00064 SnapIt(): DiagnosticNodelet("SnapIt") {} 00065 00066 protected: 00068 // methods 00070 virtual void onInit(); 00071 virtual void subscribe(); 00072 virtual void unsubscribe(); 00073 virtual void polygonCallback( 00074 const jsk_recognition_msgs::PolygonArray::ConstPtr& polygon_msg, 00075 const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients_msg); 00076 virtual void polygonAlignCallback( 00077 const geometry_msgs::PoseStamped::ConstPtr& pose_msg); 00078 virtual void convexAlignCallback( 00079 const geometry_msgs::PoseStamped::ConstPtr& pose_msg); 00080 virtual void convexAlignPolygonCallback( 00081 const geometry_msgs::PolygonStamped::ConstPtr& poly_msg); 00082 virtual std::vector<ConvexPolygon::Ptr> createConvexes( 00083 const std::string& frame_id, const ros::Time& stamp, 00084 jsk_recognition_msgs::PolygonArray::ConstPtr polygons); 00085 virtual int findNearestConvex( 00086 const Eigen::Vector3f& pose_point, 00087 const std::vector<ConvexPolygon::Ptr>& convexes); 00088 virtual geometry_msgs::PoseStamped alignPose( 00089 Eigen::Affine3f& pose, ConvexPolygon::Ptr convex); 00090 virtual bool footstepAlignServiceCallback( 00091 jsk_pcl_ros::SnapFootstep::Request& req, 00092 jsk_pcl_ros::SnapFootstep::Response& res); 00094 // ROS variables 00096 tf::TransformListener* tf_listener_; 00097 message_filters::Subscriber<jsk_recognition_msgs::PolygonArray> sub_polygons_; 00098 message_filters::Subscriber<jsk_recognition_msgs::ModelCoefficientsArray> sub_coefficients_; 00099 boost::shared_ptr<message_filters::Synchronizer<SyncPolygonPolicy> >sync_polygon_; 00100 ros::Publisher polygon_aligned_pub_; 00101 ros::Publisher convex_aligned_pub_; 00102 ros::Publisher convex_aligned_pose_array_pub_; 00103 ros::Publisher convex_aligned_pose_array_marker_pub_; 00104 ros::Subscriber polygon_align_sub_; 00105 ros::Subscriber convex_align_sub_; 00106 ros::Subscriber convex_align_polygon_sub_; 00107 bool use_service_; 00108 ros::ServiceServer align_footstep_srv_; 00109 jsk_recognition_msgs::PolygonArray::ConstPtr polygons_; 00110 boost::mutex mutex_; 00112 // parameters 00114 00115 }; 00116 } 00117 00118 #endif