Open source · Python · Robotics

AI-Based Autonomous Navigation System

A complete autonomy stack for a mobile robot: it sees obstacles with computer vision, maps them from its sensors, plans a collision-free route with A*, and drives it with pure pursuit, guarded by a safety layer.

|

LIVE REPLAYDRIVING
0/60
seeded worlds reached the goal
0
collisions across all runs
0 ms
compute per control cycle
0
event-driven replans per run

The problem

A robot must reach a goal in an environment it only partly knows, and never hit anything. Every decision depends on answering two questions continuously.

👁

What is around me?

Perception turns camera frames and range echoes into obstacle positions in the robot's own frame.

🧭

Where do I go next?

A global planner routes around everything known, and replans when the sensors reveal something new.

🛡

How do I stay safe?

Control tracks the path, slows down near obstacles, and a safety layer can override the planner.

The pipeline

Every control cycle (every 50 ms of simulated time) runs through these stages. Watch the signal travel.

Sensorsultrasonic · camera PerceptionHSV · contours Mappingfusion · grid Planninginflate · A* Controlpure pursuit Vehiclemotors · physics feedback: the vehicle's new pose returns to the sensors
Sense3 ray-cast range beams + a rendered top-down camera with noise.
DecideNew obstacle on the path, drift off path, or no route triggers a replan.
ActSpeed, turn-rate and acceleration limits keep motion physically realistic.

Live replay: a real run

This is replayed from the recorded data of an actual simulation (seed 7). Amber obstacles are unknown to the robot until its sensors see them. Watch the rays, the detection pulses, and the replan flashes.

time0.0 s
state—
speed0.00 m/s
front range—
replans0
unknown found0 / 0

Under the hood

Every layer is written in plain Python so you can read and change it.

Obstacle detection

HSV colour masking, morphological clean-up, contour fitting, pixel→metre conversion in the robot frame.

obstacle_detector.py

Free-space estimation

Ray-casts across the image to find the most open direction. Used as a reactive fallback.

free_space.py

Sensor fusion

Camera detections and ultrasonic echoes write into one occupancy grid, skipping arena-wall echoes.

navigator.py

A* planning

8-connected A* with no corner cutting, octile heuristic, line-of-sight smoothing and 0.1 m resampling.

astar.py

Pure pursuit

Geometric path tracker with a 1 m lookahead, turn-based slowdown and side repulsion.

pure_pursuit.py

Safety layer

Front-sensor braking overrides the planner. Side sensors slow and push the robot away.

navigator.py

Graceful degradation

If no path exists at full clearance, it retries at a smaller one. If that fails, it stops instead of driving blind.

navigator.py

Sim-to-real ready

The same navigator drives a Raspberry Pi robot through HC-SR04, L298N and camera drivers.

run_robot.py

Engineering journey

Real bugs found by tracing the run, and the fixes that were measured on 60 seeds.

  1. 1
    17 collisions in the first run

    Pure pursuit steered at sparse waypoints, so the lookahead point could sit across an obstacle. Fix: resample the path to 0.1 m spacing.

  2. 2
    Robot drove along the arena wall

    Walls were not inflated in the planning grid. Fix: block cells within the safety margin of every wall.

  3. 3
    Route flip-flopping

    Periodic replanning chose the other side of an obstacle each time. Fix: replan on real events and off-path drift only.

  4. 4
    Spinning in place next to a wall

    The emergency stop watched side sensors and deadlocked. Fix: brake on the front, slow down on the sides.

  5. 5
    Stuck with no path

    A narrow gap plus a 0.5 m margin left no route. Fix: graceful degradation, then a safe stop.

  6. 6
    Index froze, robot drifted

    The tracker searched only 40 points ahead. Fix: search the full path and replan on 0.5 m cross-track error.

Benchmark: 60 random worlds

Each bar is one simulated episode from the open-source benchmark_results.csv. Green reached the goal, red did not.

Steps per episode
Replans per episode

Interactive notebooks & maps

Step-by-step Jupyter notebooks for computer vision, path planning, and statistical benchmark analysis, plus pre-built custom environment maps.

📓

01 · Perception Tuning

Explore dual-band HSV red segmentation, morphological filtering, metric contour fitting, and angular free-space ray-casts.

🧭

02 · Planner Experiments

Compare grid inflation safety margins, 8-connected A* search, line-of-sight shortcutting, and 0.1 m path resampling.

📊

03 · Benchmark Analysis

Quantitative evaluation over 60 seeded runs: KPI distributions, clearance safety margins, and path efficiency metrics.

Run it yourself

Requires Python 3.11+. No GPU needed.

Install
git clone https://github.com/rohitsingh83/AI-Autonomous-Navigation-System.git
cd AI-Autonomous-Navigation-System
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
Run
python main.py run --seed 7 --gif
python main.py benchmark --episodes 60
pytest -q

Windows: use .venv\Scripts\activate. Outputs go to outputs/.

Sim-to-real wiring

The Raspberry Pi pin map (BCM). It fixes a GPIO 23 clash in the original guide.

PartSignalGPIO
HC-SR04TRIG / ECHO*23 / 24
L298N leftIN1 / IN2 / ENA17 / 18 / 12
L298N rightIN3 / IN4 / ENB27 / 22 / 13

*ECHO outputs 5 V. Use a 1 kΩ / 2 kΩ divider to protect the Pi's 3.3 V pin.

Roadmap

  • Simulation, perception, A*, pure pursuit, safety layer
  • Benchmark, pytest suite, GitHub Actions CI
  • Raspberry Pi hardware drivers
  • YOLOv8 on a real camera with calibration
  • ROS 2 / Nav2 integration
  • SLAM instead of an assumed prior map
  • CARLA urban scenarios and an RL local planner

Open source. Built to be extended.

Found a bug or have a better planner? Open an issue or a pull request. The benchmark is the regression check.