Devlog #1 – Building a Self-Driving Car Simulator in Python
Project Overview
Today I started building a self-driving car simulator in Python using Pygame. The goal of this project is to create an autonomous vehicle that can navigate a track using virtual sensors and eventually learn to drive through evolutionary algorithms and neural networks.
This project is being developed in stages, starting with a simple car and gradually adding intelligence.
What I Built
MVP 1 – Basic Car Movement
The first milestone was creating a car that could:
- Move forward and backward
- Turn left and right
- Rotate smoothly
- Move using basic trigonometry
The car’s movement is calculated using sine and cosine functions based on its current heading angle.
MVP 2 – Sensor System
After movement was working, I added five distance sensors.
The sensors act like rays extending from the front of the vehicle:
- Left
- Front-left
- Front
- Front-right
- Right
Each sensor checks for collisions with walls and returns the distance to the nearest obstacle.
This allows the car to “see” its surroundings.
Example sensor output:
[150, 120, 85, 140, 150]
The smaller the number, the closer an obstacle is.
MVP 3 – First Autonomous Driver
Using the sensor data, I implemented a simple rule-based AI.
The logic is straightforward:
- Drive forward continuously
- If an obstacle appears ahead, turn toward the side with more open space
- Avoid walls detected by side sensors
Although the AI is simple, it can already navigate parts of the track without human input.
Challenges Faced
One of the biggest issues was setting up Pygame.
Initially, installation failed because I was using Python 3.14, which caused compatibility problems with the version of Pygame being installed.
I switched to pygame-ce and successfully got the simulator running.
I also encountered several coding mistakes:
- Misspelled method names
- Incorrect variable references
- Nested functions due to indentation errors
- Collision detection bugs
Debugging these issues helped me better understand Python classes and object-oriented programming.
What I Learned
Throughout this session I learned:
- Pygame basics
- Real-time game loops
- Raycasting concepts
- Collision detection
- Trigonometry for movement
- Basic autonomous navigation
I also gained experience reading Python error messages and tracking down bugs.
Current Status
Completed:
✓ Vehicle movement
✓ Sensor system
✓ Wall collision detection
✓ Basic autonomous driving
In Progress:
□ Better collision model
□ Track checkpoints
□ Fitness scoring
□ Multiple vehicles
Planned:
□ Genetic algorithms
□ Neural networks
□ Procedural track generation
□ Training visualization
Next Steps
The next major milestone is creating multiple AI-controlled cars and implementing a fitness system.
Instead of manually programming driving behavior, future versions will evolve better drivers over time through genetic algorithms.
The long-term vision is to build a miniature autonomous driving research sandbox where hundreds of vehicles learn and improve through simulation.
This is only the beginning, but seeing the first car successfully avoid walls was a satisfying milestone.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.