reduce the lap time
Author: Bernhard Wymann
Keywords: torcs, berniw, bernhard wymann, robot, steer, lap, time, reduce, faster

# 4.4 Reduce the Lap Time ### Overview In this section we modify Driver::getAllowedSpeed, so that we can pass short turns faster. A "short" turn in this context means that the angle of the turn is small. You have seen that on the new path the radius we drive is larger than the radius in the middle of the track. As heuristic approximation we take first the turns outside radius. Further we divide the radius by the square root of the remaining angle of the turn (remember, this is a heuristic!). This will lead to a problem, but we will fix that later. An interesting feature of this approach is the growing acceleration toward the end of a turn. ### Implementation Replace getAllowedSpeed in driver.cpp with the following version:
    /* Compute the allowed speed on a segment */
    float Driver::getAllowedSpeed(tTrackSeg *segment)
    {
        if (segment->type == TR_STR) {
            return FLT_MAX;
        } else {
No changes so far. In the next part we compute the remaining angle (arc) of the turn. We need a loop because large turns can be composed from a lot of small turns.
            float arc = 0.0;
            tTrackSeg *s = segment;

            while (s->type == segment->type && arc < PI/2.0) {
                arc += s->arc;
                s = s->next;
            }
Because we divide the radius by this angle it makes no sense to have values greater than 1.0, so we normalize it.
            arc /= PI/2.0;
            float mu = segment->surface->kFriction;
Compute the magic radius.
            float r = (segment->radius + segment->width/2.0)/sqrt(arc);
            return sqrt((mu*G*r)/(1.0 - MIN(1.0, r*CA*mu/mass)));
        }
    }
### Testdrive Now we come close to some opponents with the lap times. There are just a few seconds on some tracks left. In the next section we will fix the newly introduced stability problem. ### Downloads In case you got lost, you can download my robot for TORCS 1.2.0 or later. ### Summary You are really hot to beat some opponents.