facontidavide / Bonxai

Fast, hierarchical, sparse Voxel Grid
Mozilla Public License 2.0
673 stars 59 forks source link

Feedback and Suggested Fix for Stability Issue in `insertPointCloud` #35

Open tejalbarnwal opened 1 week ago

tejalbarnwal commented 1 week ago

Hi @facontidavide , First, I would like to thank you for this amazing repository! The mapping module is really performant, and I have been testing it for 3D planning with a quadrotor in Gazebo SITL.

While working with the insertPointCloud implementation (here), I encountered performance and stability issue related to inf values in pc.points. I would like to share the details and potential impact.

I traced back the issue to the updateFreeCells(from) line present(here).

Specifically, this section of code in updateFreeCells() seemed to cause the problem:

for (const auto& coord_end : _miss_coords) {  
    RayIterator(coord_origin, coord_end, clearPoint);  
} 

Details:

This caused:

Suggested Fix: I made a small change to the insertPointCloud method in bonxai_map/include/bonxai_map/probabilistic_map.hpp to handle this edge case:

if (squared_norm >= max_range_sqr) {
      const Vector3D new_point = from + ((vect / std::sqrt(squared_norm)) * max_range);
      if (std::isfinite(new_point.x()) && std::isfinite(new_point.y()) && std::isfinite(new_point.z())) {
        addMissPoint(new_point);
      }
} else {
      addHitPoint(to);
    }

This modification ensures:

This small fix significantly reduced processing time and completely stabilized my PC, preventing hangs or crashes. I would love to hear your thoughts or suggestions on this. If you think there is a better approach or have any feedback, I would greatly appreciate it. I would be happy to create a pull request for this.