- Cleaning shadow's driver code

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5953 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 53c67651e2fa97178f9dbbe6fd7c82f340d513c0
Former-commit-id: 9f6aecd9954539b8f8b8359b52ebada377ca4ce4
This commit is contained in:
torcs-ng 2015-04-06 22:38:51 +00:00
parent a8f9d77904
commit 63480a0809
6 changed files with 107 additions and 126 deletions

View file

@ -10,7 +10,10 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
AveragedData::AveragedData( int nBinsX, double minX, double maxX, int nBinsY, double minY, double maxY )
AveragedData::AveragedData(
int nBinsX, double minX, double maxX,
int nBinsY, double minY, double maxY )
:
m_xSize(nBinsX),
m_xMin(minX),

View file

@ -4,7 +4,8 @@
class AveragedData
{
public:
AveragedData( int nBinsX, double minX, double maxX, int nBinsY, double minY, double maxY );
AveragedData( int nBinsX, double minX, double maxX,
int nBinsY, double minY, double maxY );
~AveragedData();
int GetXSize() const;

View file

@ -128,6 +128,11 @@ static const double s_sgMax[] = { 0.03, 100 };
static const int s_sgSteps[] = { 10, 18 };
TDriver::TDriver(int Index, const int robot_type):
m_pitControl(m_track, m_pitPath[PATH_NORMAL]),
m_CarType(0),
m_driveType(DT_RWD),
m_gearUpRpm(8000),
m_XXX(0),
m_SideScaleMu(0.97),
@ -142,31 +147,6 @@ TDriver::TDriver(int Index, const int robot_type):
m_WeatherCode(0),
m_DryCode(0),
m_pitControl(m_track, m_pitPath[PATH_NORMAL]),
m_CarType(0),
m_driveType(DT_RWD),
m_gearUpRpm(8000.0),
m_prevYawError(0.0),
m_prevLineError(0.0),
m_Flying(0.0),
m_avgAY(0.0),
m_raceStart(false),
m_avoidS(1.0),
m_avoidT(0.0),
m_followPath(PATH_NORMAL),
m_FuelNeeded(0.0),
m_steerGraph(2, s_sgMin, s_sgMax, s_sgSteps, 0),
m_steerAvg(19, 0.001, 0.02, 15, 20, 95),
m_lastB(0.0),
m_lastBrk(0.0),
m_lastTargV(0.0),
m_Strategy(NULL),
HasABS(false),
HasESP(false),
HasTCL(false),
@ -174,7 +154,26 @@ TDriver::TDriver(int Index, const int robot_type):
m_TclRange(10.0),
m_TclSlip(1.6),
m_TclFactor(1.0)
m_TclFactor(1.0),
m_prevYawError(0),
m_prevLineError(0),
m_Flying(0),
m_avgAY(0),
m_raceStart(false),
m_avoidS(1),
m_avoidT(0),
m_followPath(PATH_NORMAL),
m_lastB(0),
m_lastBrk(0),
m_lastTargV(0),
m_maxAccel(0, 150, 30, 1),
m_steerGraph(2, s_sgMin, s_sgMax, s_sgSteps, 0),
m_steerAvg(19, 0.001, 0.02, 15, 20, 95),
m_FuelNeeded(0),
m_Strategy(NULL)
{
INDEX = Index;
@ -520,7 +519,7 @@ void TDriver::NewRace( tCarElt* pCar, tSituation* pS )
pItem->pOther = 0;
pItem->pCar = car;
m_pShared->m_teamInfo.Add( car->index, pItem );
LogSHADOW.debug("End Shadow2 NewRace\n");
LogSHADOW.debug("End Shadow NewRace\n");
}
void TDriver::GetPtInfo( int path, double pos, PtInfo& pi ) const
@ -756,9 +755,10 @@ double TDriver::SteerAngle0( tCarElt* car, PtInfo& pi, PtInfo& aheadPi )
int k = int(floor((pi.k - K_MIN) / K_STEP));
int s = int(floor((spd0 - SPD_MIN) / SPD_STEP));
double ae = 0;
// double ae = 0; // Moved in if(...) 6th April 2015
if( k >= 0 && k < K_N && s >= 0 && s < SPD_N )
{
double ae = 0;
ae = m_angle[s][k] - ang;
}
@ -830,8 +830,8 @@ double TDriver::SteerAngle2( tCarElt* car, PtInfo& pi, PtInfo& aheadPi )
// static double oldX = x; // Removed 5th April 2015 - Not Used
// static double oldY = y; // Removed 5th April 2015 - Not Used
//double velX = (x - oldX) / 0.02; // Removed 5th April 2015 - Not Used
//double velY = (y - oldY) / 0.02; // Removed 5th April 2015 - Not Used
// double velX = (x - oldX) / 0.02; // Removed 5th April 2015 - Not Used
// double velY = (y - oldY) / 0.02; // Removed 5th April 2015 - Not Used
// oldX = x; // Removed 5th April 2015 - Not Used
// oldY = y; // Removed 5th April 2015 - Not Used
@ -907,7 +907,7 @@ double TDriver::SteerAngle3( tCarElt* car, PtInfo& pi, PtInfo& aheadPi )
double yawU = car->_yaw_rate;
// future yaw rate required ahead.
//double yawV = aheadPi.k * spd0; // Removed 5th April 2015 - Not Used
// double yawV = aheadPi.k * spd0; // Removed 5th April 2015 - Not Used
// future yaw required ahead (assuming current yaw to be 0).
double yawS = aheadPi.oang - car->_yaw;
@ -1283,7 +1283,7 @@ void TDriver::Drive( tSituation* s )
m_lastAng = m_lastAng * 0.75 + angle * 0.25;
}
//const double G = 9.81; // Removed 5th April 2015 - Not Used
// const double G = 9.81; // Removed 5th April 2015 - Not Used
double acc = 1.0;
double brk = 0;
@ -1293,6 +1293,7 @@ void TDriver::Drive( tSituation* s )
bool close = false;
bool lapper = false;
AvoidOtherCars( INDEX, car, pi.k, targetSpd, s, close, lapper );
LogSHADOW.debug("SHADOW AvoidOtherCars\n");
if( close )
{
SpeedControl( SPDC_TRAFFIC, targetSpd, spd0, car, acc, brk );
@ -2300,8 +2301,8 @@ double TDriver::ApplyTractionControl( tCarElt* car, double acc )
tract = 0.1;
wr /= count;
// double gr = car->_gearRatio[car->_gear + car->_gearOffset]; // Removed 5th April 2015 - Not Used
// double rpmForSpd = gr * car->_speed_x / wr; // Removed 5th April 2015 - Not Used
double gr = car->_gearRatio[car->_gear + car->_gearOffset]; // Removed 5th April 2015 - Not Used
double rpmForSpd = gr * car->_speed_x / wr; // Removed 5th April 2015 - Not Used
acc = 0;
}
@ -2897,7 +2898,7 @@ double TDriver::CalcHairpin(double Speed, double AbsCrv)
//==========================================================================*
/*
//==========================================================================*
// simplix
// shadow
//--------------------------------------------------------------------------*
double TDriver::CalcCrv_shadow(double Crv)
{
@ -2917,7 +2918,7 @@ double TDriver::CalcCrv_shadow(double Crv)
//==========================================================================*
*/
//==========================================================================*
// simplix
// shadow
//--------------------------------------------------------------------------*
double TDriver::CalcCrv_shadow_LP1(double Crv)
{
@ -2944,7 +2945,6 @@ double TDriver::CalcCrv_shadow_Identity(double Crv)
return 1.0;
}
//==========================================================================*
/*
//==========================================================================*
// simplix_sc
//--------------------------------------------------------------------------*
@ -2952,7 +2952,7 @@ double TDriver::CalcCrv_shadow_SC(double Crv)
{
double Offset = 1300;
if (oCrvComp)
if (m_CrvComp)
{
if (Crv < 0.0085)
return 1.0;
@ -2962,29 +2962,10 @@ double TDriver::CalcCrv_shadow_SC(double Crv)
else
return 1.0;
}
//==========================================================================*
//==========================================================================*
// simplix_36GP
//--------------------------------------------------------------------------*
double TDriver::CalcCrv_shadow_36GP(double Crv)
{
double Offset = 1300;
if (oCrvComp)
{
if (Crv < 0.0085)
return 1.0;
else
return ((1+Crv) * (400 + Offset)/(1/Crv + Offset));
}
else
return 1.0;
}
//==========================================================================*
*/
//==========================================================================*
// simplix_36GP
// shadow_36GP
//--------------------------------------------------------------------------*
double TDriver::CalcCrv_shadow_36GP(double Crv)
{
@ -3000,6 +2981,7 @@ double TDriver::CalcCrv_shadow_36GP(double Crv)
else
return 1.0;
}
//==========================================================================*
//==========================================================================*
@ -3009,6 +2991,7 @@ double TDriver::CalcHairpin_shadow_Identity(double Speed, double AbsCrv)
{
return Speed;
}
//==========================================================================*
//==========================================================================*
@ -3069,8 +3052,8 @@ double TDriver::CalcHairpin_shadow(double Speed, double AbsCrv)
return Speed;
}
//==========================================================================*
//==========================================================================*
//==========================================================================*
// If not used for a carset
//--------------------------------------------------------------------------*
@ -3078,10 +3061,10 @@ double TDriver::CalcFriction_shadow_Identity(const double Crv)
{
return 1.0;
}
//==========================================================================*
//==========================================================================*
// simplix_ls2
//==========================================================================*
// shadow_ls2
//--------------------------------------------------------------------------*
double TDriver::CalcFriction_shadow_LS2(const double Crv)
{
@ -3121,9 +3104,8 @@ double TDriver::CalcFriction_shadow_LS2(const double Crv)
}
//==========================================================================*
//==========================================================================*
// simplix
// shadow_LP1
//--------------------------------------------------------------------------*
double TDriver::CalcFriction_shadow_LP1(const double Crv)
{
@ -3163,9 +3145,8 @@ double TDriver::CalcFriction_shadow_LP1(const double Crv)
}
//==========================================================================*
//==========================================================================*
// simplix
// shadow_REF
//--------------------------------------------------------------------------*
double TDriver::CalcFriction_shadow_REF(const double Crv)
{
@ -3204,10 +3185,9 @@ double TDriver::CalcFriction_shadow_REF(const double Crv)
return FrictionFactor * m_XXX;
}
//==========================================================================*
//==========================================================================*
// simplix_TRB1
// simplix_GP36
// shadow_TRB1
// shadow_GP36
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow()
{
@ -3223,9 +3203,8 @@ void TDriver::CalcSkilling_shadow()
*/
}
//==========================================================================*
//==========================================================================*
// simplix_ls1
// shadow_ls1
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow_LS1()
{
@ -3234,9 +3213,8 @@ void TDriver::CalcSkilling_shadow_LS1()
Skill = SkillScale * (SkillGlobal + SkillDriver) + SkillOffset;
}
//==========================================================================*
//==========================================================================*
// simplix_ls2
// shadow_ls2
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow_LS2()
{
@ -3245,9 +3223,8 @@ void TDriver::CalcSkilling_shadow_LS2()
Skill = SkillScale * (SkillGlobal + SkillDriver) + SkillOffset;
}
//==========================================================================*
//==========================================================================*
// simplix_MPA1
// shadow_MPA1
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow_MPA1()
{
@ -3256,9 +3233,8 @@ void TDriver::CalcSkilling_shadow_MPA1()
Skill = SkillScale * (SkillGlobal + SkillDriver) + SkillOffset;
}
//==========================================================================*
//==========================================================================*
// simplix_SC
// shadow_SC
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow_SC()
{
@ -3269,9 +3245,8 @@ void TDriver::CalcSkilling_shadow_SC()
}
//==========================================================================*
//==========================================================================*
// simplix_lp1
// shadow_lp1
//--------------------------------------------------------------------------*
void TDriver::CalcSkilling_shadow_LP1()
{
@ -3280,7 +3255,6 @@ void TDriver::CalcSkilling_shadow_LP1()
Skill = SkillScale * (SkillGlobal + SkillDriver) + SkillOffset;
}
//==========================================================================*
//==========================================================================*
// Set name of robot (and other appendant features)
//--------------------------------------------------------------------------*
@ -3290,7 +3264,6 @@ void TDriver::SetBotName(const char* Value)
LogSHADOW.debug("#Car Name : %s\n" , m_CarType);
};
//==========================================================================*
//==========================================================================*
// Set scaling factor for avoiding racinglines
//--------------------------------------------------------------------------*
@ -3300,7 +3273,6 @@ void TDriver::ScaleSide(float FactorMu, float FactorBrake)
m_SideScaleBrake = FactorBrake;
}
//==========================================================================*
//==========================================================================*
// Set additional border to outer side
//--------------------------------------------------------------------------*
@ -3309,7 +3281,6 @@ void TDriver::SideBorderOuter(float Factor)
m_SideBorderOuter = Factor;
}
//==========================================================================*
//==========================================================================*
// Set additional border to inner side
//--------------------------------------------------------------------------*
@ -3318,7 +3289,6 @@ void TDriver::SideBorderInner(float Factor)
m_SideBorderInner = Factor;
}
//==========================================================================*
//==========================================================================*
// Meteorology
//--------------------------------------------------------------------------*
@ -3334,8 +3304,7 @@ void TDriver::Meteorology()
{
Surf = Seg->surface;
m_RainIntensity = MAX(m_RainIntensity, Surf->kFrictionDry / Surf->kFriction);
//GfLogDebug("# %.4f, %.4f %s\n",
// Surf->kFriction, Surf->kRollRes, Surf->material);
GfLogDebug("# %.4f, %.4f %s\n",Surf->kFriction, Surf->kRollRes, Surf->material);
Seg = Seg->next;
}

