From 7b7529e24e51628516b249baff54f38f97954e2b Mon Sep 17 00:00:00 2001 From: maj00r Date: Sat, 14 Nov 2026 00:48:18 +0100 Subject: [PATCH] feat(blackbox): the cab record holds the speed of the wheels, apart from the vehicle's when they slip The speed of the cab record is the vehicle's. The speedometer, and a speed recorder's tape with it, shows the speed of the wheels as they turn, which runs away from it while they slip and drops to 0 while they are locked in a skid. It is added at the end of the record (194 bytes), where the readers skip what they don't know; the .dat tapes have it already, in their second column. --- blackbox_doc.md | 6 ++++-- simulation/blackboxrecorder.cpp | 2 ++ tests/unit/test_blackbox.cpp | 3 +++ vehicle/blackbox.cpp | 1 + vehicle/blackbox.h | 5 ++++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/blackbox_doc.md b/blackbox_doc.md index ea7322ca8..d81b143bc 100644 --- a/blackbox_doc.md +++ b/blackbox_doc.md @@ -172,14 +172,15 @@ record. ### 0x20 cab -The vehicle the user is in, every 0.1 s, also while the user looks around outside it. 190 bytes. +The vehicle the user is in, every 0.1 s, also while the user looks around outside it. 194 bytes (190 in the +files written before the speed of the wheels was added at the end). | type | field | |---------|------------------------------------------------------------------------| | `f64` | t | | `u32` | number of the vehicle | | `dvec3` | position | -| `f32` | speed [km/h], positive along the front of the vehicle | +| `f32` | speed of the vehicle [km/h], positive along its front | | `f32` | acceleration along the track [m/s²] | | `f32` | odometer [km] | | `u8` | driver: 0 none, 1 the user, 2 the AI (the autopilot) | @@ -231,6 +232,7 @@ The vehicle the user is in, every 0.1 s, also while the user looks around outsid | `f32` | the clutch of a diesel's gearbox, 0 open .. 1 closed | | `f32` | the filling of a diesel's hydraulic torque converter, 0..1 | | `f32` | the highest brake cylinder pressure of the vehicles of the train [bar] | +| `f32` | speed of the wheels [km/h], as the speedometer shows it, signed as the speed of the vehicle: apart from it while the wheels slip, 0 while they are locked in a skid | The lights the train is to show follow from the movement and the two patterns after it: in a train run the head the pattern asked for, the usual one Pc 1 (both headlights and the upper one; Pc 2 is the left red marker with the right and the diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 141ff070e..bc572afbd 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -418,6 +418,8 @@ void blackbox_recorder::write_cab() { sample.vehicle = vehicle_id(vehicle); sample.position = vehicle->GetPosition(); sample.speed_kmh = static_cast(occupied->V * 3.6); + // of the wheels as they turn, which the speedometer shows: apart from that of the vehicle when they slip or skid + sample.wheel_speed_kmh = static_cast(M_PI * occupied->WheelDiameter * occupied->nrot * 3.6); sample.acceleration = static_cast(controlling->AccS); sample.lateral_acceleration = static_cast(occupied->AccN); if (owner != nullptr && owner->is_train()) { diff --git a/tests/unit/test_blackbox.cpp b/tests/unit/test_blackbox.cpp index b11253b49..cad1920a1 100644 --- a/tests/unit/test_blackbox.cpp +++ b/tests/unit/test_blackbox.cpp @@ -127,6 +127,7 @@ blackbox::cab_sample sample() { s.clutch = 0.75f; s.converter_fill = 0.25f; s.consist_brake_cylinder = 3.5f; + s.wheel_speed_kmh = 71.5f; return s; } @@ -285,6 +286,8 @@ TEST_CASE("blackbox: a sample of the user's train has the documented size and or CHECK(cab.get() == 0.25f); // the highest brake cylinder pressure of the train CHECK(cab.get() == 3.5f); + // the speed of the wheels + CHECK(cab.get() == 71.5f); CHECK(cab.done()); } diff --git a/vehicle/blackbox.cpp b/vehicle/blackbox.cpp index 8612df1bd..fc05f7483 100644 --- a/vehicle/blackbox.cpp +++ b/vehicle/blackbox.cpp @@ -205,6 +205,7 @@ void writer::cab(cab_sample const &Sample) { out.f32(Sample.clutch); out.f32(Sample.converter_fill); out.f32(Sample.consist_brake_cylinder); + out.f32(Sample.wheel_speed_kmh); emit(record::cab); } diff --git a/vehicle/blackbox.h b/vehicle/blackbox.h index 473cf677c..62fc1df38 100644 --- a/vehicle/blackbox.h +++ b/vehicle/blackbox.h @@ -257,6 +257,9 @@ struct cab_sample { float clutch{0.0f}; // the clutch of a diesel's gearbox, 0 open .. 1 closed float converter_fill{0.0f}; // the filling of a diesel's hydraulic torque converter, 0..1 float consist_brake_cylinder{0.0f}; // the highest brake cylinder pressure of the vehicles of the train [bar] + // [km/h] of the wheels as they turn, which the speedometer shows, signed as speed_kmh: apart from it while the wheels + // slip, and 0 while they are locked in a skid + float wheel_speed_kmh{0.0f}; }; // a station of the timetable of the user's train; the times in minutes of the day, -1 none @@ -354,7 +357,7 @@ struct signal_passing { // sizes of the parts of fixed size, as the readers expect them inline constexpr std::size_t header_size{12}; inline constexpr std::size_t record_header_size{5}; -inline constexpr std::size_t cab_sample_size{190}; +inline constexpr std::size_t cab_sample_size{194}; inline constexpr std::size_t vehicle_state_size{25}; // writes the records to a stream. nothing is written until header() is