@@ -128,13 +128,42 @@ void IpaPointCloudToLaserScanNodelet::configure_filter()
128
128
void IpaPointCloudToLaserScanNodelet::cameraInfoCb (const sensor_msgs::CameraInfo &camera_info_msg)
129
129
{
130
130
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
134
133
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
+ }
137
147
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
+ }
138
167
}
139
168
140
169
void IpaPointCloudToLaserScanNodelet::cloudCb (const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
@@ -163,7 +192,7 @@ void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2Cons
163
192
}
164
193
catch (tf2::TransformException ex)
165
194
{
166
- NODELET_WARN_STREAM (" Transform failure: " << ex.what ());
195
+ NODELET_WARN_STREAM (" Transform failure [cloud_in] : " << ex.what ());
167
196
return ;
168
197
}
169
198
}
@@ -181,8 +210,11 @@ void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2Cons
181
210
output.header .frame_id = target_frame_;
182
211
}
183
212
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
+ }
186
218
output.angle_increment = angle_increment_;
187
219
output.time_increment = 0.0 ;
188
220
output.scan_time = scan_time_;
@@ -266,6 +298,10 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
266
298
double angle;
267
299
int index;
268
300
301
+ // reset fov extremal points
302
+ fov_max.setValue (-1e3 , -1e3 , -1e3 );
303
+ fov_min.setValue (1e3 , 1e3 , 1e3 );
304
+
269
305
// Iterate through point cloud
270
306
for (sensor_msgs::PointCloud2ConstIterator<float >
271
307
iter_x (*cloud, " x" ), iter_y (*cloud, " y" ), iter_z (*cloud, " z" );
@@ -274,10 +310,23 @@ void IpaPointCloudToLaserScanNodelet::convert_pointcloud_to_laserscan(const sens
274
310
{
275
311
if (std::isnan (*iter_x) || std::isnan (*iter_y) || std::isnan (*iter_z))
276
312
{
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);
278
314
continue ;
279
315
}
280
316
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
+
281
330
// get reflection point in height limiting planes in order to check that point lies between borders(above or below is not clearly def):
282
331
P.setValue (*iter_x, *iter_y, *iter_z);
283
332
0 commit comments