18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 11:47:06 +01:00
Files
maszyna/tests/unit/test_pressure_switch.cpp
T
Hirek 16568d5695 refactor(physics): the brake valves, cylinders, pressures and positions in physics::Braking
The rest of the braking of physics::Vehicle moves into brakes, with English
names (physics/components/braking.h):

  the valves      Hamulec distributor, Handle driverValve,
                  LocHandle independentValve
  the definition  BrakeSystem kind, BrakeSubsystem subsystem, BrakeValve /
                  BrakeValveSize / BrakeValveParams distributorType / Size /
                  Parameters, BrakeHandle / BrakeLocHandle driverValveType /
                  independentValveType, the Handle_* driverValveSettings,
                  LocalBrake localKind, MaxBrakePress maxCylinderPressure,
                  LoadFlag loadSetting, P2FTrans pressureToForce, NBpA
                  blocksPerAxle, High/Low/DeltaPipePress pipeHigh/LowPressure
                  / pipePressureRange, CntrlPipePress controlReservoirPressure,
                  Spg pipeSection, RapidMult / RapidVel rapidRatio / rapidSpeed,
                  BrakeDelay delays, BrakeCtrlPosNo handlePositions, ...
  cylinders       BrakeCylNo / Radius / Dist / Mult / Spring, BrakeSlckAdj,
                  BrakeRigEff: count, radius, stroke, leverRatio, springForce,
                  slackAdjusterForce, riggingEfficiency
  emergencyValve  EmergencyValveOn / Off / Open / Area / Flow
  pipeLock        LockPipeOn / Off, HandleUnlock, LockPipe, UnlockPipe
  the state       BrakePress cylinderPressure, LocBrakePress
                  independentCylinderPressure, EqvtPipePress
                  equivalentPipePressure, Volume reservoirAir, dpBrake / dpPipe /
                  dpMainValve / dpLocalValve brakeFlow / pipeFlow /
                  driverValveFlow / independentValveFlow, BrakeCtrlPos(R, 2)
                  handlePosition(Real), handleCapPosition, fBrakeCtrlPos
                  handlePositionSmooth, LocalBrakePosA(EIM) independentPosition
                  (Eim), BrakeStatus status, AlarmChainFlag alarmChain,
                  BrakeDelayFlag / BrakeDelays delaySetting / availableDelays,
                  BrakeOpModeFlag / BrakeOpModes operatingMode /
                  availableOperatingModes, UnitBrakeForce unitForce, ...

Renamed in the files of the vehicle itself, and elsewhere only where reached
through -> or .: the driver keeps its own BrakeSystem, the editor its Handle,
the radio its Volume, and the brake valve classes (brakes.*, oerlikonest.*)
their fields of the same names. The C arrays (MaxBrakePress, BrakeCylMult,
the universal buttons) are std::arrays of the same values; the bits of status,
delaySetting and operatingMode stay ints for now.

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-29 01:48:33 +01:00

