mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 14:16:48 +01:00
refactor(physics): the parts of the main circuit keep their state to themselves
The line breaker, the line contactors, the protective relays and the converter
(physics/components/maincircuit.h) become classes: what the .fiz defines is in
their public `config`, their state is private, read through queries
(IsClosed(), UndervoltageHolds(), IsRunning()) and changed through operations
(Close(), ResetGround(), Switch()). The logic that concerns only them moves in:
the initialisation of the main circuit, the ground relay, the pressure switch,
the resets of the relays, and the whole step of the converter, which gets what
it needs from the vehicle as plain values (ConverterSupply).
The vehicle still decides when they act (the interlocks, the controller
positions, the voltages); the parts don't take a physics::Vehicle.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
@@ -97,11 +97,11 @@ bool physics::Vehicle::IncMainCtrl(int CtrlSpeed)
|
||||
{
|
||||
if (DelayCtrlFlag)
|
||||
{
|
||||
if (lineContactors.lastSwitchTime >= InitialCtrlDelay && MainCtrlPos == 1)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
if (lineContactors.TimeSinceSwitch() >= InitialCtrlDelay && MainCtrlPos == 1)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > CtrlDelay)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
else if (lineContactors.TimeSinceSwitch() > CtrlDelay)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
@@ -226,11 +226,11 @@ bool physics::Vehicle::DecMainCtrl(int CtrlSpeed)
|
||||
{
|
||||
if (DelayCtrlFlag)
|
||||
{
|
||||
if (lineContactors.lastSwitchTime >= InitialCtrlDelay)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
if (lineContactors.TimeSinceSwitch() >= InitialCtrlDelay)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
else if (lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
@@ -363,7 +363,7 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
|
||||
// TBD, TODO: refactor this validation as part of relay check routine (currently in tractionforce()
|
||||
// TBD, TODO: diesel electric engine utilize scndctrlactualpos like the other types?
|
||||
if (EngineType == TEngineType::DieselElectric &&
|
||||
(IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, FieldShuntSwitch, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == lineBreaker.closed))
|
||||
(IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, FieldShuntSwitch, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == lineBreaker.IsClosed()))
|
||||
{
|
||||
OK = false;
|
||||
}
|
||||
@@ -392,8 +392,8 @@ bool physics::Vehicle::IncScndCtrl(int CtrlSpeed)
|
||||
OK = false;
|
||||
// if OK then LastRelayTime:=0;
|
||||
// hunter-101012: poprawka
|
||||
if (OK && lineContactors.lastSwitchTime > CtrlDelay)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
if (OK && lineContactors.TimeSinceSwitch() > CtrlDelay)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
|
||||
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1 && MainCtrlPos > 0)
|
||||
{
|
||||
@@ -454,8 +454,8 @@ bool physics::Vehicle::DecScndCtrl(int CtrlSpeed)
|
||||
OK = false;
|
||||
// if OK then LastRelayTime:=0;
|
||||
// hunter-101012: poprawka
|
||||
if (OK && lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
if (OK && lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
lineContactors.RestartSwitchTimer();
|
||||
|
||||
if (OK && EngineType == TEngineType::ElectricInductionMotor && ScndCtrlPosNo == 1)
|
||||
{
|
||||
@@ -549,7 +549,7 @@ bool physics::Vehicle::AutoRelayCheck(void)
|
||||
// yBARC - rozlaczenie stycznikow liniowych
|
||||
if (motorconnectorsoff || (HasCamshaft ? IsMainCtrlActualNoPowerPos() : IsMainCtrlNoPowerPos()))
|
||||
{
|
||||
lineContactors.closed = false;
|
||||
lineContactors.Open();
|
||||
if (false == brakes.electrodynamic.on)
|
||||
{
|
||||
Im = 0;
|
||||
@@ -569,7 +569,7 @@ bool physics::Vehicle::AutoRelayCheck(void)
|
||||
// przejście dalej przez danie nastawnika na dalszą pozycję - tak to do
|
||||
// tej pory działało i na tym się opiera fizyka ET22-2k
|
||||
{
|
||||
if (lineContactors.closed)
|
||||
if (lineContactors.IsClosed())
|
||||
{
|
||||
if (RList[MainCtrlActualPos].R == 0 && (ScndCtrlActualPos > 0 || ScndCtrlPos > 0) && (!CoupledCtrl || RList[MainCtrlActualPos].Relay == MainCtrlPos))
|
||||
{ // zmieniaj scndctrlactualpos
|
||||
@@ -585,7 +585,7 @@ bool physics::Vehicle::AutoRelayCheck(void)
|
||||
OK = AutoRelayLineContactorsStep(motorconnectorsoff);
|
||||
}
|
||||
if (OK)
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
lineContactors.RestartSwitchTimer();
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -598,7 +598,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
|
||||
// scnd bez samoczynnego rozruchu
|
||||
if (ScndCtrlActualPos < ScndCtrlPos)
|
||||
{
|
||||
if (lineContactors.lastSwitchTime > CtrlDelay && ARFASI2)
|
||||
if (lineContactors.TimeSinceSwitch() > CtrlDelay && ARFASI2)
|
||||
{
|
||||
++ScndCtrlActualPos;
|
||||
SetFlag(SoundFlag, sound::shuntfield);
|
||||
@@ -607,7 +607,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2)
|
||||
}
|
||||
else if (ScndCtrlActualPos > ScndCtrlPos)
|
||||
{
|
||||
if (lineContactors.lastSwitchTime > CtrlDownDelay && TrainType != train_type::emu)
|
||||
if (lineContactors.TimeSinceSwitch() > CtrlDownDelay && TrainType != train_type::emu)
|
||||
{
|
||||
--ScndCtrlActualPos;
|
||||
SetFlag(SoundFlag, sound::shuntfield);
|
||||
@@ -640,7 +640,7 @@ bool physics::Vehicle::AutoRelayMainStep(bool const ARFASI)
|
||||
}
|
||||
else if (RList[MainCtrlActualPos].R > 0 && ScndCtrlActualPos > 0)
|
||||
{
|
||||
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
if (lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
{
|
||||
--ScndCtrlActualPos; // boczniki nie dzialaja na poz. oporowych
|
||||
SetFlag(SoundFlag, sound::shuntfield);
|
||||
@@ -681,7 +681,7 @@ bool physics::Vehicle::AutoRelayMainUp(bool const ARFASI)
|
||||
OK = true;
|
||||
}
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > CtrlDelay && ARFASI)
|
||||
else if (lineContactors.TimeSinceSwitch() > CtrlDelay && ARFASI)
|
||||
{
|
||||
OK = AutoRelayMainNotchUp();
|
||||
}
|
||||
@@ -704,7 +704,7 @@ bool physics::Vehicle::AutoRelayMainNotchUp()
|
||||
DelayCtrlFlag = true; // tryb przejscia
|
||||
OK = true;
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > 4 * CtrlDelay) // przejscie
|
||||
else if (lineContactors.TimeSinceSwitch() > 4 * CtrlDelay) // przejscie
|
||||
{
|
||||
|
||||
DelayCtrlFlag = false;
|
||||
@@ -753,7 +753,7 @@ bool physics::Vehicle::AutoRelayMainDown()
|
||||
SetFlag(SoundFlag, sound::parallel);
|
||||
}
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
else if (lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
{
|
||||
if (TrainType != train_type::emu) // tutaj powinien być tryb sterowania wałem
|
||||
{
|
||||
@@ -779,9 +779,9 @@ bool physics::Vehicle::AutoRelayLineContactorsStep(bool const motorconnectorsoff
|
||||
{
|
||||
|
||||
DelayCtrlFlag = true;
|
||||
if (lineContactors.lastSwitchTime >= InitialCtrlDelay)
|
||||
if (lineContactors.TimeSinceSwitch() >= InitialCtrlDelay)
|
||||
{
|
||||
lineContactors.closed = true;
|
||||
lineContactors.Close();
|
||||
MainCtrlActualPos = 1;
|
||||
DelayCtrlFlag = false;
|
||||
SetFlag(SoundFlag, sound::relay | sound::loud);
|
||||
@@ -793,7 +793,7 @@ bool physics::Vehicle::AutoRelayLineContactorsStep(bool const motorconnectorsoff
|
||||
DelayCtrlFlag = false;
|
||||
}
|
||||
|
||||
if (false == lineContactors.closed && (MainCtrlActualPos > 0 || ScndCtrlActualPos > 0))
|
||||
if (false == lineContactors.IsClosed() && (MainCtrlActualPos > 0 || ScndCtrlActualPos > 0))
|
||||
{
|
||||
OK |= CamshaftRunDown();
|
||||
}
|
||||
@@ -813,7 +813,7 @@ bool physics::Vehicle::CamshaftRunDown()
|
||||
{
|
||||
OK = CamshaftRunDownEMU();
|
||||
}
|
||||
else if (lineContactors.lastSwitchTime > CtrlDownDelay) // wal kulakowy dwukierunkowy
|
||||
else if (lineContactors.TimeSinceSwitch() > CtrlDownDelay) // wal kulakowy dwukierunkowy
|
||||
{
|
||||
if (ScndCtrlActualPos > 0)
|
||||
{
|
||||
@@ -830,7 +830,7 @@ bool physics::Vehicle::CamshaftRunDown()
|
||||
else if (HasCamshaft)
|
||||
{
|
||||
// wal kulakowy dwukierunkowy
|
||||
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
if (lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
{
|
||||
if (MainCtrlActualPos > 0)
|
||||
{
|
||||
@@ -863,7 +863,7 @@ bool physics::Vehicle::CamshaftRunDownEMU()
|
||||
else
|
||||
{
|
||||
|
||||
if (lineContactors.lastSwitchTime > CtrlDownDelay)
|
||||
if (lineContactors.TimeSinceSwitch() > CtrlDownDelay)
|
||||
{
|
||||
|
||||
if (MainCtrlActualPos < RlistSize)
|
||||
@@ -894,29 +894,29 @@ bool physics::Vehicle::MotorConnectorsCheck()
|
||||
|
||||
// hunter-111211: wylacznik cisnieniowy
|
||||
// (on some vehicles it watches the brake pipe alone)
|
||||
protection.pressureSwitch = protection.hasPressureSwitch && ((protection.pressureSwitchWatchesCylinders && brakes.cylinderPressure > 2.0) || brakePipe.pressure < 3.6);
|
||||
protection.UpdatePressureSwitch(brakes.cylinderPressure, brakePipe.pressure);
|
||||
|
||||
if (true == protection.pressureSwitch)
|
||||
if (true == protection.PressureSwitchTripped())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// a line breaker closed ahead of the pantographs holds without voltage; what cuts the motors off there is its
|
||||
// undervoltage relay, which elsewhere opens the line breaker
|
||||
auto const undervoltage{lineBreaker.pantographsRequireIt && false == protection.noVoltage};
|
||||
auto const undervoltage{lineBreaker.config.pantographsRequireIt && false == protection.UndervoltageHolds()};
|
||||
|
||||
auto const connectorsoff{false == lineBreaker.closed || undervoltage || true == FuseFlag || true == lineContactors.forcedOpen || DirActive == 0};
|
||||
auto const connectorsoff{false == lineBreaker.IsClosed() || undervoltage || true == FuseFlag || true == lineContactors.IsForcedOpen() || DirActive == 0};
|
||||
|
||||
return false == connectorsoff && LineContactorsInterlockReleased();
|
||||
}
|
||||
|
||||
bool physics::Vehicle::LineContactorsInterlockReleased() const
|
||||
{
|
||||
switch (lineContactors.interlock)
|
||||
switch (lineContactors.config.interlock)
|
||||
{
|
||||
case line_contactors_interlock::converter:
|
||||
// the converter of this very vehicle, not the 110 V of the trainset: a section with its fans off doesn't start
|
||||
return converter.running;
|
||||
return converter.IsRunning();
|
||||
case line_contactors_interlock::motor_blowers:
|
||||
return std::ranges::all_of(MotorBlowers, [this](auto const &Blower) {
|
||||
if (Blower.min_start_velocity < 0)
|
||||
@@ -1092,7 +1092,7 @@ void physics::Vehicle::EIMICFromFourPositions(double dt)
|
||||
// hamowanie nagle: pelne hamowanie od razu, przewod glowny oproznia UpdatePipePressure()
|
||||
eimic = -1.0;
|
||||
}
|
||||
else if (MainCtrlActualPos != MainCtrlPos || lineContactors.lastSwitchTime > InitialCtrlDelay)
|
||||
else if (MainCtrlActualPos != MainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
|
||||
{
|
||||
double delta = MainCtrlActualPos == MainCtrlPos ? dt * CtrlDelay : 0.01;
|
||||
// the positions below are those of the controller without the emergency brake position
|
||||
@@ -1120,10 +1120,10 @@ void physics::Vehicle::EIMICFromFourPositions(double dt)
|
||||
}
|
||||
}
|
||||
if (MainCtrlActualPos == MainCtrlPos)
|
||||
lineContactors.lastSwitchTime += dt;
|
||||
lineContactors.AdvanceSwitchTimer(dt);
|
||||
else
|
||||
{
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
lineContactors.RestartSwitchTimer();
|
||||
MainCtrlActualPos = MainCtrlPos;
|
||||
}
|
||||
}
|
||||
@@ -1136,7 +1136,7 @@ void physics::Vehicle::EIMICFromUniversalController(double dt, double const brak
|
||||
UniversalControllerTrainBrake();
|
||||
}
|
||||
|
||||
if (MainCtrlActualPos != MainCtrlPos || lineContactors.lastSwitchTime > InitialCtrlDelay)
|
||||
if (MainCtrlActualPos != MainCtrlPos || lineContactors.TimeSinceSwitch() > InitialCtrlDelay)
|
||||
{
|
||||
auto const &position{UniCtrlList[MainCtrlPos]};
|
||||
double ramped{eimic};
|
||||
@@ -1148,10 +1148,10 @@ void physics::Vehicle::EIMICFromUniversalController(double dt, double const brak
|
||||
eimic = UniCtrlValStep > 0.0 ? stepped_uc_value(eimic, ramped, position, UniCtrlValStep, MainCtrlActualPos != MainCtrlPos, eimic_step_progress) : ramped;
|
||||
}
|
||||
if (MainCtrlActualPos == MainCtrlPos)
|
||||
lineContactors.lastSwitchTime += dt;
|
||||
lineContactors.AdvanceSwitchTimer(dt);
|
||||
else
|
||||
{
|
||||
lineContactors.lastSwitchTime = 0;
|
||||
lineContactors.RestartSwitchTimer();
|
||||
MainCtrlActualPos = MainCtrlPos;
|
||||
}
|
||||
if (brakes.distributor->GetEDBCP() > 0.3 && eimic < 0 && !UniCtrlIntegratedLocalBrakeCtrl) // when braking with pneumatic brake
|
||||
|
||||
Reference in New Issue
Block a user