Skip to content

Commit 695125b

Browse files
committed
Push NAN into point array for measurement outside range limit
According to the comment in sensor_msgs/LaserScan, values < range_min or > range_max should be discarded. Without this, scan matching will fail for lidars publishing 0 for invalid measurements.
1 parent fed596e commit 695125b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/slam_toolbox/laser_utils.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ inline std::vector<double> scanToReadings(
3737
const bool & inverted)
3838
{
3939
std::vector<double> readings;
40+
float range_min = scan.range_min;
41+
float range_max = scan.range_max;
4042

4143
if (inverted) {
4244
for (std::vector<float>::const_reverse_iterator it = scan.ranges.rbegin();
4345
it != scan.ranges.rend(); ++it)
4446
{
45-
readings.push_back(*it);
47+
readings.push_back(karto::math::InRange(*it, range_min, range_max) ? *it : NAN);
4648
}
4749
} else {
4850
for (std::vector<float>::const_iterator it = scan.ranges.begin(); it != scan.ranges.end();
4951
++it)
5052
{
51-
readings.push_back(*it);
53+
readings.push_back(karto::math::InRange(*it, range_min, range_max) ? *it : NAN);
5254
}
5355
}
5456

0 commit comments

Comments
 (0)