mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 14:07:06 +01:00
d0b8d689af
The blending of the electrodynamic and the electropneumatic brakes over a consist driven by induction motors (the MED of the .fiz) moves out of TDynamicObject into physics::ConsistBrakeBlending (physics/consistbraking.*). It works on the physics of the vehicles alone, given in the order of the consist; TDynamicObject::distributeInductionBraking() only lists them from the occupied cab, as its loops walked them, and hands the result (the most deceleration of the service braking) to the driver. The state of the blending (the ED demand of the step before, the log of MEDLOGS/, the figures of the debug screen) goes with it. The code moves as it was: its arithmetic, its float and double conversions and the order of its steps are kept. Nothing in the unit tests reached it before, as they don't run TDynamicObject; now that it stands on its own, tests of it are added (test_consist_braking.cpp): the full braking demand over the mass of an Elf, the electropneumatic brake of every car standing, no demand at neutral. The figures of the debug screen start at zero rather than uninitialised for a vehicle that never led a consist.
109 lines
3.7 KiB
C++
109 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "consist.h"
|
|
#include "drive.h"
|
|
|
|
#include "physics/consistbraking.h"
|
|
#include "physics/brakes.h"
|
|
|
|
#include <vector>
|
|
|
|
// the blending of the brakes of a consist driven by induction motors (physics::ConsistBrakeBlending, the MED of the
|
|
// .fiz), which the game runs from the vehicle with the driver (TDynamicObject::distributeInductionBraking())
|
|
|
|
using test::definition;
|
|
|
|
namespace {
|
|
|
|
// a three-car Elf ready to run, standing with its brakes released, driven from the front cab of the head car
|
|
struct elf {
|
|
elf() {
|
|
for (auto const *car : {"elf_v1/21we-a", "elf_v1/21we-b", "elf_v1/21we-c"}) {
|
|
unit.add(definition::fiz(car), unit.size() == 0 ? 1 : 0);
|
|
}
|
|
ready = test::start_up(test::driving(unit), line);
|
|
for (int i = 0; i < 3 && cab().DirActive <= 0; ++i) {
|
|
cab().DirectionForward();
|
|
}
|
|
test::release_brakes(cab());
|
|
for (std::size_t index = 0; index < unit.size(); ++index) {
|
|
cars.emplace_back(&unit[index].physics());
|
|
}
|
|
}
|
|
physics::Vehicle &cab() { return unit[0].physics(); }
|
|
// the steps of the game: the physics of the cars, then the blending from the head car
|
|
double step(double Seconds, double Dt = 0.01) {
|
|
auto amax{0.0};
|
|
for (auto time{0.0}; time < Seconds; time += Dt) {
|
|
unit.step(line, Dt);
|
|
amax = blending.Update(cab(), cars, {}, Dt);
|
|
}
|
|
return amax;
|
|
}
|
|
test::consist unit;
|
|
test::track line{0.0, 0.0, test::catenary_3kv};
|
|
std::vector<physics::Vehicle *> cars;
|
|
physics::ConsistBrakeBlending blending;
|
|
bool ready{false};
|
|
};
|
|
|
|
// the figures of the debug screen, by their labels
|
|
constexpr std::size_t mass{0}; // [t]
|
|
constexpr std::size_t deceleration{1}; // the most of the service braking [m/s2]
|
|
constexpr std::size_t demand{2}; // [kN]
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("consist braking: the full braking position demands the most deceleration of the consist, over all its mass") {
|
|
elf unit;
|
|
REQUIRE(unit.ready);
|
|
unit.cab().MainCtrlPos = 0; // the full braking position of the Elf's controller
|
|
auto const amax{unit.step(2.0)};
|
|
CHECK(amax > 0.0);
|
|
CHECK(amax <= unit.cab().brakes.blending.maxDeceleration);
|
|
auto const &figures{unit.blending.Figures()};
|
|
CHECK(figures[deceleration] == doctest::Approx(amax));
|
|
auto mass_t{0.0};
|
|
for (auto const *car : unit.cars) {
|
|
mass_t += car->TotalMass * 0.001;
|
|
}
|
|
CHECK(figures[mass] == doctest::Approx(mass_t));
|
|
// the holding brake standing still asks for no more than the service braking does
|
|
CHECK(figures[demand] == doctest::Approx(amax * mass_t));
|
|
}
|
|
|
|
TEST_CASE("consist braking: standing at full braking, every car brakes with its electropneumatic brake") {
|
|
elf unit;
|
|
REQUIRE(unit.ready);
|
|
unit.cab().MainCtrlPos = 0;
|
|
unit.step(2.0);
|
|
for (auto const *car : unit.cars) {
|
|
CAPTURE(car->Name);
|
|
CHECK(car->brakes.independentPositionEim > 0.0);
|
|
CHECK(car->brakes.independentPositionEim <= 1.0);
|
|
// the shunting mode (the holding brake) of the head car goes to all of them
|
|
CHECK(car->ShuntMode == unit.cab().ShuntMode);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("consist braking: with the controller at neutral and the train released, moving, nothing is demanded") {
|
|
elf unit;
|
|
REQUIRE(unit.ready);
|
|
while (unit.cab().MainCtrlPos < unit.cab().MainCtrlNoPowerPos() && unit.cab().IncMainCtrl(1)) {
|
|
// up to neutral
|
|
}
|
|
// the controller's demand comes back from full braking to nothing gradually
|
|
unit.step(10.0);
|
|
REQUIRE(unit.cab().eimic == doctest::Approx(0.0));
|
|
for (auto *car : unit.cars) {
|
|
car->V = 10.0; // [m/s], above the speed the holding brake comes in at
|
|
car->Vel = 36.0;
|
|
}
|
|
unit.blending.Update(unit.cab(), unit.cars, {}, 0.01);
|
|
CHECK(unit.blending.Figures()[demand] == doctest::Approx(0.0));
|
|
for (auto const *car : unit.cars) {
|
|
CAPTURE(car->Name);
|
|
CHECK(car->brakes.independentPositionEim == doctest::Approx(0.0));
|
|
}
|
|
}
|