Update simuv4 and simplix (feature tire degradation)

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

Former-commit-id: e7c46be25484efaea6bdbddcb5e7d1dc4e4a99e3
Former-commit-id: ebd5ec811199c0a14446b8a679b90c265e2dd636
This commit is contained in:
wdbee 2014-12-06 10:30:41 +00:00
parent a72e54aa1f
commit 17436d2c90
10 changed files with 149 additions and 60 deletions

View file

@ -432,6 +432,7 @@ TDriver::TDriver(int Index):
oRL_RIGHT = RL_RIGHT;
TDriver::LengthMargin = LENGTH_MARGIN; // Initialize safty margin
enableCarNeedsSinLong = false;
LogSimplix.debug("\n#<<< TDriver::TDriver()\n\n");
}
@ -819,6 +820,21 @@ void TDriver::AdjustDriving(
for (int I = 0; I <= NBR_BRAKECOEFF; I++) // Initialize braking
oBrakeCoeff[I] = oInitialBrakeCoeff;
oCrvZScale = 0.05;
if (strncmp(oTrackName,"e-track-4",9) == 0)
oCrvZScale = 0.5;
else if (strncmp(oTrackName,"espie",5) == 0)
enableCarNeedsSinLong = true;
else if (strncmp(oTrackName,"ole-road-1",10) == 0)
oCrvZScale = 0.75;
oCarNeedsSinLong = false;
if (enableCarNeedsSinLong)
{
oCarNeedsSinLong = GfParmGetNum(Handle,
TDriver::SECT_PRIV, PRV_NEEDS_SIN, (char *) NULL, 0) > 0;
}
const char *enabling;
oCarHasTYC = false;
@ -1194,12 +1210,6 @@ void TDriver::SetPathAndFilenameForRacinglines()
snprintf(TrackLoadBuffer,sizeof(TrackLoadBuffer),"%s/%d-%s.trk",
oPathToWriteTo,oWeatherCode,oTrackName);
oTrackLoad = TrackLoadBuffer; // Set pointer to buffer
if (strncmp(oTrackName,"e-track-4",9) == 0)
oCrvZScale = 0.5;
else if (strncmp(oTrackName,"ole-road-1",10) == 0)
oCrvZScale = 0.75;
else
oCrvZScale = 0.05;
snprintf(TrackLoadQualifyBuffer,sizeof(TrackLoadQualifyBuffer),
"%s/%d-%s.trq",oPathToWriteTo,oWeatherCode,oTrackName);
@ -1290,6 +1300,23 @@ void TDriver::InitTrack
, (char*) NULL, 1.0);
LogSimplix.debug("#oFuelCons (TORCS) = %.2f\n",oFuelCons);
tdble TireLimitFront = 0.0;
for (int I = 0; I < 2; I++)
{
TireLimitFront = MAX(TireLimitFront,
GfParmGetNum(CarHandle,WheelSect[I],
PRM_FALLOFFGRIPMULT, (char*)NULL, (tdble) 0.85f));
LogSimplix.debug("#oTireLimitFront = %.3f\n",TireLimitFront);
}
tdble TireLimitRear = 0.0;
for (int I = 2; I < 4; I++)
{
TireLimitRear = MAX(TireLimitRear,
GfParmGetNum(CarHandle,WheelSect[I],
PRM_FALLOFFGRIPMULT, (char*)NULL, (tdble) 0.85f));
LogSimplix.debug("#oTireLimitRear = %.3f\n",TireLimitRear);
}
oBrakeLeft = 1.0f;
oBrakeRight = 1.0f;
oBrakeFront = 1.0f;
@ -1956,7 +1983,7 @@ void TDriver::FindRacinglines()
(&oTrackDesc, Param, // as main racingline
TClothoidLane::TOptions(oBase,oBaseScale,oBumpMode));
#ifdef EXPORT_RACINGLINE
oRacingLine[oRL_FREE].SaveToFile("RL_FREE.t5");
oRacingLine[oRL_FREE].SaveToFile("RL_FREE.tk5");
#endif
if (oGeneticOpti)
oRacingLine[oRL_FREE].ClearRacingline(oTrackLoad);
@ -2518,10 +2545,11 @@ void TDriver::InitCa()
float WingCd = (float) (1.23 * (FrontWingAreaCd + RearWingAreaCd));
Param.Fix.oCdWing = WingCd;
float CL =
float FCL =
GfParmGetNum(oCarHandle, SECT_AERODYNAMICS,
PRM_FCL, (char*) NULL, 0.0f);
float RCL =
GfParmGetNum(oCarHandle, SECT_AERODYNAMICS,
PRM_FCL, (char*) NULL, 0.0f)
+ GfParmGetNum(oCarHandle, SECT_AERODYNAMICS,
PRM_RCL, (char*) NULL, 0.0f);
float H = 0.0;
@ -2534,10 +2562,11 @@ void TDriver::InitCa()
H = H*H;
H = H*H;
H = (float) (2.0 * exp(-3.0 * H));
Param.Fix.oCa = H * CL + 4.0 * WingCd;
Param.Fix.oCa = H * (FCL + RCL) + 4.0 * WingCd;
Param.Fix.oCaFrontWing = 4 * 1.23 * FrontWingAreaCd;
Param.Fix.oCaRearWing = 4 * 1.23 * RearWingAreaCd;
Param.Fix.oCaGroundEffect = H * CL;
Param.Fix.oCaFrontGroundEffect = H * FCL;
Param.Fix.oCaRearGroundEffect = H * RCL;
//>>> simuv4
double CliftFrnt = 0;
@ -2657,7 +2686,7 @@ void TDriver::InitCa()
{
WingCd = (float) (1.23 * (FrontWingAreaCd + RearWingAreaCd));
Param.Fix.oCdWing = WingCd;
Param.Fix.oCa = H * CL + MeanCliftFromAoA * WingCd;
Param.Fix.oCa = H * (FCL + RCL) + MeanCliftFromAoA * WingCd;
}
//<<< simuv4
@ -4510,23 +4539,45 @@ void TDriver::SideBorderInner(float Factor)
//==========================================================================*
//==========================================================================*
// Calculate the skilling
//
//--------------------------------------------------------------------------*
double TDriver::WheelConditionFront()
double TDriver::TyreConditionFront()
{
return MIN(oCar->_tyreCondition(0),oCar->_tyreCondition(1));
}
//==========================================================================*
//==========================================================================*
// Calculate the skilling
//
//--------------------------------------------------------------------------*
double TDriver::WheelConditionRear()
double TDriver::TyreConditionRear()
{
return MIN(oCar->_tyreCondition(2),oCar->_tyreCondition(3));
}
//==========================================================================*
//==========================================================================*
//
//--------------------------------------------------------------------------*
double TDriver::TyreTreadDepthFront()
{
double Right = (oCar->_tyreTreadDepth(0) - oCar->_tyreCritTreadDepth(0));
double Left = (oCar->_tyreTreadDepth(1) - oCar->_tyreCritTreadDepth(1));
return 100 * MIN(Right,Left);
}
//==========================================================================*
//==========================================================================*
//
//--------------------------------------------------------------------------*
double TDriver::TyreTreadDepthRear()
{
double Right = (oCar->_tyreTreadDepth(2) - oCar->_tyreCritTreadDepth(2));
double Left = (oCar->_tyreTreadDepth(3) - oCar->_tyreCritTreadDepth(3));
return 100 * MIN(Right,Left);
}
//==========================================================================*
//==========================================================================*
// Calculate the skilling
//--------------------------------------------------------------------------*

