mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-18 22:16:02 +01:00
test: slippery rail skid cases, wheelslip and vehicle speed checks
- physicslog rows keep all columns (text ones as None), checks can read the wheelslip flag and the new vehicle speed column - slips: the lead vehicle's wheels slip at some point (makes sure a slippery rail case does what it's meant to) - slip_clears: once stopped, the wheels stop slipping within N seconds - holds_still: once stopped, the vehicle doesn't creep, by vehicle speed - td_red_signal_moving.scn: the red signal case starting already moving - eu07_slippery_red_signal / eu07_slippery_push_red_signal: skid on braking for the red signal with track friction 0.03; the pushing one fails without the fix for eu07/maszyna#479 (stays skidding, creeps) - sn61_td_timetable: stop hold 5 -> 2 s, the railcar arrives 5-7 s before its departure time, so 5 s made the case flaky
This commit is contained in:
@@ -71,9 +71,13 @@ scenery is newer.
|
||||
the one whose physicslog is checked. Other vehicles of the consist take names made from it,
|
||||
e.g. `{{vehicle}}_s`. The td.scn cases share two fragments, `td_timetable.scn` (route set,
|
||||
train runs to Przystanek) and `td_red_signal.scn` (no route, exit signal at stop), and differ
|
||||
only in `vars.consist`.
|
||||
only in `vars.consist`. `td_red_signal_moving.scn` is the red signal one with the train
|
||||
starting at `vars.velocity` km/h; with `track_friction` 0.03 it locks the wheels when braking.
|
||||
|
||||
Checks (speeds in km/h, times in seconds of physicslog time, distances in metres):
|
||||
Checks (speeds in km/h, times in seconds of physicslog time, distances in metres). Most use
|
||||
the physicslog Velocity column, which is the wheel speed: it stays at 0 while the wheels are
|
||||
locked in a skid. The ones marked *vehicle speed* use the vehicle speed column at the end of
|
||||
the row instead, logged by builds from this branch on.
|
||||
|
||||
- `starts` `min_speed`, `within`: reaches `min_speed` within `within` seconds.
|
||||
- `max_speed` `limit`, `tolerance`: never goes faster than `limit + tolerance`.
|
||||
@@ -86,6 +90,12 @@ Checks (speeds in km/h, times in seconds of physicslog time, distances in metres
|
||||
- `distance` `min`, `max`: total distance travelled. The physicslog has no position, so the
|
||||
distance comes from integrating the speed; on td.scn every vehicle's first stop after
|
||||
Stacja1 came out at 1400 m (+-3), and the red signal stop at 140 m.
|
||||
- `slips` `within`: the lead vehicle's wheels slip or lock at some point (within `within`
|
||||
seconds if given), so a slippery rail case does what it's meant to.
|
||||
- `slip_clears` `moving_speed`, `stop_speed`, `within` (*vehicle speed*): once stopped after
|
||||
moving off, the wheels stop slipping within `within` seconds.
|
||||
- `holds_still` `moving_speed`, `stop_speed`, `max_distance` (*vehicle speed*): once stopped
|
||||
after moving off, moves no more than `max_distance` metres, e.g. no creeping on locked wheels.
|
||||
|
||||
New check types go in `CHECKS` in `run.py`; each gets the physicslog rows and the check's
|
||||
parameters and returns `(passed, detail)`.
|
||||
|
||||
36
tests/scenarios/cases/eu07_slippery_push_red_signal.json
Normal file
36
tests/scenarios/cases/eu07_slippery_push_red_signal.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"description": "EU07 pushing three coaches on td.scn with slippery rail and no route set, starting at 30 km/h: brakes for the exit signal at stop and skids. Pushed by the train it doesn't roll back at the stop, so it used to stay skidding on locked wheels with the brakes capped by the sliding adhesion and creep (eu07/maszyna#479).",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"track_friction": 0.03,
|
||||
"fragment": "td_red_signal_moving.scn",
|
||||
"vars": {
|
||||
"velocity": "30",
|
||||
"consist": [
|
||||
"node -1 0 {{vehicle}}_w1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_w2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608011-6 BDHPUMN_NG_1 0 nobody 115 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_w3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic"
|
||||
]
|
||||
},
|
||||
"duration": 240,
|
||||
"timeout": 900,
|
||||
"checks": [
|
||||
{
|
||||
"type": "slips",
|
||||
"within": 60
|
||||
},
|
||||
{
|
||||
"type": "slip_clears",
|
||||
"moving_speed": 5,
|
||||
"stop_speed": 0.05,
|
||||
"within": 5
|
||||
},
|
||||
{
|
||||
"type": "holds_still",
|
||||
"moving_speed": 5,
|
||||
"stop_speed": 0.05,
|
||||
"max_distance": 0.01
|
||||
}
|
||||
]
|
||||
}
|
||||
36
tests/scenarios/cases/eu07_slippery_red_signal.json
Normal file
36
tests/scenarios/cases/eu07_slippery_red_signal.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"description": "EU07 with three coaches on td.scn with slippery rail and no route set, starting at 30 km/h: brakes for the exit signal at stop and skids, then the skid ends and the train holds still.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"track_friction": 0.03,
|
||||
"fragment": "td_red_signal_moving.scn",
|
||||
"vars": {
|
||||
"velocity": "30",
|
||||
"consist": [
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_w1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_w2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608011-6 BDHPUMN_NG_1 0 nobody 115 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_w3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic"
|
||||
]
|
||||
},
|
||||
"duration": 240,
|
||||
"timeout": 900,
|
||||
"checks": [
|
||||
{
|
||||
"type": "slips",
|
||||
"within": 60
|
||||
},
|
||||
{
|
||||
"type": "slip_clears",
|
||||
"moving_speed": 5,
|
||||
"stop_speed": 0.05,
|
||||
"within": 5
|
||||
},
|
||||
{
|
||||
"type": "holds_still",
|
||||
"moving_speed": 5,
|
||||
"stop_speed": 0.05,
|
||||
"max_distance": 0.01
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,6 +12,6 @@
|
||||
{ "type": "starts", "min_speed": 20, "within": 150 },
|
||||
{ "type": "max_speed", "limit": 90, "tolerance": 3 },
|
||||
{ "type": "brakes", "min_pressure": 0.5 },
|
||||
{ "type": "stops", "moving_speed": 20, "stop_speed": 0.5, "hold": 5 }
|
||||
{ "type": "stops", "moving_speed": 20, "stop_speed": 0.5, "hold": 2 }
|
||||
]
|
||||
}
|
||||
|
||||
6
tests/scenarios/cases/td_red_signal_moving.scn
Normal file
6
tests/scenarios/cases/td_red_signal_moving.scn
Normal file
@@ -0,0 +1,6 @@
|
||||
// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed.
|
||||
// like td_red_signal.scn (no route, the exit signal stacja1_j about 150 m ahead stays at stop),
|
||||
// but the train starts already moving at {{velocity}} km/h, so it has to brake right away.
|
||||
trainset td/rozklad tdo_n1734 0.0 {{velocity}}
|
||||
{{consist}}
|
||||
endtrainset
|
||||
@@ -43,8 +43,11 @@ OUT_DIR = HERE / "out"
|
||||
# physicslog columns, see TController::PhysicsLog() in vehicle/Driver.cpp.
|
||||
# Velocity is in km/h and pressures in bar, despite the header saying m/s and MPa.
|
||||
COL_TIME = 0
|
||||
COL_VELOCITY = 1
|
||||
COL_VELOCITY = 1 # wheel speed: stays at 0 while the wheels are locked in a skid
|
||||
COL_BRAKE_PRESS = 8
|
||||
COL_COMMAND = 16 # text, read as None
|
||||
COL_WHEELSLIP = 20
|
||||
COL_VEHICLE_VELOCITY = 25 # signed vehicle speed, km/h; only in builds which log it
|
||||
|
||||
# settings layered over the user's eu07.ini for a test run
|
||||
TEST_INI = """\
|
||||
@@ -145,7 +148,7 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s
|
||||
|
||||
|
||||
def read_physicslog(path: Path) -> list[list[float]]:
|
||||
"""Returns rows of numeric columns up to BrakePress; skips the header and partial lines."""
|
||||
"""Returns rows of columns, None for the text ones; skips the header and partial lines."""
|
||||
rows = []
|
||||
try:
|
||||
lines = path.read_text(errors="replace").splitlines()
|
||||
@@ -156,9 +159,15 @@ def read_physicslog(path: Path) -> list[list[float]]:
|
||||
if len(parts) <= COL_BRAKE_PRESS:
|
||||
continue # line still being written
|
||||
try:
|
||||
rows.append([float(p) for p in parts[: COL_BRAKE_PRESS + 1]])
|
||||
row = [float(p) for p in parts[: COL_BRAKE_PRESS + 1]]
|
||||
except ValueError:
|
||||
continue
|
||||
for p in parts[COL_BRAKE_PRESS + 1:]:
|
||||
try:
|
||||
row.append(float(p))
|
||||
except ValueError:
|
||||
row.append(None)
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
|
||||
@@ -331,7 +340,60 @@ def check_distance(rows, max=None, min=None):
|
||||
return ok, f"travelled {d:.0f} m (wanted {bounds})"
|
||||
|
||||
|
||||
def check_slips(rows, within=None):
|
||||
"""The lead vehicle's wheels slip (or lock in a skid) at some point, e.g. to make sure a slippery rail case does what it's meant to."""
|
||||
for r in rows:
|
||||
if within is not None and r[COL_TIME] > within:
|
||||
break
|
||||
if len(r) > COL_WHEELSLIP and r[COL_WHEELSLIP]:
|
||||
return True, f"wheels slipping at t={r[COL_TIME]:.1f}s, v={r[COL_VELOCITY]:.1f} km/h"
|
||||
return False, "the wheels never slipped"
|
||||
|
||||
|
||||
def check_holds_still(rows, moving_speed, stop_speed, max_distance):
|
||||
"""Once stopped after moving off, the vehicle doesn't creep. Uses the vehicle speed rather than the
|
||||
wheel speed, so it also catches a vehicle sliding on locked wheels."""
|
||||
if not rows or len(rows[0]) <= COL_VEHICLE_VELOCITY or rows[0][COL_VEHICLE_VELOCITY] is None:
|
||||
return False, "the physicslog has no vehicle speed column, the build is too old"
|
||||
speed = [abs(r[COL_VEHICLE_VELOCITY]) for r in rows]
|
||||
start = next((i for i, v in enumerate(speed) if v >= moving_speed), None)
|
||||
if start is None:
|
||||
return False, f"never reached {moving_speed} km/h"
|
||||
stop = next((i for i in range(start, len(rows)) if speed[i] <= stop_speed), None)
|
||||
if stop is None:
|
||||
return False, f"never came down to {stop_speed} km/h"
|
||||
d, top, top_t = 0.0, 0.0, rows[stop][COL_TIME]
|
||||
for i in range(stop + 1, len(rows)):
|
||||
d += (speed[i - 1] + speed[i]) / 2 / 3.6 * (rows[i][COL_TIME] - rows[i - 1][COL_TIME])
|
||||
if speed[i] > top:
|
||||
top, top_t = speed[i], rows[i][COL_TIME]
|
||||
held = rows[-1][COL_TIME] - rows[stop][COL_TIME]
|
||||
detail = f"stopped at t={rows[stop][COL_TIME]:.1f}s, then moved {d:.3f} m in {held:.0f}s, top {top:.4f} km/h at t={top_t:.1f}s"
|
||||
return d <= max_distance, detail
|
||||
|
||||
|
||||
def check_slip_clears(rows, moving_speed, stop_speed, within):
|
||||
"""Once the vehicle has stopped after moving off, its wheels stop slipping within `within` seconds
|
||||
(a vehicle left skidding on locked wheels keeps its brakes capped by the sliding adhesion)."""
|
||||
if not rows or len(rows[0]) <= COL_VEHICLE_VELOCITY or rows[0][COL_VEHICLE_VELOCITY] is None:
|
||||
return False, "the physicslog has no vehicle speed column, the build is too old"
|
||||
start = next((i for i, r in enumerate(rows) if abs(r[COL_VEHICLE_VELOCITY]) >= moving_speed), None)
|
||||
if start is None:
|
||||
return False, f"never reached {moving_speed} km/h"
|
||||
stop = next((i for i in range(start, len(rows)) if abs(rows[i][COL_VEHICLE_VELOCITY]) <= stop_speed), None)
|
||||
if stop is None:
|
||||
return False, f"never came down to {stop_speed} km/h"
|
||||
deadline = rows[stop][COL_TIME] + within
|
||||
late = [r for r in rows[stop:] if r[COL_TIME] > deadline and r[COL_WHEELSLIP]]
|
||||
if late:
|
||||
return False, f"stopped at t={rows[stop][COL_TIME]:.1f}s, wheels still slipping at t={late[0][COL_TIME]:.1f}s ({len(late)} rows after the {within}s grace)"
|
||||
return True, f"stopped at t={rows[stop][COL_TIME]:.1f}s, no slipping after t={deadline:.1f}s"
|
||||
|
||||
|
||||
CHECKS = {
|
||||
"slips": check_slips,
|
||||
"slip_clears": check_slip_clears,
|
||||
"holds_still": check_holds_still,
|
||||
"starts": check_starts,
|
||||
"max_speed": check_max_speed,
|
||||
"brakes": check_brakes,
|
||||
|
||||
Reference in New Issue
Block a user