18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 06:12:41 +01:00

refactor(physics): the definition of the brakes apart from their state

What the .fiz gives about the brakes of a vehicle (the kinds of the brake
system, the valves and the handles, the cylinders and the rigging, the pipe
pressures, the delays and the modes it can be set to: 35 fields) moves into
physics::Braking::Config, held as brakes.config, set as the vehicle loads and
not changed after. Six fields that sat with the definition but change in the
run (the weighted pressures of the handle position, the universal buttons
pressed, the load setting, the control reservoir, the emergency valve, the
lock of the pipe) go with the state.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 10:36:09 +01:00
parent 447fe54f3d
commit 2d67e9b1a3
42 changed files with 485 additions and 481 deletions
+56 -56
View File
@@ -46,13 +46,13 @@ void physics::Vehicle::BrakeLevelSet(double b)
brakes.handlePositionReal = brakes.handlePositionSmooth;
auto x = static_cast<int>(std::floor(brakes.handlePositionSmooth)); // jeśli odwołujemy się do BrakeCtrlPos w pośrednich, to musi być
// obcięte a nie zaokrągone
while (x > brakes.handlePosition && brakes.handlePosition < brakes.handlePositions) // jeśli zwiększyło się o 1
while (x > brakes.handlePosition && brakes.handlePosition < brakes.config.handlePositions) // jeśli zwiększyło się o 1
if (!IncBrakeLevelOld()) // physics::Vehicle::
break; // wyjście awaryjne
while (x < brakes.handlePosition && brakes.handlePosition >= -1) // jeśli zmniejszyło się o 1
if (!DecBrakeLevelOld()) // physics::Vehicle::
break;
brakes.actualPressure = brakes.pressureTable[brakes.handlePosition]; // skopiowanie pozycji
brakes.actualPressure = brakes.config.pressureTable[brakes.handlePosition]; // skopiowanie pozycji
/*
//youBy: obawiam sie, ze tutaj to nie dziala :P
//Ra 2014-03: było tak zrobione, że działało - po każdej zmianie pozycji była wywoływana ta
@@ -77,7 +77,7 @@ bool physics::Vehicle::BrakeLevelAdd(double b)
{ // dodanie wartości (b) do pozycji hamulca (w tym ujemnej)
// zwraca false, gdy po dodaniu było by poza zakresem
BrakeLevelSet(brakes.handlePositionSmooth + b);
return b > 0.0 ? brakes.handlePositionSmooth < brakes.handlePositions : brakes.handlePosition > -1.0; // true, jeśli można kontynuować
return b > 0.0 ? brakes.handlePositionSmooth < brakes.config.handlePositions : brakes.handlePosition > -1.0; // true, jeśli można kontynuować
};
bool physics::Vehicle::IncBrakeLevel()
@@ -136,7 +136,7 @@ ZN //masa
double physics::Vehicle::LocalBrakeRatio(void) const
{
double LBR;
if (brakes.driverValveType == TBrakeHandle::MHZ_EN57)
if (brakes.config.driverValveType == TBrakeHandle::MHZ_EN57)
if (brakes.operatingMode >= bom_EP)
LBR = brakes.driverValve->GetEP(brakes.handlePositionReal);
else
@@ -174,8 +174,8 @@ double physics::Vehicle::ManualBrakeRatio(void) const
// *****************************************************************************
double physics::Vehicle::BrakeVP(void) const
{
if (brakes.valveVolume > 0)
return brakes.reservoirAir / (10.0 * brakes.valveVolume);
if (brakes.config.valveVolume > 0)
return brakes.reservoirAir / (10.0 * brakes.config.valveVolume);
else
return 0;
}
@@ -188,8 +188,8 @@ double physics::Vehicle::RealPipeRatio(void) const
{
double rpp;
if (brakes.pipePressureRange > 0)
rpp = (brakes.controlReservoirPressure - brakePipe.Pressure()) / brakes.pipePressureRange;
if (brakes.config.pipePressureRange > 0)
rpp = (brakes.controlReservoirPressure - brakePipe.Pressure()) / brakes.config.pipePressureRange;
else
rpp = 0;
return rpp;
@@ -203,13 +203,13 @@ double physics::Vehicle::PipeRatio(void) const
{
double pr;
if (brakes.pipePressureRange > 0)
if (brakes.config.pipePressureRange > 0)
if (false) // SPKS!! no to jak nie wchodzimy to po co branch?
{
if (3.0 * brakePipe.Pressure() > brakes.pipeHighPressure + brakes.pipeLowPressure + brakes.pipeLowPressure)
pr = (brakes.pipeHighPressure - std::min(brakes.pipeHighPressure, brakePipe.Pressure())) / (brakes.pipePressureRange * 4.0 / 3.0);
if (3.0 * brakePipe.Pressure() > brakes.config.pipeHighPressure + brakes.config.pipeLowPressure + brakes.config.pipeLowPressure)
pr = (brakes.config.pipeHighPressure - std::min(brakes.config.pipeHighPressure, brakePipe.Pressure())) / (brakes.config.pipePressureRange * 4.0 / 3.0);
else
pr = (brakes.pipeHighPressure - 1.0 / 3.0 * brakes.pipePressureRange - std::max(brakes.pipeLowPressure, brakePipe.Pressure())) / (brakes.pipePressureRange * 2.0 / 3.0);
pr = (brakes.config.pipeHighPressure - 1.0 / 3.0 * brakes.config.pipePressureRange - std::max(brakes.config.pipeLowPressure, brakePipe.Pressure())) / (brakes.config.pipePressureRange * 2.0 / 3.0);
// if (not TestFlag(BrakeStatus, b_Ractive))
// and(BrakeMethod and 1 = 0) and TestFlag(BrakeDelays, bdelay_R) and (Power < 1) and
// (BrakeCtrlPos < 1) then pr : = std::min(0.5, pr);
@@ -217,7 +217,7 @@ double physics::Vehicle::PipeRatio(void) const
// then pr : = pr * 1.333; // dziwny rapid wywalamy
}
else
pr = (brakes.pipeHighPressure - std::max(brakes.pipeLowPressure, std::min(brakes.pipeHighPressure, brakePipe.Pressure()))) / brakes.pipePressureRange;
pr = (brakes.config.pipeHighPressure - std::max(brakes.config.pipeLowPressure, std::min(brakes.config.pipeHighPressure, brakePipe.Pressure()))) / brakes.config.pipePressureRange;
else
pr = 0;
return pr;
@@ -352,14 +352,14 @@ bool physics::Vehicle::IncBrakeLevelOld(void)
{
bool IBLO = false;
if (brakes.handlePositions > 0)
if (brakes.config.handlePositions > 0)
{
if (brakes.handlePosition < brakes.handlePositions)
if (brakes.handlePosition < brakes.config.handlePositions)
{
++brakes.handlePosition;
// youBy: EP po nowemu
IBLO = true;
if (brakes.actualPressure.PipePressureVal < 0 && brakes.pressureTable[brakes.handlePosition - 1].PipePressureVal > 0)
if (brakes.actualPressure.PipePressureVal < 0 && brakes.config.pressureTable[brakes.handlePosition - 1].PipePressureVal > 0)
brakes.pipeLimiterPressure = brakePipe.Pressure();
}
else
@@ -379,9 +379,9 @@ bool physics::Vehicle::DecBrakeLevelOld(void)
{
bool DBLO = false;
if (brakes.handlePositions > 0)
if (brakes.config.handlePositions > 0)
{
if (brakes.handlePosition > (brakes.driverValveType == TBrakeHandle::FV4a ? -2 : -1))
if (brakes.handlePosition > (brakes.config.driverValveType == TBrakeHandle::FV4a ? -2 : -1))
{
--brakes.handlePosition;
// youBy: EP po nowemu
@@ -499,7 +499,7 @@ bool physics::Vehicle::AlarmChainSwitch(bool const State)
bool physics::Vehicle::AntiSlippingBrake(void)
{
bool ASB = false; // Ra: przeniesione z końca
if (brakes.antiSlipType == 1)
if (brakes.config.antiSlipType == 1)
{
ASB = true; // SPKS!!
brakes.distributor->ASB(1);
@@ -545,7 +545,7 @@ bool physics::Vehicle::UniversalBrakeButton(int button, int state)
{
for (int i = 0; i < 3; i++)
{
flag = flag | (brakes.universalButtonPressed[i] ? brakes.universalButtonActions[i] : 0);
flag = flag | (brakes.universalButtonPressed[i] ? brakes.config.universalButtonActions[i] : 0);
}
}
@@ -555,7 +555,7 @@ bool physics::Vehicle::UniversalBrakeButton(int button, int state)
brakes.pipeLock.unlockPressed = (flag & TUniversalBrake::ub_UnlockPipe) > 0;
// if the releaser can be activated by switch
if (TestFlag(brakes.universalButtonActions[0] & brakes.universalButtonActions[1] & brakes.universalButtonActions[2], TUniversalBrake::ub_Release))
if (TestFlag(brakes.config.universalButtonActions[0] & brakes.config.universalButtonActions[1] & brakes.config.universalButtonActions[2], TUniversalBrake::ub_Release))
{
BrakeReleaser(TestFlag(flag, TUniversalBrake::ub_Release) ? 1 : 0);
}
@@ -571,7 +571,7 @@ bool physics::Vehicle::SwitchEPBrake(int state)
bool OK;
OK = false;
if (brakes.driverValveType == TBrakeHandle::St113 && CabOccupied != 0)
if (brakes.config.driverValveType == TBrakeHandle::St113 && CabOccupied != 0)
{
// the handle works the EP contactors pneumatically, their supply is cut as the Oerlikon handle's is
if (state > 0 && EPBrakeControlPowered())
@@ -676,15 +676,15 @@ bool physics::Vehicle::IncBrakeMult(void)
{
bool IBM;
if (brakes.loadSetting > 0 && brakes.maxPressureMass < 2 && brakes.loadSetting < 3)
if (brakes.loadSetting > 0 && brakes.config.maxPressureMass < 2 && brakes.loadSetting < 3)
{
if (brakes.maxCylinderPressure[2] > 0 && brakes.loadSetting == 1)
if (brakes.config.maxCylinderPressure[2] > 0 && brakes.loadSetting == 1)
brakes.loadSetting = 2;
else
brakes.loadSetting = 3;
IBM = true;
if (brakes.cylinders.leverRatio[2] > 0)
brakes.cylinders.leverRatio[0] = brakes.cylinders.leverRatio[2];
if (brakes.config.cylinders.leverRatio[2] > 0)
brakes.config.cylinders.leverRatio[0] = brakes.config.cylinders.leverRatio[2];
}
else
IBM = false;
@@ -699,15 +699,15 @@ bool physics::Vehicle::IncBrakeMult(void)
bool physics::Vehicle::DecBrakeMult(void)
{
bool DBM;
if (brakes.loadSetting > 1 && brakes.maxPressureMass < 2)
if (brakes.loadSetting > 1 && brakes.config.maxPressureMass < 2)
{
if (brakes.maxCylinderPressure[2] > 0 && brakes.loadSetting == 3)
if (brakes.config.maxCylinderPressure[2] > 0 && brakes.loadSetting == 3)
brakes.loadSetting = 2;
else
brakes.loadSetting = 1;
DBM = true;
if (brakes.cylinders.leverRatio[1] > 0)
brakes.cylinders.leverRatio[0] = brakes.cylinders.leverRatio[1];
if (brakes.config.cylinders.leverRatio[1] > 0)
brakes.config.cylinders.leverRatio[0] = brakes.config.cylinders.leverRatio[1];
}
else
DBM = false;
@@ -816,7 +816,7 @@ void physics::Vehicle::UpdatePipePressure(double dt)
brakes.driverValveFlow = 0;
if (brakes.handlePositions > 1)
if (brakes.config.handlePositions > 1)
{
UpdateLocalBrakeValve(dt);
@@ -832,7 +832,7 @@ void physics::Vehicle::UpdatePipePressure(double dt)
// Pipe.Flow(PF(PipePress, 0, d2A(7)) * dt);
// if ConverterFlag then
// Pipe.Flow(PF(PipePress, 0, d2A(12)) * dt);
brakes.driverValveFlow = brakes.driverValveFlow / (Dim.L * brakes.pipeSection * 20);
brakes.driverValveFlow = brakes.driverValveFlow / (Dim.L * brakes.config.pipeSection * 20);
brakes.controlReservoirPressure = brakes.distributor->GetVRP(); // ciśnienie komory wstępnej rozdzielacza
@@ -840,11 +840,11 @@ void physics::Vehicle::UpdatePipePressure(double dt)
UpdateDistributorSettings();
if ((brakes.driverValveType == TBrakeHandle::FVel6 || brakes.driverValveType == TBrakeHandle::FVE408) && CabOccupied != 0)
if ((brakes.config.driverValveType == TBrakeHandle::FVel6 || brakes.config.driverValveType == TBrakeHandle::FVE408) && CabOccupied != 0)
{
UpdateEPBrake();
}
else if (brakes.driverValveType == TBrakeHandle::St113 && CabOccupied != 0 && std::abs(EpForce) > 0.001 && !EPBrakeControlPowered())
else if (brakes.config.driverValveType == TBrakeHandle::St113 && CabOccupied != 0 && std::abs(EpForce) > 0.001 && !EPBrakeControlPowered())
{
// the EP brake switched on with the button drops out with the control's supply
SwitchEPBrake(0);
@@ -860,7 +860,7 @@ void physics::Vehicle::UpdatePipePressure(double dt)
// the air the brake hoses carry to and from the neighbours comes once all vehicles have stepped, UpdatePipeCouplers()
brakePipe.SetCouplersPending(true);
if (brakes.antiSlipType == 128)
if (brakes.config.antiSlipType == 128)
brakes.distributor->ASB(int(SlippingWheels && Vel > 1) * (1 + 2 * int(nrot_eps < -0.01)));
brakes.pipeFlow = 0;
@@ -887,7 +887,7 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt)
// the local brake of a vehicle prepared for hauling (PulleeMode) is held released, whatever asks for it
if (EngineType != TEngineType::ElectricInductionMotor)
{
double lbpa = brakes.independentTraxx ? eim_localbrake : brakes.independentPosition;
double lbpa = brakes.config.independentTraxx ? eim_localbrake : brakes.independentPosition;
if (EIMCtrlType > 0 && UniCtrlIntegratedLocalBrakeCtrl)
{
lbpa = std::max(0.0, -eimic_real);
@@ -905,7 +905,7 @@ void physics::Vehicle::UpdateLocalBrakeValve(double dt)
// lever should apply pneumatic pressure on the locomotive directly, bypassing MED.
// LocHandleTimeTraxx also bypasses MED, but has 3 positions (brake-hold-unbrake).
double lbpa;
if (brakes.independentTraxx)
if (brakes.config.independentTraxx)
{
lbpa = eim_localbrake;
}
@@ -932,10 +932,10 @@ void physics::Vehicle::UpdateMainValve(double dt)
// the driver's valve of a vehicle prepared for hauling is cut out, whatever its handle shows
brakes.driverValveFlow = 0;
}
else if ((brakes.availableOperatingModes & bom_PS) == 0 || (CabOccupied != 0 && brakes.operatingMode != bom_PS))
else if ((brakes.config.availableOperatingModes & bom_PS) == 0 || (CabOccupied != 0 && brakes.operatingMode != bom_PS))
{
if (brakes.operatingMode < bom_EP || brakes.driverValve->GetPos(bh_EB) - 0.5 < brakes.handlePositionReal || (brakes.driverValveType != TBrakeHandle::MHZ_EN57 && brakes.driverValveType != TBrakeHandle::MHZ_K8P))
if (brakes.operatingMode < bom_EP || brakes.driverValve->GetPos(bh_EB) - 0.5 < brakes.handlePositionReal || (brakes.config.driverValveType != TBrakeHandle::MHZ_EN57 && brakes.config.driverValveType != TBrakeHandle::MHZ_K8P))
{
brakes.driverValveFlow = brakes.driverValve->GetPF(MainValveHandlePosition(), brakePipe.Pressure(), temp, dt, brakes.equivalentPipePressure);
}
@@ -965,9 +965,9 @@ void physics::Vehicle::UpdateMainValve(double dt)
double physics::Vehicle::MainValveSupply()
{
brakes.pipeLock.locked = brakePipe.Pressure() < (brakes.pipeLock.locked ? brakes.pipeLock.offPressure : brakes.pipeLock.onPressure);
bool lock_new = (brakes.pipeLock.locked && !brakes.pipeLock.unlockPressed && brakes.handlePositionReal > brakes.pipeLock.unlockHandlePosition) || (brakes.emergencyCutsOffDriverValve && brakes.emergencyValve.flow > 0); // new simple codition based on .fiz
bool lock_old = brakes.driverValveType == TBrakeHandle::FV4a // old complex condition based on assumptions
&& brakePipe.Pressure() < 2.75 && (brakes.distributor->GetStatus() & b_rls) == 0 && brakes.subsystem == TBrakeSubSystem::ss_LSt && TrainType != train_type::emu && !brakes.pipeLock.unlockPressed;
bool lock_new = (brakes.pipeLock.locked && !brakes.pipeLock.unlockPressed && brakes.handlePositionReal > brakes.pipeLock.unlockHandlePosition) || (brakes.config.emergencyCutsOffDriverValve && brakes.emergencyValve.flow > 0); // new simple codition based on .fiz
bool lock_old = brakes.config.driverValveType == TBrakeHandle::FV4a // old complex condition based on assumptions
&& brakePipe.Pressure() < 2.75 && (brakes.distributor->GetStatus() & b_rls) == 0 && brakes.config.subsystem == TBrakeSubSystem::ss_LSt && TrainType != train_type::emu && !brakes.pipeLock.unlockPressed;
if (lock_old || lock_new)
{
@@ -1015,23 +1015,23 @@ void physics::Vehicle::UpdateEmergencyValve(double dt)
// what the distributor valve gets of the local brake and the load, by its kind
void physics::Vehicle::UpdateDistributorSettings()
{
switch (brakes.distributorType)
switch (brakes.config.distributorType)
{
case TBrakeValve::K:
case TBrakeValve::W:
{
if (brakes.independentValveType != TBrakeHandle::NoHandle)
if (brakes.config.independentValveType != TBrakeHandle::NoHandle)
{
brakes.independentCylinderPressure = brakes.independentValve->GetCP();
//(Hamulec as TWest).SetLBP(LocBrakePress);
brakes.distributor->SetLBP(brakes.independentCylinderPressure);
}
if (brakes.maxPressureMass < 2)
if (brakes.config.maxPressureMass < 2)
//(Hamulec as TWest).PLC(MaxBrakePress[LoadFlag])
brakes.distributor->PLC(brakes.maxCylinderPressure[brakes.loadSetting]);
brakes.distributor->PLC(brakes.config.maxCylinderPressure[brakes.loadSetting]);
else
//(Hamulec as TWest).PLC(TotalMass);
brakes.distributor->PLC(TotalMass - Mred);
@@ -1060,10 +1060,10 @@ void physics::Vehicle::UpdateDistributorSettings()
//(Hamulec as TLSt).SetLBP(LocBrakePress);
brakes.distributor->SetLBP(brakes.independentCylinderPressure);
if (brakes.distributorType == TBrakeValve::EStED)
if (brakes.config.distributorType == TBrakeValve::EStED)
{
if (brakes.maxPressureMass < 2)
brakes.distributor->PLC(brakes.maxCylinderPressure[brakes.loadSetting]);
if (brakes.config.maxPressureMass < 2)
brakes.distributor->PLC(brakes.config.maxCylinderPressure[brakes.loadSetting]);
else
brakes.distributor->PLC(TotalMass - Mred);
}
@@ -1089,9 +1089,9 @@ void physics::Vehicle::UpdateDistributorSettings()
case TBrakeValve::ESt4:
case TBrakeValve::ESt3:
{
if (brakes.maxPressureMass < 2)
if (brakes.config.maxPressureMass < 2)
//(Hamulec as TNESt3).PLC(MaxBrakePress[LoadFlag])
brakes.distributor->PLC(brakes.maxCylinderPressure[brakes.loadSetting]);
brakes.distributor->PLC(brakes.config.maxCylinderPressure[brakes.loadSetting]);
else
//(Hamulec as TNESt3).PLC(TotalMass);
brakes.distributor->PLC(TotalMass - Mred);
@@ -1105,9 +1105,9 @@ void physics::Vehicle::UpdateDistributorSettings()
brakes.independentCylinderPressure = brakes.independentValve->GetCP();
//(Hamulec as TKE).SetLBP(LocBrakePress);
brakes.distributor->SetLBP(brakes.independentCylinderPressure);
if (brakes.maxPressureMass < 2)
if (brakes.config.maxPressureMass < 2)
//(Hamulec as TKE).PLC(MaxBrakePress[LoadFlag])
brakes.distributor->PLC(brakes.maxCylinderPressure[brakes.loadSetting]);
brakes.distributor->PLC(brakes.config.maxCylinderPressure[brakes.loadSetting]);
else
//(Hamulec as TKE).PLC(TotalMass);
brakes.distributor->PLC(TotalMass - Mred);
@@ -1258,7 +1258,7 @@ double physics::Vehicle::GetDVc(double dt)
if (Couplers[0].Connected != nullptr && Couplers[0].CouplingFlag.HasAll(Coupling::brakeHose))
{ //*0.85
c = Couplers[0].Connected; // skrot //0.08 //e/D * L/D = e/D^2 * L
dv1 = 0.5 * dt * PF(brakePipe.Pressure(), neighbour_pipe_pressure(*c, c->brakePipe.Pressure(), *c->brakePipe.reservoir), brakes.pipeSection / (1.0 + 0.015 / brakes.pipeSection * Dim.L));
dv1 = 0.5 * dt * PF(brakePipe.Pressure(), neighbour_pipe_pressure(*c, c->brakePipe.Pressure(), *c->brakePipe.reservoir), brakes.config.pipeSection / (1.0 + 0.015 / brakes.config.pipeSection * Dim.L));
c->brakePipe.reservoir->Flow(-dv1);
if (pipe_wakes(dv1, brakePipe.Pressure(), *c->brakePipe.reservoir))
c->switch_physics(true, wake_cause::mainpipe);
@@ -1267,7 +1267,7 @@ double physics::Vehicle::GetDVc(double dt)
if (Couplers[1].Connected != nullptr && Couplers[1].CouplingFlag.HasAll(Coupling::brakeHose))
{
c = Couplers[1].Connected; // skrot
dv2 = 0.5 * dt * PF(brakePipe.Pressure(), neighbour_pipe_pressure(*c, c->brakePipe.Pressure(), *c->brakePipe.reservoir), brakes.pipeSection / (1.0 + 0.015 / brakes.pipeSection * Dim.L));
dv2 = 0.5 * dt * PF(brakePipe.Pressure(), neighbour_pipe_pressure(*c, c->brakePipe.Pressure(), *c->brakePipe.reservoir), brakes.config.pipeSection / (1.0 + 0.015 / brakes.config.pipeSection * Dim.L));
c->brakePipe.reservoir->Flow(-dv2);
if (pipe_wakes(dv2, brakePipe.Pressure(), *c->brakePipe.reservoir))
c->switch_physics(true, wake_cause::mainpipe);
@@ -1340,7 +1340,7 @@ struct train_pipe
train_pipe const brake_pipe{&physics::Vehicle::brakePipe,
Coupling::brakeHose,
&physics::Vehicle::GetDVc,
[](physics::Vehicle const &Vehicle) { return Vehicle.brakes.pipeSection / (1.0 + 0.015 / Vehicle.brakes.pipeSection * Vehicle.Dim.L); }};
[](physics::Vehicle const &Vehicle) { return Vehicle.brakes.config.pipeSection / (1.0 + 0.015 / Vehicle.brakes.config.pipeSection * Vehicle.Dim.L); }};
// the main reservoir pipe, GetScndDVc()
train_pipe const main_reservoir_pipe{&physics::Vehicle::mainPipe,
Coupling::mainHose,