Pi Racer
Building autonomous car using raspberry pi and a car kit.
Overview
In the small scale AI car projects, AWS DeepRacer Neo is the king with stereo cameras and a LIDAR and overall developer experience, where you would only focus on the Reinforcement Learning function. However this project aims to achieve similar results combining techniques from other similar projects using easily procurable components.
Similar Projects
Hardware
Total cost : $415
Base includes a servo for steering, motor for throttle, a custom PCB that includes battery case, includes raspberry pi camera and cable with screws and cables to assemble the car. For my order, the car came partially assembled.
microSD Card
Recommend at least 32GB card to allow sufficient space for keeping training data.
Software
OS Image
The latest Raspberry Pi OS, BullsEye comes with SSH disabled and installs python 3.9. I had trouble getting and installing Tensorflow and other ML frameworks. So I decided to use the legacy 32-bit OS (Buster). All the instructions below are for a Mac. I have been using Balena Etcher for writing images to microSD card.
WiFi Password and SSH
Once Etcher writes the images to microSD card, it ejects the card, so pull the card out and re-insert to get boot volume mounted in MacOS. If boot volume is not writable, remount the volume for writing.
Set ssid and psk appropriate for your setup and add the following contents to /Volumes/boot/wpa_supplicant.conf
Once the above changes are done. Eject the microSD card from PC/Mac and insert that into Raspberry Pi and turn the car board on. Find the RaspberryPi ip address using nmap.
Once you find the raspberry pi ip address, ssh into it.
Use the command below to enter configuration menu, Enable I2C interface, Enable sshd server, Enable Camera interface, Set the appropriate Timezone.
Install packages
OpenCV
For installing OpenCV on buster, I followed this blog post to get OpenCV successfully installed and working. Direct installation of OpenCV does not work as 32 bit direct installation of OpenCV binaries for arm processor are not available. The shell script below installs pre-requisites and compiles OpenCV from source.
Install python packages
Install tensorflow
Currently it is difficult to get official Google tensorflow distributions for Raspberry PI. Some developers publish pre-compiled releases for different Raspberry Pi OS distributions as Python wheels. It is easier to use them instead of compiling on our own:
Install Intel libraries
The Rpi4 due to its power constraints does not include a full blown GPU, so adding the Intel Neural Compute Stick 2 is a great option to offload some image processing.
After the above, exit the shell window to pi and do a ssh login again so that .bashrc takes effect. Run the script to update dependencies.
Run a demo app to make sure Intel NCS2 device and libraries are installed correctly. You need a picture with a human face that when run through the demo, outputs a bmp file which contains a bounding box on the face input image.
Install pi-display
This particular model of the car by WaveShare includes a OLED display on the board. This requires I2C bus to be enabled on Raspberry Pi. By default, the display server shows, the ip-address of the pi, battery level including voltage, amperage, and percent of battery available. CPU, memory and temperature. The code includes an install.sh script which installs dependencies using sudo. This would cause problems with running the included systemd service. To keep the code intact without changes, I had to run the packaged install.sh and change ownership of python libraries to the user pi and modify the systemd service to use User: pi
Install dokeycar
Pi Racer Test Drive
DonkeyCar lets you create a logical car for customization. Using donkey createcar command you can create as many logical car configurations and customizations for the same physical car.
Create a car
Using donkeycar you create a software car that you use to configure, calibrate, drive, collect data and train models etc.
Once you create the car with the above command. Use the following configure servo (steering) and motor (throttle).
Calibration
Throttle Calibration
Steering Calibration
Gamepad Operation
For moving the car using the GamePad (supplied with car kit), use the car software repo you have created earlier. The --js flag enables the gamepad operation, without it, you can operate the car using http://pi-ip-address:8887 webpage.
Last updated
Was this helpful?