Skip to content

Commit edcbde5

Browse files
committed
Added option to remove points in sensor origin (some sensors place points in sensor origin instead of using NaNs).
1 parent 005cf27 commit edcbde5

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

include/dynamic_robot_localization/common/impl/pointcloud_conversions.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool fromROSMsg(const nav_msgs::OccupancyGrid& occupancy_grid, pcl::PointCloud<P
2828
Eigen::Transform<float, 3, Eigen::Affine>(Eigen::Quaternionf(occupancy_grid.info.origin.orientation.w, occupancy_grid.info.origin.orientation.x, occupancy_grid.info.origin.orientation.y, occupancy_grid.info.origin.orientation.z));
2929

3030
pointcloud.height = 1;
31-
pointcloud.is_dense = false;
31+
pointcloud.is_dense = true;
3232
pointcloud.header.frame_id = occupancy_grid.header.frame_id;
3333
pointcloud.header.stamp = occupancy_grid.header.stamp.toNSec() / 1e3;
3434
pointcloud.clear();

include/dynamic_robot_localization/common/impl/pointcloud_utils.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,29 @@ void colorizePointCloudWithCurvature(pcl::PointCloud<PointT>& pointcloud) {
5454
}
5555

5656

57+
template <typename PointT>
58+
void removePointsOnSensorOrigin(pcl::PointCloud<PointT>& pointcloud) {
59+
size_t number_of_original_points = pointcloud.size();
60+
size_t number_of_valid_points = 0;
61+
size_t number_of_invalid_points = 0;
62+
for (size_t i = 0; i < pointcloud.size(); ++i) {
63+
if (pointcloud[i].x != pointcloud.sensor_origin_.x() || pointcloud[i].y != pointcloud.sensor_origin_.y() || pointcloud[i].z != pointcloud.sensor_origin_.z()) {
64+
if (number_of_invalid_points > 0) {
65+
pointcloud[number_of_valid_points] = pointcloud[i];
66+
}
67+
++number_of_valid_points;
68+
} else {
69+
++number_of_invalid_points;
70+
}
71+
}
72+
if (number_of_valid_points < number_of_original_points) {
73+
pointcloud.resize(number_of_valid_points);
74+
pointcloud.height = 1;
75+
pointcloud.width = static_cast<std::uint32_t>(number_of_valid_points);
76+
}
77+
}
78+
79+
5780
template <typename PointT>
5881
void colorizePointCloudClusters(const pcl::PointCloud<PointT>& pointcloud, const std::vector<pcl::PointIndices>& cluster_indices, pcl::PointCloud<PointT>& pointcloud_colored_out) {
5982
for (size_t cluster_index = 0; cluster_index < cluster_indices.size(); ++cluster_index) {

include/dynamic_robot_localization/common/pointcloud_utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void concatenatePointClouds(const std::vector< typename pcl::PointCloud<PointT>:
3131
template <typename PointT>
3232
void colorizePointCloudWithCurvature(pcl::PointCloud<PointT>& pointcloud);
3333

34+
template <typename PointT>
35+
void removePointsOnSensorOrigin(pcl::PointCloud<PointT>& pointcloud);
36+
3437
template <typename PointT>
3538
void colorizePointCloudClusters(const pcl::PointCloud<PointT>& pointcloud, const std::vector<pcl::PointIndices>& cluster_indices, pcl::PointCloud<PointT>& pointcloud_colored_out);
3639

include/dynamic_robot_localization/localization/impl/localization.hpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ void Localization<PointT>::setupMessageManagement(const std::string& configurati
455455
private_node_handle_->param(configuration_namespace + "message_management/min_seconds_between_reference_pointcloud_update", min_seconds_between_reference_pointcloud_update, 5.0);
456456
min_seconds_between_reference_pointcloud_update_.fromSec(min_seconds_between_reference_pointcloud_update);
457457

458+
private_node_handle_->param(configuration_namespace + "message_management/remove_points_in_sensor_origin", remove_points_in_sensor_origin_, false);
459+
458460
private_node_handle_->param(configuration_namespace + "message_management/minimum_number_of_points_in_ambient_pointcloud", minimum_number_of_points_in_ambient_pointcloud_, 10);
459461

460462
private_node_handle_->param(configuration_namespace + "message_management/circular_buffer_require_reception_of_pointcloud_msgs_from_all_topics_before_doing_registration", circular_buffer_require_reception_of_pointcloud_msgs_from_all_topics_before_doing_registration_, false);
@@ -1735,14 +1737,22 @@ bool Localization<PointT>::processAmbientPointCloud(typename pcl::PointCloud<Poi
17351737
}
17361738

17371739
tf2::Transform pose_tf_initial_guess = last_accepted_pose_odom_to_map_ * transform_base_link_to_odom;
1740+
17381741
size_t ambient_pointcloud_size = ambient_pointcloud->size();
17391742
std::vector<int> indexes;
17401743
ambient_pointcloud->is_dense = false;
1744+
ROS_DEBUG_STREAM("Removing NaNs from ambient cloud with " << ambient_pointcloud_size << " points");
17411745
pcl::removeNaNFromPointCloud(*ambient_pointcloud, *ambient_pointcloud, indexes);
17421746
indexes.clear();
17431747
size_t number_of_nans_in_ambient_pointcloud = ambient_pointcloud_size - ambient_pointcloud->size();
1744-
if (number_of_nans_in_ambient_pointcloud > 0) {
1745-
ROS_DEBUG_STREAM("Removed " << number_of_nans_in_ambient_pointcloud << " NaNs from ambient cloud with " << ambient_pointcloud_size << " points");
1748+
ROS_DEBUG_STREAM("Removed " << number_of_nans_in_ambient_pointcloud << " NaNs from ambient cloud with " << ambient_pointcloud_size << " points");
1749+
1750+
if (remove_points_in_sensor_origin_) {
1751+
size_t number_of_points_in_ambient_pointcloud_before_sensor_origin_removal = ambient_pointcloud->size();
1752+
ROS_DEBUG_STREAM("Removing points in sensor origin from a ambient cloud with " << number_of_points_in_ambient_pointcloud_before_sensor_origin_removal << " points");
1753+
pointcloud_utils::removePointsOnSensorOrigin(*ambient_pointcloud);
1754+
size_t number_of_points_in_sensor_origin_in_ambient_pointcloud = number_of_points_in_ambient_pointcloud_before_sensor_origin_removal - ambient_pointcloud->size();
1755+
ROS_DEBUG_STREAM("Removed " << number_of_points_in_sensor_origin_in_ambient_pointcloud << " points in sensor origin from ambient cloud with " << number_of_points_in_ambient_pointcloud_before_sensor_origin_removal << " points");
17461756
}
17471757

17481758
tf2::Quaternion pose_tf_initial_guess_q = pose_tf_initial_guess.getRotation().normalize();

include/dynamic_robot_localization/localization/localization.h

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ class Localization : public ConfigurableObject {
404404
ros::Duration pose_tracking_timeout_;
405405
ros::Duration pose_tracking_recovery_timeout_;
406406
ros::Duration initial_pose_estimation_timeout_;
407+
bool remove_points_in_sensor_origin_;
407408
int minimum_number_of_points_in_ambient_pointcloud_;
408409
int minimum_number_of_points_in_reference_pointcloud_;
409410
bool localization_detailed_use_millimeters_in_root_mean_square_error_inliers_;

yaml/schema/drl_configs.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ message_management:
140140
max_seconds_ambient_pointcloud_offset_to_last_estimated_pose: 0.0 # Point clouds that older than this offset in relation to the last [estimated pose / sensor data received] are discarded (useful when there are several sources of sensor data and one has higher update rate -> ex: kinect+lasers) -> for disabling this check, set to <= 0
141141
min_seconds_between_scan_registration: 0.0 # Ambient point clouds received before this duration is reached (after a successful pose estimation) will be discarded -> for disabling this check, set to <= 0
142142
min_seconds_between_reference_pointcloud_update: 5.0 # Clouds coming from topics reference_costmap_topic | reference_pointcloud_topic will be discarded if the last reference cloud was updated less than [this value] seconds ago
143+
remove_points_in_sensor_origin: false
143144
minimum_number_of_points_in_ambient_pointcloud: 10
144145
circular_buffer_require_reception_of_pointcloud_msgs_from_all_topics_before_doing_registration: false
145146
circular_buffer_clear_inserted_points_if_registration_fails: false

0 commit comments

Comments
 (0)