mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 11:34:57 +01:00
feat(blackbox): a black box of the session: the run, the cab, the signals and the stations to a file (#322)
* feat(blackbox): a recorder of the run, the cab, the signals and the stations to a file With the physics logs on (and the new eu07.ini setting blackbox, on by default), the simulator writes a black box of the session to physicslog/*.blackbox: the scenery map (tracks, signals, W4 stop points with their heading, W6 horn points), the timetables of the user's train, and at 10 Hz the cab of the vehicle the user sits in (speed, controllers, brakes, pressures, lights with the pattern the run asks for, the movement kind), the AI's reference for the same place (target speed, next limit, braking distance), the consist, the cameras and the vehicles around. Changes go in as they happen: switches, signal aspects, commands, signals passed with their aspect, stations stopped at, passed or missed, horn requests, the autopilot switched on or off, couplings and vehicles removed. The driving aid's next speed limit moved from the UI panel to TController::next_speed_limit(), so the panel and the recorder read the same. The format is described in blackbox_doc.md; the writer and the reader of the records have unit tests. * fix(blackbox): the aspect a signal had when passed, the lamps the ends have, vehicles taken off - A passed signal is written with the aspect the train had of it, kept in the speed table, not the one its memory cell shows when the pass is noticed: by then the train itself on the track behind has often set it to stop, and most passes were written as at stop. - The cab record gains the lamps the vehicles at the head and the tail have at their outer ends (136 bytes), so a reader can check the light pattern against them as the driver does (no upper headlight, the auxiliary lamps, the rear-end signals only). - A vehicle taken off the scenery and still pointed at by a coupler or the camera gets no new number; the camera lets go of it. - The timetable written before a station goes under the vehicle the user is in now, not the one of the last look. - The file buffer is given once the file is open: MSVC passed over one given before. - The doc tells the AI fields before the consist is started and when entering a vehicle is a driver change. * fix(blackbox): the stop of an automatic block signal passed is written as a stop The speed table keeps the stop of an automatic block signal (SetVelocity 0 x) as the speed allowed after it, with spStopOnSBL; a pass of it was written as that speed with no flag. It is written as 0 with the flag of an automatic block stop again. * feat(blackbox): the doors, the brakes of the whole train, a diesel's engine and the rest of the cab The cab record grows from 136 to 190 bytes, so that a reader can check everything the driver did: - the doors: the permits on each side, the departure signal, the steps, the door lock and whether the doors are locked; - the brakes: the equalizing reservoir of the driver's valve, the main reservoir pipe, the highest brake cylinder pressure of the train, the hand brake, the releaser, the setting (G/P/R/Mg) and the mode (PS/PN/EP/MED); - what drives the vehicle (electric, induction, diesel, diesel-electric, steam, none), its power, a diesel's oil pressure, water, oil and engine temperatures, overheating, fuel and oil pumps, clutch and torque converter, the motor fans; - the cruise control and its speed, the integrated driving handle of a unit, the radio channel, the horn's tones. New device bits use the upper half of the 32-bit field; the new fields come at the end of the record, so older readers still read it. * fix(blackbox): the driver's valve field is what its gauge shows, the radio channel has no none Handle->GetCP() is the equalizing reservoir of most valves but the time reservoir of the FV4a, empty but after an overcharge: the field is named and documented as what the valve shows. With no driver the radio channel reads as the first one, not 0. --------- Co-authored-by: maj00r <maj00r@host>
This commit is contained in:
@@ -25,6 +25,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "world/Event.h"
|
||||
#include "world/MemCell.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "simulation/blackboxrecorder.h"
|
||||
#include "simulation/simulationtime.h"
|
||||
#include "simulation/simulationtest.h"
|
||||
#include "world/Track.h"
|
||||
@@ -810,7 +811,7 @@ void TController::TableCheck(double fDistance)
|
||||
break;
|
||||
}
|
||||
// a switch is a track, the update of a signal never ends the loop above
|
||||
CheckSignalPassedAtDanger( sSpeedTable[ i ], passedbefore );
|
||||
CheckSignalPassed( sSpeedTable[ i ], passedbefore );
|
||||
if (sSpeedTable[i].iFlags & spTrack) // jeśli odcinek
|
||||
{
|
||||
if( sSpeedTable[ i ].fDist + sSpeedTable[ i ].trTrack->Length() < -fLength ) // a skład wyjechał całą długością poza
|
||||
@@ -837,7 +838,7 @@ void TController::TableCheck(double fDistance)
|
||||
auto const lastpassedbefore { TestFlag( sSpeedTable[ iLast ].iFlags, spElapsed ) };
|
||||
sSpeedTable[iLast].Update(); // aktualizacja ostatniego
|
||||
// a signal at stop often is the last, the scan doesn't go past it
|
||||
CheckSignalPassedAtDanger( sSpeedTable[ iLast ], lastpassedbefore );
|
||||
CheckSignalPassed( sSpeedTable[ iLast ], lastpassedbefore );
|
||||
// WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist));
|
||||
if( sSpeedTable[ iLast ].fDist < fDistance ) {
|
||||
TableTraceRoute( fDistance, pVehicles[ end::rear ] ); // doskanowanie dalszego odcinka
|
||||
@@ -860,16 +861,53 @@ bool is_signal_at_stop( TSpeedPos const &Point )
|
||||
&& Point.evEvent != nullptr;
|
||||
}
|
||||
|
||||
// the position is a signal, a main or a shunting one: the aspect comes from its memory cell. putvalues events
|
||||
// set speed limits by the track, and the flags they get don't make them signals
|
||||
bool is_signal( TSpeedPos const &Point )
|
||||
{
|
||||
return TestFlag( Point.iFlags, spEvent )
|
||||
&& ( TestFlag( Point.iFlags, spSemaphor ) || TestFlag( Point.iFlags, spShuntSemaphor ) )
|
||||
&& Point.evEvent != nullptr
|
||||
&& typeid( *Point.evEvent ) == typeid( getvalues_event );
|
||||
}
|
||||
|
||||
std::uint8_t passing_flags_of( TSpeedPos const &Point, double const Speedatsignal, bool const Trainmovement )
|
||||
{
|
||||
std::uint8_t flags { 0 };
|
||||
auto const shunting { TestFlag( Point.iFlags, spShuntSemaphor ) };
|
||||
if( shunting ) {
|
||||
flags |= blackbox::passing_flags::shunt;
|
||||
}
|
||||
// the speeds of the aspects are whole km/h, -1 for no limit; a shunting signal binds only the shunting
|
||||
if( std::abs( Speedatsignal ) < 0.5 && ( false == shunting || false == Trainmovement ) ) {
|
||||
flags |= ( TestFlag( Point.iFlags, spStopOnSBL ) ? blackbox::passing_flags::automatic_block : blackbox::passing_flags::at_stop );
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void TController::CheckSignalPassedAtDanger( TSpeedPos const &Point, bool const Passedbefore ) const
|
||||
void TController::CheckSignalPassed( TSpeedPos const &Point, bool const Passedbefore ) const
|
||||
{
|
||||
if( false == Passedbefore
|
||||
&& TestFlag( Point.iFlags, spElapsed )
|
||||
&& is_signal_at_stop( Point )
|
||||
&& ( mvOccupied->CategoryFlag & 1 ) != 0 ) { // railway only
|
||||
if( Passedbefore
|
||||
|| false == TestFlag( Point.iFlags, spElapsed )
|
||||
|| ( mvOccupied->CategoryFlag & 1 ) == 0 ) { // railway only
|
||||
return;
|
||||
}
|
||||
if( is_signal_at_stop( Point ) ) {
|
||||
simulation::test().signal_passed_at_danger( OwnerName(), Point.evEvent->m_name );
|
||||
}
|
||||
if( is_signal( Point ) ) {
|
||||
// the aspect the train had of it: the table keeps it once the signal is behind, while the memory cell
|
||||
// may already show stop for the train itself, past the signal on the track it guards. the stop of an
|
||||
// automatic block signal is kept as the speed allowed after it, with a flag of its own
|
||||
auto const speedatsignal { TestFlag( Point.iFlags, spStopOnSBL ) ? 0.0 : Point.fVelNext };
|
||||
simulation::Blackbox.signal_passed(
|
||||
pVehicles[ end::front ], *Point.evEvent,
|
||||
speedatsignal, Point.evEvent->input_value( 2 ),
|
||||
mvOccupied->Vel, -Point.fDist,
|
||||
passing_flags_of( Point, speedatsignal, ( OrderCurrentGet() & ( Shunt | Loose_shunt ) ) == 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
auto const passengerstopmaxdistance { 400.0 }; // maximum allowed distance between passenger stop point and consist head
|
||||
@@ -1196,6 +1234,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub
|
||||
// przy jakim dystansie (stanie licznika) ma przesunąć na następny postój
|
||||
fLastStopExpDist = mvOccupied->DistCounter + 0.250 + 0.001 * fLength;
|
||||
TrainParams.UpdateMTable( simulation::Time, asNextStop );
|
||||
record_station( Point, blackbox::station_kinds::passed );
|
||||
UpdateDelayFlag();
|
||||
TrainParams.StationIndexInc(); // przejście do następnej
|
||||
asNextStop = TrainParams.NextStop(); // pobranie kolejnego miejsca zatrzymania
|
||||
@@ -1246,6 +1285,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub
|
||||
// for human-driven vehicles discard the stop point if they leave it far enough behind
|
||||
if( false == AIControllFlag
|
||||
&& Point.fDist < -1 * std::max(fLength + 100, 250.0) - Point.fMoved ) {
|
||||
record_station( Point, blackbox::station_kinds::missed );
|
||||
Point.iFlags = 0; // nie liczy się już zupełnie (nie wyśle SetVelocity)
|
||||
Point.fVelNext = -1; // można jechać za W4
|
||||
if( Point.fDist <= 0.0 && eSignNext == Point.evEvent ) {
|
||||
@@ -1286,6 +1326,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub
|
||||
}
|
||||
if (TrainParams.UpdateMTable( simulation::Time, asNextStop) ) {
|
||||
// to się wykona tylko raz po zatrzymaniu na W4
|
||||
record_station( Point, blackbox::station_kinds::stopped );
|
||||
if( TrainParams.StationIndex < TrainParams.StationCount ) {
|
||||
// jeśli są dalsze stacje, bez trąbienia przed odjazdem
|
||||
// also ignore any horn cue that may be potentially set below 1 km/h and before the actual full stop
|
||||
@@ -1352,6 +1393,7 @@ TController::TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, doub
|
||||
// z dalszą akcją czekamy do godziny odjazdu
|
||||
// cargo trains and passenger trains at maintenance stop don't need to wait
|
||||
IsAtPassengerStop = false;
|
||||
record_station( Point, blackbox::station_kinds::ready );
|
||||
// przy jakim dystansie (stanie licznika) ma przesunąć na następny postój
|
||||
fLastStopExpDist = mvOccupied->DistCounter + 0.050 + 0.001 * fLength;
|
||||
TrainParams.StationIndexInc(); // przejście do następnej
|
||||
@@ -2881,6 +2923,98 @@ TBrakeSystem TController::consist_brake_system() const {
|
||||
return isepcapable ? TBrakeSystem::ElectroPneumatic : TBrakeSystem::Pneumatic;
|
||||
}
|
||||
|
||||
std::pair<int, double> TController::next_speed_limit() const {
|
||||
|
||||
auto const speedlimit { static_cast<int>( VelDesired ) };
|
||||
auto nextspeedlimit { speedlimit };
|
||||
auto nextspeedlimitdistance { std::numeric_limits<double>::max() };
|
||||
if( speedlimit == 0 ) {
|
||||
// if we aren't allowed to move then any next speed limit is irrelevant
|
||||
return { nextspeedlimit, nextspeedlimitdistance };
|
||||
}
|
||||
// nie przekraczać rozkladowej
|
||||
auto const schedulespeedlimit { (
|
||||
( OrderCurrentGet() & ( Obey_train | Bank ) ) != 0 && TrainParams.TTVmax > 0.0 ? static_cast<int>( TrainParams.TTVmax ) :
|
||||
( OrderCurrentGet() & ( Obey_train | Bank ) ) == 0 ? static_cast<int>( fShuntVelocity ) :
|
||||
-1 ) };
|
||||
// first take note of any speed change which should occur after passing potential current speed limit
|
||||
if( VelLimitLastDist.second > 0 ) {
|
||||
nextspeedlimit = min_speed( schedulespeedlimit, static_cast<int>( VelLimitLastDist.first ) );
|
||||
nextspeedlimitdistance = VelLimitLastDist.second;
|
||||
}
|
||||
// then take into account speed change ahead, compare it with speed after potentially clearing last limit
|
||||
// lower of these two takes priority; otherwise limit lasts at least until potential last limit is cleared
|
||||
auto const noactivespeedlimit { VelLimitLastDist.second < 0 };
|
||||
if( auto const speedatproximitydistance { min_speed( schedulespeedlimit, static_cast<int>( VelNext ) ) }; speedatproximitydistance == nextspeedlimit ) {
|
||||
if( noactivespeedlimit ) {
|
||||
nextspeedlimit = speedatproximitydistance;
|
||||
nextspeedlimitdistance = ActualProximityDist;
|
||||
}
|
||||
}
|
||||
else if( speedatproximitydistance < nextspeedlimit ) {
|
||||
// if the speed limit ahead is more strict than our current limit, it's important enough to report
|
||||
if( speedatproximitydistance < VelDesired ) {
|
||||
nextspeedlimit = speedatproximitydistance;
|
||||
nextspeedlimitdistance = ActualProximityDist;
|
||||
}
|
||||
// otherwise report it only if it's located after our current (lower) limit ends
|
||||
else if( ActualProximityDist > nextspeedlimitdistance ) {
|
||||
nextspeedlimit = speedatproximitydistance;
|
||||
nextspeedlimitdistance = ActualProximityDist;
|
||||
}
|
||||
}
|
||||
else if( noactivespeedlimit ) { // implicit proximity > last, report only if last limit isn't present
|
||||
nextspeedlimit = speedatproximitydistance;
|
||||
nextspeedlimitdistance = ActualProximityDist;
|
||||
}
|
||||
// HACK: if our current speed limit extends beyond our scan range don't display potentially misleading information about its length
|
||||
if( nextspeedlimitdistance >= EU07_AI_SPEEDLIMITEXTENDSBEYONDSCANRANGE ) {
|
||||
nextspeedlimit = speedlimit;
|
||||
}
|
||||
// HACK: hide next speed limit if the 'limit' is a vehicle in front of us
|
||||
else if( ActualProximityDist == std::abs( TrackObstacle() ) ) {
|
||||
nextspeedlimit = speedlimit;
|
||||
}
|
||||
return { nextspeedlimit, nextspeedlimitdistance };
|
||||
}
|
||||
|
||||
blackbox::ai_reference TController::ai_reference() const {
|
||||
|
||||
blackbox::ai_reference ai;
|
||||
ai.target_kmh = static_cast<float>( VelDesired );
|
||||
if( auto const [ limit, distance ] { next_speed_limit() }; limit != static_cast<int>( VelDesired ) ) {
|
||||
ai.next_limit_kmh = static_cast<float>( limit );
|
||||
ai.next_limit_distance = static_cast<float>( distance );
|
||||
}
|
||||
ai.acceleration = static_cast<float>( AccDesired );
|
||||
ai.braking_distance = static_cast<float>( fBrakeDist );
|
||||
ai.timetable_vmax_kmh = ( TrainParams.TTVmax > 0.0 ? static_cast<float>( TrainParams.TTVmax ) : -1.0f );
|
||||
ai.track_vmax_kmh = static_cast<float>( mvOccupied->RunningTrack.Velmax );
|
||||
return ai;
|
||||
}
|
||||
|
||||
void TController::record_station( TSpeedPos const &Point, std::uint8_t const Kind ) const {
|
||||
|
||||
if( Point.evEvent == nullptr ) { return; }
|
||||
blackbox::station_event entry;
|
||||
entry.kind = Kind;
|
||||
auto const row { TrainParams.StationIndex };
|
||||
entry.row = static_cast<std::uint16_t>( std::max( 0, row ) );
|
||||
entry.station = asNextStop;
|
||||
entry.position = Point.evEvent->input_location();
|
||||
// the stop point may be moved back from the indicator, to where the head of the train is to stop
|
||||
entry.distance = static_cast<float>( Point.fDist + Point.fMoved );
|
||||
entry.stop_at = static_cast<float>( Point.fMoved );
|
||||
entry.train_length = static_cast<float>( fLength );
|
||||
entry.platform = static_cast<float>( Point.evEvent->input_value( 2 ) );
|
||||
if( row >= 0 && row <= TrainParams.StationCount ) {
|
||||
auto const &line { TrainParams.TimeTable[ row ] };
|
||||
entry.arrival = ( line.Ah >= 0 ? static_cast<float>( line.Ah * 60 ) + line.Am : -1.0f );
|
||||
entry.departure = ( line.Dh >= 0 ? static_cast<float>( line.Dh * 60 ) + line.Dm : -1.0f );
|
||||
}
|
||||
simulation::Blackbox.station( pVehicles[ end::front ], std::move( entry ) );
|
||||
}
|
||||
|
||||
int TController::OrderDirectionChange(int newdir, TMoverParameters *Vehicle)
|
||||
{ // zmiana kierunku jazdy, niezależnie od kabiny
|
||||
int testd = newdir;
|
||||
@@ -5092,6 +5226,8 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
|
||||
if( NewValue1 > 0 && NewValue2 > 0 ) {
|
||||
fWarningDuration = NewValue1; // czas trąbienia
|
||||
cue_action( driver_hint::hornon, NewValue2 ); // horn combination flag
|
||||
simulation::Blackbox.horn_requested(
|
||||
pVehicles[ end::front ], NewValue1, NewValue2, NewLocation != nullptr ? *NewLocation : pVehicles[ end::front ]->GetPosition() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -5922,6 +6058,10 @@ void TController::TakeControl( bool const Aidriver, bool const Forcevehiclecheck
|
||||
{ // przejęcie kontroli przez AI albo oddanie
|
||||
if (AIControllFlag == Aidriver && !Forcevehiclecheck)
|
||||
return; // już jest jak ma być
|
||||
if( AIControllFlag != Aidriver ) {
|
||||
// the autopilot switched on or off
|
||||
simulation::Blackbox.driver_changed( pVehicle, Aidriver );
|
||||
}
|
||||
if (Aidriver) //żeby nie wykonywać dwa razy
|
||||
{ // teraz AI prowadzi
|
||||
AIControllFlag = AIdriver;
|
||||
|
||||
Reference in New Issue
Block a user