Obstacle Masking: Creating a Safety Bubbleยถ

Before we find gaps to drive through, we must ensure that the robot doesnโ€™t hit obstacles. We create a Safety Bubble โ€” an area around the closest detected object where driving is not allowed.

Obstacle Masking

๐Ÿ›  Why Create a Safety Bubble?ยถ

  • The car needs clear space to steer safely.

  • Obstacles might not be exactly at one point โ€” their edges could extend sideways.

  • Sensors have small errors, so being conservative around obstacles improves safety.

โœ… By removing all directions near obstacles, we only drive through clean, safe spaces.

๐Ÿ“ˆ What the Data Looks Likeยถ

Imagine your LiDAR scan (distances around the robot) like this:

[2.5m, 2.5m, 0.6m, 0.6m, 2.5m, 2.5m]
  • The 0.6m values indicate a close obstacle.

  • We create a bubble around it by setting nearby points to zero.

After applying the safety bubble:

[2.5m, 0.0m, 0.0m, 0.0m, 2.5m, 2.5m]

Now we clearly cannot steer toward the obstacle!

โœ๏ธ Safety Bubble Method (Skeleton Code)ยถ

def create_safety_bubble(self, ranges, bubble_radius):
    """
    Masks out a 'bubble' around the closest obstacle in LiDAR data.

    Args:
        ranges (np.array): Preprocessed LiDAR distances
        bubble_radius (float): Radius of safety bubble (meters)

    Returns:
        np.array: Updated ranges with obstacles masked
    """
    closest_idx = np.argmin(ranges)  # Find the nearest object
    closest_dist = ranges[closest_idx]

    if closest_dist == 0.0:
        return ranges  # No need to create a bubble if no valid close point

    bubble_angle = math.atan(bubble_radius / closest_dist)  # Calculate angle span of the bubble
    bubble_points = int(bubble_angle / self.angle_increment)  # How many LiDAR points wide the bubble is

    start_idx = max(closest_idx - bubble_points, 0)
    end_idx = min(closest_idx + bubble_points, len(ranges) - 1)

    # Set the bubble area to obstacle (zero)
    ranges[start_idx:end_idx + 1] = 0.0

    return ranges

โš™๏ธ How It Works Step-by-Stepยถ

Step

Action

Find the closest detected object.

Calculate how many degrees (or LiDAR points) the bubble should cover.

Mask out all points in that range by setting them to zero.

Treat zeroed points as unsafe directions during gap finding.

๐Ÿง  Why Mask Points to Zero?ยถ

  • Zero = obstacle in later steps.

  • When finding free space, we only look at non-zero points.

  • Simple, fast, and reliable method for safe navigation.

๐Ÿš€ Key Parametersยถ

Parameter

Meaning

Recommended Value

bubble_radius

Radius of safety margin (meters)

0.3m โ€“ 0.5m depending on robot size

โœ… Larger robots need larger bubbles!

๐Ÿ“š Summaryยถ

  • Obstacle masking protects the vehicle from driving dangerously close to obstacles.

  • A safety bubble around the nearest obstacle creates a clear zone of avoidance.

  • This step is critical before detecting the largest navigable gap.

โœ… Always apply the safety bubble before finding free space!