1 /*************************************************************************** 2 3 file : driver.h 4 created : Thu Dec 20 01:20:19 CET 2002 5 copyright : (C) 2002-2004 Bernhard Wymann 6 email : berniw@bluewin.ch 7 version : $Id: driver.h,v 1.12.2.1 2008/11/09 17:50:19 berniw Exp $ 8 9 ***************************************************************************/ 10 11 /*************************************************************************** 12 * * 13 * This program is free software; you can redistribute it and/or modify * 14 * it under the terms of the GNU General Public License as published by * 15 * the Free Software Foundation; either version 2 of the License, or * 16 * (at your option) any later version. * 17 * * 18 ***************************************************************************/ 19 20 #ifndef _DRIVER_H_ 21 #define _DRIVER_H_ 22 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <cstring> 26 #include <math.h> 27 28 #include <tgf.h> 29 #include <track.h> 30 #include <car.h> 31 #include <raceman.h> 32 #include <robottools.h> 33 #include <robot.h> 34 #include <portability.h> 35 36 #include "opponent.h" 37 #include "pit.h" 38 #include "learn.h" 39 #include "strategy.h" 40 #include "cardata.h" 41 42 #define BT_SECT_PRIV "bt private" 43 #define BT_ATT_FUELPERLAP "fuelperlap" 44 #define BT_ATT_MUFACTOR "mufactor" 45 #define BT_ATT_PITTIME "pittime" 46 #define BT_ATT_BESTLAP "bestlap" 47 #define BT_ATT_WORSTLAP "worstlap" 48 #define BT_ATT_TEAMMATE "teammate" 49 50 51 class Opponents; 52 class Opponent; 53 class Pit; 54 class AbstractStrategy; 55 56 57 class Driver { 58 public: 59 Driver(int index); 60 ~Driver(); 61 62 // Callback functions called from TORCS. 63 void initTrack(tTrack* t, void *carHandle, void **carParmHandle, tSituation *s); 64 void newRace(tCarElt* car, tSituation *s); 65 void drive(tSituation *s); 66 int pitCommand(tSituation *s); 67 void endRace(tSituation *s); 68 getCarPtr()69 tCarElt *getCarPtr() { return car; } getTrackPtr()70 tTrack *getTrackPtr() { return track; } getSpeed()71 float getSpeed() { return mycardata->getSpeedInTrackDirection(); /*speed;*/ } 72 73 private: 74 // Utility functions. 75 bool isStuck(); 76 void update(tSituation *s); 77 float getAllowedSpeed(tTrackSeg *segment); 78 float getAccel(); 79 float getDistToSegEnd(); 80 float getBrake(); 81 int getGear(); 82 float getSteer(); 83 float getClutch(); 84 vec2f getTargetPoint(); 85 float getOffset(); 86 float brakedist(float allowedspeed, float mu); 87 88 float filterOverlap(float accel); 89 float filterBColl(float brake); 90 float filterABS(float brake); 91 float filterBPit(float brake); 92 float filterBrakeSpeed(float brake); 93 float filterTurnSpeed(float brake); 94 95 float filterTCL(float accel); 96 float filterTrk(float accel); 97 98 float filterSColl(float steer); 99 100 float filterTCL_RWD(); 101 float filterTCL_FWD(); 102 float filterTCL_4WD(); 103 void initTCLfilter(); 104 105 void initCa(); 106 void initCw(); 107 void initTireMu(); 108 109 void computeRadius(float *radius); 110 int isAlone(); 111 112 // Per robot global data. 113 int stuck; 114 float speedangle; // the angle of the speed vector relative to trackangle, > 0.0 points to right. 115 float mass; // Mass of car + fuel. 116 float myoffset; // Offset to the track middle. 117 tCarElt *car; // Pointer to tCarElt struct. 118 119 Opponents *opponents; // The container for opponents. 120 Opponent *opponent; // The array of opponents. 121 122 Pit *pit; // Pointer to the pit instance. 123 AbstractStrategy *strategy; // Pit stop strategy. 124 125 static Cardata *cardata; // Data about all cars shared by all instances. 126 SingleCardata *mycardata; // Pointer to "global" data about my car. 127 static double currentsimtime; // Store time to avoid useless updates. 128 129 float currentspeedsqr; // Square of the current speed_x. 130 float clutchtime; // Clutch timer. 131 float oldlookahead; // Lookahead for steering in the previous step. 132 133 float *radius; 134 SegLearn *learn; 135 int alone; 136 137 // Data that should stay constant after first initialization. 138 int MAX_UNSTUCK_COUNT; 139 int INDEX; 140 float CARMASS; // Mass of the car only [kg]. 141 float CA; // Aerodynamic downforce coefficient. 142 float CW; // Aerodynamic drag coefficient. 143 float TIREMU; // Friction coefficient of tires. 144 float (Driver::*GET_DRIVEN_WHEEL_SPEED)(); 145 float OVERTAKE_OFFSET_INC; // [m/timestep] 146 float MU_FACTOR; // [-] 147 148 // Class constants. 149 static const float MAX_UNSTUCK_ANGLE; 150 static const float UNSTUCK_TIME_LIMIT; 151 static const float MAX_UNSTUCK_SPEED; 152 static const float MIN_UNSTUCK_DIST; 153 static const float G; 154 static const float FULL_ACCEL_MARGIN; 155 static const float SHIFT; 156 static const float SHIFT_MARGIN; 157 static const float ABS_SLIP; 158 static const float ABS_RANGE ; 159 static const float ABS_MINSPEED; 160 static const float TCL_SLIP; 161 static const float LOOKAHEAD_CONST; 162 static const float LOOKAHEAD_FACTOR; 163 static const float WIDTHDIV; 164 static const float SIDECOLL_MARGIN; 165 static const float BORDER_OVERTAKE_MARGIN; 166 static const float OVERTAKE_OFFSET_SPEED; 167 static const float PIT_LOOKAHEAD; 168 static const float PIT_BRAKE_AHEAD; 169 static const float PIT_MU; 170 static const float MAX_SPEED; 171 static const float TCL_RANGE; 172 static const float MAX_FUEL_PER_METER; 173 static const float CLUTCH_SPEED; 174 static const float CENTERDIV; 175 static const float DISTCUTOFF; 176 static const float MAX_INC_FACTOR; 177 static const float CATCH_FACTOR; 178 static const float CLUTCH_FULL_MAX_TIME; 179 static const float USE_LEARNED_OFFSET_RANGE; 180 181 static const float TEAM_REAR_DIST; 182 static const int TEAM_DAMAGE_CHANGE_LEAD; 183 184 // Track variables. 185 tTrack* track; 186 }; 187 188 #endif // _DRIVER_H_ 189 190