Friday, April 13, 2012

Robotic car racing in Python

Now this is really cool.

TORCS is a racing car game / simulator. Here's a good video (has music, so maybe mute your speakers). However, standard TORCS clients have a lot of information, and writing bots for them is cool, but is IMO about writing great game bots.

If you're interested in the idea of autonomous robots at all, you've probably heard of Udacity's online course, "Programming a Robotic Car". Following some discussions on there, someone pointed out the http://games.ws.dei.polimi.it/competitions/scr/ Simulated Car Racing Championship, which gives clients artificial sensor readings as though fitted to a self-driving car. You have a standard set of car controls and a standard set of sensors.

One of the other students, "lanquarden", wrote a Python client which fits this. His original post in the forums describes the modules. Note, this is compatible with TORCS 1.3.1, which works just fine.


I saw you're post and started looking for more information, I ended up reading the manual they provide with a patch for torcs and their client example. It's a lot more realistic using the setup for the SCRC, you don't have all the information available to you like any other 'torcs driver' program. The range finders can even have a noisy measurement output. The people organizing SCRC have made software examples available for both C++ and Java, but no Python. As the server - client interface are UDP messages, it's pretty straightforward to make a Python version. I'm sharing my code that implements a client for the SCRC.
Its devided in 5 files:
pyclient.py: main file, you can make it executable on linux and it has the same command line parameters as the C++/Java client.
driver.py: file holding the driver class, with a method drive that should hold drive the car.
carState.py: file holding the car state class, the state can be updated with a message from the torcs server.
carControl.py: file holding the car control class, the control parameters can be set and then transformed in a message for the torcs server
msgParser.py: file holding a parser class for translating the torcs server message in usable variables and vice versa
Anyone wanting to toy around with the code can download it from GitHub. Install instructions for the torcs server can be found at here.
So, I thought I'd share that this exists, because it's awesome. The car supplied in the standard driver.py file has a max speed set of 100 kph, which is slow enough to drive around the default track without skidding, allowing it to simply follow the "track axis", which you have sensor data for.
Seriously, how awesome is this? My next steps are going to be to try and simply map out the track, then start improving the performance of the car. It's a great problem, really open-ended, and allows you to exercise state-of-the-art robotics algorithms for localisation, navigation and mapping.