Code for a Raspberry Pi Model B self-driving car (heavily modified version of picar).
- Raspberry Pi Model B
- GETIHU Power Bank BG-120
- HP Webcam HD-4110
- Ovonic 11.1V 2200mAh Lipo Battery (yes, it's overkill)
- L298N H-bridge motor controller
- 4-Wheel Drive Yellow Robot Smart Car Chassis
The car uses image recognition to determine which direction the car should go in (left, right, or straight). It is built to stay on a track made with two lines of black duct tape.
To teach the car to drive, I captured 20,000 images of me controlling the car with my phone. From this data, I trained a deep neural network with Keras.
Install Node.js on your Raspberry Pi
sudo apt-get install -y nodejs
Install node modules on your Raspberry Pi
npm install zerorpc socket.io node-static
Install python libraries on your Raspberry Pi
pip3 install zerorpc opencv-python tensorflow numpy
Install Python (with pip) on your Windows PC
Install python libraries on your Windows PC
pip install opencv-python tensorflow numpy
- Build a car using the same (or similar) components
- Set the pi's hostname in
hostname.txt
- Move files from
pi_code
to your Raspberry Pi (underDocuments/sdc/
)
.\upload_to_pi.bat
- Make the scripts executable
chmod u+x manual.sh auto.sh record.sh
Run the following script on the Pi to drive in "manual" mode
./manual.sh
or in "auto" mode
./auto.sh
or in "record" mode
./record.sh
Then navigate to [raspberry-pi-ip-address]:8080/socket.html
on your phone's web browser.
Example link: http://192.168.1.106:8080/socket.html
Wait a few seconds for everything to initialize... and enjoy!
File to run
1. Modify 'constants.txt' if necessary | ---------------
2. Clear 'train_data/' of all files | ---------------
3. Record raw data on pi | record.sh
4. Download raw data from pi | update_data.bat
5. Process data | process_data.py
6. Add processed data to training data | merge_data.py
7. Repeat steps 3-6 until training data is full | ---------------
8. Duplicate and flip training data | flip.py
9. Repeat steps 2-8, but this time for test data | ---------------
- Download and unzip the dataset or use your own
- Put training data under
train_data
and testing data undertest_data
- Edit the hyperparameters in
train.py
- Train the neural network:
python train.py