Simulator for training machine vision racing AIs, created with Unity.
Clone this repo and open it in Unity. Select the "Track" scene on the editor (Project -> Scenes -> Track) and start the simulator using the Play button. You should see the race track and the message "Free practice".
The point is to connect your AI to localhost:11000. The simulator will feed you PNG images from the car's front camera.
Your bot should do the following:
- Connect to simulator:11000
- Send a "login" JSON message:
{"name":"your bot name", "color": "team color e.g. #ff0000", "teamId": "your team ID"}
followed by\n
. - Read a frame: 2 bytes indicating the size of image, followed by PNG image data
- Respond with 1 or more commands (see below)
- goto 3
The simulator accepts control commands as a JSON string terminated with \n
from the bot:
{ "action": "forward", "value": 0.5}\n
where value is the throttle value between 0 and 1.{ "action": "turn", "value": -0.1}\n
where value is the direction for the front wheels. 1.0 is full left and -1.0 is full right.
Prepare to process 60 frames per second using a single thread.
Remember to use the TCP_NODELAY option in your bot TCP socket to ensure that the commands are sent without delay.
The RaceParameters.json file can be used to control the operating mode of the Simulator. First of all, mode
can be one of development
, race
or playback
for different modes.
In development
mode the simulator accepts bot connections and places cars immediately on the track for free practice with lap timing
In race
mode the simulator accepts bot connections while in the "race lobby" phase. Then it starts Qualifying and finally the Race. You can move tho the next phase using SPACEBAR.
It also moves automatically forward based on RaceParameters, see self-documenting code in RaceParameters.cs.
In playback
mode the simulators plays back a recorded race log. When running in WebGL, the playback mode is always assumed. See below.
The simulator saves all race events into the file race.log
, or a file specified by the raceLogFile
property in RaceParameters.json.
This file can be played back by running the simulator in playback
mode (set in RaceParameters.json). When playing back in Unity Editor, it will use the file specified in RaceParameters (defaults to race.log
).
You can build a WebGL build with Unity. It results into an index.html file containing the player. You need to server it over HTTP though - file protocol is not supported. The web build can only be used to playback earlierly recorded race.log
files. At the moment it always looks for race data at http://localhost:8000/race.log.
To build and play with WebGL:
- In build settings, choose WebGL build
- In player settings disable compression (otherwise won't work, at the moment)
- Build it to
./robotini-web-player
Note: if you get an error along the lines of "No such file or directory", this may be because you don't have a Python2.7 on path. In the PreBuildProcessing.cs
we've defined that Python should be found at /usr/local/bin/python
. Make sure it's there.
- Copy a
race.log
file to./robotini-web-player
- Start a HTTP server in
./robotini-web-player
, serving the files on port 8000. - Open http://localhost:8000
To publish the latest WebGL player build it first and the run make publish-web-player
. This will require AWS permissions.
The simulator serves a full capture of race events on port 11001 as a newline-separated JSON stream. This could be used for watching the race live.
You can also send UICommands through the socket, such as:
{"type":"ProceedToNextPhase"}
To build on the command-line, Unity editor must be closed.
make linux-player