Skip to content

Commit ec9490e

Browse files
coderbaibaiSteveMacenski
authored andcommitted
Adding epsilon for voxel_layer precision loss (ros-navigation#5314)
* Adding epsilon for voxel_layer precision loss Signed-off-by: bhx <[email protected]> * Update nav2_costmap_2d/plugins/voxel_layer.cpp Signed-off-by: Steve Macenski <[email protected]> * Update nav2_costmap_2d/plugins/voxel_layer.cpp Signed-off-by: Steve Macenski <[email protected]> * Update nav2_costmap_2d/plugins/voxel_layer.cpp Signed-off-by: Steve Macenski <[email protected]> --------- Signed-off-by: bhx <[email protected]> Signed-off-by: Steve Macenski <[email protected]> Co-authored-by: Steve Macenski <[email protected]>
1 parent b2ada71 commit ec9490e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

nav2_costmap_2d/plugins/voxel_layer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,31 +342,47 @@ void VoxelLayer::raytraceFreespace(
342342
double b = wpy - oy;
343343
double c = wpz - oz;
344344
double t = 1.0;
345+
bool wp_outside = false;
345346

346347
// we can only raytrace to a maximum z height
347348
if (wpz > map_end_z) {
348349
// we know we want the vector's z value to be max_z
349350
t = std::max(0.0, std::min(t, (map_end_z - 0.01 - oz) / c));
351+
wp_outside = true;
350352
} else if (wpz < origin_z_) {
351353
// and we can only raytrace down to the floor
352354
// we know we want the vector's z value to be 0.0
353355
t = std::min(t, (origin_z_ - oz) / c);
356+
wp_outside = true;
354357
}
355358

356359
// the minimum value to raytrace from is the origin
357360
if (wpx < origin_x_) {
358361
t = std::min(t, (origin_x_ - ox) / a);
362+
wp_outside = true;
359363
}
360364
if (wpy < origin_y_) {
361365
t = std::min(t, (origin_y_ - oy) / b);
366+
wp_outside = true;
362367
}
363368

364369
// the maximum value to raytrace to is the end of the map
365370
if (wpx > map_end_x) {
366371
t = std::min(t, (map_end_x - ox) / a);
372+
wp_outside = true;
367373
}
368374
if (wpy > map_end_y) {
369375
t = std::min(t, (map_end_y - oy) / b);
376+
wp_outside = true;
377+
}
378+
379+
constexpr double wp_epsilon = 1e-5;
380+
if (wp_outside) {
381+
if (t > 0.0) {
382+
t -= wp_epsilon;
383+
} else if (t < 0.0) {
384+
t += wp_epsilon;
385+
}
370386
}
371387

372388
wpx = ox + a * t;

0 commit comments

Comments
 (0)