18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 09:36:48 +01:00
Files
maszyna/tests/unit/test_camshaft.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

136 lines
5.9 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::vehicle;
// eu07/maszyna#393: running backwards, a camshaft which reached the last position of the series connection (the
// next one already joins the motors in more branches than BackwardsBranchesAllowed) stayed there whatever the driver
// did with the master controller, with the line contactors closed and the motors pulling, until the line contactors
// were opened by hand
namespace {
// the starting resistances of the Skoda 181 (cd/181_v2): 6 motors in series up to position 22, then two branches of
// 3 up to 34, then three branches of 2 up to 43; columns: position, resistance, branches, motors in a branch, auto
nlohmann::ordered_json skoda_rlist() {
nlohmann::ordered_json rows{nlohmann::ordered_json::array({0, 0, 0, 0, 0}), nlohmann::ordered_json::array({1, 999999, 1, 6, 0})};
auto const series{std::vector<double>{15.87, 12.32, 10.03, 8.54, 6.98, 5.84, 5.35, 4.87, 3.88, 2.92, 2.68, 2.43, 2.19, 1.95, 1.70, 1.46, 1.22, 0.97, 0.49, 0.24, 0.00}};
auto const seriesparallel{std::vector<double>{4.50, 3.63, 3.11, 2.42, 2.08, 1.73, 1.38, 1.04, 0.69, 0.35, 0.17, 0.00}};
auto const parallel{std::vector<double>{2.78, 2.29, 1.80, 1.41, 1.02, 0.73, 0.44, 0.24, 0.00}};
auto position{2};
for (auto const resistance : series) {
rows.push_back(nlohmann::ordered_json::array({position++, resistance, 1, 6, 0}));
}
for (auto const resistance : seriesparallel) {
rows.push_back(nlohmann::ordered_json::array({position++, resistance, 2, 3, 0}));
}
for (auto const resistance : parallel) {
rows.push_back(nlohmann::ordered_json::array({position++, resistance, 3, 2, 0}));
}
return rows;
}
// an electric locomotive with a camshaft, made after the Skoda 181
definition skoda() {
auto result{definition::load("wagon")
.set("Param", "M", 124200)
.set("Param", "Vmax", 90)
.set("Dimensions", "L", 18.8)
.set("Wheels", "D", 1.25)
.set("Wheels", "Axle", "Co'Co'")
.set("Engine", "EngineType", "ElectricSeriesMotor")
.set("Engine", "Volt", 967)
.set("Engine", "Trans", "21:89")
.set("Engine", "WindingRes", 0.084)
.set("Engine", "nmax", 1870)
.set("Circuit", "CircuitRes", 0.01)
.set("Circuit", "ImaxLo", 550)
.set("Circuit", "ImaxHi", 550)
.set("Circuit", "IminLo", 307)
.set("Circuit", "IminHi", 332)
.set("Cntrl", "MCPN", 43)
.set("Cntrl", "SCPN", 3)
.set("Cntrl", "CoupledCtrl", "No")
.set("Cntrl", "IniCDelay", 0.2)
.set("Cntrl", "SCDelay", 0.18)
.set("Cntrl", "SCDDelay", 0.18)
.set("Cntrl", "Camshaft", "Yes")
.set("MotorParamTable0", "rows",
nlohmann::ordered_json::array({nlohmann::ordered_json::array({0, 33.75, 57, 0.4, 225.70, 57, 0.4}), nlohmann::ordered_json::array({1, 31.66, 69, 0.4, 217.10, 69, 0.4}),
nlohmann::ordered_json::array({2, 30.52, 90, 0.4, 212.80, 90, 0.4}), nlohmann::ordered_json::array({3, 28.74, 107, 0.4, 199.55, 107, 0.4})}))
.set("RList", "Size", 43)
.set("RList", "rows", skoda_rlist())};
return result;
}
// the locomotive running with the line contactors closed and the camshaft at Position, the master controller moved
// to Controller, in the given direction; the time since the last step of the camshaft long enough for the next one
void running(physics::Vehicle &Locomotive, int const Direction, int const Position, int const Controller) {
Locomotive.CabActive = 1;
Locomotive.DirActive = Direction;
Locomotive.Mains = true;
Locomotive.brakePipe.pressure = 5.0; // bar, the pressure switch lets the line contactors close
Locomotive.brakes.cylinderPressure = 0.0;
Locomotive.StLinFlag = true;
Locomotive.MainCtrlActualPos = Position;
Locomotive.MainCtrlPos = Controller;
Locomotive.LastRelayTime = 10.0;
}
// steps the camshaft as the physics does, each step once the delay since the previous one passed; returns where it
// ended up
int run_camshaft(physics::Vehicle &Locomotive, int const Steps) {
for (int step = 0; step < Steps; ++step) {
Locomotive.LastRelayTime = 10.0;
Locomotive.AutoRelayCheck();
}
return Locomotive.MainCtrlActualPos;
}
} // namespace
TEST_CASE("camshaft: running backwards, the camshaft goes back down from the last series position (eu07/maszyna#393)") {
vehicle locomotive{skoda()};
auto &physics{locomotive.physics()};
REQUIRE(physics.HasCamshaft);
REQUIRE(physics.RlistSize == 43);
REQUIRE(physics.RList[22].Bn == 1);
REQUIRE(physics.RList[23].Bn == 2);
SUBCASE("the controller turned back a few positions") {
running(physics, -1, 22, 15);
CHECK(run_camshaft(physics, 1) == 21); // it used to stay at 22
CHECK(run_camshaft(physics, 10) == 15);
}
SUBCASE("the controller turned back to zero: the camshaft runs down and the line contactors open") {
running(physics, -1, 22, 0);
run_camshaft(physics, 30);
CHECK(physics.MainCtrlActualPos == 0);
CHECK_FALSE(physics.StLinFlag); // the motors don't pull any more
}
}
TEST_CASE("camshaft: running backwards, the camshaft still doesn't go past the series connection") {
vehicle locomotive{skoda()};
auto &physics{locomotive.physics()};
running(physics, -1, 20, 43);
CHECK(run_camshaft(physics, 10) == 22);
SUBCASE("unless more branches are allowed backwards") {
physics.BackwardsBranchesAllowed = 2;
CHECK(run_camshaft(physics, 20) == 34);
}
}
TEST_CASE("camshaft: running forwards, the camshaft goes through all the connections and back") {
vehicle locomotive{skoda()};
auto &physics{locomotive.physics()};
running(physics, 1, 20, 43);
CHECK(run_camshaft(physics, 30) == 43);
physics.MainCtrlPos = 10;
CHECK(run_camshaft(physics, 40) == 10);
}