Skip to content

Commit 0e7d70d

Browse files
committed
Merge branch 'master' of github.com:dash-robotics/perception
2 parents e38b478 + dec4800 commit 0e7d70d

File tree

3 files changed

+7325
-21
lines changed

3 files changed

+7325
-21
lines changed

cuboid_detection/launch/iterative_closest_point.launch

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<launch>
33

44
<!-- Launch Bounding Box Filter -->
5-
<include file="$(find cuboid_detection)/launch/bbox_filter.launch"/>
5+
<!-- <include file="$(find cuboid_detection)/launch/bbox_filter.launch"/> -->
66

77
<!-- Launch surface normal estimation -->
8-
<include file="$(find cuboid_detection)/launch/surface_normal_estimation.launch"/>
8+
<!-- <include file="$(find cuboid_detection)/launch/surface_normal_estimation.launch"/> -->
9+
10+
<!-- Launch ground plane segmentation -->
11+
<include file="$(find cuboid_detection)/launch/ground_plane_segmentation.launch"/>
912

1013
<!-- Run ICP node -->
1114
<node
@@ -18,14 +21,14 @@
1821
<param
1922
name="template_cuboid_path"
2023
type="string"
21-
value="$(find cuboid_detection)/templates/template_cuboid_L200_W75_H100_3faces.pcd" />
24+
value="$(find cuboid_detection)/templates/template_cuboid_L200_W100_H30_3faces.pcd" />
2225

2326
<!-- Set topics and params -->
2427
<rosparam>
2528
<!-- Dimensions -->
2629
length: 0.2
27-
width: 0.075
28-
height: 0.1
30+
width: 0.1
31+
height: 0.03
2932
</rosparam>
3033
</node>
3134

cuboid_detection/src/iterative_closest_point.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ using namespace std;
2626
ros::Publisher pcl_pub;
2727
ros::Publisher bbox_pub;
2828
ros::Publisher template_pub;
29+
ros::Publisher pose_pub;
30+
2931
Eigen::Matrix4d icp_transform;
3032
string template_cuboid_filename;
3133
sensor_msgs::PointCloud2 bbox_msg;
@@ -49,6 +51,41 @@ tf::Transform get_tf_from_stamped_tf(tf::StampedTransform sTf)
4951
return tf;
5052
}
5153

54+
void publish_pose(Eigen::Matrix4d H)
55+
{
56+
// Set translation
57+
tf::Vector3 origin;
58+
origin.setValue(H(0, 3), H(1, 3), H(2, 3));
59+
60+
// Set rotation
61+
tf::Quaternion quaternion;
62+
tf::Matrix3x3 rotation_matrix;
63+
rotation_matrix.setValue(H(0, 0), H(0, 1), H(0, 2),
64+
H(1, 0), H(1, 1), H(1, 2),
65+
H(2, 0), H(2, 1), H(2, 2));
66+
rotation_matrix.getRotation(quaternion);
67+
68+
// Make tf transform message
69+
tf::Transform transform;
70+
transform.setOrigin(origin);
71+
transform.setRotation(quaternion);
72+
73+
// Make pose message
74+
geometry_msgs::Pose p;
75+
p.position.x = H(0, 3);
76+
p.position.y = H(1, 3);
77+
p.position.z = H(2, 3);
78+
p.orientation.x = quaternion.x();
79+
p.orientation.y = quaternion.y();
80+
p.orientation.z = quaternion.z();
81+
p.orientation.w = quaternion.w();
82+
83+
// Broadcast the transforms
84+
static tf::TransformBroadcaster br;
85+
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "camera_depth_optical_frame", "icp_cuboid_frame"));
86+
pose_pub.publish(p);
87+
}
88+
5289
void publish_bounding_box(Eigen::Matrix4d H)
5390
{
5491
// Extract cuboid dimensions
@@ -98,14 +135,15 @@ void pose_callback(const geometry_msgs::Pose::ConstPtr& msg)
98135
void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
99136
{
100137
// Compute ICP only once
101-
// if (ICP_SUCCESS)
102-
// {
103-
// pcl_pub.publish(output_msg);
104-
// template_msg.header.frame_id = "camera_depth_optical_frame";
105-
// template_pub.publish(template_msg);
106-
// publish_bounding_box(icp_transform);
107-
// return;
108-
// }
138+
if (ICP_SUCCESS)
139+
{
140+
pcl_pub.publish(output_msg);
141+
template_msg.header.frame_id = "camera_depth_optical_frame";
142+
template_pub.publish(template_msg);
143+
publish_bounding_box(icp_transform);
144+
publish_pose(icp_transform);
145+
return;
146+
}
109147

110148
// Point cloud containers
111149
pcl::PointCloud<pcl::PointXYZ>::Ptr template_input(new pcl::PointCloud<pcl::PointXYZ>);
@@ -117,15 +155,15 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
117155
pcl::fromROSMsg(*msg, *input_cuboid);
118156

119157
// Read template point cloud
120-
if (pcl::io::loadPCDFile<pcl::PointXYZ>(template_cuboid_filename, *template_input) == -1)
158+
if (pcl::io::loadPCDFile<pcl::PointXYZ>(template_cuboid_filename, *template_cuboid) == -1)
121159
{
122160
PCL_ERROR("Couldn't read the template PCL file");
123161
return;
124162
}
125163

126164
// Transform the template point cloud to the estimated frame
127-
if (!POSE_FLAG) return;
128-
pcl::transformPointCloud(*template_input, *template_cuboid, pose_transform.cast<float>());
165+
// if (!POSE_FLAG) return;
166+
// pcl::transformPointCloud(*template_input, *template_cuboid, pose_transform.cast<float>());
129167

130168
// Run ICP
131169
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
@@ -143,22 +181,23 @@ void icp_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
143181
if (icp.hasConverged())
144182
{
145183
// Display ICP results
146-
ICP_SUCCESS = true;
147184
if (DEBUG || !ICP_SUCCESS)
148185
{
149186
cerr << "\nICP Score: " << icp.getFitnessScore() << endl;
150187
cerr << "ICP Transform:\n" << icp_transform << endl;
151188
}
189+
ICP_SUCCESS = true;
190+
191+
// Convert to ROS data type
192+
pcl::toROSMsg(*output_cloud, output_msg);
193+
pcl::toROSMsg(*template_cuboid, template_msg);
152194

153195
// Publish template point cloud
154196
template_msg.header.frame_id = "camera_depth_optical_frame";
155197
pcl_pub.publish(output_msg);
156198
template_pub.publish(template_msg);
157199
publish_bounding_box(icp_transform);
158-
159-
// Convert to ROS data type
160-
pcl::toROSMsg(*output_cloud, output_msg);
161-
pcl::toROSMsg(*template_cuboid, template_msg);
200+
publish_pose(icp_transform);
162201
}
163202
}
164203

@@ -188,6 +227,7 @@ int main(int argc, char **argv)
188227
pcl_pub = nh.advertise<sensor_msgs::PointCloud2>("/icp/aligned_points", 1);
189228
bbox_pub = nh.advertise<sensor_msgs::PointCloud2>("/icp/bbox_points", 1);
190229
template_pub = nh.advertise<sensor_msgs::PointCloud2>("/icp/template", 1);
230+
pose_pub = nh.advertise<geometry_msgs::Pose>("/icp/pose", 1);
191231

192232
// Spin
193233
ros::spin();

0 commit comments

Comments
 (0)