Definition of pit
TORCS defines the pitlane and the pit by a set of Points:
- P0: Start of pit entry
- P1: Start of first pit and start of pitspeedlimit
- P3: Center of the own pit
- P5: End of the last pit and end of pitspeedlimit
- P6: End of pit exit
For this points the length from the startline is given as coordinate along the track and the sideoffset from the middle of the track (P1 and P5) or from the pitlane (P3) is used as coordinate across the track.
In the first picture we see a part of the track street-1.
The middle of the track defined by TORCS is drawn as gray line. The left and right borders of the track are calculated from the robot! TORCS uses a constant width for the main track segments, but defines side segments with different parameters (start width, end width, friction, rolling resistance, height etc.).
Depending on this parameters, the robot marks parts of the sides as drivable or not drivable. This results in the different width of the usable track width. The black lines across the track show the sections, calculated from the robot. Here we have two different parts: Along the normal track, the TORCS track segments are divided in sections beeing up to 2.5 m long, along the pitting area, this is reduced to a maximum length of 1 m for the sections. The dividing is done with adjustable values for the length in a way, that brings section borders to the original segment borders at the start and the end of a segment, avoiding very short sections.
The red line along the track is the main racingline calculated from the robot for driving without traffic. The second red line along the pitlane is calculated from this main racingline starting at P0 and ending at P6. The part from P1 to P5 is the pitlane. TORCS allways defines this line parallel to the main track (sideoffset P1 = sideoffset P5). In fact, this part is used as straight to make TORCS draw the doors of the pitbuildings correct. The doors are drawn while runtime, the rest of the pit buildings is made with the track. This way of definition could be used for a pitlane along a curve too, but TORCS doesn't draw the doors correct in this case.
It is up to the robot, to calculate the way from P0 to P1, braking down (at least) to the speedlimit, drive from P1 to P2, start steering into the pit, and stop at P3.
If the car stands in the pit (near P3) TORCS starts the service (refueling and repairing). After beeing serviced, the robot has to drive from P3 to P4 to avoid possible opponents in the next pit, go along the rest of the pitlane to P5 regarding the speedlimit and then speed up and go back to the track (P6).
This definitions are used in principle for all tracks, but there are some problems with it. While the first sort of bugs could be fixed by changing the track definition (i.e. there are tracks, where the length from the startline to P5 is greater than the one to P6!), the definition of P1 is used for concurrenting things!
P1 is used as start of the pitlane (pitwall, speedlimit, pitbuildings etc.) and start of the first pit. Most robots define the distance from P2 to P3 and P3 to P4 by the length of a pit. If a robot gets the first pit, P2 is in front of P1!
The pitracingline is build by several parts:
- The part form P0 to P1 is calculated from the offset of the main racingline and the direction of it at P0 to the given offset at P1 by fitting a spline.
- For P1 to P2 and P4 to P5 straights are used.
- From P2 to P3 and P4 again a spline is fitted.
- The spline from P5 to P6 is calculated to match the offset and direction of the main racingline at P6.
Problems with the standard pitting
The points P0 and P6 are defined regarding the visible representation of the track, not the cars physics!
The Points P1 and P2 can change the order.
To be able to stop in the pit, a car using the first pit has to brake earlier. So pitting spends more time for it than for a car using it's pit in the middle of the pilane. The same problem at the end of the pitlane, but mostly the last pits aren't used.
The distance from P0 to P1 is too short on several tracks.
The resulting pitracingline isn't good, the car has to cross the whole track at the entry and/or the exit and has to drive narrow curves not really needed.
In the next picture we see a pitracingline better adjusted to the track at the start and the end of the pitlane. This is done by defining additional parameters to correct the position of the points P0 and P6 along the track.
To get good pitracinglines, the calculation can be made in some steps:
- Modify a copy of the main racingline by changing the sections of the pitlane, without regarding the pit itself: sideoffset P3 = (sideoffset P2 + sideoffset P4)/2).
- Use the optimizing subroutine with this modifed racingline
- Modify the sections between P2 and P4 to fit the cars need by using splines.
This works for all pits but pit1
To get a better pitracingline for the first pit it should be calculated in a different way. In the third picture we see a compare of the pitracingline to pit1 as made for the other pits (red, without special handling for P2) and the optimized version (green). Here P1, P2 and P3 got the same sideoffset to the middle of the main track.
The calculation of the modified pitracinglines is fast, but the optimization is slow. By using a common optimized pitracingline for all pits but pit1 we can reduce the needed time. The separate optimizazion for pit1 is done only, if we got the first pit.
If we compare the last three pictures with the first, we see, that the track is drawn different! To be able to calculate an optimal way to the pit1 the optimizing subroutine needs to know, how fast the pit entry widens up to the full pitlane. Therefore we have to use a separate value for the possible space on each side for the main racingline (without pitlane) and the pitracinglines (with pitlane).
Till now, we have looked to the situation without traffic! If the robot drives in traffic it has to know, how to avoid. To be able to avoid to the sides without loosing too much speed, we calculate avoiding-racinglines for the main track.
To get this avoiding-racinglines we just modify the usable width of the track at one side and use our optimizing subroutine. The usable width is reduced, like using only one lane of a multilaned road. By setting the usable width as offset from the middle we can get two (or, if the track is wide enough, more) lanes. This lanes are used from the robot while avoiding or overtaking.
The change from driving alone to driving in traffic is made by a smooth change of the interpolating factor of the main racingline to the avoiding-racingline to use. The same principle we can use for switching from the main racingline to a pitracingline.