18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 05:57:08 +01:00
Files
maszyna/tests/unit/test_line_contactors.cpp
T
Hirek 1bea280010 refactor(physics): the line breaker, the line contactors, the relays and the converter as components
The main circuit of physics::Vehicle becomes components, with English names
(physics/components/maincircuit.h):

  lineBreaker (LineBreaker)     Mains closed, MainsInitTime(Countdown)
                                initTime / initCountdown, MainsStart start,
                                JointEngineStart jointStart,
                                PantographsRequireMains pantographsRequireIt,
                                LineBreakerClosesOnlyAtNoPowerPos
                                closesOnlyAtNoPower,
                                EmergencyBrakeMainOffPressure emergencyOffPressure
  lineContactors (LineContactors) StLinFlag closed, StLinSwitchOff forcedOpen,
                                StLinSwitchType switchType,
                                LineContactorsInterlock interlock,
                                LastRelayTime lastSwitchTime
  protection (ProtectionRelays) NoVoltRelay noVoltage, OvervoltageRelay
                                overvoltage, GroundRelay(Start) ground(Start),
                                ControlPressureSwitch pressureSwitch,
                                HasControlPressureSwitch hasPressureSwitch,
                                PressureSwitchBrakeCylinder
                                pressureSwitchWatchesCylinders
  converter (PowerConverter)    the Converter* fields: start, startDelay(Timer),
                                allow(Local), running, overloadRelayStart,
                                overloadRelayOffWithLineBreaker; ConvOvldFlag
                                overloaded, ConvSwitchType switchType

The long comments of the fields went with them into the header. Where the
loading of the .fiz has using enum start_t, the member is this->converter:
the enumerator start_t::converter would hide it there.

No string literal changed (checked over all the changed files).

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

131 lines
4.8 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// the lamp of the open line contactors (eu07/maszyna#470): lit, it tells the start can be made, so it should go out
// where the start is cut off, by the pressure switch at 2 bar in the brake cylinders, not at 1 bar already
namespace {
test::vehicle locomotive(bool const Pressureswitch) {
test::vehicle vehicle{test::definition::load("wagon").set("Engine", "PressureSwitch", Pressureswitch)};
vehicle->lineContactors.closed = false; // the line contactors open
vehicle->brakePipe.pressure = 5.0;
return vehicle;
}
} // namespace
TEST_CASE("line contactors: with a pressure switch the lamp goes out with the start cut off") {
auto vehicle{locomotive(true)};
REQUIRE(vehicle->protection.hasPressureSwitch);
vehicle->brakes.cylinderPressure = 1.5; // braked, the start can still be made
vehicle->MotorConnectorsCheck(); // updates the pressure switch
REQUIRE_FALSE(vehicle->protection.pressureSwitch);
CHECK(vehicle->LineContactorsLampLit());
vehicle->brakes.cylinderPressure = 2.5; // the pressure switch cuts the start off
vehicle->MotorConnectorsCheck();
REQUIRE(vehicle->protection.pressureSwitch);
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: without a pressure switch the lamp goes out with the brakes applied, as before") {
auto vehicle{locomotive(false)};
vehicle->brakes.cylinderPressure = 0.5;
vehicle->MotorConnectorsCheck();
CHECK(vehicle->LineContactorsLampLit());
vehicle->brakes.cylinderPressure = 1.5;
vehicle->MotorConnectorsCheck();
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: closed contactors put the lamp out") {
auto vehicle{locomotive(true)};
vehicle->lineContactors.closed = true;
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: the ground relay and overload lamps follow the same rule") {
// all the lamps of the main circuit go out together, with the pressure switch where it's fitted
auto vehicle{locomotive(true)};
vehicle->brakes.cylinderPressure = 1.5;
vehicle->MotorConnectorsCheck();
CHECK(vehicle->MainCircuitLampsEnabled());
vehicle->brakes.cylinderPressure = 2.5;
vehicle->MotorConnectorsCheck();
CHECK_FALSE(vehicle->MainCircuitLampsEnabled());
}
// on the diesel-electric SU45 and SU46 (eu07/maszyna#263) the lamp tells just the line contactors are open: lit with the
// master controller at 0 and with the start cut off by too low a pressure in the main pipe, out on the power positions
namespace {
// the diesel-electric locomotive with its engine running and the brakes released, the master controller at 0
test::vehicle diesel_electric() {
test::vehicle vehicle{test::definition::load("diesel_electric")};
vehicle->CabOccupied = 1;
vehicle->CabActivisation();
vehicle->BatterySwitch(true);
vehicle->OilPumpSwitch(true);
vehicle->FuelPumpSwitch(true);
vehicle.run(20.0); // the oil pressure builds up
vehicle.hold_brake_pipe(5.0); // bar
vehicle->MainSwitch(true);
vehicle.run(30.0);
vehicle->DirectionForward();
vehicle.run(60.0); // the brakes release
return vehicle;
}
} // namespace
TEST_CASE("line contactors: on a diesel-electric the lamp is lit at 0 and goes out on a power position") {
auto vehicle{diesel_electric()};
REQUIRE(vehicle->EngineType == TEngineType::DieselElectric);
REQUIRE(vehicle->lineBreaker.closed);
REQUIRE_FALSE(vehicle->protection.pressureSwitch);
CHECK_FALSE(vehicle->lineContactors.closed);
CHECK(vehicle->LineContactorsLampLit());
vehicle->IncMainCtrl(1);
vehicle.run(3.0);
CHECK(vehicle->lineContactors.closed);
CHECK_FALSE(vehicle->LineContactorsLampLit());
vehicle->DecMainCtrl(1);
vehicle.run(3.0);
CHECK_FALSE(vehicle->lineContactors.closed);
CHECK(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: on a diesel-electric the lamp lights with the contactors opened by too low a main pipe pressure") {
auto vehicle{diesel_electric()};
vehicle->IncMainCtrl(1);
vehicle.run(1.0);
vehicle->IncMainCtrl(1);
vehicle.run(2.0);
REQUIRE(vehicle->lineContactors.closed);
vehicle.hold_brake_pipe(2.5); // bar, below the 3.6 bar of the pressure switch
vehicle.run(10.0);
REQUIRE(vehicle->protection.pressureSwitch);
CHECK_FALSE(vehicle->lineContactors.closed);
CHECK(vehicle->LineContactorsLampLit()); // it went out here
CHECK_FALSE(vehicle->MainCircuitLampsEnabled()); // the ground relay and overload lamps still go out with the start cut off
// the pressure back, the contactors stay open on the second position and the lamp stays lit, as it should;
// they close again only on the first one
vehicle.hold_brake_pipe(5.0);
vehicle.run(60.0);
REQUIRE_FALSE(vehicle->protection.pressureSwitch);
CHECK_FALSE(vehicle->lineContactors.closed);
CHECK(vehicle->LineContactorsLampLit());
vehicle->DecMainCtrl(1);
vehicle.run(3.0);
CHECK(vehicle->lineContactors.closed);
CHECK_FALSE(vehicle->LineContactorsLampLit());
}