Skip to content

Commit 55b3d6f

Browse files
committed
transform fov into target_frame
1 parent 940bb78 commit 55b3d6f

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

include/pointcloud_to_laserscan/ipa_pointcloud_to_laserscan_nodelet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ namespace pointcloud_to_laserscan
9898
double min_height_, max_height_, angle_min_, angle_max_, angle_increment_, scan_time_, range_min_, range_max_;
9999
bool use_inf_;
100100
bool use_outlier_filter_;
101+
tf2::Vector3 fov_max, fov_min;
102+
std::mutex fov_mutex, angle_mutex;
101103
};
102104

103105
} // pointcloud_to_laserscan

src/ipa_pointcloud_to_laserscan_nodelet.cpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,42 @@ void IpaPointCloudToLaserScanNodelet::configure_filter()
128128
void IpaPointCloudToLaserScanNodelet::cameraInfoCb(const sensor_msgs::CameraInfo &camera_info_msg)
129129
{
130130

131-
// calculate field of view from camera_info topic
132-
std::size_t fx = camera_info_msg.K[0];
133-
std::size_t fy = camera_info_msg.K[4];
131+
geometry_msgs::PointStamped P_min_c, P_max_c; // min and max points of FOV in camera_frame
132+
geometry_msgs::PointStamped P_min_t, P_max_t; // min and max points of FOV in target_frame
134133

135-
angle_max_ = atan2(camera_info_msg.width, 2*fx);
136-
angle_min_ = -atan2(camera_info_msg.width, 2*fx);
134+
{
135+
std::lock_guard<std::mutex> lock(fov_mutex);
136+
P_max_c.point.x = fov_max.x();
137+
P_max_c.point.y = fov_max.y();
138+
P_max_c.point.z = fov_max.z();
139+
140+
P_min_c.point.x = fov_min.x();
141+
P_min_c.point.y = fov_min.y();
142+
P_min_c.point.z = fov_min.z();
143+
144+
// std::cout << "MAX POINT: " << fov_max.x() << ", " << fov_max.y() << ", " << fov_max.z() << ", " << std::endl;
145+
// std::cout << "MIN POINT: " << fov_min.x() << ", " << fov_min.y() << ", " << fov_min.z() << ", " << std::endl;
146+
}
137147

148+
P_max_c.header.frame_id = camera_info_msg.header.frame_id;
149+
P_min_c.header.frame_id = camera_info_msg.header.frame_id;
150+
try
151+
{
152+
tf2_->transform(P_max_c, P_max_t, target_frame_);
153+
tf2_->transform(P_min_c, P_min_t, target_frame_);
154+
}
155+
catch (tf2::TransformException &ex)
156+
{
157+
NODELET_WARN_STREAM("Transform failure: " << ex.what());
158+
}
159+
160+
// calculate FOV angle in x-y plane of target_frame
161+
{
162+
std::lock_guard<std::mutex> lock(angle_mutex);
163+
angle_max_ = angles::normalize_angle_positive(atan2(P_max_t.point.y, P_max_t.point.x));
164+
angle_min_ = angles::normalize_angle_positive(atan2(P_min_t.point.y, P_min_t.point.x));
165+
// std::cout << "ANGLES: " << angle_max_ << ", " << angle_min_ << std::endl;
166+
}
138167
}
139168

140169
void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
@@ -163,7 +192,7 @@ void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2Cons
163192
}
164193
catch (tf2::TransformException ex)
165194
{
166-
NODELET_WARN_STREAM("Transform failure: " << ex.what());
195+
NODELET_WARN_STREAM("Transform failure [cloud_in]: " << ex.what());
167196
return;
168197
}
169198
}
@@ -181,8 +210,11 @@ void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2Cons
181210
output.header.frame_id = target_frame_;
182211
}
183212

184-
output.angle_min = angle_min_;
185-
output.angle_max = angle_max_;
213+
{
214+
std::lock_guard<std::mutex> lock(angle_mutex);
215+
output.angle_min = angle_min_;
216+
output.angle_max = angle_max_;
217+
}
186218
output.angle_increment = angle_increment_;
187219
output.time_increment = 0.0;
188220
output.scan_time = scan_time_;
@@ -266,6 +298,10 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
266298
double angle;
267299
int index;
268300

301+
// reset fov extremal points
302+
fov_max.setValue(-1e3, -1e3, -1e3);
303+
fov_min.setValue(1e3, 1e3, 1e3);
304+
269305
// Iterate through point cloud
270306
for (sensor_msgs::PointCloud2ConstIterator<float>
271307
iter_x(*cloud, "x"), iter_y(*cloud, "y"), iter_z(*cloud, "z");
@@ -274,10 +310,23 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
274310
{
275311
if (std::isnan(*iter_x) || std::isnan(*iter_y) || std::isnan(*iter_z))
276312
{
277-
NODELET_DEBUG("rejected for nan in point(%f, %f, %f)\n", *iter_x, *iter_y, *iter_z);
313+
// NODELET_DEBUG("rejected for nan in point(%f, %f, %f)\n", *iter_x, *iter_y, *iter_z);
278314
continue;
279315
}
280316

317+
// check if furthest point on y axis
318+
// std::cout << "CHECKING POINT: " << *iter_x << ", " << *iter_y << ", " << *iter_z << ", " << std::endl;
319+
if (*iter_y > fov_max.y()) {
320+
std::lock_guard<std::mutex> lock(fov_mutex);
321+
fov_max.setValue(*iter_x, *iter_y, *iter_z);
322+
// std::cout << "SET POINT: " << *iter_x << ", " << *iter_y << ", " << *iter_z << ", " << std::endl;
323+
}
324+
if (*iter_y < fov_min.y()) {
325+
std::lock_guard<std::mutex> lock(fov_mutex);
326+
fov_min.setValue(*iter_x, *iter_y, *iter_z);
327+
// std::cout << "SET POINT: " << *iter_x << ", " << *iter_y << ", " << *iter_z << ", " << std::endl;
328+
}
329+
281330
//get reflection point in height limiting planes in order to check that point lies between borders(above or below is not clearly def):
282331
P.setValue(*iter_x, *iter_y, *iter_z);
283332

0 commit comments

Comments
 (0)