mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 19:57:06 +01:00
22ebc41d70
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.
290 lines
11 KiB
C++
290 lines
11 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
// the main circuit of a vehicle: the line breaker, the line contactors, the protective relays, the converter. Held by
|
|
// physics::Vehicle as lineBreaker, lineContactors, protection and converter.
|
|
//
|
|
// each part holds its definition in `config`, filled from the .fiz and not changed after, and keeps its state to itself:
|
|
// the rest of the vehicle reads the state through the queries and changes it through the operations. what decides when
|
|
// they act (the interlocks of the cab, the controller positions, the voltages) stays with the vehicle, which hands the
|
|
// parts what they need as plain values
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "physics/vehicletypes.h"
|
|
|
|
namespace physics
|
|
{
|
|
|
|
// the line breaker (the main switch) of the vehicle
|
|
class LineBreaker
|
|
{
|
|
public:
|
|
struct Config
|
|
{
|
|
double initTime{0.0}; // how long the main circuit initialises after it gets its power, before the breaker can close [s]
|
|
start_t start{start_t::manual};
|
|
// Engine:JointEngineStart: the line breaker / engine start switch of the cab works the vehicles in multiple too; when it
|
|
// doesn't, the cab has separate switches for them (mainb_*, mainc_*)
|
|
bool jointStart{true};
|
|
// Cntrl.PantRequiresMain: the line breaker closes without traction voltage and holds without it, and the pantographs
|
|
// rise and stay up only while it's closed (EU05, EP05, ČD 181 family); off, the pantographs come first and the line
|
|
// breaker needs their voltage. what the main circuit feeds still needs the voltage (MainCircuitPowered()), and without
|
|
// it the undervoltage relay opens the line contactors (protection.UndervoltageHolds())
|
|
bool pantographsRequireIt{false};
|
|
bool closesOnlyAtNoPower{false}; // it closes only with the master controller at a position of no power
|
|
// Cntrl.EmergencyBrakeMainOff: the brake pipe pressure [bar] taken for an emergency brake application: below it, with
|
|
// the master controller on a power position, the line breaker opens and doesn't close again. where the pantographs
|
|
// stay up only through the closed line breaker (pantographsRequireIt) they drop with it (EP05). 0: an emergency
|
|
// application leaves the line breaker alone
|
|
double emergencyOffPressure{0.0};
|
|
};
|
|
Config config;
|
|
|
|
bool IsClosed() const { return closed; }
|
|
void Close() { closed = true; }
|
|
void Open() { closed = false; }
|
|
|
|
// how long the main circuit still initialises [s]; below zero once it's done
|
|
double RemainingInitTime() const { return initCountdown; }
|
|
// the main circuit is done initialising, the breaker may close
|
|
bool IsInitialised() const { return initCountdown <= 0.0; }
|
|
// the step of the supply of the main circuit: with it the initialisation counts down, without it it starts over.
|
|
// returns whether the circuit has its supply and was done initialising before this step, when it may start on its own
|
|
bool UpdateInitialisation(bool const supplied, double const dt)
|
|
{
|
|
if (false == supplied)
|
|
{
|
|
initCountdown = config.initTime;
|
|
return false;
|
|
}
|
|
// NOTE: readiness means a countdown below zero, which rules out at once the vehicles of no initialisation time
|
|
if (initCountdown >= 0.0)
|
|
{
|
|
initCountdown -= dt;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
bool closed{false};
|
|
double initCountdown{0.0}; // how long it still initialises [s]
|
|
};
|
|
|
|
// the line contactors of the traction motors
|
|
class LineContactors
|
|
{
|
|
public:
|
|
struct Config
|
|
{
|
|
std::string switchType; // StLinSwitchType: the kind of the switch of the cab
|
|
line_contactors_interlock interlock{line_contactors_interlock::none}; // what else they need to close
|
|
};
|
|
Config config;
|
|
|
|
bool IsClosed() const { return closed; }
|
|
void Close() { closed = true; }
|
|
void Open() { closed = false; }
|
|
|
|
// the button of the cab that forces them open
|
|
bool IsForcedOpen() const { return forcedOpen; }
|
|
void ForceOpen(bool const State) { forcedOpen = State; }
|
|
|
|
// the time since the master controller or the relays of the start last switched [s]
|
|
double TimeSinceSwitch() const { return lastSwitchTime; }
|
|
void RestartSwitchTimer() { lastSwitchTime = 0.0; }
|
|
void AdvanceSwitchTimer(double const dt) { lastSwitchTime += dt; }
|
|
|
|
private:
|
|
bool closed{false};
|
|
bool forcedOpen{false};
|
|
double lastSwitchTime{0.0};
|
|
};
|
|
|
|
// the protective relays and the pressure switch of the main circuit. the relays hold (true) while all is well and drop
|
|
// (false) when they protect the circuit
|
|
class ProtectionRelays
|
|
{
|
|
public:
|
|
struct Config
|
|
{
|
|
start_t groundStart{start_t::manual}; // how the ground relay is reset
|
|
bool hasPressureSwitch{true};
|
|
// Engine:PressureSwitchBrakeCylinder: the pressure switch watches the brake cylinders (it cuts the start off above 2 bar
|
|
// there) as well as the brake pipe (below 3.6 bar). off, it's left with the brake pipe alone, and the vehicle takes
|
|
// current whatever the pressure in its brake cylinders (EP05)
|
|
bool pressureSwitchWatchesCylinders{true};
|
|
};
|
|
Config config;
|
|
|
|
// the undervoltage relay: it drops if the voltage falls below its threshold, which opens the line breaker; with
|
|
// lineBreaker.config.pantographsRequireIt it opens the line contactors instead, and picks up again only with the master
|
|
// controller at zero or the first position
|
|
bool UndervoltageHolds() const { return noVoltage; }
|
|
// the overvoltage relay, which drops above the voltage it's set to
|
|
bool OvervoltageHolds() const { return overvoltage; }
|
|
// the voltage relays as the drive of the vehicle judges them from the voltage of its supply
|
|
void SetVoltageRelays(bool const undervoltageHolds, bool const overvoltageHolds)
|
|
{
|
|
noVoltage = undervoltageHolds;
|
|
overvoltage = overvoltageHolds;
|
|
}
|
|
|
|
// the ground relay, which drops to protect against damage from earths
|
|
bool GroundHolds() const { return ground; }
|
|
// the ground relay of a series motor vehicle in the step: it drops without the low voltage, and one that isn't reset
|
|
// by hand picks up again with it
|
|
void UpdateGround(bool const lowVoltagePower)
|
|
{
|
|
ground &= lowVoltagePower;
|
|
if (config.groundStart != start_t::manual)
|
|
{
|
|
// NOTE: we're ignoring intricaties of battery and converter types as they're unlikely to be used
|
|
// TODO: generic check method which takes these into account
|
|
ground |= lowVoltagePower;
|
|
}
|
|
}
|
|
// the reset of the ground relay, which needs the low voltage; returns whether it picked up
|
|
bool ResetGround(bool const lowVoltagePower)
|
|
{
|
|
auto const reset{false == ground && lowVoltagePower};
|
|
ground |= lowVoltagePower;
|
|
return reset;
|
|
}
|
|
|
|
// tripped while the brake pipe and/or the brake cylinders aren't at their working pressures
|
|
bool PressureSwitchTripped() const { return pressureSwitch; }
|
|
// the pressure switch in the step, from the pressures [bar]
|
|
void UpdatePressureSwitch(double const cylinderPressure, double const pipePressure)
|
|
{
|
|
pressureSwitch = config.hasPressureSwitch && ((config.pressureSwitchWatchesCylinders && cylinderPressure > 2.0) || pipePressure < 3.6);
|
|
}
|
|
|
|
private:
|
|
bool noVoltage{true};
|
|
bool overvoltage{true};
|
|
bool ground{true};
|
|
bool pressureSwitch{false};
|
|
};
|
|
|
|
// what the converter of the vehicle needs to know in the step
|
|
struct ConverterSupply
|
|
{
|
|
bool lineBreakerClosed{false};
|
|
bool lowVoltage24v{false}; // the 24 V circuits have their power
|
|
bool directionActive{false}; // the reverser is set
|
|
bool pantographPressureLock{false}; // the pressure lock of the pantographs is on
|
|
bool highVoltage{false}; // the main circuit, or for a vehicle of no power of its own the train line, has its voltage
|
|
bool damaged{false}; // the converter is damaged
|
|
};
|
|
|
|
// the converter of the vehicle
|
|
class PowerConverter
|
|
{
|
|
public:
|
|
struct Config
|
|
{
|
|
start_t start{start_t::manual}; // whether it is started by hand, or another way
|
|
float startDelay{0.0f}; // the delay before it starts, once its conditions are met [s]
|
|
start_t overloadRelayStart{start_t::manual}; // whether its overload relay is reset by a button of its own
|
|
bool overloadRelayOffWithLineBreaker{false}; // ConverterOverloadRelayOffWhenMainIsOff
|
|
std::string switchType; // ConvSwitchType: the kind of the switch of the cab. TODO: the kinds of the switches belong to the cab definition
|
|
};
|
|
Config config;
|
|
|
|
bool IsRunning() const { return running; }
|
|
// it may run, as its switch (or its start) has it
|
|
bool IsAllowed() const { return allow; }
|
|
// the switch of the converter, where it is worked by hand; returns whether that changed it
|
|
bool Switch(bool const State)
|
|
{
|
|
auto const initialstate{allow};
|
|
if (config.start == start_t::manual)
|
|
{
|
|
allow = State;
|
|
}
|
|
return allow != initialstate;
|
|
}
|
|
// the switch of the vehicle itself; most have none, so it allows
|
|
bool LocalSwitchOn() const { return allowLocal; }
|
|
void SetLocalSwitch(bool const State) { allowLocal = State; }
|
|
|
|
// the overload relay of the converter and the heating
|
|
bool IsOverloaded() const { return overloaded; }
|
|
void Overload() { overloaded = true; }
|
|
// the reset of the overload relay, which needs the low voltage; returns whether it was tripped
|
|
bool ResetOverloadRelay(bool const lowVoltagePower)
|
|
{
|
|
auto const reset{overloaded && lowVoltagePower};
|
|
overloaded &= false == lowVoltagePower;
|
|
return reset;
|
|
}
|
|
|
|
// the converter in the step
|
|
void Update(ConverterSupply const &supply, double const dt)
|
|
{
|
|
if (config.start != start_t::disabled && config.overloadRelayOffWithLineBreaker)
|
|
{
|
|
overloaded |= false == supply.lineBreakerClosed && supply.lowVoltage24v;
|
|
}
|
|
switch (config.start)
|
|
{
|
|
case start_t::disabled:
|
|
allow = false;
|
|
// NOTE: if there's no converter in vehicle we can end the check here
|
|
return;
|
|
case start_t::automatic:
|
|
allow = supply.lineBreakerClosed;
|
|
break;
|
|
case start_t::direction:
|
|
allow = supply.directionActive;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (allow && allowLocal && false == overloaded && false == supply.pantographPressureLock && supply.highVoltage)
|
|
{
|
|
// delay timer can be optionally configured, and is set anew whenever converter goes off
|
|
if (startDelayTimer <= 0.0)
|
|
{
|
|
running = true;
|
|
}
|
|
else
|
|
{
|
|
startDelayTimer -= dt;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
running = false;
|
|
startDelayTimer = static_cast<double>(config.startDelay);
|
|
}
|
|
if (config.overloadRelayStart == start_t::converter && false == (allow && allowLocal) && false == supply.damaged)
|
|
{
|
|
// reset converter overload relay if the converter was switched off, unless it's damaged
|
|
overloaded = false;
|
|
}
|
|
}
|
|
|
|
// for the tests of the parts it feeds: the converter running, or not, whatever its conditions
|
|
void SetRunningForTest(bool const State) { running = State; }
|
|
|
|
private:
|
|
bool allow{false};
|
|
bool allowLocal{true};
|
|
bool running{false};
|
|
bool overloaded{false};
|
|
double startDelayTimer{0.0}; // how long its conditions have been met
|
|
};
|
|
|
|
} // namespace physics
|