mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +01:00
refactor(physics): the faults of the equipment are a named set the physics sets
The faults the scenery or the network sets on a vehicle (TDynamicObject::
Damage() with the number of a message, held as EngDmgFlag and tested as its
bits 1, 4) are EquipmentFault and EquipmentFaultSet, and what each does moves
out of TDynamicObject into physics::Vehicle::SetEquipmentFaults(). The number of
a message comes in through FromBits() and goes back out through Bits(), as it
was.
The faults of the control and of the camshaft still hold the start and the
steps of the controller by delays moved out of reach by 100000001 and back,
the very same arithmetic, now named and in one place. Tests of it are added
(test_equipment_faults.cpp), as nothing reached it before.
The setters of the parts that took a parameter named as one of their queries
(Pressure, Voltage) take Value instead.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
+1
-1
@@ -188,7 +188,7 @@ OnCommandGet(multiplayer::DaneRozkaz const *pRozkaz)
|
||||
d->Damage( pRozkaz->cString[ 0 ] );
|
||||
d = d->Prev(); // w drugą stronę też
|
||||
}
|
||||
WyslijUszkodzenia( lookup->asName, static_cast<char>(lookup->physics->EngDmgFlag) ); // zwrot informacji o pojeździe
|
||||
WyslijUszkodzenia( lookup->asName, static_cast<char>(lookup->physics->equipmentFaults.Bits()) ); // zwrot informacji o pojeździe
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -33,7 +33,7 @@ class TrainPipe
|
||||
// the pressure in the pipe [bar], as it was last taken from its reservoir
|
||||
double const &Pressure() const { return pressure; }
|
||||
// the pressure taken from the reservoir of the pipe, after the flows of a step
|
||||
void SetPressure(double const Pressure) { pressure = Pressure; }
|
||||
void SetPressure(double const Value) { pressure = Value; }
|
||||
|
||||
// the pipe stepped, its exchange of air through the hoses is yet to come (UpdatePipeCouplers())
|
||||
bool CouplersPending() const { return couplersPending; }
|
||||
@@ -316,7 +316,7 @@ class AirSupply
|
||||
}
|
||||
|
||||
// for the tests: the pressure in the reservoir as given, whatever its air
|
||||
void SetPressureForTest(double const Pressure) { mainReservoirPressure = Pressure; }
|
||||
void SetPressureForTest(double const Value) { mainReservoirPressure = Value; }
|
||||
|
||||
private:
|
||||
double mainReservoirPressure{0.0};
|
||||
|
||||
@@ -1300,3 +1300,47 @@ namespace simulation
|
||||
weights_table Weights;
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
void physics::Vehicle::SetEquipmentFaults(EquipmentFaultSet const Faults)
|
||||
{
|
||||
if (Faults.HasAll(EquipmentFault::differentialRelay)) // różnicówka nie robi nic
|
||||
{
|
||||
MainSwitch(false);
|
||||
FuseOff();
|
||||
}
|
||||
// the faults of the control and of the camshaft hold the start, or the steps of the controller, by delays that never
|
||||
// pass: the delays of the definition moved out of reach, and back when the fault clears
|
||||
constexpr double faultoffset{100000001};
|
||||
constexpr double faultthreshold{100000000};
|
||||
if (Faults.HasAll(EquipmentFault::control)) // usterka sterowania
|
||||
{
|
||||
lineContactors.Open();
|
||||
if (InitialCtrlDelay < faultthreshold)
|
||||
InitialCtrlDelay += faultoffset;
|
||||
}
|
||||
else if (InitialCtrlDelay > faultthreshold)
|
||||
{
|
||||
InitialCtrlDelay -= faultoffset;
|
||||
}
|
||||
if (Faults.HasAll(EquipmentFault::converter) && converter.config.start != start_t::disabled) // blokada przetwornicy
|
||||
{
|
||||
converter.Overload();
|
||||
}
|
||||
air.compressor.SetFault(Faults.HasAll(EquipmentFault::compressor)); // blokada sprezarki
|
||||
if (Faults.HasAll(EquipmentFault::camshaft)) // blokada wału
|
||||
{
|
||||
if (CtrlDelay < faultthreshold)
|
||||
CtrlDelay += faultoffset;
|
||||
if (CtrlDownDelay < faultthreshold)
|
||||
CtrlDownDelay += faultoffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CtrlDelay > faultthreshold)
|
||||
CtrlDelay -= faultoffset;
|
||||
if (CtrlDownDelay > faultthreshold)
|
||||
CtrlDownDelay -= faultoffset;
|
||||
}
|
||||
// hamowanie nagłe (emergencyBrake): nothing yet
|
||||
equipmentFaults = Faults;
|
||||
}
|
||||
|
||||
@@ -782,7 +782,7 @@ void physics::Vehicle::rerail()
|
||||
void physics::Vehicle::repair_damage()
|
||||
{
|
||||
DamageFlag = {};
|
||||
EngDmgFlag = 0;
|
||||
equipmentFaults = {};
|
||||
WheelFlat = 0.0;
|
||||
brakes.alarmChain = false;
|
||||
// the crushed ends rebuilt
|
||||
|
||||
@@ -518,7 +518,7 @@ void physics::Vehicle::ConverterCheck(double const Timestep)
|
||||
supply.pantographPressureLock = pantographAir.IsPressureLockActive();
|
||||
// HACK: allow carriages to operate converter without (missing) fuse prerequisite
|
||||
supply.highVoltage = Power > 1.0 ? MainCircuitPowered() : GetTrainsetHighVoltage() > 0.0;
|
||||
supply.damaged = TestFlag(EngDmgFlag, 4);
|
||||
supply.damaged = equipmentFaults.HasAll(EquipmentFault::converter);
|
||||
converter.Update(supply, Timestep);
|
||||
}
|
||||
|
||||
@@ -869,7 +869,7 @@ bool physics::Vehicle::MainSwitchCheck() const
|
||||
(HasCamshaft ? IsMainCtrlActualNoPowerPos() :
|
||||
lineBreaker.config.closesOnlyAtNoPower ? IsMainCtrlNoPowerPos() :
|
||||
true) &&
|
||||
false == DamageFlag.HasAll(VehicleDamage::derailed) && false == TestFlag(EngDmgFlag, 1) && false == EmergencyBrakeHoldsMainOff();
|
||||
false == DamageFlag.HasAll(VehicleDamage::derailed) && false == equipmentFaults.HasAll(EquipmentFault::differentialRelay) && false == EmergencyBrakeHoldsMainOff();
|
||||
}
|
||||
|
||||
// *************************************************************************************************
|
||||
|
||||
@@ -33,10 +33,10 @@ class LowVoltageSupply
|
||||
Config config;
|
||||
|
||||
// the battery of the definition (LMaxVoltage), charged
|
||||
void SetBattery(double const Voltage)
|
||||
void SetBattery(double const Value)
|
||||
{
|
||||
batteryVoltage = Voltage;
|
||||
config.nominalBatteryVoltage = static_cast<float>(Voltage);
|
||||
batteryVoltage = Value;
|
||||
config.nominalBatteryVoltage = static_cast<float>(Value);
|
||||
}
|
||||
|
||||
bool IsBatteryOn() const { return batteryOn; }
|
||||
@@ -85,9 +85,9 @@ class LowVoltageSupply
|
||||
// the voltage of the battery circuit
|
||||
double Voltage24v() const { return power24vVoltage; }
|
||||
// the circuits in the step: the 24 V one from its voltage, the 110 V one as given
|
||||
void SetSupply(double const Voltage24v, bool const Available110v)
|
||||
void SetSupply(double const Volts24, bool const Available110v)
|
||||
{
|
||||
power24vVoltage = Voltage24v;
|
||||
power24vVoltage = Volts24;
|
||||
power24vAvailable = power24vVoltage > 0;
|
||||
power110vAvailable = Available110v;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ class PantographCircuit
|
||||
double Voltage(VehicleEnd const End) const { return End == VehicleEnd::front ? frontVoltage : rearVoltage; }
|
||||
double FrontVoltage() const { return frontVoltage; }
|
||||
double RearVoltage() const { return rearVoltage; }
|
||||
void SetFrontVoltage(double const Voltage) { frontVoltage = Voltage; }
|
||||
void SetRearVoltage(double const Voltage) { rearVoltage = Voltage; }
|
||||
void SetFrontVoltage(double const Value) { frontVoltage = Value; }
|
||||
void SetRearVoltage(double const Value) { rearVoltage = Value; }
|
||||
// the voltage supplied to the pantographs, from the overhead line the vehicle is under
|
||||
double SupplyVoltage() const { return supplyVoltage; }
|
||||
void SetSupplyVoltage(double const Voltage) { supplyVoltage = Voltage; }
|
||||
void SetSupplyVoltage(double const Value) { supplyVoltage = Value; }
|
||||
|
||||
// the switch that lowers all of them
|
||||
bool AllDown() const { return allDown; }
|
||||
@@ -195,9 +195,9 @@ class PantographAir
|
||||
}
|
||||
|
||||
// for the tests: the reservoirs at the given pressure, with the pressure switch primed or not
|
||||
void SetForTest(double const Pressure, bool const PressureSwitchPrimed)
|
||||
void SetForTest(double const Value, bool const PressureSwitchPrimed)
|
||||
{
|
||||
pressure = Pressure;
|
||||
pressure = Value;
|
||||
pressureSwitchActive = PressureSwitchPrimed;
|
||||
}
|
||||
|
||||
|
||||
@@ -1462,14 +1462,14 @@ bool physics::Vehicle::RelayReset(int const Relays, range_t const Notify)
|
||||
|
||||
if (TestFlag(Relays, relay_t::maincircuitground) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) &&
|
||||
(protection.config.groundStart == start_t::manual || protection.config.groundStart == start_t::manualwithautofallback) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 &&
|
||||
!TestFlag(EngDmgFlag, 1))
|
||||
false == equipmentFaults.HasAll(EquipmentFault::differentialRelay))
|
||||
{
|
||||
// NOTE: true means the relay is operational
|
||||
reset |= protection.ResetGround(lowvoltagepower);
|
||||
}
|
||||
|
||||
if (TestFlag(Relays, relay_t::tractionnmotoroverload) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 &&
|
||||
!TestFlag(EngDmgFlag, 1))
|
||||
false == equipmentFaults.HasAll(EquipmentFault::differentialRelay))
|
||||
{
|
||||
// NOTE: false means the relay is operational
|
||||
// TODO: cleanup, flip the FuseFlag code to match other relays
|
||||
|
||||
+3
-1
@@ -962,7 +962,7 @@ class Vehicle
|
||||
double ActFlowSpeed = 0.0; /*szybkosc stabilizatora*/
|
||||
|
||||
DamageSet DamageFlag; // the damage of the vehicle
|
||||
int EngDmgFlag = 0; // kombinacja bitowa stalych usterek}
|
||||
EquipmentFaultSet equipmentFaults; // the faults of the equipment set on the vehicle (SetEquipmentFaults())
|
||||
|
||||
// EndSignalsFlag: byte; {ABu 060205: zmiany - koncowki: 1/16 - swiatla prz/tyl, 2/31 - blachy prz/tyl}
|
||||
// HeadSignalsFlag: byte; {ABu 060205: zmiany - swiatla: 1/2/4 - przod, 16/32/63 - tyl}
|
||||
@@ -1646,6 +1646,8 @@ class Vehicle
|
||||
bool FuseOn(range_t const Notify = range_t::consist); // bezpiecznik nadamiary
|
||||
bool FuseFlagCheck(void) const; // sprawdzanie flagi nadmiarowego
|
||||
void FuseOff(void); // wylaczenie nadmiarowego
|
||||
// the faults of the equipment the scenery or the network sets: each sets its fault, or clears it where it was set
|
||||
void SetEquipmentFaults(EquipmentFaultSet Faults);
|
||||
bool UniversalResetButton(int const Button, range_t const Notify = range_t::consist);
|
||||
bool RelayReset(int const Relays, range_t const Notify = range_t::consist); // resets specified relays
|
||||
// the drive of the kind of engine of the vehicle (physics/components/drive.h)
|
||||
|
||||
@@ -92,6 +92,22 @@ template <> struct IsEnumSetKind<VehicleDamage> : std::true_type
|
||||
};
|
||||
using DamageSet = EnumSet<VehicleDamage>;
|
||||
|
||||
// the faults of the equipment of a vehicle the scenery or the network sets (TDynamicObject::Damage()), in the numbers of
|
||||
// the messages that carry them
|
||||
enum class EquipmentFault : unsigned
|
||||
{
|
||||
differentialRelay = 0x1, // the differential relay tripped: the line breaker opens and the fuse with it
|
||||
control = 0x2, // the control: the line contactors open and the start doesn't go on
|
||||
converter = 0x4, // the converter locked
|
||||
compressor = 0x8, // the compressor locked
|
||||
camshaft = 0x10, // the camshaft locked: the controller doesn't step
|
||||
emergencyBrake = 0x20, // an emergency brake application, which does nothing more yet
|
||||
};
|
||||
template <> struct IsEnumSetKind<EquipmentFault> : std::true_type
|
||||
{
|
||||
};
|
||||
using EquipmentFaultSet = EnumSet<EquipmentFault>;
|
||||
|
||||
/// <summary>Reason for a derailment event.</summary>
|
||||
enum DerailReason
|
||||
{
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
// the faults of the equipment the scenery or the network sets on a vehicle (physics::Vehicle::SetEquipmentFaults(),
|
||||
// TDynamicObject::Damage() with the number of a message)
|
||||
|
||||
TEST_CASE("equipment faults: the number of a message comes back as it went in") {
|
||||
auto const faults{EquipmentFaultSet::FromBits(0x2A)};
|
||||
CHECK(faults.HasAll(EquipmentFault::control));
|
||||
CHECK(faults.HasAll(EquipmentFault::compressor));
|
||||
CHECK(faults.HasAll(EquipmentFault::emergencyBrake));
|
||||
CHECK_FALSE(faults.HasAny(EquipmentFault::differentialRelay | EquipmentFault::converter | EquipmentFault::camshaft));
|
||||
CHECK(faults.Bits() == 0x2A);
|
||||
}
|
||||
|
||||
TEST_CASE("equipment faults: the fault of the control opens the line contactors and holds the start until it clears") {
|
||||
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
|
||||
auto const delay{loco->InitialCtrlDelay};
|
||||
loco->lineContactors.Close();
|
||||
loco->SetEquipmentFaults(EquipmentFault::control);
|
||||
CHECK(loco->equipmentFaults.HasAll(EquipmentFault::control));
|
||||
CHECK_FALSE(loco->lineContactors.IsClosed());
|
||||
CHECK(loco->InitialCtrlDelay > 100000000.0);
|
||||
// set again, it doesn't move the delay further
|
||||
loco->SetEquipmentFaults(EquipmentFault::control);
|
||||
CHECK(loco->InitialCtrlDelay < 200000000.0);
|
||||
loco->SetEquipmentFaults({});
|
||||
CHECK(loco->equipmentFaults.Empty());
|
||||
CHECK(loco->InitialCtrlDelay == doctest::Approx(delay));
|
||||
}
|
||||
|
||||
TEST_CASE("equipment faults: the fault of the compressor moves its pressures out of reach, and back") {
|
||||
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
|
||||
auto const minpressure{loco->air.compressor.config.minPressure};
|
||||
auto const maxpressure{loco->air.compressor.config.maxPressure};
|
||||
REQUIRE(minpressure > 0.0);
|
||||
loco->SetEquipmentFaults(EquipmentFault::compressor);
|
||||
CHECK(loco->air.compressor.config.minPressure < 0.0);
|
||||
CHECK(loco->air.compressor.config.maxPressure < 0.0);
|
||||
loco->SetEquipmentFaults({});
|
||||
CHECK(loco->air.compressor.config.minPressure == doctest::Approx(minpressure));
|
||||
CHECK(loco->air.compressor.config.maxPressure == doctest::Approx(maxpressure));
|
||||
}
|
||||
|
||||
TEST_CASE("equipment faults: the fault of the camshaft holds the steps of the controller until it clears") {
|
||||
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
|
||||
auto const delay{loco->CtrlDelay};
|
||||
auto const downdelay{loco->CtrlDownDelay};
|
||||
loco->SetEquipmentFaults(EquipmentFault::camshaft);
|
||||
CHECK(loco->CtrlDelay > 100000000.0);
|
||||
CHECK(loco->CtrlDownDelay > 100000000.0);
|
||||
loco->SetEquipmentFaults({});
|
||||
CHECK(loco->CtrlDelay == doctest::Approx(delay));
|
||||
CHECK(loco->CtrlDownDelay == doctest::Approx(downdelay));
|
||||
}
|
||||
@@ -1110,63 +1110,9 @@ void TDynamicObject::RadioStop()
|
||||
//---------------------------------------------------------------------------
|
||||
void TDynamicObject::Damage(char flag)
|
||||
{
|
||||
if (flag & 1) //różnicówka nie robi nic
|
||||
{
|
||||
physics->MainSwitch(false);
|
||||
physics->FuseOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
if (flag & 2) //usterka sterowania
|
||||
{
|
||||
physics->lineContactors.Open();
|
||||
if (physics->InitialCtrlDelay<100000000)
|
||||
physics->InitialCtrlDelay += 100000001;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (physics->InitialCtrlDelay>100000000)
|
||||
physics->InitialCtrlDelay -= 100000001;
|
||||
}
|
||||
|
||||
if (flag & 4) //blokada przetwornicy
|
||||
{
|
||||
if( physics->converter.config.start != start_t::disabled ) {
|
||||
physics->converter.Overload();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
physics->air.compressor.SetFault((flag & 8) != 0); //blokada sprezarki
|
||||
|
||||
if (flag & 16) //blokada wału
|
||||
{
|
||||
if (physics->CtrlDelay<100000000)
|
||||
physics->CtrlDelay += 100000001;
|
||||
if (physics->CtrlDownDelay<100000000)
|
||||
physics->CtrlDownDelay += 100000001;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (physics->CtrlDelay>100000000)
|
||||
physics->CtrlDelay -= 100000001;
|
||||
if (physics->CtrlDownDelay>100000000)
|
||||
physics->CtrlDownDelay -= 100000001;
|
||||
}
|
||||
|
||||
if (flag & 32) //hamowanie nagŁe
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
physics->EngDmgFlag = flag;
|
||||
};
|
||||
// the number of the message, as a char (sign extended as the number was)
|
||||
physics->SetEquipmentFaults(EquipmentFaultSet::FromBits(flag));
|
||||
}
|
||||
|
||||
void TDynamicObject::OverheadTrack(float o)
|
||||
{ // ewentualne wymuszanie jazdy
|
||||
|
||||
Reference in New Issue
Block a user