TORCS robot driving
How to drive a torcs car with a robot
After initializing all data, TORCS calls the drive function of the robot for each driving timestep. To drive a TORCS car, the robot has to set the following values:
- Brake pressure
- Steering angle
These values are part of the race command structure holding the data to be send to TORCS in the Drive-API-Call.
Acceleration, Brake pressure and Clutch are normalized to be values from 0 to 1. The corresponding acceleration is calculated from the engines data, read from a cartype specific setup file. The max brake pressure is initially set in this cartype specific setup file too, but may be redefined in a driver specific setup file merged with the initial settings of the cartype. The steering angle is scaled to be in -1 +1 range. The scaling is done with a cartype specific constant, the steerlock value. The Gear numbers include the reverse gear (0), the neutral gear (1) and than the other gears (2 = first, ...). The total number of gears is also cartype specific.
What to learn from it?
- To be sure, that we take the same values like TORCS, we have to read it from the normal TORCS-setup files (XML-Format). The merging of cartype + driver +... setup files is controlled by min and max values, giving the allowed range. You can not define a driver specific value out of range.
Because all these parameters are known, we can implement the reading in the wrapper using the handles to the ready merged setup files provided to us by TROCS. We can set this values while our DriverBase.Init call in our C#-Objects using our TStaticData structure.
It is practice to have additional parameters in the drivers setup file, only used from the driver. Here we are free to define all we need and to read it with the C#-code!
- To get a replay, we only have to save Acceleration, Brake pressure, Clutch, Gear and Steering angle off all cars in the race.
- These values will come from our code, so we are free, where and when to save it (Our Dispatcher handles all cars). TORCS can reproduce a race exactly, as long as no random input came from the cars (like uninitialized variables used in some robots!)