mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +01:00
d0387753f8
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:
physics/mover.h physics/vehicle.h
TMoverParameters physics::Vehicle (in namespace physics)
TDynamicObject::MoverParameters physics
mvOccupied, mvControlled occupied, controlled (TTrain, TController)
mvSecond, mvThird secondUnit, thirdUnit
mvPantographUnit pantographUnit
mover, Mover, movers physics, Physics, vehicles (locals, params)
m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
m_physics, otherPhysics, currentPhysics,
from_vehicles, renderPhysicsEventSounds
The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.
By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).
For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.
The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
136 lines
5.9 KiB
C++
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.PipePress = 5.0; // bar, the pressure switch lets the line contactors close
|
|
Locomotive.BrakePress = 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);
|
|
}
|