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 #ifndef JSK_PCL_ROS_HINTED_HANDLE_ESTIMATOR_H_
00038 #define JSK_PCL_ROS_HINTED_HANDLE_ESTIMATOR_H_
00039
00040 #include <jsk_topic_tools/diagnostic_nodelet.h>
00041 #include <jsk_recognition_msgs/ClusterPointIndices.h>
00042 #include <geometry_msgs/PointStamped.h>
00043 #include <geometry_msgs/PoseStamped.h>
00044 #include <geometry_msgs/Pose.h>
00045 #include <std_msgs/Float64.h>
00046 #include <sensor_msgs/PointCloud2.h>
00047 #include <visualization_msgs/Marker.h>
00048 #include <visualization_msgs/MarkerArray.h>
00049 #include <message_filters/subscriber.h>
00050 #include <message_filters/time_synchronizer.h>
00051 #include <message_filters/synchronizer.h>
00052 #include <message_filters/sync_policies/approximate_time.h>
00053 #include <tf/transform_listener.h>
00054 #include <tf/tf.h>
00055
00056
00057 class handle_model
00058 {
00059 public:
00060 double finger_l;
00061 double finger_d;
00062 double finger_w;
00063 double arm_l;
00064 double arm_d;
00065 double arm_w;
00066 handle_model(){
00067 }
00068 };
00069
00070 tf::Transform pose_to_tf(geometry_msgs::Pose pose){
00071 return tf::Transform(tf::Quaternion(pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w), tf::Vector3(pose.position.x, pose.position.y, pose.position.z));
00072 }
00073 geometry_msgs::Pose tf_to_pose(tf::Transform transform){
00074 geometry_msgs::Pose pose;
00075 tf::Quaternion q;
00076 transform.getBasis().getRotation(q);
00077 pose.orientation.x = q.getX(); pose.orientation.y=q.getY(); pose.orientation.z=q.getZ(), pose.orientation.w=q.getW();
00078 pose.position.x=transform.getOrigin().getX(), pose.position.y=transform.getOrigin().getY(), pose.position.z=transform.getOrigin().getZ();
00079 return pose;
00080 }
00081 geometry_msgs::Pose change_pose(geometry_msgs::Pose base_pose, geometry_msgs::Pose child_pose){
00082 return tf_to_pose(pose_to_tf(base_pose)*pose_to_tf(child_pose));
00083 }
00084
00085 visualization_msgs::Marker make_box(float s_x, float s_y, float s_z, float r, float g, float b, float x, float y, float z)
00086 {
00087 visualization_msgs::Marker marker;
00088 marker.type = visualization_msgs::Marker::CUBE;
00089 marker.scale.x = s_x;
00090 marker.scale.y = s_y;
00091 marker.scale.z = s_z;
00092 marker.color.r = r;
00093 marker.color.g = g;
00094 marker.color.b = b;
00095 marker.color.a = 1.0;
00096 marker.pose.position.x = x;
00097 marker.pose.position.y = y;
00098 marker.pose.position.z = z;
00099 marker.pose.orientation.x = marker.pose.orientation.y = marker.pose.orientation.z = 0;
00100 marker.pose.orientation.w = 1.0;
00101 return marker;
00102 }
00103
00104 visualization_msgs::MarkerArray make_handle_array(geometry_msgs::PoseStamped pose, handle_model handle){
00105 visualization_msgs::MarkerArray markerArray_msg;
00106 visualization_msgs::Marker marker_msg = make_box(handle.finger_l, handle.finger_w, handle.finger_d, 1.0, 0, 0, handle.finger_l*0.5, handle.arm_w*0.5 -handle.finger_w*0.5, 0);
00107 marker_msg.pose = change_pose(pose.pose, marker_msg.pose);
00108 marker_msg.header = pose.header;
00109 marker_msg.ns = std::string("debug_grasp_model");
00110 marker_msg.id = 1;
00111 markerArray_msg.markers.push_back(marker_msg);
00112 marker_msg = make_box(handle.finger_l, handle.finger_w, handle.finger_d, 0, 1.0, 0, handle.finger_l*0.5, -handle.arm_w*0.5 +handle.finger_w*0.5, 0);
00113 marker_msg.pose = change_pose(pose.pose, marker_msg.pose);
00114 marker_msg.header = pose.header;
00115 marker_msg.ns = std::string("debug_grasp_model");
00116 marker_msg.id = 2;
00117 markerArray_msg.markers.push_back(marker_msg);
00118 marker_msg = make_box(handle.arm_l-handle.finger_l, handle.arm_w, handle.arm_d, 0, 0, 1.0, -(handle.arm_l-handle.finger_l)*0.5, 0, 0);
00119 marker_msg.pose = change_pose(pose.pose, marker_msg.pose);
00120 marker_msg.header = pose.header;
00121 marker_msg.ns = std::string("debug_grasp_model");
00122 marker_msg.id = 3;
00123 markerArray_msg.markers.push_back(marker_msg);
00124 return markerArray_msg;
00125 }
00126
00127 namespace jsk_pcl_ros
00128 {
00129 class HintedHandleEstimator: public jsk_topic_tools::DiagnosticNodelet
00130 {
00131 public:
00132 HintedHandleEstimator(): DiagnosticNodelet("HintedHandleEstimator") {}
00133 typedef message_filters::sync_policies::ApproximateTime<
00134 sensor_msgs::PointCloud2,
00135 geometry_msgs::PointStamped
00136 > SyncPolicy;
00137 tf::TransformListener listener_;
00138 handle_model handle;
00139 protected:
00140 virtual void onInit();
00141 virtual void subscribe();
00142 virtual void unsubscribe();
00143 virtual void estimate(
00144 const sensor_msgs::PointCloud2::ConstPtr& cloud_msg,
00145 const geometry_msgs::PointStampedConstPtr &point_msg);
00146
00147 boost::mutex mutex_;
00148 ros::Publisher pub_pose_;
00149 ros::Publisher pub_length_;
00150 ros::Publisher pub_debug_marker_;
00151 ros::Publisher pub_debug_marker_array_;
00152 message_filters::Subscriber<sensor_msgs::PointCloud2> sub_cloud_;
00153 message_filters::Subscriber<geometry_msgs::PointStamped> sub_point_;
00154 boost::shared_ptr<message_filters::Synchronizer<SyncPolicy> >sync_;
00155 private:
00156
00157 };
00158 }
00159
00160 #endif