Skip to content

shrirampai3000/self-driving-car-simulation

Repository files navigation

Self-Driving Car Simulation

A neural network-based self-driving car simulation built with pure JavaScript, demonstrating artificial intelligence and machine learning concepts in a real-time driving environment.

Project Overview

This simulation implements a self-driving car that navigates through traffic using a custom neural network. The car uses sensor inputs to make driving decisions, providing a practical demonstration of AI and machine learning principles.

Features

  • Neural Network AI: Custom-built neural network for autonomous driving decisions
  • Sensor System: Ray-casting sensors for obstacle and road boundary detection
  • Real-Time Visualization: Live visualization of neural network decision processes
  • Traffic Simulation: Multiple AI-controlled vehicles for realistic driving scenarios
  • Training System: Save and load functionality for the best-performing neural networks

Project Structure

self-driving-car/
├── index.html          # Main HTML file
├── style.css           # Application styling
├── main.js             # Core application logic and animation
├── car.js              # Car physics and AI controls
├── road.js             # Road generation and management
├── sensor.js           # Sensor system implementation
├── network.js          # Neural network architecture
├── visualizer.js       # Neural network visualization
├── controls.js         # Control system for driving
├── utils.js            # Utility functions
├── car.png             # Car sprite image
└── README.md           # Project documentation

Neural Network Architecture

The neural network uses a feedforward architecture with:

  • Input Layer: 5 sensor rays (configurable)
  • Hidden Layer: 6 neurons
  • Output Layer: 4 neurons (forward, left, right, reverse controls)

Usage

  1. Open index.html in a web browser to start the simulation
  2. The AI car will automatically begin navigating through traffic
  3. Interface controls:
    • Save Button: Save the current best neural network to localStorage
    • Discard Button: Remove saved network and reset simulation

Technical Implementation

Car Physics System

  • Acceleration and friction modeling
  • Collision detection with road borders and vehicles
  • Damage assessment system
  • Turning mechanics based on speed

Sensor System

  • Ray-casting implementation for environmental scanning
  • Multiple sensor configuration for comprehensive detection
  • Distance measurement to obstacles

Neural Network

  • Custom implementation without external dependencies
  • Feedforward propagation
  • Mutation capabilities for training optimization
  • Local storage integration for model persistence

Getting Started

To run the simulation:

  1. Download or clone the project files
  2. Open index.html in any modern web browser
  3. The simulation will start automatically

Training Methodology

The AI learning process follows these steps:

  1. Generate multiple cars with varied neural network configurations
  2. Evaluate performance based on distance traveled
  3. Select and save the best-performing neural network
  4. Use mutation to explore new behavioral patterns
  5. Repeat the process for continuous improvement

Customization Options

The project supports various modifications:

  • Sensor configuration in sensor.js
  • Neural network architecture in network.js
  • Traffic patterns in main.js
  • Physics parameters in car.js

Educational Value

This project demonstrates:

  • Neural network fundamentals and implementation
  • Genetic algorithms and evolutionary strategies
  • Computer vision concepts through ray-casting
  • Real-time physics simulation
  • Canvas-based graphics rendering

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published