16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 12:49:18 +02:00

ai driving logic tweaks, minor bug fixes

This commit is contained in:
tmj-fstate
2017-10-11 20:30:17 +02:00
parent de4e10ab39
commit a12b84f50f
4 changed files with 71 additions and 27 deletions

View File

@@ -73,7 +73,8 @@ double GetDistanceToEvent(TTrack const *track, TEvent const *event, double scan_
{ // przejście na inny tor { // przejście na inny tor
track = track->Connected(int(sd), sd); track = track->Connected(int(sd), sd);
start_dist += (1 == krok) ? 0 : back ? -segment->GetLength() : segment->GetLength(); start_dist += (1 == krok) ? 0 : back ? -segment->GetLength() : segment->GetLength();
if( track->eType == tt_Cross ) { if( ( track != nullptr )
&& ( track->eType == tt_Cross ) ) {
// NOTE: tracing through crossroads currently poses risk of tracing through wrong segment // NOTE: tracing through crossroads currently poses risk of tracing through wrong segment
// as it's possible to be performerd before setting a route through the crossroads // as it's possible to be performerd before setting a route through the crossroads
// as a stop-gap measure we don't trace through crossroads which should be reasonable in most cases // as a stop-gap measure we don't trace through crossroads which should be reasonable in most cases
@@ -312,7 +313,7 @@ bool TSpeedPos::Update()
std::string TSpeedPos::GetName() std::string TSpeedPos::GetName()
{ {
if (iFlags & spTrack) // jeśli tor if (iFlags & spTrack) // jeśli tor
return trTrack->NameGet(); return trTrack->name();
else if( iFlags & spEvent ) // jeśli event else if( iFlags & spEvent ) // jeśli event
return evEvent->asName; return evEvent->asName;
else else
@@ -526,7 +527,7 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
if (pTrack != tLast) // ostatni zapisany w tabelce nie był jeszcze sprawdzony if (pTrack != tLast) // ostatni zapisany w tabelce nie był jeszcze sprawdzony
{ // jeśli tor nie był jeszcze sprawdzany { // jeśli tor nie był jeszcze sprawdzany
if( Global::iWriteLogEnabled & 8 ) { if( Global::iWriteLogEnabled & 8 ) {
WriteLog( "Speed table for " + OwnerName() + " tracing through track " + pTrack->NameGet() ); WriteLog( "Speed table for " + OwnerName() + " tracing through track " + pTrack->name() );
} }
if( ( pEvent = CheckTrackEvent( pTrack, fLastDir ) ) != nullptr ) // jeśli jest semafor na tym torze if( ( pEvent = CheckTrackEvent( pTrack, fLastDir ) ) != nullptr ) // jeśli jest semafor na tym torze
@@ -723,7 +724,7 @@ void TController::TableCheck(double fDistance)
if (sSpeedTable[i].Update()) if (sSpeedTable[i].Update())
{ {
if( Global::iWriteLogEnabled & 8 ) { if( Global::iWriteLogEnabled & 8 ) {
WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->NameGet() + " (generating fresh trace)" ); WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->name() + " (generating fresh trace)" );
} }
// usuwamy wszystko za tym torem // usuwamy wszystko za tym torem
while (sSpeedTable.back().trTrack != sSpeedTable[i].trTrack) while (sSpeedTable.back().trTrack != sSpeedTable[i].trTrack)
@@ -827,7 +828,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
WriteLog( WriteLog(
pVehicle->asName + " as " + TrainParams->TrainName pVehicle->asName + " as " + TrainParams->TrainName
+ ": at " + std::to_string(simulation::Time.data().wHour) + ":" + std::to_string(simulation::Time.data().wMinute) + ": at " + std::to_string(simulation::Time.data().wHour) + ":" + std::to_string(simulation::Time.data().wMinute)
+ " skipped " + asNextStop); // informacja + " passed " + asNextStop); // informacja
#endif #endif
// przy jakim dystansie (stanie licznika) ma przesunąć na następny postój // przy jakim dystansie (stanie licznika) ma przesunąć na następny postój
fLastStopExpDist = mvOccupied->DistCounter + 0.250 + 0.001 * fLength; fLastStopExpDist = mvOccupied->DistCounter + 0.250 + 0.001 * fLength;
@@ -3651,6 +3652,14 @@ TController::UpdateSituation(double dt) {
// dla nastawienia G koniecznie należy wydłużyć drogę na czas reakcji // dla nastawienia G koniecznie należy wydłużyć drogę na czas reakcji
fBrakeDist += 2 * mvOccupied->Vel; fBrakeDist += 2 * mvOccupied->Vel;
} }
/*
// take into account effect of gravity (but to stay on safe side of calculations, only downhill)
if( fAccGravity > 0.025 ) {
fBrakeDist *= ( 1.0 + fAccGravity );
// TBD: use version which shortens route going uphill, too
//fBrakeDist = std::max( fBrakeDist, fBrakeDist * ( 1.0 + fAccGravity ) );
}
*/
// route scan // route scan
double routescanrange = ( double routescanrange = (
mvOccupied->Vel > 5.0 ? mvOccupied->Vel > 5.0 ?
@@ -4461,6 +4470,7 @@ TController::UpdateSituation(double dt) {
AbsAccS /= fMass; AbsAccS /= fMass;
} }
AbsAccS_pub = AbsAccS; AbsAccS_pub = AbsAccS;
AbsAccS_avg = interpolate( AbsAccS_avg, mvOccupied->AccS * iDirection, 0.25 );
#if LOGVELOCITY #if LOGVELOCITY
// WriteLog("VelDesired="+AnsiString(VelDesired)+", // WriteLog("VelDesired="+AnsiString(VelDesired)+",
@@ -4589,26 +4599,53 @@ TController::UpdateSituation(double dt) {
// decisions based on current speed // decisions based on current speed
if( mvOccupied->CategoryFlag == 1 ) { if( mvOccupied->CategoryFlag == 1 ) {
// try to estimate increase of current velocity before engaged brakes start working
auto const speedestimate = vel + vel * ( 1.0 - fBrake_a0[ 0 ] ) * AbsAccS; if( fAccGravity < 0.025 ) {
if( speedestimate > VelDesired ) { // on flats on uphill we can be less careful
// jesli jedzie za szybko do AKTUALNEGO if( vel > VelDesired ) {
if( VelDesired == 0.0 ) { // jesli jedzie za szybko do AKTUALNEGO
// jesli stoj, to hamuj, ale i tak juz za pozno :) if( VelDesired == 0.0 ) {
AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie // jesli stoj, to hamuj, ale i tak juz za pozno :)
} AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie
else {
if( speedestimate > ( VelDesired + fVelPlus ) ) {
// if it looks like we'll exceed maximum allowed speed start thinking about slight slowing down
AccDesired = std::min( AccDesired, -0.25 );
} }
else { else {
// close enough to target to stop accelerating // slow down, not full stop
AccDesired = std::min( if( vel > ( VelDesired + fVelPlus ) ) {
AccDesired, // but don't override decceleration for VelNext // hamuj tak średnio
interpolate( // ease off as you close to the target velocity AccDesired = std::min( AccDesired, -0.25 );
-0.06, AccPreferred, }
clamp( speedestimate - vel, 0.0, fVelPlus ) / fVelPlus ) ); else {
// o 5 km/h to olej (zacznij luzować)
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
std::max( 0.0, AccPreferred ) );
}
}
}
}
else {
// going sharply downhill we may need to start braking sooner than usual
// try to estimate increase of current velocity before engaged brakes start working
auto const speedestimate = vel + ( 1.0 - fBrake_a0[ 0 ] ) * 30.0 * AbsAccS;
if( speedestimate > VelDesired ) {
// jesli jedzie za szybko do AKTUALNEGO
if( VelDesired == 0.0 ) {
// jesli stoj, to hamuj, ale i tak juz za pozno :)
AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie
}
else {
if( speedestimate > ( VelDesired + fVelPlus ) ) {
// if it looks like we'll exceed maximum allowed speed start thinking about slight slowing down
AccDesired = std::min( AccDesired, -0.25 );
}
else {
// close enough to target to stop accelerating
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
interpolate( // ease off as you close to the target velocity
-0.06, AccPreferred,
clamp( speedestimate - vel, 0.0, fVelPlus ) / fVelPlus ) );
}
} }
} }
} }
@@ -4640,8 +4677,10 @@ TController::UpdateSituation(double dt) {
// last step sanity check, until the whole calculation is straightened out // last step sanity check, until the whole calculation is straightened out
AccDesired = std::min( AccDesired, AccPreferred ); AccDesired = std::min( AccDesired, AccPreferred );
if( mvOccupied->CategoryFlag == 1 ) {
// also take into account impact of gravity if( ( mvOccupied->CategoryFlag == 1 )
&& ( fAccGravity > 0.025 ) ) {
// going downhill also take into account impact of gravity
AccDesired = clamp( AccDesired - fAccGravity, -0.9, 0.9 ); AccDesired = clamp( AccDesired - fAccGravity, -0.9, 0.9 );
} }
@@ -5164,7 +5203,7 @@ std::string TController::StopReasonText()
if (eStopReason != 7) // zawalidroga będzie inaczej if (eStopReason != 7) // zawalidroga będzie inaczej
return StopReasonTable[eStopReason]; return StopReasonTable[eStopReason];
else else
return "Blocked by " + (pVehicles[0]->PrevAny()->GetName()); return "Blocked by " + (pVehicles[0]->PrevAny()->name());
}; };
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------

View File

@@ -209,6 +209,7 @@ public:
double BrakeAccFactor(); double BrakeAccFactor();
double fBrakeReaction = 1.0; //opóźnienie zadziałania hamulca - czas w s / (km/h) double fBrakeReaction = 1.0; //opóźnienie zadziałania hamulca - czas w s / (km/h)
double fAccThreshold = 0.0; // próg opóźnienia dla zadziałania hamulca double fAccThreshold = 0.0; // próg opóźnienia dla zadziałania hamulca
double AbsAccS_avg = 0.0; // averaged out directional acceleration
double AbsAccS_pub = 0.0; // próg opóźnienia dla zadziałania hamulca double AbsAccS_pub = 0.0; // próg opóźnienia dla zadziałania hamulca
double fBrake_a0[BrakeAccTableSize+1] = { 0.0 }; // próg opóźnienia dla zadziałania hamulca double fBrake_a0[BrakeAccTableSize+1] = { 0.0 }; // próg opóźnienia dla zadziałania hamulca
double fBrake_a1[BrakeAccTableSize+1] = { 0.0 }; // próg opóźnienia dla zadziałania hamulca double fBrake_a1[BrakeAccTableSize+1] = { 0.0 }; // próg opóźnienia dla zadziałania hamulca

View File

@@ -706,6 +706,7 @@ public:
headlight_upper = 0x04, headlight_upper = 0x04,
headlight_right = 0x10, headlight_right = 0x10,
redmarker_right = 0x20, redmarker_right = 0x20,
rearendsignals = 0x40
}; };
int ScndInMain{ 0 }; /*zaleznosc bocznika od nastawnika*/ int ScndInMain{ 0 }; /*zaleznosc bocznika od nastawnika*/
bool MBrake = false; /*Czy jest hamulec reczny*/ bool MBrake = false; /*Czy jest hamulec reczny*/

View File

@@ -6923,7 +6923,7 @@ void TMoverParameters::LoadFIZ_Brake( std::string const &line ) {
} }
if( true == extract_value( AirLeakRate, "AirLeakRate", line, "" ) ) { if( true == extract_value( AirLeakRate, "AirLeakRate", line, "" ) ) {
// the parameter is provided in form of a multiplier, where 1.0 means the default rate of 0.001 // the parameter is provided in form of a multiplier, where 1.0 means the default rate of 0.01
AirLeakRate *= 0.01; AirLeakRate *= 0.01;
} }
} }
@@ -7826,10 +7826,13 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir)
BrakeCtrlPos = static_cast<int>( Handle->GetPos( bh_NP ) ); BrakeCtrlPos = static_cast<int>( Handle->GetPos( bh_NP ) );
else else
BrakeCtrlPos = static_cast<int>( Handle->GetPos( bh_RP ) ); BrakeCtrlPos = static_cast<int>( Handle->GetPos( bh_RP ) );
/*
// NOTE: disabled and left up to the driver, if there's any
MainSwitch( false ); MainSwitch( false );
PantFront( true ); PantFront( true );
PantRear( true ); PantRear( true );
MainSwitch( true ); MainSwitch( true );
*/
ActiveDir = 0; // Dir; //nastawnik kierunkowy - musi być ustawiane osobno! ActiveDir = 0; // Dir; //nastawnik kierunkowy - musi być ustawiane osobno!
DirAbsolute = ActiveDir * CabNo; // kierunek jazdy względem sprzęgów DirAbsolute = ActiveDir * CabNo; // kierunek jazdy względem sprzęgów
LimPipePress = CntrlPipePress; LimPipePress = CntrlPipePress;