Skip to content

Commit 01a6fe0

Browse files
committed
ICP working! ⭐⭐⭐
1 parent 05410cf commit 01a6fe0

File tree

3 files changed

+1736
-8
lines changed

3 files changed

+1736
-8
lines changed

cuboid_detection/launch/iterative_closest_point.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<param
99
name="template_cuboid_path"
1010
type="string"
11-
value="$(find cuboid_detection)/templates/template_cuboid_L200_W100_H75.pcd" />
11+
value="$(find cuboid_detection)/templates/template_cuboid_L200_W100_H75_3faces.pcd" />
1212

1313
<!-- Run ICP node -->
1414
<node

cuboid_detection/src/iterative_closest_point.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1819
using namespace std;
1920

2021
// Globals
2122
ros::Publisher pcl_pub;
23+
ros::Publisher template_pub;
2224
Eigen::Matrix4d icp_transform;
2325
string 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
2731
bool 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

5458
void 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

Comments
 (0)