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

AI uses pneumatic brake in EMUs when pulling non-ep-brake vehicles

This commit is contained in:
Królik Uszasty
2020-10-24 17:30:09 +02:00
parent d6b650c87e
commit 40cc1cf083
5 changed files with 98 additions and 19 deletions

View File

@@ -1996,8 +1996,8 @@ void TController::Activation()
}
ControllingSet(); // utworzenie połączenia do sterowanego pojazdu (może się zmienić) - silnikowy dla EZT
if( ( mvOccupied->BrakeCtrlPosNo > 0 )
&& ( ( mvOccupied->BrakeSystem == TBrakeSystem::Pneumatic )
|| ( mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ) ) ) {
&& ( ( BrakeSystem == TBrakeSystem::Pneumatic )
|| ( BrakeSystem == TBrakeSystem::ElectroPneumatic ) ) ) {
mvOccupied->LimPipePress = mvOccupied->PipePress;
mvOccupied->ActFlowSpeed = 0;
}
@@ -2126,6 +2126,7 @@ void TController::AutoRewident()
}
// potentially release manual brake
d->MoverParameters->DecManualBrakeLevel( ManualBrakePosNo );
d->MoverParameters->SpringBrake.Activate = false;
}
d = d->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła)
}
@@ -2217,6 +2218,31 @@ void TController::AutoRewident()
}
fAccThreshold = fNominalAccThreshold;
}
BrakeSystem = mvOccupied->BrakeSystem;
if (BrakeSystem == TBrakeSystem::ElectroPneumatic)
{
bool fullep = true;
if (pVehicles[end::front] != pVehicles[end::rear]) {
// more detailed version, will use manual braking also for coupled sets of controlled vehicles
auto *vehicle = pVehicles[end::front]; // start from first
while ((true == fullep)
&& (vehicle != nullptr)) {
// NOTE: we could simplify this by doing only check of the rear coupler, but this can be quite tricky in itself
// TODO: add easier ways to access front/rear coupler taking into account vehicle's direction
fullep =
(((vehicle->MoverParameters->Couplers[end::front].Connected == nullptr)
|| ((vehicle->MoverParameters->Couplers[end::front].CouplingFlag & coupling::control)
&& (vehicle->MoverParameters->Couplers[end::front].Connected->Power > -1)))
&& ((vehicle->MoverParameters->Couplers[end::rear].Connected == nullptr)
|| ((vehicle->MoverParameters->Couplers[end::rear].CouplingFlag & coupling::control)
&& (vehicle->MoverParameters->Couplers[end::rear].Connected->Power > -1))));
vehicle = vehicle->Next(); // kolejny pojazd, podłączony od tyłu (licząc od czoła)
}
}
if (!fullep) BrakeSystem = TBrakeSystem::Pneumatic;
mvOccupied->EpFuseSwitch( fullep );
}
}
double TController::ESMVelocity(bool Main)
@@ -2966,7 +2992,9 @@ bool TController::ReleaseEngine() {
bool TController::IncBrake()
{ // zwiększenie hamowania
bool OK = false;
switch( mvOccupied->BrakeSystem ) {
TBrakeSystem bs = BrakeSystem == TBrakeSystem::ElectroPneumatic && ForcePNBrake ?
TBrakeSystem::Pneumatic : BrakeSystem;
switch( bs ) {
case TBrakeSystem::Individual: {
if( mvOccupied->LocalBrake == TLocalBrake::ManualBrake ) {
OK = mvOccupied->IncManualBrakeLevel( 1 + static_cast<int>( std::floor( 0.5 + std::fabs( AccDesired ) ) ) );
@@ -2977,6 +3005,13 @@ bool TController::IncBrake()
break;
}
case TBrakeSystem::Pneumatic: {
if (bs != mvOccupied->BrakeSystem)
{
while (mvOccupied->BrakeOpModeFlag > bom_PN)
{
mvOccupied->BrakeOpModeFlag >>= 1;
}
}
// NOTE: can't perform just test whether connected vehicle == nullptr, due to virtual couplers formed with nearby vehicles
bool standalone { true };
if( ( mvOccupied->TrainType == dt_ET41 )
@@ -3028,7 +3063,7 @@ bool TController::IncBrake()
//standalone = standalone && ( mvControlling->EIMCtrlType == 0 );
if( true == standalone ) {
if( true == standalone && false == ForcePNBrake ) {
if( mvControlling->EIMCtrlType > 0 ) {
OK = IncBrakeEIM();
}
@@ -3106,6 +3141,10 @@ bool TController::IncBrake()
break;
}
case TBrakeSystem::ElectroPneumatic: {
while ((mvOccupied->BrakeOpModeFlag << 1) <= mvOccupied->BrakeOpModes)
{
mvOccupied->BrakeOpModeFlag <<= 1;
}
if( mvOccupied->EngineType == TEngineType::ElectricInductionMotor ) {
if (mvOccupied->BrakeHandle == TBrakeHandle::MHZ_EN57) {
if (mvOccupied->BrakeCtrlPos < mvOccupied->Handle->GetPos(bh_FB))
@@ -3194,7 +3233,9 @@ bool TController::DecBrake()
bool OK = false;
double deltaAcc = -1.0;
double pos_diff = 1.0;
switch (mvOccupied->BrakeSystem)
TBrakeSystem bs = BrakeSystem == TBrakeSystem::ElectroPneumatic && ForcePNBrake ?
TBrakeSystem::Pneumatic : BrakeSystem;
switch (bs)
{
case TBrakeSystem::Individual:
if (mvOccupied->LocalBrake == TLocalBrake::ManualBrake)
@@ -3928,7 +3969,7 @@ void TController::SpeedCntrl(double DesiredSpeed)
void TController::SetTimeControllers()
{
//1. Check the type of Main Brake Handle
if (mvOccupied->BrakeSystem == TBrakeSystem::Pneumatic)
if (BrakeSystem == TBrakeSystem::Pneumatic)
{
if (mvOccupied->Handle->Time)
{
@@ -3944,7 +3985,8 @@ void TController::SetTimeControllers()
mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_NP));
}
if (mvOccupied->BrakeHandle == TBrakeHandle::FV4a) mvOccupied->BrakeLevelSet(BrakeCtrlPosition);
if (mvOccupied->BrakeHandle == TBrakeHandle::MHZ_K8P)
if ((mvOccupied->BrakeHandle == TBrakeHandle::MHZ_K8P)
|| (mvOccupied->BrakeHandle == TBrakeHandle::MHZ_EN57))
{
if (BrakeCtrlPosition == 0)
mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_RP));
@@ -4129,11 +4171,11 @@ void TController::SetTimeControllers()
void TController::CheckTimeControllers()
{
//1. Check the type of Main Brake Handle
if (mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic && mvOccupied->Handle->TimeEP)
if (BrakeSystem == TBrakeSystem::ElectroPneumatic && mvOccupied->Handle->TimeEP)
{
mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_EPN));
}
if (mvOccupied->BrakeSystem == TBrakeSystem::Pneumatic && mvOccupied->Handle->Time)
if (BrakeSystem == TBrakeSystem::Pneumatic && mvOccupied->Handle->Time)
{
if (BrakeCtrlPosition > 0)
mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_MB));
@@ -5861,7 +5903,7 @@ TController::UpdateSituation(double dt) {
// powino zostać wyłączone)
// WriteLog("Zahamowanie składu");
AccDesired = std::min( AccDesired, -0.9 ); // HACK: make sure the ai doesn't try to release the brakes to accelerate
if( mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ) {
if( BrakeSystem == TBrakeSystem::ElectroPneumatic ) {
mvOccupied->BrakeLevelSet( mvOccupied->Handle->GetPos( bh_EPB ) );
}
else {
@@ -5873,11 +5915,11 @@ TController::UpdateSituation(double dt) {
// TODO: zabezpieczenie przed dziwnymi CHK do czasu wyjaśnienia sensu 0 oraz -1 w tym miejscu
p = 3.9;
}
if (mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ?
if (BrakeSystem == TBrakeSystem::ElectroPneumatic ?
mvOccupied->BrakePress > 2 :
mvOccupied->PipePress < p + 0.1)
{ // jeśli w miarę został zahamowany (ciśnienie mniejsze niż podane na pozycji 3, zwyle 0.37)
if( mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ) {
if( BrakeSystem == TBrakeSystem::ElectroPneumatic ) {
// wyłączenie EP, gdy wystarczy (może nie być potrzebne, bo na początku jest)
mvOccupied->BrakeLevelSet( 0 );
}
@@ -6548,7 +6590,7 @@ TController::UpdateSituation(double dt) {
ReactionTime = 0.25;
}
}
if (mvOccupied->BrakeSystem == TBrakeSystem::Pneumatic) {
if (BrakeSystem == TBrakeSystem::Pneumatic) {
// napełnianie uderzeniowe
if( ( mvOccupied->BrakeHandle == TBrakeHandle::FV4a )
|| ( mvOccupied->BrakeHandle == TBrakeHandle::MHZ_6P )
@@ -7662,6 +7704,7 @@ void TController::ControllingSet()
// dzięki temu będzie wirtualna kabina w silnikowym, działająca w rozrządczym
// w plikach FIZ zostały zgubione ujemne maski sprzęgów, stąd problemy z EZT
mvOccupied = pVehicle->MoverParameters; // domyślny skrót do obiektu parametrów
BrakeSystem = mvOccupied->BrakeSystem; // domyślny sposób hamowania
mvControlling = pVehicle->FindPowered()->MoverParameters; // poszukiwanie członu sterowanego
{
auto *lookup { pVehicle->FindPantographCarrier() };

View File

@@ -347,6 +347,10 @@ private:
double ReactionTime = 0.0; // czas reakcji Ra: czego i na co? świadomości AI
double fBrakeTime = 0.0; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca
double BrakeChargingCooldown{}; // prevents the ai from trying to charge the train brake too frequently
TBrakeSystem BrakeSystem = TBrakeSystem::Individual; //type of main brake
bool ForcePNBrake = false; //is it necessary to use PN brake instead of EP brake
int DynamicBrakeTest = 0; //is it necessary to make brake test while driving
int StaticBrakeTest = 0; //is it necessary to make brake test while standing
double LastReactionTime = 0.0;
double fActionTime = 0.0; // czas używany przy regulacji prędkości i zamykaniu drzwi
double m_radiocontroltime{ 0.0 }; // timer used to control speed of radio operations

View File

@@ -3877,7 +3877,7 @@ bool TMoverParameters::SwitchEPBrake(int state)
if ((BrakeHandle == TBrakeHandle::St113) && (CabOccupied != 0))
{
if (state > 0)
temp = Handle->GetCP(); // TODO: przetlumaczyc
temp = Handle->GetEP(); // TODO: przetlumaczyc
else
temp = 0;
Hamulec->SetEPS(temp);
@@ -4422,7 +4422,7 @@ void TMoverParameters::UpdatePipePressure(double dt)
&& (DirActive != 0)
&& (EpFuse)) // tu powinien byc jeszcze bezpiecznik EP i baterie -
// temp = (Handle as TFVel6).GetCP
temp = Handle->GetCP();
temp = Handle->GetEP();
else
temp = 0.0;

View File

@@ -2282,6 +2282,11 @@ double TDriverHandle::GetCP()
return 0;
}
double TDriverHandle::GetEP()
{
return 0;
}
double TDriverHandle::GetSound(int i)
{
return 0;
@@ -3133,6 +3138,8 @@ double TSt113::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double ActFlowSpeed;
int BCP;
CP = PP;
BCP = lround(i_bcp);
EPS = BEP_K[BCP];
@@ -3169,7 +3176,12 @@ double TSt113::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double TSt113::GetCP()
{
return EPS;
return CP;
}
double TSt113::GetEP()
{
return EPS;
}
double TSt113::GetPos(int i)
@@ -3301,6 +3313,8 @@ double TFVel6::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double dpMainValve;
double ActFlowSpeed;
CP = PP;
LimPP = Min0R(5 * int(i_bcp < 3.5), HP);
if ((i_bcp >= 3.5) && ((i_bcp < 4.3) || (i_bcp > 5.5)))
ActFlowSpeed = 0;
@@ -3334,7 +3348,12 @@ double TFVel6::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double TFVel6::GetCP()
{
return EPS;
return CP;
}
double TFVel6::GetEP()
{
return EPS;
}
double TFVel6::GetPos(int i)
@@ -3366,6 +3385,8 @@ double TFVE408::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double dpMainValve;
double ActFlowSpeed;
CP = PP;
LimPP = Min0R(5 * int(i_bcp < 6.5), HP);
if ((i_bcp >= 6.5) && ((i_bcp < 7.5) || (i_bcp > 9.5)))
ActFlowSpeed = 0;
@@ -3398,6 +3419,11 @@ double TFVE408::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
}
double TFVE408::GetCP()
{
return CP;
}
double TFVE408::GetEP()
{
return EPS;
}

View File

@@ -541,6 +541,7 @@ class TDriverHandle {
virtual double GetPF(double i_bcp, double PP, double HP, double dt, double ep);
virtual void Init(double Press);
virtual double GetCP();
virtual double GetEP();
virtual void SetReductor(double nAdj); //korekcja pozycji reduktora cisnienia
virtual double GetSound(int i); //pobranie glosnosci wybranego dzwieku
virtual double GetPos(int i); //pobranie numeru pozycji o zadanym kodzie (funkcji)
@@ -617,7 +618,7 @@ class TMHZ_EN57 : public TDriverHandle {
double GetSound(int i)/*override*/;
double GetPos(int i)/*override*/;
double GetCP()/*override*/;
double GetEP(double pos);
double GetEP(double pos);
void SetParams(bool AO, bool MO, double OverP, double, double OMP, double OPD);
inline TMHZ_EN57(void) :
TDriverHandle()
@@ -762,10 +763,11 @@ class TSt113 : public TH14K1 {
static double const BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2];
static double const BEP_K[/*?*/ /*-1..5*/ (5) - (-1) + 1];
static double const pos_table[11]; // = {-1, 5, -1, 0, 2, 3, 4, 5, 0, 0, 1};
double CP = 0;
public:
double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/;
double GetCP()/*override*/;
double GetEP()/*override*/;
double GetPos(int i)/*override*/;
void Init(double Press)/*override*/;
@@ -830,10 +832,12 @@ class TFVel6 : public TDriverHandle {
private:
double EPS = 0.0;
static double const pos_table[ 11 ]; // = {-1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1};
double CP = 0.0;
public:
double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/;
double GetCP()/*override*/;
double GetEP()/*override*/;
double GetPos(int i)/*override*/;
double GetSound(int i)/*override*/;
void Init(double Press)/*override*/;
@@ -848,10 +852,12 @@ class TFVE408 : public TDriverHandle {
private:
double EPS = 0.0;
static double const pos_table[11]; // = {-1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1};
double CP = 0.0;
public:
double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/;
double GetCP()/*override*/;
double GetEP()/*override*/;
double GetPos(int i)/*override*/;
double GetSound(int i)/*override*/;
void Init(double Press)/*override*/;