Donkey Car is an open-source platform designed for building and experimenting with small-scale autonomous vehicles. It provides a framework for training and deploying deep learning models that enable self-driving capabilities. Originally created for hobbyists and educators, Donkey Car allows users to explore artificial intelligence, robotics, and machine learning in a hands-on manner. The system is built on a combination of a Raspberry Pi, a camera, Infineon's XMC1100 Microcontroller Board and a remote-controlled car chassis, along with a trained neural network to make real-time driving decisions.
Understanding Deep Learning and Autonomous DrivingDeep learning is a subset of machine learning that uses artificial neural networks to recognize patterns in data. In the context of Donkey Car, deep learning is used to train a model that learns how to drive by analyzing images from the car’s camera and associating them with steering and throttle inputs.
The process involves:
Data Collection: The car is manually driven around a track to collect images and corresponding control inputs.
Training the Model: A convolutional neural network (CNN) is trained using the collected data to recognize features such as lane boundaries and turns.
Inference and Control: Once trained, the model is deployed onto the car, where it processes live camera feeds and autonomously controls the steering and throttle based on its learned patterns.
Donkey Car V3 builds upon previous designs, maintaining a reliable hardware setup while refining software and control mechanisms to improve autonomous driving capabilities. We will be exploring the advancements in the Project and such new features to improve the user experience and make the process more efficient.
Building the Donkey Car V3: Step-by-Step Guide1. Required Hardware ComponentsProcessing Unit: Raspberry Pi 4 Model B
Camera: Raspberry Pi Camera Module V2
Motor Driver: XMC1100 Boot Kit + DC Motor Control Shield to control the Servo and our DC Motor.
DC Motor: Any DC Motor suitable for an RC Car
Chassis: Reely Onroad-Chassis 1:10
Servo: Savöx SC-0254MG Digital-Servo for Steering
Battery: Nimh 7.2 V Battery
2. Assembly ProcessChassis and component mounting
First off, we will mount the Motor and the Servo to their designated places on the Reely Onroad Chassis.
For the motor you will have to remove the Part holding the back wheels completely and install the DC Motor with two screws. Next thing you need to screw on the gear on the shaft of the Motor. You will need a 1/16 Hex Key to tighten the set screw at the side of the pinion gear. Then you can test if the gears engage correctly and mount the wheel part back on the chassis .
The Servo motor is much less complicated. You just need to screw the triangle shaped plastic brackets at the two sides of the servo and screw in the steering arm to the servo's gear. After that you can mount it on the chassis and done!
Now you can install the 3D printed base with the already installed screws on top.
Wiring connections
Solder the female header pins on the holes of the XMC1100 , if yours came with pins already, you can skip this step. Lastly, insert the Motor Driver on top of the XMC1100
After screwing the Raspberry pi and the Microcontroller on the chassis, connect them using 3 cables and route them inside the designated tunnel under the 3d printed base part.
After this step, you need to plug in the Motors cables to the DC Motor Shield as you can see on the image. For the servo you need to solder 3 cables to 5V, GND and Pin 20 (P 2.10) of the Controller Board/DC Shield.
Programming the XMC1100
Firstly you need to download Arduino IDE on your computer and paste the following URL into the 'Additional boards manager URLs' input field under File > Preferences to add Infineon's XMC microcontroller boards to the Arduino IDE.
https://github.com/Infineon/XMC-for-Arduino/releases/latest/download/package_infineon_index.json
To be able to program the XMC1100 Board, please go now to Tools > Board > Boards Manager...and search for XMC. You will see options to install the board files for the microcontrollers. Click "Install" to add the boards to your Arduino IDE.
Lastly installing the library for the Btn9970LV shield is very simple. All you have to do is to click on Sketch>Include Library>Manage Libraries,search for "motix" and install the "motix-btn99x0" library
Installing the Operating System to the Raspberry Pi and Donkey Car Setup
Using the "Raspberry Pi Imager" tool , choose Raspberry Pi 4 as the Board and Raspberry Pi OS 64 Bit.
Do not pick the headless/lite version of the Raspbian OS with the hopes of an increased performance because for some reason the installation fails and Donkey Car can not be used with the lite version of the OS.
After plugging in your SD Card and picking it from the menu, click the next button and you will be given the option to apply 'OS customization settings'. Select 'Edit Settings' Enable ssh, set a Username and Password . Set hostname and configure WLAN for your home network.
Boot up the Raspberry Pi and connect it to Wi-Fi.
Find out the IP address of you Raspberry pi using this command
arp -a
after finding out the ip address, access it via ssh
ssh "Raspberry Pi's IP Adress"
Now
we will have to run a system-wide update by typing
sudo apt-get update
sudo apt-get upgrade
After that, we will make sure the GPIO pins of the Raspberry Pi and the whole SD card storage is usable by
sudo raspi-config
Enable Interfacing Options > I2C
Select Advanced Options > Expand Filesystem
Now reboot after making these changes.
You need to test whether your camera functions or not since the Raspberry Pi Cam can sometimes be problematic. For this use this command to test it:
rpi-cam hello
If you see any errors like the one you see below, you might have to do some additional steps.
In my specific error I had to type in the following;
sudo apt-get upgrade python3-libcamera
and with this command my error was solved.
other approaches which could help are;
- Update other Camera related libraries
- Check the wiring of the camera, since the cable might have came loose.
- Reboot the Raspberry Pi and hope it works :)
Setup virtual Environment
To create a virtual enviroment run the following from your home directory:
python3 -m venv env --system-site-packages
echo "source ~/env/bin/activate" >> ~/.bashrc
source ~/.bashrc
Install required libraries
sudo apt install libcap-dev libhdf5-dev libhdf5-serial-dev
Lastly, install the Donkey Car project
pip install donkeycar[pi]
Now we can create a Donkey Car from a Template
Create a set of files to control your Donkey with this command:
donkey createcar --path ~/mycar
Calibrate your CarCalibrating Throttle
Run
donkey calibrate --pwm-pin PCA9685.1:40.0
Now type in values to pick max forward, max reverse and still ( wheels shouldn't be moving or making any noise)
Now write these values down and with the command
nano ~/mycar/myconfig.py
scroll down and find the "THROTTLE_FORWARD_PWM" , "THROTTLE_STOPPED_PWM" , "THROTTLE_REVERSE_PW" . Change the default values with the ones you wrote down.
Calibrating Steering
Just like before, with the pin changed run;
donkey calibrate --pwm-pin PCA9685.1:40.1
Find the max right and left steering values by trial and error.
Edit the myconfig.py file again and change the STEERING_LEFT_PWM (PWM for full left turn) , STEERING_RIGHT_PWM ( PWM value for full right turn)
DrivingNow the most fun part, driving. Open your car's folder and start your car.
cd ~/mycar
python manage.py drive
You can now control your car from a web browser at the URL: <your car's hostname.local>:8887 ( for me this was 192.168.178.105:8887 )
Recording - Press record data to start recording images, steering angels and throttle value
Pilot mode - Choose this if the pilot should control the angle and/or throttle.
Max throttle - Select the maximum throttle.
Donkey Car Remote AppThe Donkey Car App on App Store and Google Play Store allows us to drive the car with no command prompt needed each time and creates a more seamless experience.
To set it up on your Donkey Car;
Clone the Donkeycar-console Project,
git clone https://github.com/robocarstore/donkeycar-console
sudo mv donkeycar-console /opt
cd /opt/donkeycar-console
Install Dependencies,
pip install -r requirements/production.txt
Run
the init script to set up database,
python manage.py migrate
L
astly, test to see if the script works or not.
python manage.py runserver 0.0.0.0:8000
Open up the Donkey Car App on your phone and search for devices on your network.
Note: Your phone needs to be connected to the same network as the car.
You will see your car appear.
Now that you are sure the Project was successfully installed and works, use this command line to install the servers as a service.
sudo cp gunicorn.service /etc/systemd/system/gunicorn.service
then,
sudo systemctl enable gunicorn.service
Now reboot for it to take effect.
After rebooting, type this command to see whether it is working or not;
sudo service gunicorn status
This command will make sure you don't need to type the "run server" command every time you reboot by starting itself automatically every time.
Now you can drive the car and change its settings without the need of any commands simply by using this app.
The Donkey Car V3 is a major leap forward in DIY autonomous vehicle technology. By integrating advanced processing, precise motor control, and enhanced vision systems, it offers a robust platform for learning and innovation. Whether you're a student, researcher, or hobbyist, Donkey Car V3 provides an exciting opportunity to explore and develop self-driving algorithms in a hands-on manner.
Comments