Video by freeCodeCamp.org · taught by Radu Mariescu-Istodor · streamed from YouTube. All rights remain with the creator.
Lesson 3: A Self-Driving Car from Scratch
About this lesson
This project course by Radu Mariescu-Istodor teaches neural networks by building a self-driving car simulation in plain JavaScript, with no libraries or frameworks, so that every part of the system is written and understood from scratch. Everything runs in an ordinary web browser and is drawn on an HTML canvas element. The course begins with the car's driving mechanics, programming how it accelerates, slows down through friction, reverses and steers, so that it can first be driven with the keyboard. Next it defines the road, with lanes and borders, and makes the view follow the car as it moves forward. The car is then given artificial sensors, a fan of rays that measure how far away the road edges and other objects are, which become the inputs of its brain. Collision detection follows, using the geometry of intersecting line segments to work out when the car has hit a border or another vehicle. The course then adds simulated traffic, other cars for the self-driving car to avoid. With the world in place, it builds a neural network from scratch, connects the sensor readings to it and lets its outputs control the car, visualising the network as it makes decisions. Parallelisation runs many cars at the same time, each with its own brain, and a genetic algorithm keeps the best brain and mutates it, so that the cars improve from one run to the next. Afterwards, read Chapter 3 of the course book, which works the sensor geometry by hand.