Skip to content

Commit

Permalink
fix: avoid zero division on the slope estimation
Browse files Browse the repository at this point in the history
Signed-off-by: Taekjin LEE <[email protected]>
  • Loading branch information
technolojin committed Nov 25, 2024
1 parent b98e0ba commit f4b894a
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ void GridGroundFilter::fitLineFromGndGrid(const std::vector<int> & idx, float &
sum_x2 += cell.avg_radius_ * cell.avg_radius_;
}
const float n = static_cast<float>(idx.size());
a = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x * sum_x);
// limit gradient
a = std::clamp(a, -param_.global_slope_max_ratio, param_.global_slope_max_ratio);
b = (sum_y - a * sum_x) / n;
const float denominator = n * sum_x2 - sum_x * sum_x;
if (denominator != 0.0f) {
a = (n * sum_xy - sum_x * sum_y) / denominator;
a = std::clamp(a, -param_.global_slope_max_ratio, param_.global_slope_max_ratio);
b = (sum_y - a * sum_x) / n;
} else {
const auto & cell = grid_ptr_->getCell(idx.front());
a = cell.avg_height_ / cell.avg_radius_;
b = 0.0f;

Check warning on line 106 in perception/autoware_ground_segmentation/src/scan_ground_filter/grid_ground_filter.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_ground_segmentation/src/scan_ground_filter/grid_ground_filter.cpp#L104-L106

Added lines #L104 - L106 were not covered by tests
}
}

void GridGroundFilter::initializeGround(pcl::PointIndices & out_no_ground_indices)
Expand Down

0 comments on commit f4b894a

Please sign in to comment.