An autonomous robocar simulation client, designed to work with donkey gym.
The project is inspired by, and has taken reference from donkeycar.
Driving and training pipeline is up and running.
Config added. Use python manage.py generateconfig
to create one.
- Speed-based models
- Throttle and steering lock at launch
- Adjustable image resolution in donkey gym
- Ability to reset the car to startline
- Ability to break
- Inter-deployable models with donkeycar (throttle-based models only)
- Compatability with donkeycar parts
Installing on a laptop/desktop/server: follow host setup and repo download.
Installing on a Jetson series SBC: follow Jetson setup and repo download.
- Install miniconda
conda create -n tritonracer python=3.8
conda activate tritonracer
pip install docopt pyserial tensorflow==2.3.0 pillow keras==2.3.0 opencv-python pygame==2.0.0.dev10
conda install scikit-learn
- If you are going to use donkey simulator: set up donkey gym in this environment (omit
conda activate donkey
in the original installation procedure)- If you have a donkeycar installation with donkey gym setup, navigate to the donkey gym repository. If not, find a suitable place and
git clone https://github.com/tawnkramer/gym-donkeycar
- Make sure you are still in tritonracer environment
conda activate tritonracer
pip install -e .[gym-donkeycar]
- If you have a donkeycar installation with donkey gym setup, navigate to the donkey gym repository. If not, find a suitable place and
- Check python3 version to be 3.6-3.8
python3 --version
. If not, install and update python3. - Install virtualenv
sudo apt-get install virtualenv
- Create a new environment
python3 -m virtualenv -p python3 tritonracer
- Invoke tritonracer environment
source ~/tritonracer/bin/activate
- Install tensorflow for Jetson
- Install dependencies
pip install docopt pyserial pillow keras pygame
- More on the hardware setup later.
git clone https://github.com/Triton-AI/Triton-Racer-Sim
- Copy
Triton-Racer-Sim/TritonRacerSim/car_templates/
folder to somewhere outside the repository (and optionally rename it). This is your car folder, like "d3" of donkeycar. - IMPORTANT: Go to your car folder, open manage.py and edit line 11 to be your path to the Triton-Racer-Sim repo in your system
sys.path.append('/home/haoru/Projects/Triton-Racer-Sim/')
Creation of car instances will be supported later.
python manage.py generateconfig
will create a myconfig.json under the car_template.
For detailed information about what each setting does: check out TritonRacerSim/core/config.py
for detailed explanations.
Create a config file, then enter
python manage.py drive
IMPORTANT: by default data collection is turned OFF
Use a PS4 joystick:
- Left X axis: steering
- Right Y axis: throttle
- Right Trigger: breaking
- Circle: toggle recording
- Triangle: delete 100 records
- Square: reset the car
- Share: switch driving mode
Use an XBOX joystick:
- Left X axis: steering
- Right Y axis: throttle
- Right Trigger: breaking
- B: toggle recording
- Y: delete 100 records
- X: reset the car
- Back (below XBOX icon on the left): switch driving mode
Use a G28 Driving Wheel (oof)
- Steering, throttle and breaking are mapped to the corresponding equipment
- The rest is the same as PS4
Data recorded can be found in data/records_x/
If you have a GPU: install CUDA support for tensorflow
Note: If you have CUDA installed, and tensorflow says Could not load dynamic library 'libcublas.so.10'
and falls back to CPU during training, add these lines to your ~/.bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.2/lib64
python manage.py train --tub data/records_1 --model ./models/pilot.h5
--tub
: path to the data folder--model
: where you would like to put your model--transfer
: (optional) which old model you would like to train upon
IMPORTANT: --tub
param is mandatory.
RAM usage (120 * 160 image, 7000 Records): 8GB
VRAM usage (120 * 160 image, 128 batch size): 3GB
IMPORTANT If you run into insufficient memory issue, follow this guide to pre-allocate space for Ubuntu swap file (Allocate more than the size of your physical RAM). Windows users, click here. If you do this, your system may stall momentarily duing training in the first two epoches, but that's still better than the training getting killed.
cnn_2d
: Take an image and predict throttle and steering;cnn_2d_speed_as_feature
: Take an image and current speed, and predict throttle and steeringcnn_2d_speed_control
: Take an image and predict speed and steering;cnn_2d_full_house
: Take an image, segment of track, and current speed, and predict speed and steering. (Speed prediction is unrelated to current speed)
python manage.py drive --model ./models/pilot.h5
Switch between modes:
- Full human control
- Human throttle + AI steering
- Full AI control
How to write your custom component for tritonracer:
- Subclass the Component class
from TritonRacerSim.components.component import Component
. - Define the names of the inputs and outputs for the component in the constructor
super().__init__(self, inputs=['cam/img'], outputs=['ai/steering', 'ai/throttle'], threaded=False)
- Implement
step(self, *args)
. Called when the car's main loop iterate through its parts at 20Hz (equivalent torun()
of donkeycar). Expect args to have the same number of elements as defined in the inputs, and remember to return the same number of outputs as defined in the outputs. - Implement
thread_step(self)
if it is a component with its own thread of, for example, polling information from peripherals. thread_step is started before the car starts (equivalent toupdate()
of donkeycar). Remember to put a loop, and some delay time inbetween, for the code to run periodically. - (Optional) Implement other APIs
onStart(self)
,onShutdown(self)
,getName(self)
- Add your component in manage.py's
assemble_car()
:car.addComponent(my_component)
Features to come:
- 3D covolution networks
- Reinforcement learning
- Migration to real car
Image filtering- Packaging the software
- Merging with donkeycar