Skip to content

Commit 0b4179b

Browse files
authored
Add a min_obstacle_height param to the nav2_costmap_2d's ObstacleLayer plugin (#3211)
This allows considering full range observations, specified by the <data source>.min_obstacle_height and <data source>.max_obstacle_height especially used for the raytracing, but to still be able to specify a minimum obstacle height to report obstacles onto the costmap. This is in particular required in the case a PointCloud2 source points slightly towards the ground, sometimes detecting obstacles, that should be cleared once the ground reappears behind the obstacle when it has moved away: we don't want to detect the ground as an obstacle, but still want it to be used in the raytracing to clear the previously detected obstacle.
1 parent 664c09f commit 0b4179b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

nav2_costmap_2d/include/nav2_costmap_2d/obstacle_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class ObstacleLayer : public CostmapLayer
226226
double * max_y);
227227

228228
std::string global_frame_; ///< @brief The global frame for the costmap
229+
double min_obstacle_height_; ///< @brief Max Obstacle Height
229230
double max_obstacle_height_; ///< @brief Max Obstacle Height
230231

231232
/// @brief Used to project laser scans into point clouds

nav2_costmap_2d/plugins/obstacle_layer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void ObstacleLayer::onInitialize()
7878

7979
declareParameter("enabled", rclcpp::ParameterValue(true));
8080
declareParameter("footprint_clearing_enabled", rclcpp::ParameterValue(true));
81+
declareParameter("min_obstacle_height", rclcpp::ParameterValue(0.0));
8182
declareParameter("max_obstacle_height", rclcpp::ParameterValue(2.0));
8283
declareParameter("combination_method", rclcpp::ParameterValue(1));
8384
declareParameter("observation_sources", rclcpp::ParameterValue(std::string("")));
@@ -89,6 +90,7 @@ void ObstacleLayer::onInitialize()
8990

9091
node->get_parameter(name_ + "." + "enabled", enabled_);
9192
node->get_parameter(name_ + "." + "footprint_clearing_enabled", footprint_clearing_enabled_);
93+
node->get_parameter(name_ + "." + "min_obstacle_height", min_obstacle_height_);
9294
node->get_parameter(name_ + "." + "max_obstacle_height", max_obstacle_height_);
9395
node->get_parameter(name_ + "." + "combination_method", combination_method_);
9496
node->get_parameter("track_unknown_space", track_unknown_space);
@@ -296,7 +298,9 @@ ObstacleLayer::dynamicParametersCallback(
296298
const auto & param_name = parameter.get_name();
297299

298300
if (param_type == ParameterType::PARAMETER_DOUBLE) {
299-
if (param_name == name_ + "." + "max_obstacle_height") {
301+
if (param_name == name_ + "." + "min_obstacle_height") {
302+
min_obstacle_height_ = parameter.as_double();
303+
} else if (param_name == name_ + "." + "max_obstacle_height") {
300304
max_obstacle_height_ = parameter.as_double();
301305
}
302306
} else if (param_type == ParameterType::PARAMETER_BOOL) {
@@ -453,6 +457,12 @@ ObstacleLayer::updateBounds(
453457
for (; iter_x != iter_x.end(); ++iter_x, ++iter_y, ++iter_z) {
454458
double px = *iter_x, py = *iter_y, pz = *iter_z;
455459

460+
// if the obstacle is too low, we won't add it
461+
if (pz < min_obstacle_height_) {
462+
RCLCPP_DEBUG(logger_, "The point is too low");
463+
continue;
464+
}
465+
456466
// if the obstacle is too high or too far away from the robot we won't add it
457467
if (pz > max_obstacle_height_) {
458468
RCLCPP_DEBUG(logger_, "The point is too high");

0 commit comments

Comments
 (0)