Skip to content

Commit 05410cf

Browse files
committed
TF errors fixed
1 parent d0b1ec5 commit 05410cf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cuboid_detection/src/iterative_closest_point.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using namespace std;
2121
ros::Publisher pcl_pub;
2222
Eigen::Matrix4d icp_transform;
2323
string template_cuboid_filename;
24+
sensor_msgs::PointCloud2 output;
2425

2526
// Flags
2627
bool DEBUG = false;
@@ -46,15 +47,17 @@ void convert_icp_eigen_to_tf(Eigen::Matrix4d Tm)
4647
transform.setRotation(quaternion);
4748

4849
// Broadcast the transforms
49-
tf::TransformBroadcaster br;
50-
while (true) br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "map", "cuboid_frame"));
50+
static tf::TransformBroadcaster br;
51+
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "cuboid_frame", "camera_depth_frame"));
5152
}
5253

5354
void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
5455
{
5556
// Compute ICP only once
5657
if (ICP_SUCCESS)
5758
{
59+
convert_icp_eigen_to_tf(icp_transform);
60+
pcl_pub.publish(output);
5861
return;
5962
}
6063

@@ -78,7 +81,7 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
7881
icp.setInputSource(input_cuboid);
7982
icp.setInputTarget(template_cuboid);
8083
icp.align(*output_cloud);
81-
icp_transform = icp.getFinalTransformation().cast<double>();
84+
icp_transform = icp.getFinalTransformation().cast<double>().inverse();
8285

8386
// Convert ICP results and broadcast TF
8487
if (icp.hasConverged())
@@ -87,10 +90,9 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
8790
cerr << "ICP Transform:\n" << icp_transform << endl;
8891

8992
ICP_SUCCESS = true;
90-
// convert_icp_eigen_to_tf(icp_transform);
93+
convert_icp_eigen_to_tf(icp_transform);
9194

9295
// Convert to ROS data type
93-
sensor_msgs::PointCloud2 output;
9496
pcl::toROSMsg(*output_cloud, output);
9597
pcl_pub.publish(output);
9698
}

0 commit comments

Comments
 (0)