TORCS  1.3.9
The Open Racing Car Simulator
robottools.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : robottools.h
4  created : Mon Feb 28 22:31:13 CET 2000
5  copyright : (C) 2000 by Eric Espie
6  email : berniw@bluewin.ch
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
24 #ifndef _ROBOTTOOLS_H_
25 #define _ROBOTTOOLS_H_
26 
27 #include <car.h>
28 #include <track.h>
29 
30 #define RELAXATION2(target, prev, rate) \
31 do { \
32  tdble __tmp__; \
33  __tmp__ = target; \
34  target = (prev) + (rate) * ((target) - (prev)) * 0.01; \
35  prev = __tmp__; \
36 } while (0)
37 
38 #define RELAXATION(target, prev, rate) \
39 do { \
40  target = (prev) + (rate) * ((target) - (prev)) * 0.01; \
41  prev = (target); \
42 } while (0)
43 
44 /*
45  * Track Utilities
46  */
47 
48 /* for variable width segments */
49 extern tdble RtTrackGetWidth(tTrackSeg *seg, tdble toStart);
50 
51 /*
52  * Convert a Local position (segment, toRight, toStart)
53  * into a Global one (X, Y)
54  *
55  * The ToStart position refers to the current segment,
56  * the function will not search for next segment if toStart
57  * is greater than the segment length.
58  * toStart represent an angle in radian for curves
59  * and a length in meters for straights.
60  *
61  */
62 extern void RtTrackLocal2Global(tTrkLocPos *p, tdble *X, tdble *Y, int flag);
63 
64 /*
65  * Convert a Global (segment, X, Y) position into a Local one (segment, toRight, toStart)
66  *
67  * The segment in the Global position is used to start the search of a good segment
68  * in term of toStart value.
69  * The segments are scanned in order to find a toStart value between 0 and the length
70  * of the segment for straights or the arc of the curve.
71  *
72  * The sides parameters is to indicate wether to use the track sides (1) or not (0) in
73  * the toRight computation.
74  */
75 extern void RtTrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type);
76 
77 
78 /*
79  * Returns the absolute height in meters of the road
80  * at the Local position p.
81  *
82  * If the point lies outside the track (and sides)
83  * the height is computed using the tangent to the banking
84  * of the segment (or side).
85 
86  + Point given
87  .^
88  . |
89  . |
90  . |
91  / | heigth
92  / |
93  ______/ v
94  ^ ^^ ^
95  | || |
96  track side
97 
98  */
100 
101 
102 /*
103  * Returns the absolute height in meters of the road
104  * at the Global position (segment, X, Y)
105  */
106 extern tdble RtTrackHeightG(tTrackSeg *seg, tdble X, tdble Y);
107 
108 
109 /*
110  * Give the normal vector of the border of the track
111  * including the sides.
112  *
113  * The side parameter is used to indicate the right (TR_RGT)
114  * of the left (TR_LFT) side to consider.
115  *
116  * The Global position given (segment, X, Y) is used
117  * to project the point on the border, it is not necessary
118  * to give a point directly on the border itself.
119  *
120  * The vector is normalized.
121  */
122 extern void RtTrackSideNormalG(tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm);
123 
124 
125 /*
126  * Used to get the tangent angle for a track position
127  * The angle is given in radian.
128  *
129  * the angle 0 is parallel to the first segment start.
130  */
132 
133 
134 /*
135  * Used to get the normal vector of the road itself (pointing
136  * upward).
137  *
138  * Local coordinates are used to locate the point where to
139  * get the road normal vector.
140  *
141  * The vector is normalized.
142  */
143 extern void RtTrackSurfaceNormalL(tTrkLocPos *p, t3Dd *norm);
144 
145 extern int RtDistToPit(struct CarElt *car, tTrack *track, tdble *dL, tdble *dW);
146 
147 extern tdble RtGetDistFromStart(tCarElt *car);
149 
150 /****************
151  * Telemetry *
152  ****************/
153 
159 extern void RtTelemInit(tdble ymin, tdble ymax);
160 
164 
165 extern tTrackSeg *RtTrackGetSideNeighbourSeg(tTrackSeg *main, tTrackSeg *current, int tr_side);
166 
174 extern void RtTelemNewChannel(const char * name, tdble * var, tdble min, tdble max);
175 extern void RtTelemStartMonitoring(const char * filename);
176 extern void RtTelemStopMonitoring(void);
177 extern void RtTelemUpdate(double time);
178 extern void RtTelemShutdown(void);
179 
180 typedef enum rtCarPitSetupType {
181  PRACTICE = 0,
183  RACE = 2,
184  BACKUP1 = 3,
185  BACKUP2 = 4,
188 
189 extern void RtGetCarPitSetupFilename(rtCarPitSetupType type, int robidx, const char* carname, const char* trackname, char* filename, const int len);
190 extern void RtSaveCarPitSetup(void *hdlecar, tCarPitSetup* s, rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
191 extern void RtSaveCarPitSetupFile(void *hdlecar, tCarPitSetup* s, const char* filepath, const char* carname);
192 extern void RtInitCarPitSetup(void* carparmhandle, tCarPitSetup* setup, bool minmaxonly);
193 extern bool RtCarPitSetupExists(rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
194 extern bool RtLoadCarPitSetup(void* hdlecar, tCarPitSetup* s, rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname, bool minmaxonly);
195 extern bool RtLoadCarPitSetupFilename(void* hdlecar, const char* filepath, tCarPitSetup* s, bool minmaxonly);
196 extern void* RtLoadOriginalCarSettings(const char* carname);
197 extern bool RtInitCarPitSetupFromDefault(tCarPitSetup* s, const char* carname);
198 extern void* RtParmReadSetup(rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
199 
200 
201 #endif /* _ROBOTTOOLS_H_ */
202 
203 
204 
tdble RtTrackHeightL(tTrkLocPos *p)
Returns the absolute height in meters of the road at the Local position p.
Definition: rttrack.cpp:314
void RtTelemStartMonitoring(const char *filename)
Start recording into a file.
Definition: rttelem.cpp:98
static tdble ymax
Definition: track3.cpp:30
void RtInitCarPitSetup(void *carparmhandle, tCarPitSetup *setup, bool minmaxonly)
Initialize tCarPitSetup from data in parameter set given in handle hdle.
Definition: rttrack.cpp:714
tTrackSeg * RtTrackGetSeg(tTrkLocPos *p)
Get the current segment.
Definition: rttrack.cpp:413
Scalar max(Scalar x, Scalar y)
Definition: Basic.h:50
bool RtCarPitSetupExists(rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname)
Checks if a specific car setup is available.
Definition: rttrack.cpp:988
tdble RtTrackHeightG(tTrackSeg *seg, tdble X, tdble Y)
Returns the absolute height in meters of the road at the Global position (segment, X, Y)
Definition: rttrack.cpp:443
bool RtLoadCarPitSetupFilename(void *hdlecar, const char *filepath, tCarPitSetup *s, bool minmaxonly)
Load a custom car setup from a given filename.
Definition: rttrack.cpp:1022
Location on the track in local coordinates.
Definition: track.h:418
void RtTrackLocal2Global(tTrkLocPos *p, tdble *X, tdble *Y, int flag)
Calculate global coordinates from a local position relative to the given track segment (segment...
Definition: rttrack.cpp:80
Car structure (tCarElt).
Definition: car.h:455
void RtSaveCarPitSetup(void *hdlecar, tCarPitSetup *s, rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname)
Save a custom car setup for a given robot, car, track and session (race, practice, qualifying, ...) type.
Definition: rttrack.cpp:952
Track structure.
Definition: track.h:502
rtCarPitSetupType
Definition: robottools.h:180
void RtTelemInit(tdble ymin, tdble ymax)
Initialization of a telemetry session.
Definition: rttelem.cpp:59
Definition: Basic.h:58
void RtTelemStopMonitoring(void)
Stop recording and close the file.
Definition: rttelem.cpp:109
void * RtLoadOriginalCarSettings(const char *carname)
Gets a handle to a parameter file containing the original TORCS car setup, that means the car setup m...
Definition: rttrack.cpp:1080
void RtTrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type)
Convert a Global (segment, X, Y) position into a Local one (segment, toRight, toStart)The segment in ...
Definition: rttrack.cpp:156
int RtDistToPit(struct CarElt *car, tTrack *track, tdble *dL, tdble *dW)
Get the distance to the pit stop.
Definition: rttrack.cpp:662
void RtTrackSideNormalG(tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm)
Give the normal vector of the border of the track including the sides.
Definition: rttrack.cpp:470
void RtTelemNewChannel(const char *name, tdble *var, tdble min, tdble max)
Create a new telemetry channel.
Definition: rttelem.cpp:86
int main(int argc, char *argv[])
Definition: main.cpp:124
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
static tdble ymin
Definition: track3.cpp:30
static Point p[4]
Definition: Convex.cpp:54
void RtTelemShutdown(void)
Deinstall the telemetry module.
Definition: rttelem.cpp:132
Definition: Basic.h:58
void RtTelemUpdate(double time)
Record a new set of values.
Definition: rttelem.cpp:121
This is the car structure.
tTrackSeg * RtTrackGetSideNeighbourSeg(tTrackSeg *main, tTrackSeg *current, int tr_side)
Get the neighbour segment of the given current segment.
Definition: rttrack.cpp:383
void * RtParmReadSetup(rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname)
Load a custom car setup file for a given robot, car, track and session (race, practice, qualifying, ...) type.
Definition: rttrack.cpp:1149
void RtGetCarPitSetupFilename(rtCarPitSetupType type, int robidx, const char *carname, const char *trackname, char *filename, const int len)
Compose filename from given strings.
Definition: rttrack.cpp:813
tdble RtTrackGetWidth(tTrackSeg *seg, tdble toStart)
Get the track width at the specified point.
Definition: rttrack.cpp:58
Scalar min(Scalar x, Scalar y)
Definition: Basic.h:49
Track segment (tTrackSeg) The segments can be straights (type TR_STR): (the track goes from the right...
Definition: track.h:276
tdble RtGetDistFromStart(tCarElt *car)
Get the distance from the start lane.
Definition: rttrack.cpp:619
int track(tModInfo *modInfo)
Definition: trackitf.cpp:85
bool RtInitCarPitSetupFromDefault(tCarPitSetup *s, const char *carname)
Initialize the given tCarPitSetup with the original TORCS setup, that means the car setup merged with...
Definition: rttrack.cpp:1125
bool RtLoadCarPitSetup(void *hdlecar, tCarPitSetup *s, rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname, bool minmaxonly)
Load a custom car setup for a given robot, car, track and session (race, practice, qualifying, ...) type.
Definition: rttrack.cpp:1051
void RtSaveCarPitSetupFile(void *hdlecar, tCarPitSetup *s, const char *filepath, const char *carname)
Save a custom car setup to a given filename.
Definition: rttrack.cpp:850
3D point.
Definition: tgf.h:115
Track Structure and Track Loader Module Definition.
void RtTrackSurfaceNormalL(tTrkLocPos *p, t3Dd *norm)
Used to get the normal vector of the road (pointing upward).
Definition: rttrack.cpp:540
tdble RtTrackSideTgAngleL(tTrkLocPos *p)
Used to get the tangent angle for a track position The angle is given in radian.
Definition: rttrack.cpp:514
tdble RtGetDistFromStart2(tTrkLocPos *p)
Get the distance from the start lane.
Definition: rttrack.cpp:631