Skip to content

Commit 6dffbec

Browse files
committed
cleanup
1 parent 7ee3c7e commit 6dffbec

File tree

1 file changed

+18
-106
lines changed

1 file changed

+18
-106
lines changed

src/ipa_pointcloud_to_laserscan_nodelet.cpp

Lines changed: 18 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151

5252
namespace pointcloud_to_laserscan
5353
{
54-
//void scan_outlier_removal_filter(sensor_msgs::LaserScan &scan, double cluster_break_distance, int max_noise_cluster_size, double max_noise_cluster_distance);
55-
5654
IpaPointCloudToLaserScanNodelet::IpaPointCloudToLaserScanNodelet() {}
5755

5856
void IpaPointCloudToLaserScanNodelet::onInit()
@@ -159,25 +157,24 @@ namespace pointcloud_to_laserscan
159157
{
160158
NODELET_WARN_STREAM_THROTTLE(1.0, "Can't transform pointcloud from frame " << cloud_msg->header.frame_id << " to "
161159
<< message_filter_->getTargetFramesString());
160+
161+
try
162+
{
163+
geometry_msgs::TransformStamped T_geom = tf2_->lookupTransform(cloud_msg->header.frame_id, target_frame_, cloud_msg->header.stamp, ros::Duration(0.1));
164+
NODELET_INFO_STREAM("Transform worked at retry ");
165+
}
166+
catch (tf2::TransformException ex)
167+
{
168+
NODELET_WARN_STREAM("Transform failure again after retry in failureCB, exception: " << ex.what());
169+
return;
170+
}
162171
}
163172

164173
void IpaPointCloudToLaserScanNodelet::cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg)
165174
{
166175
ros::Time start_time = ros::Time::now();
167-
NODELET_INFO_STREAM("PC with timestamp " << cloud_msg->header.stamp << " recevied at time " << start_time);
168-
// TODO move to config and add dynamic reconfiguring
169-
// Get filter related parameters
170-
/*
171-
bool use_outlier_filter;
172-
double max_noise_cluster_distance;
173-
double cluster_break_distance;
174-
int max_noise_cluster_size;
175-
private_nh_.param<bool>("use_outlier_filter", use_outlier_filter, false);
176-
private_nh_.param<double>("max_noise_cluster_distance", max_noise_cluster_distance, 2.0);
177-
private_nh_.param<double>("cluster_break_distance", cluster_break_distance, 0.3);
178-
private_nh_.param<int>("max_noise_cluster_size", max_noise_cluster_size, 5);
179-
*/
180-
176+
NODELET_INFO_STREAM("PC with timestamp from init " << cloud_msg->header.stamp.toSec() << " recevied with a delay of " << (start_time - cloud_msg->header.stamp).toSec() << " ");
177+
181178
// convert const ptr to ptr to support downsampling
182179
sensor_msgs::PointCloud2Ptr cloud(boost::const_pointer_cast<sensor_msgs::PointCloud2>(cloud_msg));
183180

@@ -197,9 +194,9 @@ namespace pointcloud_to_laserscan
197194
{
198195
try
199196
{
200-
geometry_msgs::TransformStamped T_geom = tf2_->lookupTransform(cloud_msg->header.frame_id, target_frame_, cloud_msg->header.stamp);
201-
// Convert geometry msgs transform to tf2 transform.
202-
tf2::fromMsg(T_geom.transform, T);
197+
geometry_msgs::TransformStamped T_geom = tf2_->lookupTransform(cloud_msg->header.frame_id, target_frame_, cloud_msg->header.stamp, ros::Duration(0.1));
198+
// Convert geometry msgs transform to tf2 transform.
199+
tf2::fromMsg(T_geom.transform, T);
203200
}
204201
catch (tf2::TransformException ex)
205202
{
@@ -333,100 +330,15 @@ namespace pointcloud_to_laserscan
333330

334331
if(use_outlier_filter_)
335332
{
336-
//scan_outlier_removal_filter(output, cluster_break_distance, max_noise_cluster_size, max_noise_cluster_distance);
337333
outlier_filter_.remove_outliers(output);
338334
}
339335

340336
ros::Time end_time = ros::Time::now();
341-
NODELET_INFO_STREAM("Transform for PC took " << end_time - start_time);
337+
ros::Duration dur = end_time-start_time;
338+
NODELET_INFO_STREAM("Transform for PC took " << dur.toSec());
342339

343340
pub_.publish(output);
344341
}
345-
346-
/**
347-
* @brief scan_outlier_removal_filter
348-
* Remove clusters that are small enough (specified by parameter max_noise_cluster_size) and
349-
* closer to the sensor (has smaller range) than the surrounding clusters.
350-
* A cluster is defined as a collection of point with a specified range jump (specified by parameter cluster_break_distance) to neigboring points.
351-
* The "closer to the sensor" is determined by the sign of the range jump at the beginning and end of the cluster.
352-
*
353-
* The implementation assumes ordered scan, meaning that the points are sorted according to the angle.
354-
*
355-
* @param scan The 2d sensor msgs laser scan
356-
* @param cluster_break_distance The range jump to cause a cluster separation
357-
* @param max_noise_cluster_size The maximum number of points a cluster can contain in order to be seen as noise and thereby removed
358-
*/
359-
void scan_outlier_removal_filter(sensor_msgs::LaserScan &scan, double cluster_break_distance, int max_noise_cluster_size, double max_noise_cluster_distance)
360-
{
361-
// help function initialization
362-
int ranges_size = scan.ranges.size();
363-
int i_current_cluster = 0;
364-
bool cluster_further_away = false;
365-
std::vector<int> cluster_indecies;
366-
double diffs[ranges_size-1];
367-
368-
// calculate diffs
369-
for (int i = 1; i< ranges_size; i++)
370-
{
371-
diffs[i-1] = scan.ranges[i] - scan.ranges[i-1];
372-
}
373-
374-
// find and remove outliers
375-
for (int i = 0; i< ranges_size-1; i++)
376-
{
377-
// add point to cluster
378-
cluster_indecies.push_back(i);
379-
i_current_cluster ++;
380-
381-
// check if last point in cluster; find diff larger than border -> cluster separation
382-
if (diffs[i] > cluster_break_distance || diffs[i] < -cluster_break_distance)
383-
{
384-
bool new_cluster_further_away = (diffs[i] > 0);
385-
386-
// Only remove cluster if it is closer than surrounding clusters
387-
if ((i_current_cluster < max_noise_cluster_size) && (new_cluster_further_away != cluster_further_away))
388-
{
389-
// check if all cluster points are closer than the max noise distance
390-
bool is_noise_cluster = true;
391-
for (int k = 0; k < i_current_cluster; k++)
392-
{
393-
if (scan.ranges[cluster_indecies[k]] > max_noise_cluster_distance)
394-
{
395-
is_noise_cluster = false;
396-
break;
397-
}
398-
}
399-
400-
// Only remove cluster points if all points are closer than the max noise distance
401-
if(is_noise_cluster)
402-
{
403-
for (int k = 0; k < i_current_cluster; k++)
404-
{
405-
if (scan.ranges[cluster_indecies[k]] < max_noise_cluster_distance)
406-
scan.ranges[cluster_indecies[k]] = scan.range_max;
407-
}
408-
}
409-
}
410-
411-
// initialize new cluster
412-
cluster_further_away = new_cluster_further_away;
413-
cluster_indecies.clear();
414-
i_current_cluster = 0;
415-
}
416-
}
417-
418-
419-
// remove last cluster if small enough
420-
if ((i_current_cluster < cluster_break_distance) && !cluster_further_away)
421-
{
422-
for (int k = 0; k < i_current_cluster; k++)
423-
{
424-
scan.ranges[cluster_indecies[k]] = scan.range_max;
425-
}
426-
// remove last point as well
427-
scan.ranges[ranges_size-1] = scan.range_max;
428-
}
429-
}
430342
}
431343

432344
PLUGINLIB_DECLARE_CLASS(ipa_pointcloud_to_laserscan, IpaPointCloudToLaserScanNodelet, pointcloud_to_laserscan::IpaPointCloudToLaserScanNodelet, nodelet::Nodelet);

0 commit comments

Comments
 (0)