View file

@ -415,6 +415,8 @@ private:
bool oStanding; // Fahrzeug steht#
TCubicSpline CarCharacteristic; // Car characteristic
TParam Param; // Parameters
bool enableCarNeedsSinLong;
bool oCarNeedsSinLong;
double oCrvZScale;
double oFuelPer100km; //
double oMaxFuel; // tank capacity
@ -498,8 +500,10 @@ private:
void Meteorology();
int GetWeather();
double WheelConditionFront();
double WheelConditionRear();
double TyreConditionFront();
double TyreConditionRear();
double TyreTreadDepthFront();
double TyreTreadDepthRear();
void CalcSkilling();
double CalcFriction(const double Crv);
double CalcCrv(double Crv);

View file

@ -58,7 +58,8 @@ TFixCarParam::TFixCarParam():
oBorderScale(50.0),
oCa(0),
oCaFrontWing(0),
oCaGroundEffect(0),
oCaFrontGroundEffect(0),
oCaRearGroundEffect(0),
oCaRearWing(0),
oCdBody(0),
oCdWing(0),
@ -111,9 +112,9 @@ double TFixCarParam::CalcAcceleration(
double MU = Friction * oTyreMu;
if (oDriver->oCarHasTYC)
{
double WcF = oDriver->WheelConditionFront();
double WcR = oDriver->WheelConditionRear();
MU = MIN(WcF*MU,WcR*MU);
double TcF = oDriver->TyreConditionFront();
double TcR = oDriver->TyreConditionRear();
MU = MIN(TcF*MU,TcR*MU);
}
double CD = oCdBody *
@ -197,9 +198,9 @@ double TFixCarParam::CalcBraking
MuR = Friction * oTyreMuRear;
if (oDriver->oCarHasTYC)
{
double WcF = oDriver->WheelConditionFront();
double WcR = oDriver->WheelConditionRear();
Mu = MIN(WcF*MuF,WcR*MuR);
double TcF = oDriver->TyreConditionFront();
double TcR = oDriver->TyreConditionRear();
Mu = MIN(TcF*MuF,TcR*MuR);
}
else
Mu = MIN(MuF,MuR);
@ -228,7 +229,7 @@ double TFixCarParam::CalcBraking
double Froad;
double Fdown = oTmpCarParam->oMass * Gdown
+ (oTmpCarParam->oMass * Crvz + oCaGroundEffect) * AvgV2;
+ (oTmpCarParam->oMass * Crvz + (oCaFrontGroundEffect + oCaRearGroundEffect)) * AvgV2;
double Ffrnt = oCaFrontWing * AvgV2;
double Frear = oCaRearWing * AvgV2;
@ -309,9 +310,9 @@ double TFixCarParam::CalcBrakingPit
MuR = Friction * oTyreMuRear;
if (oDriver->oCarHasTYC)
{
double WcF = oDriver->WheelConditionFront();
double WcR = oDriver->WheelConditionRear();
Mu = MIN(WcF*MuF,WcR*MuR);
double TcF = oDriver->TyreConditionFront();
double TcR = oDriver->TyreConditionRear();
Mu = MIN(TcF*MuF,TcR*MuR);
}
else
Mu = MIN(MuF,MuR);
@ -339,7 +340,7 @@ double TFixCarParam::CalcBrakingPit
double Froad;
double Fdown = oTmpCarParam->oMass * Gdown
+ (oTmpCarParam->oMass * Crvz + oCaGroundEffect) * AvgV2;
+ (oTmpCarParam->oMass * Crvz + (oCaFrontGroundEffect + oCaRearGroundEffect)) * AvgV2;
double Ffrnt = oCaFrontWing * AvgV2;
double Frear = oCaRearWing * AvgV2;
@ -389,7 +390,7 @@ double TFixCarParam::CalcBrakingPit
double TFixCarParam::CalcMaxSpeed
(TCarParam& CarParam, // Lane specific parameters
double Crv0, // Curvature in xy at P
double Crv1, // Curvature in xy at P
double Crv1, // Curvature in xy at Q
double CrvZ, // Curvature in z at P
double Friction, // Friction
double TrackRollAngle, // Track roll angle
@ -407,8 +408,15 @@ double TFixCarParam::CalcMaxSpeed
double Mu;
double Cos = cos(TrackRollAngle)*cos(TrackTiltAngle);
double Sin = sin(TrackRollAngle);
//double ICos = 0.125/cos(TrackTiltAngle);
double SinLat = sin(TrackRollAngle);
double SinLong = sin(TrackTiltAngle);
double Sin = SinLat;
if (oDriver->oCarNeedsSinLong)
{
if (SinLat < SinLong)
Sin = SinLong;
}
double AbsCrv0 = MAX(0.001, fabs(Crv0));
double AbsCrv1 = MAX(0.001, fabs(Crv1));
@ -444,29 +452,27 @@ double TFixCarParam::CalcMaxSpeed
double MuR = Friction * oTyreMuRear * CarParam.oScaleMu;
if (oDriver->oCarHasTYC)
{
double WcF = oDriver->WheelConditionFront();
double WcR = oDriver->WheelConditionRear();
Mu = MIN(WcF*MuF,WcR*MuR) / oTmpCarParam->oSkill;
double TcF = oDriver->TyreConditionFront();
double TcR = oDriver->TyreConditionRear();
Mu = MIN(TcF*MuF,TcR*MuR) / oTmpCarParam->oSkill;
}
else
Mu = MIN(MuF,MuR) / oTmpCarParam->oSkill;
Den = (AbsCrv - ScaleBump * CrvZ)
- (oCaFrontWing * MuF + oCaRearWing * MuR
+ oCaGroundEffect * Mu) / oTmpCarParam->oMass;
+ oCaFrontGroundEffect * MuF + oCaRearGroundEffect * MuR) / oTmpCarParam->oMass;
if (Den < 0.00001)
Den = 0.00001;
if (AbsCrv > 0.01)
if (AbsCrv > 0.002)
{
if (Sin * SGN(Crv0) < 0)
Sin *= 8.0;
}
double Speed = factor * sqrt((Cos * G * Mu + Sin * G * SGN(Crv0) + CrvZ) / Den);
// fprintf(stderr,"S:%g f:%g C:%g M:%g S:%g AbsCrv:%g Crv0:%d CrvZ:%g Den:%g\n",
// Speed,factor,Cos,Mu,Sin,AbsCrv,SGN(Crv0),CrvZ,Den);
if (oDriver->CarCharacteristic.IsValidX(Speed))
Speed *= oDriver->CarCharacteristic.CalcOffset(Speed);

View file

@ -105,7 +105,8 @@ class TFixCarParam
double oBorderScale; // Scale var. Buffer to inner
double oCa; // Aerodynamic downforce constant
double oCaFrontWing; // Aerod. d. const. front wing
double oCaGroundEffect; // Aerod. d. const. ground effect
double oCaFrontGroundEffect; // Aerod. d. const. ground effect front
double oCaRearGroundEffect; // Aerod. d. const. ground effect rear
double oCaRearWing; // Aerod. d. const. rear wing
double oCdBody; // Aerodynamic drag constant car body
double oCdWing; // Aerod. drag const. wings

View file

@ -509,6 +509,7 @@ enum
#define PRV_OMEGAAHEAD "omegaahead"
#define PRV_OMEGAAHEADFACTOR "omegaaheadfactor"
#define PRV_INIT_BRAKE "initial brake" // Scale brake coeff
#define PRV_NEEDS_SIN "sin long" // default false
#define PRV_TCL_RANGE "tcl range" // default 10.0
#define PRV_TCL_SLIP "tcl slip" // default 1.6

View file

@ -430,17 +430,11 @@ void TLane::CalcMaxSpeeds
{
int P = (Start + I) % N;
int Q = (P + 1) % N;
int O1 = (P + N - 12) % N;
int O2 = (P + 12) % N;
double CrvZ1 = MIN(0.0,oPathPoints[O1].CrvZ) * 1000;
double CrvZ2 = MIN(0.0,oPathPoints[O2].CrvZ) * 1000;
TVec3d Delta = oPathPoints[P].CalcPt() - oPathPoints[Q].CalcPt();
double Dist = TUtils::VecLenXY(Delta);
double TrackRollAngle = atan2(oPathPoints[P].Norm().z, 1);
double TrackTiltAngle = 1.1 * atan2(Delta.z, Dist);
double CrvZ = ((CrvZ1+CrvZ2) * fabs(CrvZ1+CrvZ2)) / 10000;
CrvZ = oPathPoints[Q].CrvZ;
double CrvZ = oPathPoints[Q].CrvZ;
double Speed = oFixCarParam.CalcMaxSpeed(
oCarParam,

View file

@ -59,6 +59,8 @@ const float TSimpleStrategy::cMAX_FUEL_PER_METER = 0.0008f;
const int TSimpleStrategy::cPIT_DAMMAGE = 5000;
const short int NEEDED_MAJOR_VERSION = 1;
const short int NEEDED_MINOR_VERSION = 1;
static const char *WheelSect[4] =
{SECT_FRNTRGTWHEEL, SECT_FRNTLFTWHEEL, SECT_REARRGTWHEEL, SECT_REARLFTWHEEL};
//==========================================================================*
//==========================================================================*
@ -98,6 +100,11 @@ void TSimpleStrategy::Init(TDriver *Driver)
{
oDriver = Driver;
oPit = new TPit(Driver);
oTireLimitFront = oDriver->TyreTreadDepthFront();
oTireLimitRear = oDriver->TyreTreadDepthRear();
oDegradationPerLap = 0.0;
oLaps = 0;
}
//==========================================================================*
@ -108,9 +115,11 @@ bool TSimpleStrategy::IsPitFree()
{
bool IsFree = RtTeamIsPitFree(oDriver->TeamIndex());
if (IsFree)
LogSimplix.debug("#%s pit is free (%d)\n",oDriver->GetBotName(),oDriver->TeamIndex());
LogSimplix.debug("#%s pit is free (%d)\n",
oDriver->GetBotName(),oDriver->TeamIndex());
else
LogSimplix.debug("#%s pit is locked (%d)\n",oDriver->GetBotName(),oDriver->TeamIndex());
LogSimplix.debug("#%s pit is locked (%d)\n",
oDriver->GetBotName(),oDriver->TeamIndex());
return IsFree;
}
//==========================================================================*
@ -131,14 +140,25 @@ bool TSimpleStrategy::NeedPitStop()
if (oDriver->oCarHasTYC)
{
double WcF = oDriver->WheelConditionFront(); // Check tyre condition
double WcR = oDriver->WheelConditionRear(); // Pit stop needed if
if (MIN(WcF,WcR) < 0.90) // tyres are below 90%
LogSimplix.warning("Tyre condition F: %.3f R: %.3f (%s)\n",
WcF,WcR,oDriver->GetBotName());
double TdF = oDriver->TyreTreadDepthFront(); // Check tyre condition
double TdR = oDriver->TyreTreadDepthRear(); // Pit stop needed if
oDegradationPerLap = (oLaps * oDegradationPerLap
+ MAX(oTireLimitFront - TdF,oTireLimitRear - TdR));
oDegradationPerLap /= ++oLaps;
if (MIN(WcF,WcR) < 0.88) // tyres are below 88%
Result = true; // to stop in pit
if (MIN(TdF,TdR) < 1.5 * oDegradationPerLap) // tyres become critical
{
LogSimplix.warning("Tyre condition D: %.1f%% F: %.1f%% R: %.1f%% (%s)\n",
oDegradationPerLap,TdF,TdR,oDriver->GetBotName());
if ((TdF < 1.1 * oDegradationPerLap)
|| (TdR < 1.1 * oDegradationPerLap))
{
Result = true; // to stop in pit
}
}
oTireLimitFront = TdF;
oTireLimitRear = TdR;
}
if (oDriver->oTestPitStop) // If defined, try

View file

@ -95,6 +95,10 @@ class TAbstractStrategy
double oDistToSwitch; // Dist to Pit
double oStartFuel; // Fuel at start
double oTireLimitFront;
double oTireLimitRear;
double oDegradationPerLap;
int oLaps;
TAbstractStrategy()
:oState(PIT_NONE),oGoToPit(false),oCar(NULL),oTrack(NULL),oPit(NULL),oDriver(NULL),oDistToSwitch(100),oStartFuel(-1){};

View file

@ -297,7 +297,9 @@ typedef struct {
tTrackSeg *seg; /**< Track segment where the wheel is */
tdble rollRes; /**< rolling resistance, useful for sound */
tdble temp_in, temp_mid, temp_out;
tdble condition;
tdble condition; /**< tire condition, between 0 and 1 */
tdble treadDepth; /**< tread depth, between 0 and 1 */
tdble critTreadDepth; /**< critical tread depth, when grip falls off suddenly, between 0 and treadDepth */
tdble slipNorm; /* normalized slip, the variable of Magic Formula */
tdble slipSide;
tdble slipAccel;
@ -321,6 +323,8 @@ typedef struct {
#define _tyreT_mid(i) priv.wheel[i].temp_mid
#define _tyreT_out(i) priv.wheel[i].temp_out
#define _tyreCondition(i) priv.wheel[i].condition
#define _tyreTreadDepth(i) priv.wheel[i].treadDepth
#define _tyreCritTreadDepth(i) priv.wheel[i].critTreadDepth
#define _tyreEffMu(i) priv.wheel[i].effectiveMu
#define MAX_GEARS 10 /* including reverse and neutral */

View file

@ -123,6 +123,8 @@ SimWheelConfig(tCar *car, int index)
if (car->features & FEAT_TIRETEMPDEG) {
// Assume new wheels
carElt->_tyreCondition(index) = 1.0;
car->carElt->_tyreTreadDepth(index) = wheel->treadDepth;
car->carElt->_tyreCritTreadDepth(index) = wheel->critTreadDepth;
}
wheel->mfC = (tdble)(2.0 - asin(RFactor) * 2.0 / PI);
@ -365,6 +367,8 @@ void SimWheelUpdateForce(tCar *car, int index)
car->carElt->_tyreT_mid(index) = wheel->Ttire;
car->carElt->_tyreT_out(index) = wheel->Ttire;
car->carElt->_tyreCondition(index) = tireCond;
car->carElt->_tyreTreadDepth(index) = wheel->treadDepth;
car->carElt->_tyreCritTreadDepth(index) = wheel->critTreadDepth;
}
// Option TCL ...