TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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-2026 by Eric EspiƩ, Bernhard Wymann
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
23
24#ifndef _ROBOTTOOLS_H_
25#define _ROBOTTOOLS_H_
26
27#include <car.h>
28#include <track.h>
29
39#define RELAXATION2(target, prev, rate) \
40do { \
41 tdble __tmp__; \
42 __tmp__ = target; \
43 target = (prev) + (rate) * ((target) - (prev)) * 0.01; \
44 prev = __tmp__; \
45} while (0)
46
57#define RELAXATION(target, prev, rate) \
58do { \
59 target = (prev) + (rate) * ((target) - (prev)) * 0.01; \
60 prev = (target); \
61} while (0)
62
63/*
64 * Track Utilities
65 */
66
67/* for variable width segments */
68extern tdble RtTrackGetWidth(tTrackSeg *seg, tdble toStart);
69
70/*
71 * Convert a Local position (segment, toRight, toStart)
72 * into a Global one (X, Y)
73 *
74 * The ToStart position refers to the current segment,
75 * the function will not search for next segment if toStart
76 * is greater than the segment length.
77 * toStart represent an angle in radian for curves
78 * and a length in meters for straights.
79 *
80 */
81extern void RtTrackLocal2Global(tTrkLocPos *p, tdble *X, tdble *Y, int flag);
82
83/*
84 * Convert a Global (segment, X, Y) position into a Local one (segment, toRight, toStart)
85 *
86 * The segment in the Global position is used to start the search of a good segment
87 * in term of toStart value.
88 * The segments are scanned in order to find a toStart value between 0 and the length
89 * of the segment for straights or the arc of the curve.
90 *
91 * type selects TR_LPOS_MAIN, TR_LPOS_SEGMENT or TR_LPOS_TRACK; see the API docs.
92 */
93extern void RtTrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type);
94
95/* Double-coordinate variant preserving precision before conversion to tTrkLocPos. */
96extern void RtTrackGlobal2LocalD(tTrackSeg *segment, double X, double Y, tTrkLocPos *p, int type);
97
98
99/* Returns the absolute height in meters of the road at a local position.
100 * The effective side segment is resolved and the lateral coordinate is
101 * rebased relative to that segment before calculating its height.
102 * If the point lies outside the track and sides, the height is computed using
103 * the tangent to the banking of the segment or side.
104 + Point given
105 .^
106 . |
107 . |
108 . |
109 / | height
110 / |
111 ______/ v
112 ^ ^^ ^
113 | || |
114 track side
115 */
117
118
119/*
120 * Returns the absolute height in meters of the road
121 * at the Global position (segment, X, Y)
122 */
124
125
126/*
127 * Give the normal vector of the border of the track
128 * including the sides.
129 *
130 * The side parameter is used to indicate the right (TR_RGT)
131 * of the left (TR_LFT) side to consider.
132 *
133 * The Global position given (segment, X, Y) is used
134 * to project the point on the border, it is not necessary
135 * to give a point directly on the border itself.
136 *
137 * Only x/y are written and normalized; z is unchanged. The normal points
138 * inward toward the road. The supplied segment is used without side traversal.
139 */
140extern void RtTrackSideNormalG(tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm);
141
142
143/*
144 * Used to get the tangent angle for a track position
145 * The angle is given in radian.
146 *
147 * The angle 0 points along global positive X.
148 */
150
151
152/*
153 * Used to get the normal vector of the road itself (pointing
154 * upward).
155 *
156 * Local coordinates are used to locate the point where to
157 * get the road normal vector.
158 *
159 * The vector is normalized.
160 */
161extern void RtTrackSurfaceNormalL(tTrkLocPos *p, t3Dd *norm);
162
163extern int RtDistToPit(struct CarElt *car, tTrack *track, tdble *dL, tdble *dW);
164
165extern tdble RtGetDistFromStart(tCarElt *car);
167
168/****************
169 * Telemetry *
170 ****************/
171
172/* Legacy telemetry initialization; currently a no-op. */
173extern void RtTelemInit(tdble ymin, tdble ymax);
174
175/* Get the effective segment for a local position.
176 The position must be relative to a main segment. Only side segments are
177 searched; previous and next track segments are not considered. The
178 supplied position is not modified.
179 */
181
182extern tTrackSeg *RtTrackGetSideNeighbourSeg(tTrackSeg *main, tTrackSeg *current, int tr_side);
183
184/* Legacy telemetry wrappers; currently no-ops. */
185extern void RtTelemNewChannel(const char * name, tdble * var, tdble min, tdble max);
186extern void RtTelemStartMonitoring(const char * filename);
187extern void RtTelemStopMonitoring(void);
188extern void RtTelemUpdate(double time);
189extern void RtTelemShutdown(void);
190
199
200extern void RtGetCarPitSetupFilename(rtCarPitSetupType type, int robidx, const char* carname, const char* trackname, char* filename, const int len);
201extern void RtSaveCarPitSetup(void *hdlecar, tCarPitSetup* s, rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
202extern void RtSaveCarPitSetupFile(void *hdlecar, tCarPitSetup* s, const char* filepath, const char* carname);
203extern void RtInitCarPitSetup(void* carparmhandle, tCarPitSetup* setup, bool minmaxonly);
204extern bool RtCarPitSetupExists(rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
205extern bool RtLoadCarPitSetup(void* hdlecar, tCarPitSetup* s, rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname, bool minmaxonly);
206extern bool RtLoadCarPitSetupFilename(void* hdlecar, const char* filepath, tCarPitSetup* s, bool minmaxonly);
207extern void* RtLoadOriginalCarSettings(const char* carname);
208extern bool RtInitCarPitSetupFromDefault(tCarPitSetup* s, const char* carname);
209extern void* RtParmReadSetup(rtCarPitSetupType type, const char* modulename, int robidx, const char* trackname, const char* carname);
210
211
212#endif /* _ROBOTTOOLS_H_ */
Scalar min(Scalar x, Scalar y)
Definition Basic.h:49
@ Y
Definition Basic.h:58
@ X
Definition Basic.h:58
Scalar max(Scalar x, Scalar y)
Definition Basic.h:50
static Point p[4]
Definition Convex.cpp:54
struct CarElt tCarElt
Car structure (tCarElt).
float tdble
Floating point type used in TORCS.
Definition tgf.h:47
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:848
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:1028
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:1172
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:1127
void RtSaveCarPitSetup(void *hdlecar, tCarPitSetup *s, rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname)
Save a custom setup in the robot's local setups directory.
Definition rttrack.cpp:991
bool RtLoadCarPitSetup(void *hdlecar, tCarPitSetup *s, rtCarPitSetupType type, const char *modulename, int robidx, const char *trackname, const char *carname, bool minmaxonly)
Load a custom setup from the robot's local setups directory.
Definition rttrack.cpp:1097
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,...
Definition rttrack.cpp:1198
bool RtLoadCarPitSetupFilename(void *hdlecar, const char *filepath, tCarPitSetup *s, bool minmaxonly)
Load a custom setup and merge its entries with hdlecar's restrictions.
Definition rttrack.cpp:1067
void RtSaveCarPitSetupFile(void *hdlecar, tCarPitSetup *s, const char *filepath, const char *carname)
Save adjustable setup entries to a file, merging them with hdlecar's restrictions.
Definition rttrack.cpp:888
void RtInitCarPitSetup(void *carparmhandle, tCarPitSetup *setup, bool minmaxonly)
Initialize tCarPitSetup from data in parameter set given in handle hdle.
Definition rttrack.cpp:748
void RtTelemInit(tdble ymin, tdble ymax)
Legacy telemetry initialization; currently does nothing.
Definition rttelem.cpp:63
void RtTelemShutdown(void)
Legacy telemetry shutdown; currently does nothing.
Definition rttelem.cpp:131
void RtTelemStartMonitoring(const char *filename)
Legacy start-recording request; currently creates no file and does nothing.
Definition rttelem.cpp:100
void RtTelemStopMonitoring(void)
Legacy stop-recording request; currently does nothing.
Definition rttelem.cpp:110
void RtTelemNewChannel(const char *name, tdble *var, tdble min, tdble max)
Legacy channel registration; currently does nothing.
Definition rttelem.cpp:89
void RtTelemUpdate(double time)
Legacy sample-recording request; currently does nothing.
Definition rttelem.cpp:121
struct trackSeg tTrackSeg
Track segment (tTrackSeg) The segments can be straights (type TR_STR): (the track goes from the right...
tTrackSeg * RtTrackGetSeg(tTrkLocPos *p)
Get the effective segment of the given position starting from a segment of type TR_MAIN,...
Definition rttrack.cpp:450
void RtTrackGlobal2LocalD(tTrackSeg *segment, double X, double Y, tTrkLocPos *p, int type)
Convert global coordinates to a local track position using double intermediates.
Definition rttrack.cpp:276
void RtTrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type)
Convert global coordinates to a local track position.
Definition rttrack.cpp:298
tdble RtTrackHeightL(tTrkLocPos *p)
Returns the absolute height in meters of the road at the Local position p.
Definition rttrack.cpp:365
tdble RtGetDistFromStart(tCarElt *car)
Get distance along the track from the start/finish line.
Definition rttrack.cpp:646
tdble RtTrackSideTgAngleL(tTrkLocPos *p)
Used to get the tangent angle for a track position The angle is given in radian.
Definition rttrack.cpp:539
int RtDistToPit(struct CarElt *car, tTrack *track, tdble *dL, tdble *dW)
Get the distance to the pit stop.
Definition rttrack.cpp:692
tdble RtTrackGetWidth(tTrackSeg *seg, tdble toStart)
Get the track width at the specified point.
Definition rttrack.cpp:59
tdble RtGetDistFromStart2(tTrkLocPos *p)
Get distance along the track from the start/finish line.
Definition rttrack.cpp:659
tdble RtTrackHeightG(tTrackSeg *seg, tdble X, tdble Y)
Returns the absolute height in meters of the road at the Global position (segment,...
Definition rttrack.cpp:465
void RtTrackSurfaceNormalL(tTrkLocPos *p, t3Dd *norm)
Used to get the normal vector of the road (pointing upward).
Definition rttrack.cpp:567
tTrackSeg * RtTrackGetSideNeighbourSeg(tTrackSeg *main, tTrackSeg *current, int tr_side)
Get the neighbour segment of the given current segment.
Definition rttrack.cpp:419
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:81
void RtTrackSideNormalG(tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm)
Compute the horizontal inward border normal using the supplied segment.
Definition rttrack.cpp:495
int main(int argc, char *argv[])
Definition main.cpp:124
rtCarPitSetupType
Definition robottools.h:191
@ BACKUP2
Definition robottools.h:196
@ PRACTICE
Definition robottools.h:192
@ RACE
Definition robottools.h:194
@ BACKUP3
Definition robottools.h:197
@ QUALIFYING
Definition robottools.h:193
@ BACKUP1
Definition robottools.h:195
Car structure (tCarElt).
Definition car.h:458
3D point.
Definition tgf.h:114
Track structure.
Definition track.h:533
Location on the track in local coordinates.
Definition track.h:434
static tdble ymin
Definition track3.cpp:30
static tdble ymax
Definition track3.cpp:30
int track(tModInfo *modInfo)
Definition trackitf.cpp:85