View file

@ -230,7 +230,8 @@ public:
double CalcFriction_shadow_LP1(double Crv);
double CalcFriction_shadow_REF(double Crv);
//double CalcCrv_shadow(double Crv);
double CalcCrv_shadow(double Crv);
double CalcCrv_shadow_SC(double Crv);
double CalcCrv_shadow_Identity(double Crv);
double CalcCrv_shadow_36GP(double Crv);
double CalcCrv_shadow_LP1(double Crv);
@ -254,18 +255,6 @@ public:
float m_DeltaAccel; //
float m_DeltaAccelRain; //
double m_XXX;
float m_SideScaleMu;
float m_SideScaleBrake;
float m_SideBorderOuter;
float m_SideBorderInner;
bool m_Rain;
double m_RainIntensity;
double m_ScaleMuRain;
double m_ScaleBrakeRain;
int m_WeatherCode; // Track specific weather
int m_DryCode; // Track specific dry weather
double m_BrakeCoeff[NBR_BRAKECOEFF+1]; // Brake coefficients
int m_LastBrakeCoefIndex; // Index of last brake coef.
double m_LastTargetSpeed; // Last target speed
@ -333,7 +322,30 @@ private:
tSituation *m_Situation; // situation
int m_driveType;
double m_gearUpRpm; // for gear changing.
double m_gearUpRpm; // for gear changing.
double m_XXX;
float m_SideScaleMu;
float m_SideScaleBrake;
float m_SideBorderOuter;
float m_SideBorderInner;
bool m_Rain;
double m_RainIntensity;
double m_ScaleMuRain;
double m_ScaleBrakeRain;
int m_WeatherCode; // Track specific weather
int m_DryCode; // Track specific dry weather
bool HasABS;
bool HasESP;
bool HasTCL;
bool HasTYC;
double m_TclRange; // TCL range
double m_TclSlip; // Max TCL slip
double m_TclFactor; // TCL scale
PidController m_lineControl; // controller for line error.
PidController m_velAngControl; // controller for direction of car.
PidController m_angControl; // controller for attack angle error.
@ -358,28 +370,30 @@ private:
double m_attractor; // where we want to be.
int m_followPath; // path we want to follow;
LinearRegression m_accBrkCoeff; //
double m_brkCoeff[50];
double m_steerCoeff[STEER_SPD_MAX][STEER_K_MAX];
int m_lastB;
double m_lastBrk;
double m_lastTargV;
LearnedGraph m_maxAccel;
double m_angle[SPD_N][K_N];
LearnedGraph m_steerGraph;
AveragedData m_steerAvg;
double m_FuelNeeded;
double m_RepairNeeded;
LinearAttractor m_avoidX;
LinearAttractor m_avoidY;
LearnedGraph m_maxAccel;
double m_angle[SPD_N][K_N];
Vec2d m_lastPts[HIST];
double m_lastSpd;
double m_lastAng;
LinearRegression m_accBrkCoeff; //
double m_brkCoeff[50];
double m_steerCoeff[STEER_SPD_MAX][STEER_K_MAX];
LearnedGraph m_steerGraph;
AveragedData m_steerAvg;
int m_lastB;
double m_lastBrk;
double m_lastTargV;
AbstractStrategy *m_Strategy; // Pit strategy
bool m_CrvComp; // Crv compensation
@ -402,15 +416,6 @@ private:
unsigned int RandomSeed; // seed of generator
bool HasABS;
bool HasESP;
bool HasTCL;
bool HasTYC;
double m_TclRange; // TCL range
double m_TclSlip; // Max TCL slip
double m_TclFactor; // TCL scale
double CA;
double CW;
double CR;

