17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 10:19:20 +02:00
Files
maszyna/tests/unit/test_wheelslip.cpp
jerrrrycho b07e28adcb fix: single horn lever tones, skid of a stopped vehicle, destination signs after the timetable
- a cab with only the combined horn lever (horn_bt:) and no separate tone buttons could sound the low
  and high tones at once, which the lever can't do; the tones are now exclusive there, and releasing
  the other tone's key keeps the lever in place (eu07/maszyna#392),
- a skid ends when the wheel speed crosses the vehicle speed, which never happens with wheels locked
  by the brakes once the vehicle has stopped; it stayed flagged as slipping, its braking force capped by
  the sliding adhesion, so a few such wagons could push a braked consist around (eu07/maszyna#479).
  Like the Vel > 0.1 trap of the skid start, a (nearly) stopped vehicle with wheels turning at its
  speed is no longer slipping,
- lit electronic destination signs kept showing the relation after the timetable had ended, until the
  battery was switched off (eu07/maszyna#446); they are blanked when the timetable runs out, physical
  signs stay up until changed.

What the horn keys do to WarningSignal moves out of the TTrain command handlers into vehicle/horn, which
the unit tests call; the handlers keep the gauges. Tests: tests/unit/test_horn.cpp, both kinds of cabs,
and tests/unit/test_wheelslip.cpp, a wagon which stopped in a skid on slippery rail holds on a slope
like one which stopped on dry rail (without the fix it runs away, ~70 km/h after 30 s).
2026-10-17 13:27:08 +02:00

63 lines
2.3 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::track;
using test::vehicle;
namespace {
struct braking_result {
bool skidded{false}; // the wheels locked while braking
bool stopped{false}; // came (almost) to a stop on the braking rail
};
// brakes the wagon from 40 km/h on the Braking rail until it's (nearly) stopped, then has it stand on the
// Standing one for 30 seconds
braking_result brake_to_stop_then_stand(vehicle &Coach, track const &Braking, track const &Standing) {
braking_result result;
Coach.hold_brake_pipe(5.0);
Coach.run(5.0, Braking);
Coach.hold_brake_pipe(3.5); // service braking
// a skidding wagon brakes on the sliding adhesion only, give it time
for (auto step = 0; step < 60000; ++step) { // 600 s in 0.01 s steps
result.skidded |= Coach->SlippingWheels;
if (auto const speed{std::abs(Coach.speed())}; speed > 0.0 && speed < 0.1) {
// almost stopped; a skidding wagon is still skidding at this point
result.stopped = true;
break;
}
Coach.step(Braking);
}
Coach.run(30.0, Standing);
return result;
}
} // namespace
// the engine doesn't let a stopped, braked vehicle slip (the Vel > 0.1 trap in TMoverParameters::ComputeTotalForce),
// so a wagon which stopped in a skid should be no different from one which stopped without it. it used to stay
// skidding instead, with its brakes capped by the sliding adhesion, and slid or crept away (eu07/maszyna#479)
TEST_CASE("wheelslip: a wagon which stopped in a skid holds like one which stopped without it") {
track const dry{0.15, 0.0};
track const slippery{0.02, 0.0};
// held only by the brakes: the sliding adhesion on this rail is too low for the slope
track const slipperyslope{0.02, 0.08};
vehicle normal{definition::load("wagon"), 40.0};
auto const normalbraking{brake_to_stop_then_stand(normal, dry, slipperyslope)};
vehicle skidding{definition::load("wagon"), 40.0};
auto const skiddingbraking{brake_to_stop_then_stand(skidding, slippery, slipperyslope)};
// the test means something only when the braking went as planned
REQUIRE(normalbraking.stopped);
REQUIRE_FALSE(normalbraking.skidded);
REQUIRE(skiddingbraking.stopped);
REQUIRE(skiddingbraking.skidded);
CHECK(std::abs(normal.speed()) < 0.1);
CHECK(std::abs(skidding.speed()) < 0.1);
CHECK_FALSE(skidding->SlippingWheels);
}