Update shadow's driver
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6680 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 8490e7825f5296f16a182f1964e7ee4fb63afe9b Former-commit-id: 2dd6c43f41c904e26658b6d175dd9545ed86d9ff
This commit is contained in:
parent
3b1b16cbcb
commit
9dda55e873
6 changed files with 120 additions and 78 deletions
|
@ -156,8 +156,7 @@ double CarModel::CalcMaxSpeed(double k, double k1, double kz, double kFriction,
|
||||||
LogSHADOW.debug("MU = %.f\n", Mu);
|
LogSHADOW.debug("MU = %.f\n", Mu);
|
||||||
}
|
}
|
||||||
|
|
||||||
Den = (AbsCrv - ScaleBump * kz) - (CA_FW * MuF + CA_RW * MuR
|
Den = (AbsCrv - ScaleBump * kz) - (CA_FW * MuF + CA_RW * MuR + CA_GE_F * MuF + CA_GE_R * MuR) / MASS;
|
||||||
+ CA_GE_F * MuF + CA_GE_R * MuR) / MASS;
|
|
||||||
|
|
||||||
if (Den < 0.00001)
|
if (Den < 0.00001)
|
||||||
Den = 0.00001;
|
Den = 0.00001;
|
||||||
|
@ -329,7 +328,7 @@ double CarModel::CalcAcceleration(double k0, double kz0, double k1, double kz1,
|
||||||
// 3m/ss @ 60m/s
|
// 3m/ss @ 60m/s
|
||||||
// 1m/ss @ 75m/s
|
// 1m/ss @ 75m/s
|
||||||
// 0m/ss @ 85m/s
|
// 0m/ss @ 85m/s
|
||||||
//Quadratic accFromSpd(0.001852, -0.35, 17.7); // approx. clkdtm
|
//Quadratic accFromSpd(0.001852, -0.35, 17.7); // approx. clkdtm
|
||||||
Quadratic accFromSpd(21.0/5400, -43.0/60, 30); // approx. clkdtm
|
Quadratic accFromSpd(21.0/5400, -43.0/60, 30); // approx. clkdtm
|
||||||
double OldV = 0.0;
|
double OldV = 0.0;
|
||||||
// Power (kW) = Torque (Nm) x Speed (RPM) / 9.5488
|
// Power (kW) = Torque (Nm) x Speed (RPM) / 9.5488
|
||||||
|
@ -348,8 +347,8 @@ double CarModel::CalcAcceleration(double k0, double kz0, double k1, double kz1,
|
||||||
|
|
||||||
if( Flatroad > Froad )
|
if( Flatroad > Froad )
|
||||||
Flatroad = Froad;
|
Flatroad = Froad;
|
||||||
double Ftanroad = sqrt(Froad * Froad - Flatroad * Flatroad) + Ftan;
|
|
||||||
|
|
||||||
|
double Ftanroad = sqrt(Froad * Froad - Flatroad * Flatroad) + Ftan;
|
||||||
double acc = Ftanroad / M;
|
double acc = Ftanroad / M;
|
||||||
double maxAcc = MIN(11.5, accFromSpd.CalcY(avgV));
|
double maxAcc = MIN(11.5, accFromSpd.CalcY(avgV));
|
||||||
|
|
||||||
|
@ -398,6 +397,7 @@ double CarModel::CalcMaxLateralF( double spd, double kFriction, double kz ) cons
|
||||||
double CarModel::CalcMaxSpeedCrv() const
|
double CarModel::CalcMaxSpeedCrv() const
|
||||||
{
|
{
|
||||||
const double MAX_SPD = 112; // 400 km/h
|
const double MAX_SPD = 112; // 400 km/h
|
||||||
|
|
||||||
return GRAVITY * TYRE_MU / (MAX_SPD * MAX_SPD);
|
return GRAVITY * TYRE_MU / (MAX_SPD * MAX_SPD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
double lftOH;
|
double lftOH;
|
||||||
double rgtOH;
|
double rgtOH;
|
||||||
double AVOID_KZ_SCALE; // bump sensitivity.
|
double AVOID_KZ_SCALE; // bump sensitivity.
|
||||||
double WIDTH; // width of car (m).
|
double WIDTH; // width of car (m).
|
||||||
double BRAKE_FACTOR; // higher number = slower braking
|
double BRAKE_FACTOR; // higher number = slower braking
|
||||||
double CT_FACTOR;
|
double CT_FACTOR;
|
||||||
|
|
||||||
|
|
|
@ -1318,36 +1318,54 @@ void TDriver::SpeedControl1( double targetSpd, double spd0, double& acc, double&
|
||||||
|
|
||||||
void TDriver::SpeedControl2( double targetSpd, double spd0, double& acc, double& brk )
|
void TDriver::SpeedControl2( double targetSpd, double spd0, double& acc, double& brk )
|
||||||
{
|
{
|
||||||
if( m_lastBrk && m_lastTargV )
|
if (m_lastBrk && m_lastTargV)
|
||||||
{
|
{
|
||||||
if( m_lastBrk > 0 )
|
if (m_lastBrk > 0)//|| (car->ctrl.accelCmd == -m_lastBrk) )
|
||||||
{
|
{
|
||||||
double err = m_lastTargV - spd0;
|
double err = m_lastTargV - spd0;
|
||||||
m_accBrkCoeff.Sample( err, m_lastBrk );
|
m_accBrkCoeff.Sample(err, m_lastBrk);
|
||||||
}
|
// GfOut( "accbrk sample %g -> %g\n", err, m_lastBrk );
|
||||||
m_lastBrk = 0;
|
}
|
||||||
m_lastTargV = 0;
|
m_lastBrk = 0;
|
||||||
}
|
m_lastTargV = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if( spd0 > targetSpd )
|
if (spd0 > targetSpd)
|
||||||
{
|
// if( targetSpd < 100 )
|
||||||
{
|
{
|
||||||
double MAX_BRK = 0.5;
|
// if( spd0 - 1 > targetSpd )
|
||||||
double err = spd0 - targetSpd;
|
{
|
||||||
brk = MX(0, MN(m_accBrkCoeff.CalcY(err), MAX_BRK));
|
double MAX_BRK = 0.9;
|
||||||
acc = 0;
|
// double MAX_BRK = 0.75;
|
||||||
|
double err = spd0 - targetSpd;
|
||||||
|
brk = MX(0, MN(m_accBrkCoeff.CalcY(err), MAX_BRK));
|
||||||
|
// GfOut( "accbrk calcy %g -> %g\n", err, t );
|
||||||
|
acc = 0;
|
||||||
|
|
||||||
m_lastBrk = brk;
|
m_lastBrk = brk;
|
||||||
m_lastTargV = 0;
|
m_lastTargV = 0;
|
||||||
|
|
||||||
if( brk > 0 )
|
if (brk > 0)
|
||||||
{
|
{
|
||||||
if( targetSpd > 0 )
|
if (targetSpd > 0)
|
||||||
m_lastTargV = spd0;
|
m_lastTargV = spd0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// GfOut( "*** brake *** spd0 %g targ %g brk %g acc %g\n",
|
||||||
}
|
// spd0, targetSpd, brk, acc );
|
||||||
|
}
|
||||||
|
// else
|
||||||
|
// acc = MN(acc, 0.1);
|
||||||
|
}
|
||||||
|
#if 1
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double x = (0 + spd0) * (targetSpd - spd0) / 200;
|
||||||
|
|
||||||
|
if (x > 0)
|
||||||
|
acc = x;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDriver::SpeedControl3( double targetSpd, double spd0, double& acc, double& brk )
|
void TDriver::SpeedControl3( double targetSpd, double spd0, double& acc, double& brk )
|
||||||
|
@ -1546,15 +1564,38 @@ void TDriver::Drive( tSituation* s )
|
||||||
PtInfo pi, aheadPi;
|
PtInfo pi, aheadPi;
|
||||||
double angle = 0.0;
|
double angle = 0.0;
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
/*if (m_Strategy->WantToPit())
|
||||||
|
angle = SteerAngle2(car, pi, aheadPi);
|
||||||
|
else*/
|
||||||
|
{
|
||||||
|
int steerControl = ((MN(car->_trkPos.toLeft, car->_trkPos.toRight) < 0.0 && car->_speed_x < MN(20.0f, m_lastTargV - 10.0f)) ? STEERCONTROL_RECOVERY : STEERCONTROL);
|
||||||
|
|
||||||
|
switch (steerControl)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
angle = SteerAngle0(car, pi, aheadPi); break;
|
||||||
|
case 1:
|
||||||
|
angle = SteerAngle1(car, pi, aheadPi); break;
|
||||||
|
case 2:
|
||||||
|
angle = SteerAngle2(car, pi, aheadPi); break;
|
||||||
|
case 3:
|
||||||
|
angle = SteerAngle3(car, pi, aheadPi); break;
|
||||||
|
case 4:
|
||||||
|
angle = SteerAngle4(car, pi, aheadPi); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
switch (STEER_CTRL)
|
switch (STEER_CTRL)
|
||||||
{
|
{
|
||||||
case 0: angle = SteerAngle0(car, pi, aheadPi); break;
|
case 0: angle = SteerAngle0(car, pi, aheadPi); break;
|
||||||
case 1: angle = SteerAngle1(car, pi, aheadPi); break;
|
case 1: angle = SteerAngle1(car, pi, aheadPi); break;
|
||||||
case 2: angle = SteerAngle2(car, pi, aheadPi); break;
|
case 2: angle = SteerAngle2(car, pi, aheadPi); break;
|
||||||
case 3: angle = SteerAngle3(car, pi, aheadPi); break;
|
case 3: angle = SteerAngle3(car, pi, aheadPi); break;
|
||||||
case 4: angle = SteerAngle4(car, pi, aheadPi); break;
|
case 4: angle = SteerAngle4(car, pi, aheadPi); break;
|
||||||
default: angle = SteerAngle0(car, pi, aheadPi); break;
|
default: angle = SteerAngle0(car, pi, aheadPi); break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
double steer = angle / car->_steerLock;
|
double steer = angle / car->_steerLock;
|
||||||
|
|
||||||
|
|
|
@ -183,35 +183,35 @@ public:
|
||||||
TDriver(int index); // Constructor
|
TDriver(int index); // Constructor
|
||||||
~TDriver(); // Destructor
|
~TDriver(); // Destructor
|
||||||
|
|
||||||
void InitTrack(tTrack* track, void* carHandle, void** carParmHandle, tSituation* s);
|
void InitTrack(tTrack* track, void* carHandle, void** carParmHandle, tSituation* s);
|
||||||
void NewRace(tCarElt* car, tSituation* s );
|
void NewRace(tCarElt* car, tSituation* s );
|
||||||
|
|
||||||
void GetPtInfo( int path, double pos, PtInfo& pi ) const;
|
void GetPtInfo( int path, double pos, PtInfo& pi ) const;
|
||||||
void GetPosInfo( double pos, PtInfo& pi, double u, double v ) const;
|
void GetPosInfo( double pos, PtInfo& pi, double u, double v ) const;
|
||||||
void GetPosInfo( double pos, PtInfo& pi ) const;
|
void GetPosInfo( double pos, PtInfo& pi ) const;
|
||||||
double CalcPathTarget( double pos, double offs, double s ) const;
|
double CalcPathTarget( double pos, double offs, double s ) const;
|
||||||
double CalcPathTarget( double pos, double offs ) const;
|
double CalcPathTarget( double pos, double offs ) const;
|
||||||
Vec2d CalcPathTarget2( double pos, double offs ) const;
|
Vec2d CalcPathTarget2( double pos, double offs ) const;
|
||||||
double CalcPathOffset( double pos, double s, double t ) const;
|
double CalcPathOffset( double pos, double s, double t ) const;
|
||||||
void CalcBestPathUV( double pos, double offs, double& u, double& v ) const;
|
void CalcBestPathUV( double pos, double offs, double& u, double& v ) const;
|
||||||
double CalcBestSpeed( double pos, double offs ) const;
|
double CalcBestSpeed( double pos, double offs ) const;
|
||||||
void GetPathToLeftAndRight( const CarElt* pCar, double& toL, double& toR ) const;
|
void GetPathToLeftAndRight( const CarElt* pCar, double& toL, double& toR ) const;
|
||||||
|
|
||||||
double filterTCL(double accel);
|
double filterTCL(double accel);
|
||||||
double filterTrk(double accel);
|
double filterTrk(double accel);
|
||||||
double filterAccel(double Accel);
|
double filterAccel(double Accel);
|
||||||
|
|
||||||
void initCa();
|
void initCa();
|
||||||
//void initCa_MPA1();
|
//void initCa_MPA1();
|
||||||
//void initCa_MPA11();
|
//void initCa_MPA11();
|
||||||
void initCw();
|
void initCw();
|
||||||
void initCR();
|
void initCR();
|
||||||
|
|
||||||
void initDriveTrain();
|
void initDriveTrain();
|
||||||
void initWheelRadius();
|
void initWheelRadius();
|
||||||
void initTireMu();
|
void initTireMu();
|
||||||
void initWheelPos();
|
void initWheelPos();
|
||||||
void initBrake();
|
void initBrake();
|
||||||
|
|
||||||
double SteerAngle0( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
double SteerAngle0( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
||||||
double SteerAngle1( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
double SteerAngle1( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
||||||
|
@ -219,21 +219,21 @@ public:
|
||||||
double SteerAngle3( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
double SteerAngle3( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
||||||
double SteerAngle4( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
double SteerAngle4( tCarElt* car, PtInfo& pi, PtInfo& aheadPi );
|
||||||
|
|
||||||
void SpeedControl0( double targetSpd, double spd0, double& acc, double& brk );
|
void SpeedControl0( double targetSpd, double spd0, double& acc, double& brk );
|
||||||
void SpeedControl1( double targetSpd, double spd0, double& acc, double& brk );
|
void SpeedControl1( double targetSpd, double spd0, double& acc, double& brk );
|
||||||
void SpeedControl2( double targetSpd, double spd0, double& acc, double& brk );
|
void SpeedControl2( double targetSpd, double spd0, double& acc, double& brk );
|
||||||
void SpeedControl3( double targetSpd, double spd0, double& acc, double& brk );
|
void SpeedControl3( double targetSpd, double spd0, double& acc, double& brk );
|
||||||
void SpeedControl4( double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
void SpeedControl4( double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
||||||
void SpeedControl5(double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
void SpeedControl5(double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
||||||
void SpeedControl6(double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
void SpeedControl6(double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
||||||
void SpeedControl( int which, double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
void SpeedControl( int which, double targetSpd, double spd0, CarElt* car, double& acc, double& brk );
|
||||||
|
|
||||||
void Drive(tSituation* s );
|
void Drive(tSituation* s );
|
||||||
int PitCmd(tSituation* s );
|
int PitCmd(tSituation* s );
|
||||||
void EndRace(tSituation* s );
|
void EndRace(tSituation* s );
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
double CurrSimTime; // Current simulation time
|
double CurrSimTime; // Current simulation time
|
||||||
double Frc; // Friction coefficient
|
double Frc; // Friction coefficient
|
||||||
//bool UseBrakeLimit; // Enable/disable brakelimit
|
//bool UseBrakeLimit; // Enable/disable brakelimit
|
||||||
|
|
||||||
|
@ -470,15 +470,15 @@ private:
|
||||||
PidController m_speedController; // controller for speed.
|
PidController m_speedController; // controller for speed.
|
||||||
double m_prevYawError;
|
double m_prevYawError;
|
||||||
double m_prevLineError;
|
double m_prevLineError;
|
||||||
double m_Jumping; // Car is jumping
|
double m_Jumping; // Car is jumping
|
||||||
double m_JumpOffset; // Offset for calculation of jumps
|
double m_JumpOffset; // Offset for calculation of jumps
|
||||||
bool m_FirstJump;
|
bool m_FirstJump;
|
||||||
int m_Flying; // Flag prepare landing
|
int m_Flying; // Flag prepare landing
|
||||||
int m_nCars;
|
int m_nCars;
|
||||||
int m_myOppIdx;
|
int m_myOppIdx;
|
||||||
Opponent *m_opp; // info about other cars.
|
Opponent *m_opp; // info about other cars.
|
||||||
double m_avgAY;
|
double m_avgAY;
|
||||||
bool m_raceStart;
|
bool m_raceStart;
|
||||||
double m_avoidS; // where we are LR->T (0..1).
|
double m_avoidS; // where we are LR->T (0..1).
|
||||||
double m_avoidSVel;
|
double m_avoidSVel;
|
||||||
double m_avoidT; // where we are L->R (-1..1).
|
double m_avoidT; // where we are L->R (-1..1).
|
||||||
|
@ -495,7 +495,7 @@ private:
|
||||||
int m_lastB;
|
int m_lastB;
|
||||||
double m_lastBrk;
|
double m_lastBrk;
|
||||||
double m_lastTargV;
|
double m_lastTargV;
|
||||||
double m_maxbrkPressRatio;
|
double m_maxbrkPressRatio;
|
||||||
|
|
||||||
LearnedGraph m_maxAccel;
|
LearnedGraph m_maxAccel;
|
||||||
double m_angle[SPD_N][K_N];
|
double m_angle[SPD_N][K_N];
|
||||||
|
|
|
@ -55,6 +55,7 @@ SimpleStrategy::SimpleStrategy()
|
||||||
m_expectedfuelperlap = 0; // [Kg] Expected fuel per lap
|
m_expectedfuelperlap = 0; // [Kg] Expected fuel per lap
|
||||||
TrackLength = 0;
|
TrackLength = 0;
|
||||||
RaceDistance = 0;
|
RaceDistance = 0;
|
||||||
|
m_timeOfPitExit = -30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -522,6 +523,3 @@ double SimpleStrategy::getRefuel2(int laps)
|
||||||
|
|
||||||
return refuelforrace;
|
return refuelforrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ protected:
|
||||||
PIT_EXIT,
|
PIT_EXIT,
|
||||||
PIT_GONE
|
PIT_GONE
|
||||||
};
|
};
|
||||||
|
|
||||||
int m_State; // Current pitting state
|
int m_State; // Current pitting state
|
||||||
bool m_GoToPit; // Pit stop needed
|
bool m_GoToPit; // Pit stop needed
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbstractStrategy()
|
AbstractStrategy()
|
||||||
:m_State(PIT_NONE), m_GoToPit(false), Car(NULL), Track(NULL), pitPath(NULL), Driver(NULL), DistToSwitch(100), StartFuel(-1){};
|
:m_State(PIT_NONE), m_GoToPit(false), Car(NULL), Track(NULL), pitPath(NULL), Driver(NULL), DistToSwitch(100), StartFuel(-1) {};
|
||||||
// Need this empty constructor... do not remove.
|
// Need this empty constructor... do not remove.
|
||||||
virtual ~AbstractStrategy() {}
|
virtual ~AbstractStrategy() {}
|
||||||
// Set Initial fuel at race start.
|
// Set Initial fuel at race start.
|
||||||
|
@ -116,6 +117,7 @@ public:
|
||||||
int pitRepair(tCarElt* car, tSituation *s);
|
int pitRepair(tCarElt* car, tSituation *s);
|
||||||
bool isPitFree(tCarElt* car);
|
bool isPitFree(tCarElt* car);
|
||||||
int pitStopPenalty() { return m_stopPenalty; }
|
int pitStopPenalty() { return m_stopPenalty; }
|
||||||
|
double TimeSincePit(double simtime) { return simtime - m_timeOfPitExit; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool test_Pitstop;
|
bool test_Pitstop;
|
||||||
|
@ -145,6 +147,7 @@ protected:
|
||||||
float calcFuel(double totalFuel);
|
float calcFuel(double totalFuel);
|
||||||
double getRefuel1(int laps); // How much fuel it takes to reach the finish line.
|
double getRefuel1(int laps); // How much fuel it takes to reach the finish line.
|
||||||
double getRefuel2(int laps);
|
double getRefuel2(int laps);
|
||||||
|
double m_timeOfPitExit;
|
||||||
|
|
||||||
float MAX_FUEL_PER_METER; // max fuel consumtion.
|
float MAX_FUEL_PER_METER; // max fuel consumtion.
|
||||||
double MAX_FUEL_TANK; // max fuel for this car(fuel tank capacity).
|
double MAX_FUEL_TANK; // max fuel for this car(fuel tank capacity).
|
||||||
|
|
Loading…
Reference in a new issue