Skip to content

CodeName-Detective/F1Tenth-Racing-Reactive-Obstacle-Avoidance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

F1Tenth Racing Reactive Obstacle Avoidance

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.


Overview

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.py node
  • gap_follow.launch.py that launches f1tenth simulation + controller
  • Tuned speed + steering controllers for smooth behavior

Gap Follow Algorithm – Implementation Summary

Your implementation (in gap_follow.py) includes:

1. LiDAR Preprocessing

  • Subscribes to /scan
  • Converts scan into usable ranges
  • Clips invalid/inf values
  • Restricts view to ±120° FOV

2. Obstacle Inflation

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).

3. Gap Detection

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_factor

The highest-scoring gap is selected.

4. Steering Command

Heading direction = angle of center of chosen gap Steering is smoothed:

smoothed = α * desired + (1-α) * previous

Speed-dependent steering reduction prevents over-steering.

5. Speed Controller

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)

Running the Simulation

1. Build the Workspace

colcon build
source install/setup.bash

2. Launch the Gap Follow System

ros2 launch gap_follow gap_follow.launch.py

This will:

  • Start the f1tenth_gym_bridge
  • Load the Spielberg obstacle map
  • Launch the Gap Follow controller
  • Open RViz2 with LiDAR + vehicle visualization

Simulation Results

Obstacle-Free Map — Gap Follow

The racer navigates smoothly with high speed.

Obstacle Free Map Gap Follow

Obstacle Map — Gap Follow

Obstacle inflation and adaptive gap scoring make the racer safely avoid blocked regions.

Obstacle Map Gap Follow

Maps Used

Obstacle Free Map Obstacle Map

Notes

  • Uses AckermannDriveStamped for control
  • Runs at 10 Hz publish rate
  • ROS 2 Humble required
  • Must install:
sudo apt install ros-humble-ackermann-msgs

Resources

About

Reactive obstacle-avoidance controller for the F1Tenth platform using a custom Gap-Follow algorithm. Includes full ROS 2 integration, simulation setup, and validation on obstacle-free and obstacle maps.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors