mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-24 13:09:16 +01:00
fix(ai): an uphill start keeps the power on until the train brake is off (#396)
* fix(ai): an uphill start keeps the power on until the train brake is off The uphill start of #265 ended as soon as the power held the train (or the head of the train moved back 0.5 km/h). From then on the brake still on in the wagons made Ready false, the power went off, the train rolled back, was braked again and the start began anew; only the cylinders falling below 0.8 bar let the train get away. - Once the power holds the train, the start goes on while the train brake is released: Ready holds, the power stays on, bounded to 1.5 x the grade force. It ends when the consist is released (the same test as Ready, without the hold) or after 60 s. - A start is given up for rolling back on the mass-weighted speed of the consist, not on the speed of the locomotive, which runs back into the slack of the train held by its brake. - A train slipping back uphill is not released by the rule for a train to go on. * fix(ai): an uphill start begins only with the whole train at a stand * fix(ai): an uphill start applies the train brake further while it doesn't hold the train without the locomotive brake * fix(ai): the speed and the tractive force of an uphill start in the direction of travel also from cab 2 * fix(ai): an uphill start tops up the train brake a full application time a step, at most to full service, and keeps the power between 1.1 and 1.5 times the grade force while the brake releases * fix(ai): an uphill start no longer takes a notch back in the release phase: the notch below doesn't hold the train * refactor(ai): the train brake top-up of an uphill start in uphill_start::brake_top_up(), with unit tests
This commit is contained in:
@@ -3751,7 +3751,7 @@ bool TController::DecBrake() {
|
||||
// a position short of the first one brakes no weaker than that
|
||||
deltaAcc = -AccDesired * BrakeAccFactor() - ( fBrake_a0[ 0 ] + 4 * std::max( 0.0, BrakeCtrlPosition - pos_diff ) * fBrake_a1[ 0 ] );
|
||||
}
|
||||
if( bUphillStart ) {
|
||||
if( bUphillStart && ( false == bUphillRelease ) ) {
|
||||
// starting uphill the train brake holds the train until the power does
|
||||
break;
|
||||
}
|
||||
@@ -6549,24 +6549,35 @@ TController::determine_consist_state() {
|
||||
ConsistShade = 0.0;
|
||||
auto *p { pVehicles[ end::front ] }; // pojazd na czole składu
|
||||
double dy; // składowa styczna grawitacji, w przedziale <0,1>
|
||||
// starting uphill the power is applied against the train brake on purpose, until the power holds the train and
|
||||
// then while the brake releases
|
||||
auto const heldforstart { bUphillStart };
|
||||
auto released { true }; // the brakes are off, the hold of an uphill start not counted
|
||||
auto mostapplied { 0.0 }; // the most applied brake, the hold of an uphill start not counted
|
||||
auto momentum { 0.0 };
|
||||
while (p)
|
||||
{ // sprawdzenie odhamowania wszystkich połączonych pojazdów
|
||||
auto *vehicle { p->MoverParameters };
|
||||
auto const bp { std::max( 0.0, vehicle->BrakePress - ( vehicle->SpeedCtrlUnit.Parking ? vehicle->MaxBrakePress[ 0 ] * vehicle->StopBrakeDecc : 0.0 ) ) };
|
||||
// starting uphill the power is applied against the train brake on purpose, until the power holds the train
|
||||
auto const heldforstart { bUphillStart };
|
||||
if (Ready) {
|
||||
momentum += vehicle->TotalMass * vehicle->V * ( p->DirectionGet() == iDirection ? 1 : -1 );
|
||||
mostapplied = std::max( bp, mostapplied );
|
||||
auto const wasready { Ready };
|
||||
if( released || Ready ) {
|
||||
// bo jak coś nie odhamowane, to dalej nie ma co sprawdzać
|
||||
if( auto const isbraking { TestFlagAny( vehicle->Hamulec->GetBrakeStatus(), b_hld | b_on ) };
|
||||
vehicle->Vel < 1.0 ?
|
||||
auto const isbraking { TestFlagAny( vehicle->Hamulec->GetBrakeStatus(), b_hld | b_on ) };
|
||||
if( vehicle->Vel < 1.0 ?
|
||||
isbraking || bp > 0.4 : // ensure the brakes are sufficiently released when starting to move
|
||||
// once in motion a brake down to 0.4 bar counts as released (UIC), even if its distributor
|
||||
// is still in the lap position while the brake pipe recharges
|
||||
( isbraking && bp > 0.4 ) || vehicle->Fb > 10000.0 ) { // 10 kN
|
||||
// ready all the same only at a standstill with the power going on against the brake on purpose;
|
||||
// in motion a braking force left anywhere in the train (a hand brake) stops it as before
|
||||
Ready = heldforstart && ( vehicle->Vel < 1.0 );
|
||||
released = false;
|
||||
// ready all the same with the power going on against the brake on purpose: at a standstill, and once
|
||||
// the power holds the train, while the brake releases; otherwise in motion a braking force left
|
||||
// anywhere in the train (a hand brake) stops it as before
|
||||
Ready = Ready && heldforstart && ( bUphillRelease || ( vehicle->Vel < 1.0 ) );
|
||||
}
|
||||
}
|
||||
if( wasready ) {
|
||||
// Ra: odluźnianie przeładowanych lokomotyw, ciągniętych na zimno - prowizorka...
|
||||
if( bp >= 0.4 && (AIControllFlag || Global.AITrainman && mvOccupied->Vel < EU07_AI_NOMOVEMENT && !is_emu() && !is_dmu()) && BrakeCtrlPosition == gbh_RP // jest pozycja jazdy
|
||||
&& false == TestFlag(vehicle->Hamulec->GetBrakeStatus(), b_dmg) // brake isn't broken
|
||||
@@ -6583,7 +6594,8 @@ TController::determine_consist_state() {
|
||||
vehicle->BrakeReleaser(0);
|
||||
}
|
||||
}
|
||||
fReady = std::max( heldforstart ? 0.0 : bp, fReady ); // szukanie najbardziej zahamowanego
|
||||
// the brake held for the start counts again once it is being released
|
||||
fReady = std::max( ( heldforstart && ( false == bUphillRelease ) ) ? 0.0 : bp, fReady ); // szukanie najbardziej zahamowanego
|
||||
if( ( dy = p->VectorFront().y ) != 0.0 ) {
|
||||
// istotne tylko dla pojazdów na pochyleniu
|
||||
// ciężar razy składowa styczna grawitacji
|
||||
@@ -6679,6 +6691,10 @@ TController::determine_consist_state() {
|
||||
&& fReady < 0.8 ) { // delikatniejszy warunek, obejmuje wszystkie wagony
|
||||
Ready = true; //żeby uznać za odhamowany
|
||||
}
|
||||
// the same test without the hold of an uphill start
|
||||
IsConsistReleased = released || ( fAccGravity < -0.05 && mostapplied < 0.8 );
|
||||
// the frame of the vehicle the AI drives from, as for fAccGravity and AbsAccS
|
||||
fConsistVelocity = 3.6 * momentum / std::max( 1.0, fMass ) * ( iDirection >= 0 ? 1 : -1 );
|
||||
auto const departblocked {
|
||||
AIControllFlag
|
||||
&& mvOccupied->Vel < EU07_AI_NOMOVEMENT
|
||||
@@ -8717,6 +8733,12 @@ void TController::control_tractive_force() {
|
||||
if( AccDesired > EU07_AI_NOACCELERATION // don't add power if not asked for actual speed-up
|
||||
&& (AbsAccS < AccDesired /*- std::min( 0.05, 0.01 * iDriverFailCount )*/ || mvOccupied->SpeedCtrlUnit.IsActive && velocity < mvOccupied->SpeedCtrlUnit.FullPowerVelocity) &&
|
||||
false == TestFlag(iDrivigFlags, movePress) &&
|
||||
// starting uphill against the releasing brake, the power that holds the train is enough: the brake coming off
|
||||
// speeds the train up, more power only drags the brake and slips the wheels. nor is a notch past that taken
|
||||
// back: the power got there in one notch from below, and the notch below doesn't hold the train
|
||||
( false == bUphillRelease || fUphillTractiveForce < uphill_start::holding_force * fUphillHoldingForce ) &&
|
||||
// nor while the train brake is still being applied further to hold the train
|
||||
false == bUphillBrakeTopUp &&
|
||||
velocity < (VelDesired == 1.0 ? // work around for trains getting stuck on tracks with speed limit = 1
|
||||
VelDesired :
|
||||
VelDesired - fVelMinus) &&
|
||||
@@ -8773,15 +8795,19 @@ void TController::control_uphill_start() {
|
||||
&& ( false == is_emu() ) && ( false == is_dmu() ) // a multiple unit has no locomotive to hold a train behind it
|
||||
&& ( fAccGravity < EU07_AI_UPHILLGRAVITY ) };
|
||||
false == uphill ) {
|
||||
bUphillStart = false;
|
||||
end_uphill_start();
|
||||
return;
|
||||
}
|
||||
if( false == bUphillStart ) {
|
||||
if( ( std::abs( velocity ) < EU07_AI_NOMOVEMENT )
|
||||
// the whole train at a stand, not only its head stopped for a moment while the train rolls back
|
||||
&& ( fConsistVelocity > -0.5 )
|
||||
&& ( AccDesired > EU07_AI_NOACCELERATION )
|
||||
&& ( VelDesired > 0.0 )
|
||||
&& ( BrakeCtrlPosition > 0.0 ) ) { // only with the train brake still applied to hold the train
|
||||
bUphillStart = true;
|
||||
bUphillRelease = false;
|
||||
UphillTopUp = {};
|
||||
fUphillStartTime = ElapsedTime;
|
||||
}
|
||||
else {
|
||||
@@ -8790,31 +8816,86 @@ void TController::control_uphill_start() {
|
||||
}
|
||||
if( AccDesired <= EU07_AI_NOACCELERATION ) {
|
||||
// no longer to start: the standing rules take over
|
||||
bUphillStart = false;
|
||||
end_uphill_start();
|
||||
return;
|
||||
}
|
||||
if( velocity < -0.5 ) {
|
||||
// rolling back all the same: the rules for a train slipping back take over and apply the brakes
|
||||
bUphillStart = false;
|
||||
if( fConsistVelocity < -0.5 ) {
|
||||
// the train rolls back all the same: the rules for a train slipping back take over and apply the brakes.
|
||||
// the train as a whole, not its head: with the locomotive brake off, the locomotive and the first vehicles
|
||||
// run back into the slack of a long train still held by its brake
|
||||
end_uphill_start();
|
||||
return;
|
||||
}
|
||||
if( ( mvOccupied->LocalBrake != TLocalBrake::ManualBrake )
|
||||
&& ( mvOccupied->LocalBrakePosA > 0.0 ) ) {
|
||||
cue_action( driver_hint::independentbrakerelease );
|
||||
}
|
||||
auto tractiveforce { 0.0 };
|
||||
fUphillTractiveForce = 0.0;
|
||||
for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) {
|
||||
// Ft is signed in the vehicle's own frame
|
||||
tractiveforce += std::max( 0.0, vehicle->MoverParameters->Ft * ( vehicle->DirectionGet() == iDirection ? 1 : -1 ) );
|
||||
// Ft is signed in the vehicle's own frame, and turned into the direction of travel as AbsAccS is
|
||||
fUphillTractiveForce += std::max( 0.0, vehicle->MoverParameters->Ft * ( vehicle->DirectionGet() == iDirection ? 1 : -1 ) * ( iDirection >= 0 ? 1 : -1 ) );
|
||||
}
|
||||
auto const holdingforce { fMass * -fAccGravity };
|
||||
if( ( velocity > 1.0 )
|
||||
|| ( tractiveforce > 1.1 * holdingforce )
|
||||
// a locomotive that can't hold the train on its own power gets the brake off in the end all the same
|
||||
|| ( ElapsedTime - fUphillStartTime > 45.0 ) ) {
|
||||
// the power holds the train: the train brake can be released
|
||||
bUphillStart = false;
|
||||
fUphillHoldingForce = fMass * -fAccGravity;
|
||||
bUphillBrakeTopUp = false;
|
||||
if( false == bUphillRelease ) {
|
||||
bUphillBrakeTopUp = uphill_brake_top_up();
|
||||
if( bUphillBrakeTopUp ) {
|
||||
return;
|
||||
}
|
||||
if( ( mvOccupied->LocalBrake != TLocalBrake::ManualBrake )
|
||||
&& ( mvOccupied->LocalBrakePosA > 0.0 ) ) {
|
||||
cue_action( driver_hint::independentbrakerelease );
|
||||
}
|
||||
if( ( velocity > 1.0 )
|
||||
|| ( fUphillTractiveForce > uphill_start::holding_force * fUphillHoldingForce )
|
||||
// a locomotive that can't hold the train on its own power gets the brake off in the end all the same
|
||||
|| ( ElapsedTime - fUphillStartTime > 45.0 ) ) {
|
||||
// the power holds the train: the train brake can be released
|
||||
bUphillRelease = true;
|
||||
fUphillReleaseTime = ElapsedTime;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// the train brake is being released with the power on. the start ends once the brakes are off: ended before,
|
||||
// the brake still on takes the power off, the train rolls back and has to be braked to a stand again
|
||||
if( IsConsistReleased
|
||||
// a brake that doesn't come off (a hand brake) ends it all the same
|
||||
|| ( ElapsedTime - fUphillReleaseTime > EU07_AI_UPHILLRELEASETIME ) ) {
|
||||
end_uphill_start();
|
||||
}
|
||||
}
|
||||
|
||||
// the locomotive brake comes off only once the brake of the rest of the train holds the train on its own: a train
|
||||
// stopped on a light application stands on the locomotive brake too, and rolls back as soon as it is off. until then
|
||||
// the train brake is applied further, a step at a time; true while it is
|
||||
bool TController::uphill_brake_top_up() {
|
||||
|
||||
auto trainbrakeforce { 0.0 };
|
||||
auto haswagons { false };
|
||||
for( auto const *vehicle { pVehicles[ end::front ] }; vehicle != nullptr; vehicle = vehicle->Next() ) {
|
||||
if( vehicle->MoverParameters->Power < 0.01 ) {
|
||||
trainbrakeforce += vehicle->MoverParameters->Fb;
|
||||
haswagons = true;
|
||||
}
|
||||
}
|
||||
if( false == haswagons ) {
|
||||
return false;
|
||||
}
|
||||
auto const action { uphill_start::brake_top_up(
|
||||
UphillTopUp, trainbrakeforce, fUphillHoldingForce, BrakeCtrlPosition, fBrakeHeldTime,
|
||||
mvOccupied->BrakeDelay[ mvOccupied->BrakeDelayFlag > bdelay_G ? 1 : 3 ] ) };
|
||||
if( action == uphill_start::top_up_action::none ) {
|
||||
return false;
|
||||
}
|
||||
// the time for the power to hold the train starts once the brake does
|
||||
fUphillStartTime = ElapsedTime;
|
||||
if( action == uphill_start::top_up_action::step ) {
|
||||
BrakeLevelAdd( BrakingLevelIncrease );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TController::end_uphill_start() {
|
||||
|
||||
bUphillStart = false;
|
||||
bUphillRelease = false;
|
||||
bUphillBrakeTopUp = false;
|
||||
}
|
||||
|
||||
void TController::increase_tractive_force() {
|
||||
@@ -8888,10 +8969,17 @@ void TController::control_braking_force() {
|
||||
if( TestFlag( iDrivigFlags, movePress ) ) { return; }
|
||||
|
||||
auto const velocity { DirectionalVel() };
|
||||
// a train slipping back uphill is braked, also when it is to go on: released now it only rolls back further.
|
||||
// its head, or the train as a whole: the locomotive may stop for a moment while the rest of the train runs into it
|
||||
auto const slippingbackuphill {
|
||||
( fAccGravity < -0.05 )
|
||||
&& ( std::min( velocity, fConsistVelocity ) < -0.1 )
|
||||
&& ( false == bUphillStart ) };
|
||||
|
||||
// jeśli przyspieszamy, to nie hamujemy
|
||||
if( AccDesired > 0.0 && OrderCurrentGet() != Disconnect // przy odłączaniu nie zwalniamy tu hamulca
|
||||
&& false == TestFlag(iDrivigFlags, movePress) ) {
|
||||
&& false == TestFlag(iDrivigFlags, movePress)
|
||||
&& false == slippingbackuphill ) {
|
||||
cue_action(driver_hint::brakingforcesetzero);
|
||||
}
|
||||
|
||||
@@ -8946,7 +9034,7 @@ void TController::control_braking_force() {
|
||||
else {
|
||||
// a stara wersja w miarę dobrze działa na składy wagonowe
|
||||
if( (accdesiredresultant < fAccGravity - 0.1 && AbsAccS > accdesiredresultant + brake_increase_margin() // regular braking
|
||||
|| fAccGravity < -0.05 && velocity < -0.1 && false == bUphillStart) && // also brake if uphill and slipping back
|
||||
|| slippingbackuphill) && // also brake if uphill and slipping back
|
||||
(fBrakeTime < 0.0
|
||||
// the size of the brake demand decides whether to skip the reaction time, so the brake-only part
|
||||
// (on a descent a heavy train needs its brake built up at once, the gravity does not help it slow)
|
||||
|
||||
@@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "world/mtable.h"
|
||||
#include "utilities/translation.h"
|
||||
#include "application/driverhints.h"
|
||||
#include "vehicle/uphillstart.h"
|
||||
#include "vehicle/blackbox.h"
|
||||
|
||||
auto const EU07_AI_ACCELERATION = 0.05;
|
||||
@@ -27,6 +28,7 @@ auto const EU07_AI_BRAKINGTESTACCELERATION = -0.06;
|
||||
auto const EU07_AI_NOMOVEMENT = 0.05; // standstill velocity threshold
|
||||
auto const EU07_AI_MOVEMENT = 1.0; // deliberate movement velocity threshold
|
||||
auto const EU07_AI_UPHILLGRAVITY = -0.025; // [m/s2] about 2.5 per mille up: the gradient that rolls a standing train back
|
||||
auto const EU07_AI_UPHILLRELEASETIME = 60.0; // [s] the longest an uphill start keeps the power on while the train brake releases
|
||||
auto const EU07_AI_SPEEDLIMITEXTENDSBEYONDSCANRANGE = 10000.0;
|
||||
|
||||
enum TOrders
|
||||
@@ -337,6 +339,8 @@ private:
|
||||
bool uphill_stop_hold() const;
|
||||
bool uphill_brake_committed( double const Velocity ) const;
|
||||
void control_uphill_start();
|
||||
void end_uphill_start();
|
||||
bool uphill_brake_top_up();
|
||||
std::pair<double, double> train_proximity_margins( bool const Passengerstop ) const;
|
||||
|
||||
void update_timers( double const dt );
|
||||
@@ -441,6 +445,14 @@ private:
|
||||
int iShortfallGrowth = 0; // how many checks in a row the shortfall has grown
|
||||
bool bUphillStart = false; // starting uphill: the train brake holds the train until the power does
|
||||
double fUphillStartTime = 0.0; // when the uphill start began
|
||||
bool bUphillRelease = false; // starting uphill, the power holds the train and the train brake is being released
|
||||
bool bUphillBrakeTopUp = false; // starting uphill, the train brake is applied further before the locomotive brake comes off
|
||||
uphill_start::top_up UphillTopUp; // starting uphill, what has been done to apply the train brake further
|
||||
double fUphillReleaseTime = 0.0; // when the release began
|
||||
double fUphillTractiveForce = 0.0; // the tractive force of the consist while starting uphill [N]
|
||||
double fUphillHoldingForce = 0.0; // the grade force on the consist while starting uphill [N]
|
||||
bool IsConsistReleased = true; // the brakes of the consist are off, the hold of an uphill start not counted
|
||||
double fConsistVelocity = 0.0; // the mass-weighted speed of the consist, positive in the direction of travel [km/h]
|
||||
double fAccDesiredGravity = 0.0; // część AccDesired odjęta na spadku jako kompensacja pochylenia; AbsAccS zawiera ją już sam
|
||||
double VelforDriver = -1.0; // prędkość, używana przy zmianie kierunku (ograniczenie przy nieznajmości szlaku?)
|
||||
double VelSignal = 0.0; // ograniczenie prędkości z kompilacji znaków i sygnałów // normalnie na początku ma stać, no chyba że jedzie
|
||||
|
||||
36
vehicle/uphillstart.cpp
Normal file
36
vehicle/uphillstart.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "vehicle/uphillstart.h"
|
||||
|
||||
namespace uphill_start {
|
||||
|
||||
top_up_action brake_top_up(
|
||||
top_up &State, double const Brakeforce, double const Holdingforce, double const Brakeposition, double const Heldtime,
|
||||
double const Applicationtime) {
|
||||
|
||||
if (State.done || (Brakeforce >= holding_force * Holdingforce) || (Brakeposition >= top_up_position)) {
|
||||
return top_up_action::none;
|
||||
}
|
||||
// each step is given the full application time of the train brake, for the cylinders along the train to fill
|
||||
if (Heldtime < Applicationtime) {
|
||||
return top_up_action::wait;
|
||||
}
|
||||
if ((State.last_force >= 0.0) && (Brakeforce - State.last_force < top_up_gain * Holdingforce)) {
|
||||
// the last step added next to nothing: the brake of this train can't hold it (brakes cut out, a load setting
|
||||
// too low), and the start goes on without
|
||||
State.done = true;
|
||||
return top_up_action::none;
|
||||
}
|
||||
State.last_force = Brakeforce;
|
||||
return top_up_action::step;
|
||||
}
|
||||
|
||||
} // namespace uphill_start
|
||||
41
vehicle/uphillstart.h
Normal file
41
vehicle/uphillstart.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// starting uphill (TController::control_uphill_start()), the AI's driver lets the locomotive brake off only once
|
||||
// the brake of the rest of the train holds the train on its own: a train stopped on a light application stands on
|
||||
// the locomotive brake too, and rolls back as soon as it is off. until then the train brake is applied further, a
|
||||
// step at a time
|
||||
namespace uphill_start {
|
||||
|
||||
auto const holding_force{1.1}; // a force that holds a train uphill, as a multiple of the grade force
|
||||
auto const top_up_position{4.0}; // full service: the furthest the train brake is applied to hold the train
|
||||
// a step that adds less brake force than this, as a multiple of the grade force, is the last one
|
||||
auto const top_up_gain{0.02};
|
||||
|
||||
// what has been done to apply the train brake further, in one start
|
||||
struct top_up {
|
||||
double last_force{-1.0}; // the brake force when the last step was given, -1 before the first [N]
|
||||
bool done{false}; // a step added next to nothing: no more of them in this start
|
||||
};
|
||||
|
||||
enum class top_up_action {
|
||||
none, // the brake holds the train, or can't be made to: the start goes on
|
||||
wait, // the cylinders are still filling after the last step
|
||||
step // apply the train brake one step further
|
||||
};
|
||||
|
||||
// Brakeforce: the brake force of the unpowered vehicles [N]; Holdingforce: the grade force on the train [N];
|
||||
// Brakeposition: the train brake handle, as BrakeCtrlPosition; Heldtime: how long the handle has been where it
|
||||
// is [s]; Applicationtime: the time the train brake takes to apply, for the cylinders along the train to fill [s]
|
||||
top_up_action brake_top_up(
|
||||
top_up &State, double Brakeforce, double Holdingforce, double Brakeposition, double Heldtime, double Applicationtime);
|
||||
|
||||
} // namespace uphill_start
|
||||
Reference in New Issue
Block a user