View file

@ -86,7 +86,7 @@ void SimpleStrategy::setFuelAtRaceStart(tTrack* t, void **carParmHandle, tSituat
}
m_expectedfuelperlap = fuelPerLap;
double raceDist = 0.0;
//double raceDist = 0.0; // Removed 6th April 2015 - Not Used
float fuelForRace = 0.0;
int numPitstop = 0;
int raceLaps = s->_totLaps + 1;
@ -364,7 +364,7 @@ float SimpleStrategy::pitRefuel(tCarElt* car, tSituation *s)
int lapsToEnd;
lapsToEnd = car->_remainingLaps - car->_lapsBehindLeader;
int inLap = s->_totLaps - car->_remainingLaps;
// int inLap = s->_totLaps - car->_remainingLaps; // Removed 6th April 2015 - Not Used
fuelToEnd = MIN(getRefuel1(lapsToEnd), getRefuel2(lapsToEnd));
//m_remainingstops = int(floor(fuelToEnd / car->_tank));

View file

@ -62,6 +62,8 @@ protected:
bool releasePit;
public:
AbstractStrategy()
:oState(PIT_NONE), oGoToPit(false), Car(NULL), Track(NULL), pitPath(NULL), Driver(NULL), DistToSwitch(100), StartFuel(-1){};
// Need this empty constructor... do not remove.
virtual ~AbstractStrategy() {}
// Set Initial fuel at race start.
@ -77,8 +79,9 @@ public:
// Pit Free?
virtual bool isPitFree(tCarElt* car) = 0;
tCarElt *Car; // TORCS-Daten
tTrack *Track; // Track-Daten
tCarElt *Car;
tTrack *Track;
PitPath *pitPath;
TDriver *Driver;
//Pit Pit;
//TDriver Driver;