Skip to main content

Deep Learning with DonkeyCar

Virtual Machine

To work on this assignment, we needed to run a virtual machine that had an Ubuntu 18.04 64-bit image on it. Looking back, we could have used a dockerized container but this was beyond our level of understanding.

We ran the virtual machine on VMWare Workstation. In addition, we created a virtual environment to isolate all the dependencies. In fact, it's recommended to do so even if we had a virtual machine as other assignments needed different dependency versions and compatability.

DonkeyCar

The virtual machine had all the necessary software on it, including the DonkeyCar framework. If ever interested, you can find the framework here. The DonkeyCar framework allows us to train a machine learning model and deploy it both virtually and physically.

To run the framework locally, we only had to navigate to the DonkeyCar directory for our Ubuntu environment. Before running the simulator, we had to modify the configuration file for our simulator.

DONKEY_GYM = True
DONKEY_SIM_PATH = "/home/ucsd/projects/DonkeySimLinux/donkey_sim.x86_64" ## path to your simulator
DONKEY_GYM_ENV_NAME = "donkey-warren-track-v0" # donkey-circuit-launch-track-v0, donkey-warren-track-v0, donkey-mountain-track-v0
GYM_CONF = { "body_style" : "car01", "body_rgb" : (255, 205, 0), "car_name" : "Pororo", "font_size" : 30}
GYM_CONF["racer_name"] = "Pororo"
GYM_CONF["country"] = "South Korea"
GYM_CONF["bio] = "Hi!"

SIM_ARTIFICIAL_LATENCY = 0
SIM_HOST = "127.0.0.1"

USE_JOYSTICK_AS_DEFAULT = True # when starting the manage.py, when True, will not require a --js option to use the joystick
JOYSTICK_MAX_THROTTLE = 1.0 # this scalar is multiplied with the -1 to 1 throttle value to limit the maximum throttle. This can help if you drop the controller or just don't need the full speed available.
JOYSTICK_STEERING_SCALE = 0.8 # some people want a steering that is less sensitve. This scalar is multiplied with the steering -1 to 1. It can be negative to reverse dir.
AUTO_RECORD_ON_THROTTLE = True # if true, we will record whenever throttle is not zero. if false, you must manually toggle recording with some other trigger. Usually circle button on joystick.
JOYSTICK_DEADZONE = 0.2 # when non zero, this is the smallest throttle before recording triggered.
#

If everything was set correctly, we could now run this command in our terminal which would show our simulator running locally on port 8887.

python manage.py drive

The simulator allows for different controls, but as we configured our Logitech F710 controller, it was easy to collect data. The recommended number of laps was 20 to train our model. The simulator autocollects data in the root directory of our DonkeyCar framework in d4_sim/data

Once we had our data, all we had to do was run another command in the terminal to start training a model.

python train.py --model=models/model_name.h5 --type=linear --tubs=data/

To test our model, we ran:

python manage.py drive --model=models/model_name.h5 --type=linear

If everything worked, you would get this.