A Python project that uses the SAC algorithm to learn to drive autonomously in the racing simulator game Assetto Corsa through Reinforcement Learning.
This project is the bachelor assignment of Jurre de Ruiter (s2580160), Technical Computer Science student at the University of Twente.
The project consists of two main components:
- The Assetto Corsa app (
ACRL/
), which is a Python script that runs inside Assetto Corsa and communicates real-time data with the Python project outside of Assetto Corsa. - The standalone Python project (
standalone/
), which is a Python script that runs outside of Assetto Corsa and uses the real-time data from the Assetto Corsa app to train a model using the SAC algorithm. It sends the model's actions back to the Assetto Corsa app through a virtual controller from vgamepad.
- Purchase and install Assetto Corsa on Steam, and download the free Content Manager extension software.
- Clone this repository to your local machine. (See here for instructions on how to clone a repository.
- Download and install the Microsoft Visual C++ 2015-2019 Redistributable from here.
- Download and install the Microsoft Messaging Passing Interface standard (MS-MPI) v10.1.3 here.
- Getting the Assetto Corsa app working:
- Install the Python 3.3.5 interpreter. This is what Assetto Corsa uses and we need this locally for the socket import to not throw errors in AC.
- Copy the
ACRL
folder to theapps/python
folder in your Assetto Corsa installation directory. (e.g.C:\Program Files (x86)\Steam\steamapps\common\assettocorsa\apps\python
) - Run Assetto Corsa and enable the
ACRL
app in theGeneral
tab of theSettings
menu. (You can also enable it through theContent Manager
settings, or in theCustom Shaders Patch
tab if you have CSP installed).
- Getting the standalone Python project working:
- Install a modern Python interpreter (tested on: Python 3.10.11). This is what we use for the part of the project that runs outside of AC. Make sure to add Python to your PATH environment variable.
- Install the required Python packages by running
pip install -r requirements.txt
in the root of the/standalone
directory.
- Set up a new session in Assetto Corsa through Content Manager:
- Select Practice Mode and choose track "Silverstone 1967" and car "Ferrari 458 GT2"
- Confirm tires are the default option
- Set the number of AI opponents to 0
- Turn on
penalties
andideal conditions
- Limit the framerate to 30 FPS
- Set controls to
Gamepad
, with speed sensitivity set to 0, steering speed set to 100%, steering gamma set to 100%, and steering filter set to 0%
- Start the session and wait for the car to spawn on the track. Make sure automatic gear switching is enabled (
ctrl + G
). - Change directory using
cd standalone
, and run thestandalone/main.py
file to start listening for an incoming connection from Assetto Corsa. - Start training by clicking the
Start Training
button in the ACRL app window in Assetto Corsa. The car should start driving around the track and the model should start training. You can monitor the training progress in the console window where you started themain.py
script.