296 lines
12 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "drive.h"
#include "physics/brakes.h"
// the pressure switch of the EP05 (git.eu07.pl eu07/maszyna#48). the pressure switch of the simulator is two
// conditions in one: it cuts the traction motors off above 2 bar in the brake cylinders and below 3.6 bar in the
// brake pipe. the EP05 takes current whatever the pressure in its brake cylinders (Engine: PressureSwitchBrakeCylinder=No
// leaves the brake pipe half alone), and an emergency brake application made with the master controller on a power
// position opens its line breaker (Cntrl. EmergencyBrakeMainOff=<bar in the brake pipe>), which on this locomotive
// drops the pantographs too, as they stay up only through the closed line breaker (Cntrl. PantRequiresMain)
namespace {
constexpr test::track line{0.15, 0.0, test::catenary_3kv};
// the brake pipe pressure taken for an emergency application in these tests [bar]: below the 2.8 bar the FV4a
// gives on its last service position, above what is left in the pipe once it's vented
constexpr double emergency_pressure{2.5};
struct keys {
bool brakecylinder{true}; // Engine: PressureSwitchBrakeCylinder
bool mainoff{false}; // Cntrl. EmergencyBrakeMainOff
bool mainsfirst{true}; // Cntrl. PantRequiresMain, which the game's EP05 has
};
test::definition ep05(keys const &Keys) {
auto definition{test::definition::fiz("ep05_v2/ep05")};
if (Keys.mainsfirst) {
// the game's definition got it after the one of the tests was converted
definition.set("Cntrl", "PantRequiresMain", "Yes");
}
if (false == Keys.brakecylinder) {
definition.set("Engine", "PressureSwitchBrakeCylinder", "No");
}
if (Keys.mainoff) {
definition.set("Cntrl", "EmergencyBrakeMainOff", emergency_pressure);
}
return definition;
}
// the locomotive started up the way the driver does it and its brakes released, until the pressure switch lets go
void get_ready(test::vehicle &Loco, test::driven const &Driven) {
REQUIRE(test::start_up(Driven, line));
test::release_brakes(Driven.cab);
test::drive(Driven, line, 20.0);
for (int i = 0; i < 120 && Loco->ControlPressureSwitch; ++i) {
test::drive(Driven, line, 1.0);
}
REQUIRE_FALSE(Loco->ControlPressureSwitch);
REQUIRE(Loco->Mains);
REQUIRE(Loco->Pantographs[VehicleEnd::rear].is_active);
}
// the master controller taken to the given position a notch a second
void notch_up(test::vehicle &Loco, test::driven const &Driven, int const Position) {
while (Loco->MainCtrlPos < Position && Loco->IncMainCtrl(1)) {
test::drive(Driven, line, 1.0);
}
test::drive(Driven, line, 2.0);
REQUIRE(Loco->MainCtrlPos == Position);
}
void get_under_power(test::vehicle &Loco, test::driven const &Driven, int const Position) {
get_ready(Loco, Driven);
notch_up(Loco, Driven, Position);
REQUIRE(Loco->StLinFlag);
REQUIRE(std::abs(Loco->Im) > 10.0);
}
// the independent brake applied in full: 3.8 bar in the brake cylinders of the locomotive (Brake: MaxBP)
void apply_independent_brake(test::vehicle &Loco, test::driven const &Driven) {
Loco->IncLocalBrakeLevel(LocalBrakePosNo);
test::drive(Driven, line, 20.0);
REQUIRE(Loco->brakes.cylinderPressure == doctest::Approx(3.8).epsilon(0.03));
REQUIRE(Loco->brakePipe.pressure > 4.8);
}
void emergency_application(test::vehicle &Loco, test::driven const &Driven) {
Loco->BrakeLevelSet(Loco->brakes.driverValve->GetPos(bh_EB));
test::drive(Driven, line, 10.0);
REQUIRE(Loco->brakePipe.pressure < 1.0);
}
} // namespace
TEST_CASE("pressure switch: the keys are off by default") {
test::vehicle loco{ep05({}), 0.0, "test", 1};
CHECK(loco->HasControlPressureSwitch);
CHECK(loco->PressureSwitchBrakeCylinder);
CHECK(loco->EmergencyBrakeMainOffPressure == 0.0);
test::vehicle changed{ep05({.brakecylinder = false, .mainoff = true}), 0.0, "test", 1};
CHECK(changed->HasControlPressureSwitch);
CHECK_FALSE(changed->PressureSwitchBrakeCylinder);
CHECK(changed->EmergencyBrakeMainOffPressure == doctest::Approx(emergency_pressure));
}
TEST_CASE("pressure switch: with the brake cylinders at 3.8 bar the EP05 takes no current, as before") {
test::vehicle loco{ep05({}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_ready(loco, driven);
apply_independent_brake(loco, driven);
CHECK(loco->ControlPressureSwitch);
CHECK_FALSE(loco->MainCircuitLampsEnabled());
notch_up(loco, driven, 3);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: without its brake cylinder half the EP05 takes current with the brake cylinders at 3.8 bar") {
test::vehicle loco{ep05({.brakecylinder = false}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_ready(loco, driven);
apply_independent_brake(loco, driven);
CHECK_FALSE(loco->ControlPressureSwitch);
// the lamps of the main circuit tell the start can be made
CHECK(loco->MainCircuitLampsEnabled());
CHECK(loco->LineContactorsLampLit());
notch_up(loco, driven, 3);
CHECK(loco->StLinFlag);
CHECK(loco->MainCtrlActualPos == 3);
CHECK(std::abs(loco->Im) > 100.0);
CHECK(loco->brakes.cylinderPressure == doctest::Approx(3.8).epsilon(0.03));
MESSAGE("current with 3.8 bar in the brake cylinders, position 3: " << std::abs(loco->Im) << " A");
}
TEST_CASE("pressure switch: without its brake cylinder half the brake pipe still cuts the traction motors off") {
test::vehicle loco{ep05({.brakecylinder = false}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
SUBCASE("a service application") {
loco->BrakeLevelSet(loco->brakes.driverValve->GetPos(bh_FB));
test::drive(driven, line, 15.0);
REQUIRE(loco->brakePipe.pressure < 3.6);
REQUIRE(loco->brakePipe.pressure > 3.0);
}
SUBCASE("an emergency application") {
emergency_application(loco, driven);
}
CHECK(loco->ControlPressureSwitch);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
// nothing else lets go without the other key
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: an emergency application with the master controller on a power position opens the line breaker and drops the pantographs") {
test::vehicle loco{ep05({.brakecylinder = false, .mainoff = true}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
SUBCASE("made with the brake handle") {
loco->BrakeLevelSet(loco->brakes.driverValve->GetPos(bh_EB));
}
SUBCASE("made with the emergency brake of the train") {
loco->AlarmChainSwitch(true);
}
test::drive(driven, line, 10.0);
REQUIRE(loco->brakePipe.pressure < emergency_pressure);
REQUIRE(loco->MainCtrlPos == 5);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[VehicleEnd::front].is_active);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == 0.0);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
// the line breaker doesn't close again while the master controller is where it was
loco->MainSwitch(true);
test::drive(driven, line, 2.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: an emergency application with the master controller at zero leaves the line breaker and the pantographs alone") {
test::vehicle loco{ep05({.brakecylinder = false, .mainoff = true}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
while (loco->DecMainCtrl(1)) {
// down to zero
}
test::drive(driven, line, 2.0);
REQUIRE(loco->MainCtrlPos == 0);
emergency_application(loco, driven);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK(loco->Im == 0.0);
// and the master controller moved with the pipe empty is the same as the application made with it moved
loco->IncMainCtrl(1);
test::drive(driven, line, 2.0);
CHECK_FALSE(loco->Mains);
CHECK_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
}
TEST_CASE("pressure switch: a service application with the master controller on a power position doesn't open the line breaker") {
test::vehicle loco{ep05({.brakecylinder = false, .mainoff = true}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
// the last service position of the FV4a, 2.8 bar in the pipe
loco->BrakeLevelSet(5.0);
auto lowest{loco->brakePipe.pressure};
for (int second = 0; second < 60; ++second) {
test::drive(driven, line, 1.0);
lowest = std::min(lowest, loco->brakePipe.pressure);
}
MESSAGE("the lowest brake pipe pressure of the service application: " << lowest << " bar");
REQUIRE(lowest < 3.0);
CHECK(lowest > emergency_pressure);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
// the pressure switch has cut the motors off
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
}
TEST_CASE("pressure switch: without the key an emergency application leaves the line breaker closed and the pantographs up, as before") {
test::vehicle loco{ep05({}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
emergency_application(loco, driven);
REQUIRE(loco->MainCtrlPos == 5);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
// the pressure switch cuts the motors off
CHECK(loco->ControlPressureSwitch);
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
}
TEST_CASE("pressure switch: where the pantographs don't hang on the line breaker the emergency application opens only the line breaker") {
test::vehicle loco{ep05({.brakecylinder = false, .mainoff = true, .mainsfirst = false}), 0.0, "test", 1};
REQUIRE_FALSE(loco->PantographsRequireMains);
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
emergency_application(loco, driven);
CHECK_FALSE(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
CHECK_FALSE(loco->StLinFlag);
CHECK(loco->Im == 0.0);
}
TEST_CASE("pressure switch: after the emergency application the driver's start-up gets the locomotive going again") {
// test::start_up() takes the AI's steps of TController::PrepareEngine(): the master controller to zero, the relays
// reset, the line breaker closed. the pantograph switches stay as they were, so the pantograph rises with the line
// breaker
test::vehicle loco{ep05({.brakecylinder = false, .mainoff = true}), 0.0, "test", 1};
auto driven{test::driving(loco)};
get_under_power(loco, driven, 5);
emergency_application(loco, driven);
REQUIRE_FALSE(loco->Mains);
REQUIRE_FALSE(loco->Pantographs[VehicleEnd::rear].is_active);
REQUIRE(loco->Pantographs[VehicleEnd::rear].valve.is_enabled);
// with the brake pipe still empty
REQUIRE(test::start_up(driven, line, 60.0));
CHECK(loco->MainCtrlPos == 0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv));
REQUIRE(loco->brakePipe.pressure < emergency_pressure);
// and it stays so
test::drive(driven, line, 30.0);
CHECK(loco->Mains);
CHECK(loco->Pantographs[VehicleEnd::rear].is_active);
// the brakes released (the AI fills an emptied pipe with the releaser held, TController::control_releaser()),
// the pressure switch lets the start be made
test::release_brakes(driven.cab);
for (int i = 0; i < 180 && loco->ControlPressureSwitch; ++i) {
loco->BrakeReleaser(loco->brakePipe.pressure < 3.0 ? 1 : 0);
test::drive(driven, line, 1.0);
}
loco->BrakeReleaser(0);
REQUIRE_FALSE(loco->ControlPressureSwitch);
notch_up(loco, driven, 3);
CHECK(loco->Mains);
CHECK(loco->StLinFlag);
CHECK(std::abs(loco->Im) > 10.0);
}