@@ -6,22 +6,26 @@ Date: Apr 03, 2019
66
77#include < iostream>
88#include < ros/ros.h>
9+ #include < tf/tf.h>
10+ #include < tf/transform_broadcaster.h>
911#include < pcl_ros/point_cloud.h>
1012#include < pcl_conversions/pcl_conversions.h>
1113#include < pcl/io/pcd_io.h>
1214#include < pcl/point_types.h>
1315#include < pcl/registration/icp.h>
16+ #include < pcl_ros/transforms.h>
1417#include < sensor_msgs/PointCloud2.h>
15- #include < tf/tf.h>
16- #include < tf/transform_broadcaster.h>
1718
1819using namespace std ;
1920
2021// Globals
2122ros::Publisher pcl_pub;
23+ ros::Publisher template_pub;
2224Eigen::Matrix4d icp_transform;
2325string template_cuboid_filename;
24- sensor_msgs::PointCloud2 output;
26+ tf::TransformListener *tf_listener;
27+ sensor_msgs::PointCloud2 output_msg;
28+ sensor_msgs::PointCloud2 template_msg;
2529
2630// Flags
2731bool DEBUG = false ;
@@ -48,7 +52,7 @@ void convert_icp_eigen_to_tf(Eigen::Matrix4d Tm)
4852
4953 // Broadcast the transforms
5054 static tf::TransformBroadcaster br;
51- br.sendTransform (tf::StampedTransform (transform, ros::Time::now (), " cuboid_frame" , " camera_depth_frame" ));
55+ // br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "cuboid_frame", "camera_depth_frame"));
5256}
5357
5458void icp_callback (const sensor_msgs::PointCloud2::ConstPtr& msg)
@@ -57,7 +61,9 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
5761 if (ICP_SUCCESS)
5862 {
5963 convert_icp_eigen_to_tf (icp_transform);
60- pcl_pub.publish (output);
64+ pcl_pub.publish (output_msg);
65+ template_msg.header .frame_id = " camera_depth_optical_frame" ;
66+ template_pub.publish (template_msg);
6167 return ;
6268 }
6369
@@ -80,6 +86,11 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
8086 pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
8187 icp.setInputSource (input_cuboid);
8288 icp.setInputTarget (template_cuboid);
89+ icp.setMaximumIterations (2000 );
90+ icp.setTransformationEpsilon (1e-9 );
91+ // icp.setMaxCorrespondenceDistance(0.05);
92+ // icp.setEuclideanFitnessEpsilon(1);
93+ // icp.setRANSACOutlierRejectionThreshold(1.5);
8394 icp.align (*output_cloud);
8495 icp_transform = icp.getFinalTransformation ().cast <double >().inverse ();
8596
@@ -92,9 +103,14 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
92103 ICP_SUCCESS = true ;
93104 convert_icp_eigen_to_tf (icp_transform);
94105
106+ // Publish template point cloud
107+ template_msg.header .frame_id = " camera_depth_optical_frame" ;
108+ pcl_pub.publish (output_msg);
109+ template_pub.publish (template_msg);
110+
95111 // Convert to ROS data type
96- pcl::toROSMsg (*output_cloud, output );
97- pcl_pub. publish (output );
112+ pcl::toROSMsg (*output_cloud, output_msg );
113+ pcl::toROSMsg (*template_cuboid, template_msg );
98114 }
99115}
100116
@@ -113,6 +129,7 @@ int main(int argc, char **argv)
113129
114130 // Publishers
115131 pcl_pub = nh.advertise <sensor_msgs::PointCloud2>(" /icp/aligned_points" , 1 );
132+ template_pub = nh.advertise <sensor_msgs::PointCloud2>(" /icp/template" , 1 );
116133
117134 ros::spin ();
118135}
0 commit comments