This project implements a complete Gap Follow algorithm for the F1Tenth autonomous racing simulation using ROS 2 Humble and f1tenth_gym_ros. The objective is to navigate safely through static obstacles using LiDAR scans and reactive control.
Gap Follow is a reactive method where the racer:
- Reads the LiDAR scan
- Identifies all obstacles in its field of view
- Inflates obstacles (safety bubble)
- Detects gaps between obstacles
- Selects the largest & safest gap
- Steers toward the gap center
- Sets speed based on forward clearance & steering
This repository contains:
- Updated simulation using Spielberg obstacle map
- A fully implemented
gap_follow.pynode gap_follow.launch.pythat launches f1tenth simulation + controller- Tuned speed + steering controllers for smooth behavior
Your implementation (in gap_follow.py) includes:
- Subscribes to
/scan - Converts scan into usable ranges
- Clips invalid/inf values
- Restricts view to ±120° FOV
Every detected obstacle creates a “bubble” to avoid clipping corners:
bubble_radius = f(distance_to_obstacle)
inflation_size = min(max(obstacle_inflated, angular_bubble), 60)All ranges inside the bubble are set to zero (blocked).
A continuous set of non-zero LiDAR points = a gap For each gap, compute:
- Average distance
- Maximum distance
- Gap width
- Center index
- Gap score (weighted by distance + center alignment)
gap_score = 0.4 * gap_max + 0.6 * gap_avg
gap_score *= center_alignment_factorThe highest-scoring gap is selected.
Heading direction = angle of center of chosen gap Steering is smoothed:
smoothed = α * desired + (1-α) * previousSpeed-dependent steering reduction prevents over-steering.
Your proportional controller:
- Slows down when gap clearance is low
- Speeds up in open regions
- Scales speed based on steering angle (cosine factor)
speed = Kp * clearance * steering_factor
speed clipped between (min_speed, max_speed)colcon build
source install/setup.bashros2 launch gap_follow gap_follow.launch.pyThis will:
- Start the f1tenth_gym_bridge
- Load the Spielberg obstacle map
- Launch the Gap Follow controller
- Open RViz2 with LiDAR + vehicle visualization
The racer navigates smoothly with high speed.
| Obstacle Free Map Gap Follow |
|---|
![]() |
Obstacle inflation and adaptive gap scoring make the racer safely avoid blocked regions.
| Obstacle Map Gap Follow |
|---|
![]() |
| Obstacle Free Map | Obstacle Map |
|---|---|
![]() |
![]() |
- Uses
AckermannDriveStampedfor control - Runs at 10 Hz publish rate
- ROS 2 Humble required
- Must install:
sudo apt install ros-humble-ackermann-msgs- F1Tenth Follow-The-Gap - Video
- f1tenth gym ros
- AckermannDriveStamped



