16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 14:39:18 +02:00

build 180718. ai slope logic tweaks, track grade ui indicator, minor bug fixes

This commit is contained in:
tmj-fstate
2018-07-19 02:25:52 +02:00
parent 387f396ecb
commit cd10b72821
7 changed files with 121 additions and 84 deletions

View File

@@ -1410,16 +1410,24 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
if( Targetvelocity > 65.f ) { return 1.f; }
if( Targetvelocity < 5.f ) {
// HACK: engaged automatic transmission means extra/earlier braking effort is needed for the last leg before full stop
if( ( mvOccupied->TrainType == dt_DMU )
&& ( mvOccupied->Vel < 40.0 )
&& ( Targetvelocity == 0.f ) ) {
// HACK: engaged automatic transmission means extra/earlier braking effort is needed for the last leg before full stop
return interpolate( 2.f, 1.f, static_cast<float>( mvOccupied->Vel / 40.0 ) );
}
else {
return 1.f;
// HACK: cargo trains or trains going downhill with high braking threshold need more distance to come to a full stop
if( ( fBrake_a0[ 0 ] > 0.2 )
&& ( ( mvOccupied->BrakeDelayFlag & bdelay_G ) != 0 )
|| ( fAccGravity > 0.025 ) ) {
return interpolate(
1.f, 3.f,
clamp(
( fBrake_a0[ 0 ] - 0.2 ) / 0.2,
0.0, 1.0 ) );
}
return 1.f;
}
// stretch the braking distance up to 3 times; the lower the speed, the greater the stretch
return interpolate( 3.f, 1.f, ( Targetvelocity - 5.f ) / 60.f );
@@ -1546,7 +1554,7 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
// fAccThreshold może podlegać uczeniu się - hamowanie powinno być rejestrowane, a potem analizowane
// próg opóźnienia dla zadziałania hamulca
fAccThreshold = (
mvOccupied->TrainType == dt_EZT ? -0.6 :
mvOccupied->TrainType == dt_EZT ? -0.55 :
mvOccupied->TrainType == dt_DMU ? -0.45 :
-0.2 );
}
@@ -1868,7 +1876,7 @@ void TController::AutoRewident()
fBrake_a1[i+1] /= (12*fMass);
}
if( mvOccupied->TrainType == dt_EZT ) {
fAccThreshold = std::max(-fBrake_a0[BrakeAccTableSize] - 8 * fBrake_a1[BrakeAccTableSize], -0.6);
fAccThreshold = std::max(-fBrake_a0[BrakeAccTableSize] - 8 * fBrake_a1[BrakeAccTableSize], -0.55);
fBrakeReaction = 0.25;
}
else if( mvOccupied->TrainType == dt_DMU ) {
@@ -2744,12 +2752,12 @@ bool TController::IncSpeed()
// na pozycji 0 przejdzie, a na pozostałych będzie czekać, aż się załączą liniowe (zgaśnie DelayCtrlFlag)
if (Ready || (iDrivigFlags & movePress)) {
// use series mode:
// to build up speed to 30/40 km/h for passenger/cargo train,
// to build up speed to 30/40 km/h for passenger/cargo train (less if going uphill, more if downhill)
// if high threshold is set for motor overload relay,
// if the power station is heavily burdened
auto const useseriesmodevoltage { 0.80 * mvControlling->EnginePowerSource.CollectorParameters.MaxV };
auto const useseriesmode = (
( mvOccupied->Vel <= ( ( mvOccupied->BrakeDelayFlag & bdelay_G ) != 0 ? 35 : 25 ) + ( mvControlling->ScndCtrlPos == 0 ? 0 : 5 ) )
( mvOccupied->Vel <= ( ( mvOccupied->BrakeDelayFlag & bdelay_G ) != 0 ? 35 : 25 ) + ( mvControlling->ScndCtrlPos == 0 ? 0 : 5 ) + ( fAccGravity * 100 ) )
|| ( mvControlling->Imax > mvControlling->ImaxLo )
|| ( fVoltage < useseriesmodevoltage ) );
// when not in series mode use the first available parallel mode configuration until 50/60 km/h for passenger/cargo train
@@ -3731,13 +3739,14 @@ TController::UpdateSituation(double dt) {
if( ( dy = p->VectorFront().y ) != 0.0 ) {
// istotne tylko dla pojazdów na pochyleniu
// ciężar razy składowa styczna grawitacji
fAccGravity -= p->DirectionGet() * p->MoverParameters->TotalMassxg * dy;
fAccGravity -= p->MoverParameters->TotalMassxg * dy * ( p->DirectionGet() == iDirection ? 1 : -1 );
}
p = p->Next(); // pojazd podłączony z tyłu (patrząc od czoła)
}
if( iDirection ) {
// siłę generują pojazdy na pochyleniu ale działa ona całość składu, więc a=F/m
fAccGravity /= iDirection * fMass;
fAccGravity *= iDirection;
fAccGravity /= fMass;
}
if (!Ready) // v367: jeśli wg powyższych warunków skład nie jest odhamowany
if (fAccGravity < -0.05) // jeśli ma pod górę na tyle, by się stoczyć
@@ -4924,30 +4933,29 @@ TController::UpdateSituation(double dt) {
// decisions based on current speed
if( mvOccupied->CategoryFlag == 1 ) {
if( fAccGravity < 0.025 ) {
// on flats on uphill we can be less careful
if( vel > 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
// on flats or uphill we can be less careful
if( vel > 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 {
// slow down, not full stop
if( vel > ( VelDesired + fVelPlus ) ) {
// hamuj tak średnio
AccDesired = std::min( AccDesired, -0.25 );
}
else {
// slow down, not full stop
if( vel > ( VelDesired + fVelPlus ) ) {
// hamuj tak średnio
AccDesired = std::min( AccDesired, -0.25 );
}
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 ) );
}
// 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 {
if( fAccGravity > 0.025 ) {
// 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;
@@ -4958,20 +4966,39 @@ TController::UpdateSituation(double dt) {
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 ) );
// if it looks like we'll exceed maximum speed start thinking about slight slowing down
AccDesired = std::min( AccDesired, -0.25 );
// HACK: for cargo trains with high braking threshold ensure we cross that threshold
if( ( ( mvOccupied->BrakeDelayFlag & bdelay_G ) != 0 )
&& ( fBrake_a0[ 0 ] > 0.2 ) ) {
AccDesired -= clamp( fBrake_a0[ 0 ] - 0.2, 0.0, 0.15 );
}
}
}
else {
// stop accelerating when close enough to target speed
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( VelDesired - speedestimate, 0.0, fVelMinus ) / fVelMinus ) );
}
// final tweaks
if( vel > 0.1 ) {
// going downhill also take into account impact of gravity
AccDesired -= fAccGravity;
// HACK: if the max allowed speed was exceeded something went wrong; brake harder
AccDesired -= 0.15 * clamp( vel - VelDesired, 0.0, 5.0 );
/*
if( ( vel > VelDesired )
&& ( ( mvOccupied->BrakeDelayFlag & bdelay_G ) != 0 )
&& ( fBrake_a0[ 0 ] > 0.2 ) ) {
AccDesired = clamp(
AccDesired - clamp( fBrake_a0[ 0 ] - 0.2, 0.0, 0.15 ),
-0.9, 0.9 );
}
*/
}
}
}
else {
@@ -5001,14 +5028,7 @@ TController::UpdateSituation(double dt) {
// last step sanity check, until the whole calculation is straightened out
AccDesired = std::min( AccDesired, AccPreferred );
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, -0.9, 0.9 );
if (AIControllFlag) {
// część wykonawcza tylko dla AI, dla człowieka jedynie napisy
@@ -5214,7 +5234,12 @@ TController::UpdateSituation(double dt) {
if( mvOccupied->TrainType == dt_EZT ) {
// właściwie, to warunek powinien być na działający EP
// Ra: to dobrze hamuje EP w EZT
if( ( AccDesired <= fAccThreshold ) // jeśli hamować - u góry ustawia się hamowanie na fAccThreshold
// HACK: when going downhill be more responsive to desired deceleration
auto const accthreshold { (
fAccGravity < 0.025 ?
fAccThreshold :
std::max( -0.2, fAccThreshold ) ) };
if( ( AccDesired <= accthreshold ) // jeśli hamować - u góry ustawia się hamowanie na fAccThreshold
&& ( ( AbsAccS > AccDesired )
|| ( mvOccupied->BrakeCtrlPos < 0 ) ) ) {
// hamować bardziej, gdy aktualne opóźnienie hamowania mniejsze niż (AccDesired)
@@ -5242,7 +5267,7 @@ TController::UpdateSituation(double dt) {
} // type & dt_ezt
else {
// a stara wersja w miarę dobrze działa na składy wagonowe
if( ( ( fAccGravity < -0.05 ) && ( vel < 0.0 ) )
if( ( ( fAccGravity < -0.05 ) && ( vel < -0.1 ) ) // brake if uphill and slipping back
|| ( ( AccDesired < fAccGravity - 0.1 ) && ( AbsAccS > AccDesired + fBrake_a1[ 0 ] ) ) ) {
// u góry ustawia się hamowanie na fAccThreshold
if( ( fBrakeTime < 0.0 )

View File

@@ -564,12 +564,12 @@ private:
inline double ABuGetDirection() const { // ABu.
return (Axle1.GetTrack() == MyTrack ? Axle1.GetDirection() : Axle0.GetDirection()); };
// zwraca kierunek pojazdu na torze z aktywną osą
inline double RaDirectionGet() {
inline double RaDirectionGet() const {
return iAxleFirst ?
Axle1.GetDirection() :
Axle0.GetDirection(); };
// zwraca przesunięcie wózka względem Point1 toru z aktywną osią
inline double RaTranslationGet() {
inline double RaTranslationGet() const {
return iAxleFirst ?
Axle1.GetTranslation() :
Axle0.GetTranslation(); };

View File

@@ -606,6 +606,28 @@ bool TTrain::is_eztoer() const {
&& ( mvControlled->ActiveDir != 0 ) ); // od yB
}
// mover master controller to specified position
void TTrain::set_master_controller( double const Position ) {
auto positionchange {
std::min<int>(
Position,
( mvControlled->CoupledCtrl ?
mvControlled->MainCtrlPosNo + mvControlled->ScndCtrlPosNo :
mvControlled->MainCtrlPosNo ) )
- ( mvControlled->CoupledCtrl ?
mvControlled->MainCtrlPos + mvControlled->ScndCtrlPos :
mvControlled->MainCtrlPos ) };
while( ( positionchange < 0 )
&& ( true == mvControlled->DecMainCtrl( 1 ) ) ) {
++positionchange;
}
while( ( positionchange > 0 )
&& ( true == mvControlled->IncMainCtrl( 1 ) ) ) {
--positionchange;
}
}
// moves train brake lever to specified position, potentially emits switch sound if conditions are met
void TTrain::set_train_brake( double const Position ) {
@@ -746,22 +768,9 @@ void TTrain::OnCommand_mastercontrollerdecreasefast( TTrain *Train, command_data
void TTrain::OnCommand_mastercontrollerset( TTrain *Train, command_data const &Command ) {
auto positionchange {
std::min<int>(
Command.param1,
( Train->mvControlled->CoupledCtrl ?
Train->mvControlled->MainCtrlPosNo + Train->mvControlled->ScndCtrlPosNo :
Train->mvControlled->MainCtrlPosNo ) )
- ( Train->mvControlled->CoupledCtrl ?
Train->mvControlled->MainCtrlPos + Train->mvControlled->ScndCtrlPos :
Train->mvControlled->MainCtrlPos ) };
while( ( positionchange < 0 )
&& ( true == Train->mvControlled->DecMainCtrl( 1 ) ) ) {
++positionchange;
}
while( ( positionchange > 0 )
&& ( true == Train->mvControlled->IncMainCtrl( 1 ) ) ) {
--positionchange;
if( Command.action != GLFW_RELEASE ) {
// on press or hold
Train->set_master_controller( Command.param1 );
}
}
@@ -5099,16 +5108,12 @@ bool TTrain::Update( double const Deltatime )
if (ggMainCtrl.SubModel) {
#ifdef _WIN32
if ((DynamicObject->Mechanik != nullptr)
&& (false == DynamicObject->Mechanik->AIControllFlag) // nie blokujemy AI
&& (Global.iFeedbackMode == 4)
&& (Global.fCalibrateIn[2][1] != 0.0)) {
auto const b = clamp<double>(
Console::AnalogCalibrateGet(2) * mvOccupied->MainCtrlPosNo,
0.0,
mvOccupied->MainCtrlPosNo);
while (mvOccupied->MainCtrlPos < b) { mvOccupied->MainCtrlPos = b - 1; mvOccupied->IncMainCtrl(1); }
while (mvOccupied->MainCtrlPos > b) { mvOccupied->MainCtrlPos = b + 1; mvOccupied->DecMainCtrl(1); }
if( ( DynamicObject->Mechanik != nullptr )
&& ( false == DynamicObject->Mechanik->AIControllFlag ) // nie blokujemy AI
&& ( Global.iFeedbackMode == 4 )
&& ( Global.fCalibrateIn[ 2 ][ 1 ] != 0.0 ) ) {
set_master_controller( Console::AnalogCalibrateGet( 2 ) * mvOccupied->MainCtrlPosNo );
}
#endif

View File

@@ -132,6 +132,8 @@ class TTrain
bool is_eztoer() const;
// locates nearest vehicle belonging to the consist
TDynamicObject *find_nearest_consist_vehicle() const;
// mover master controller to specified position
void set_master_controller( double const Position );
// moves train brake lever to specified position, potentially emits switch sound if conditions are met
void set_train_brake( double const Position );
// sets specified brake acting speed for specified vehicle, potentially updating state of cab controls to match

View File

@@ -293,13 +293,18 @@ ui_layer::update() {
uitextline2 +=
" Speed: " + std::to_string( static_cast<int>( std::floor( mover->Vel ) ) ) + " km/h"
+ " (limit: " + std::to_string( speedlimit ) + " km/h";
auto const nextspeedlimit { static_cast<int>( std::floor( controlled->Mechanik->VelNext ) ) };
auto const nextspeedlimit { static_cast<int>( std::floor( driver->VelNext ) ) };
if( nextspeedlimit != speedlimit ) {
uitextline2 +=
", new limit: " + std::to_string( nextspeedlimit ) + " km/h"
+ " in " + to_string( controlled->Mechanik->ActualProximityDist * 0.001, 1 ) + " km";
+ " in " + to_string( driver->ActualProximityDist * 0.001, 1 ) + " km";
}
uitextline2 += ")";
auto const reverser { ( mover->ActiveDir > 0 ? 1 : -1 ) };
auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser };
if( std::abs( grade ) >= 0.25 ) {
uitextline2 += " Grade: " + to_string( grade, 1 ) + "%";
}
uitextline3 +=
" Pressure: " + to_string( mover->BrakePress * 100.0, 2 ) + " kPa"
+ " (train pipe: " + to_string( mover->PipePress * 100.0, 2 ) + " kPa)";
@@ -513,7 +518,7 @@ ui_layer::update() {
+ ( vehicle->MoverParameters->SlippingWheels ? " (!)" : "" );
if( vehicle->Mechanik ) {
uitextline2 += "; Ag: " + to_string( vehicle->Mechanik->fAccGravity, 2 );
uitextline2 += "; Ag: " + to_string( vehicle->Mechanik->fAccGravity, 2 ) + " (" + ( vehicle->Mechanik->fAccGravity > 0.01 ? "\\" : ( vehicle->Mechanik->fAccGravity < -0.01 ? "/" : "-" ) ) + ")";
}
uitextline2 +=

View File

@@ -254,14 +254,14 @@ template <typename Type_>
Type_
interpolate( Type_ const &First, Type_ const &Second, float const Factor ) {
return ( First * ( 1.0f - Factor ) ) + ( Second * Factor );
return static_cast<Type_>( ( First * ( 1.0f - Factor ) ) + ( Second * Factor ) );
}
template <typename Type_>
Type_
interpolate( Type_ const &First, Type_ const &Second, double const Factor ) {
return ( First * ( 1.0 - Factor ) ) + ( Second * Factor );
return static_cast<Type_>( ( First * ( 1.0 - Factor ) ) + ( Second * Factor ) );
}
// tests whether provided points form a degenerate triangle

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 18
#define VERSION_MINOR 708
#define VERSION_MINOR 718
#define VERSION_REVISION 0