Hi Chang,
The insertRay method updates the map using the DDA raycasting algorithm. Put simply, a ray is traced between two points, iteratively stepped through the map (matrix). If the ray is less than the max ray length, then it registers a hit at the final cell location (increasing the occupancy value), and all other traced cells register a "miss" (decreasing the occupancy value). The reason for the large gap is most likely due to a few beams passing along that verticle "wall" when the robot rounds the corner (near the top of the circles you've drawn). During that time, the beams will be close to parallel with the wall, allowing the ray to pass through previously occupied cells until it registers a "hit" lower down and thus causing previously occupied cells to become free:
It's worth remembering that maps are only accurate to their resolution, so if the true location of the wall lies close to the edge of a cell, there's a higher chance the wall can disappear later.
There are a few things you can try to mitigate these effects:
- This example uses a Lidar with 360 FOV, meaning the chance of spawning these parallel rays is fairly high. A fan-shaped spread of lasers could help to mitigate this, as the robot will be less likely to clear previously visited cells unless it's heading is pointed directly down a wall.
- By default, insertRay will update cells using the LogoddsMiss and LogoddsHit properties of the occupancyMap, which are 0.4 and 0.7, respectively.
- You can provide your own hit and miss update values in the inverseModel argument of insertRay. Setting values closer to 0.5 will cause them to have less of an effect, so to prevent clearing of cells, you can try something like [0.48 0.9].
3) Refine the map resolution
- Lastly, you can reduce the chances of this occurring by increasing the map resolution. This will reduce the potential error between cell-boundaries and ground-truth wall, reducing the gaps through which these parallel beams can pass.
Hope this helps,
Cameron