18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 14:16:48 +01:00
Files
maszyna/physics/components/pantographs.h
T
Hirek 6b9558f588 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.
2026-11-29 10:56:17 +01:00

214 lines
8.3 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 circuit and the air of the pantographs of a vehicle, held by physics::Vehicle as pantographCircuit and
// pantographAir beside its pantographs. as the parts of the main circuit (maincircuit.h): the definition in `config`, the
// state behind queries and operations
#pragma once
#include <algorithm>
#include <string>
#include <utility>
#include "physics/components/devices.h"
namespace physics
{
// the circuit of the pantographs: their voltages, the kind of their switches, the presets of the cabs
class PantographCircuit
{
public:
struct Config
{
std::string switchType; // PantSwitchType: the kind of the switches of the cab
};
Config config;
// the voltage at the pantograph of the given end, from the overhead line it touches
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 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 Value) { supplyVoltage = Value; }
// the switch that lowers all of them
bool AllDown() const { return allDown; }
void SetAllDown(bool const State) { allDown = State; }
// the presets of the pantographs: the setups they can be switched to as chars, and the one selected in each cab
std::pair<std::string, ByEnd<int>> presets{"0132", {0, 0}};
private:
double frontVoltage{0.0};
double rearVoltage{0.0};
double supplyVoltage{0.0};
bool allDown{false};
};
// what the air of the pantographs needs to know in the step
struct PantographAirSupply
{
bool anyPantographActive{false}; // a pantograph of the vehicle is up or rising
bool lowVoltage{false}; // the low voltage circuits have their power
bool collectors{false}; // the vehicle takes its power through pantographs: they have air of their own
bool multipleUnit{false}; // an electric multiple unit: its small compressor fills slower, its pressure switch locks
double mainReservoirPressure{0.0}; // [bar]
double controlReservoirPressure{0.0}; // [bar], what the gauge shows on a vehicle of no pantographs
double maxPressure{0.0}; // of the pantographs [bar], CollectorParameters.MaxPress
double minPressure{0.0}; // below which the pressure switch trips [bar], CollectorParameters.MinPress
};
// the air of the pantographs: their reservoir, the small compressor that fills it, the valves
class PantographAir
{
public:
struct Config
{
start_t compressorStart{start_t::manual}; // PantCompressorStart
int compressorPower{0}; // SmallCompressorPower
bool autoValve{false}; // the kind of the valve of the small compressor fitted
};
Config config;
basic_valve valve;
// in the reservoirs of the pantographs [bar]
double const &Pressure() const { return pressure; }
// the air in them, in the units of the model of their reservoir
double Volume() const { return volume; }
// the reservoirs of a vehicle placed with its pantographs down and empty
void Empty()
{
volume = 0.1;
pressure = 0.0;
}
// the small compressor
bool IsCompressorRunning() const { return compressorRunning; }
void SwitchCompressor(bool const State) { compressorRunning = State; }
// the three-way cock: to the main reservoir, or to the small compressor
bool IsConnectedToMainReservoir() const { return connectedToMainReservoir; }
void ConnectToMainReservoir(bool const State) { connectedToMainReservoir = State; }
// the pressure switch, primed at the pressure set in the air of the pantographs
bool IsPressureSwitchPrimed() const { return pressureSwitchActive; }
// the lock of the converter and the heating of a multiple unit, set when the pressure switch trips
bool IsPressureLockActive() const { return pressureLockActive; }
// the step of the air of the pantographs. returns whether the pressure switch tripped in it, by the pressure falling
// below its level: the switch is spent then, and the lock of a multiple unit set; what else follows is up to the vehicle
bool Update(PantographAirSupply const &Supply, double const dt)
{
// automatic start if the pressure is too low
compressorRunning |= pressure < 4.2 && Supply.anyPantographActive && (config.compressorStart == start_t::automatic || config.compressorStart == start_t::manualwithautofallback);
compressorRunning &= Supply.lowVoltage;
if (false == Supply.collectors)
{
// a tu coś dla SM42 i SM31, aby pokazywać na manometrze
pressure = Supply.controlReservoirPressure;
return false;
}
// Ra 2014-07: zasadniczo, to istnieje zbiornik rozrządu i zbiornik pantografów - na razie mamy razem
// Ra 2014-07: kurek trójdrogowy łączy spr.pom. z pantografami i wyłącznikiem ciśnieniowym WS
// Ra 2014-07: zbiornika rozrządu nie pompuje się tu, tylko pantografy; potem można zamknąć
// WS i odpalić resztę
if (config.autoValve ? pressure < Supply.mainReservoirPressure : connectedToMainReservoir) // kurek zamyka połączenie z ZG
{
// zbiornik pantografu połączony ze zbiornikiem głównym - małą sprężarką się tego nie napompuje
// Ra 2013-12: Niebugocław mówi, że w EZT nie ma potrzeby odcinać kurkiem
// ograniczenie ciśnienia do MaxPress (tylko w pantografach!)
// (the bounds as the .fiz gives them, which may cross)
pressure = std::min(std::max(Supply.mainReservoirPressure, 0.0), Supply.maxPressure);
volume = (pressure + 1.0) * 0.1; // objętość, na wypadek odcięcia kurkiem
}
else
{
// zbiornik główny odcięty, można pompować pantografy
if (compressorRunning)
{
// włączona mała sprężarka
volume += dt
// Ra 2013-12: Niebugocław mówi, że w EZT nabija 1.5 raz wolniej niż jak było 0.005
* (Supply.multipleUnit ? 0.003 : 0.005) / std::max(1.0, pressure) * (0.45 - (0.1 / volume / 10 - 0.1)) / 0.45;
}
pressure = std::min(std::max(10.0 * volume - 1.0, 0.0), Supply.maxPressure); // tu by się przydała objętość zbiornika
}
if (false == compressorRunning && volume > 0.1)
{
volume -= dt * 0.0003 * std::max(1.0, pressure * 0.5); // nieszczelności: 0.0003=0.3l/s
}
return UpdatePressureSwitch(Supply);
}
// the pressure switch: low, it trips once (see Update()); primed again over 4.6 bar, where the small compressor stops
// at 4.8. returns whether it tripped
bool UpdatePressureSwitch(PantographAirSupply const &Supply)
{
if (pressure < Supply.minPressure)
{
// 3.5 wg http://www.transportszynowy.pl/eu06-07pneumat.php
if (false == pressureSwitchActive)
{
return false;
}
// specialized variant for EMU -- pwr system disables converter and heating,
// and prevents their activation until pressure switch is set again
if (Supply.multipleUnit)
{
pressureLockActive = true;
}
// mark the pressure switch as spent
pressureSwitchActive = false;
return true;
}
if (pressure >= 4.6)
{
// NOTE: we require active low power source to prime the pressure switch
// this is a work-around for potential isssues caused by the switch activating on otherwise idle vehicles, but should check whether it's accurate
if (Supply.lowVoltage)
{
// prime the pressure switch
pressureSwitchActive = true;
// turn off the subsystems lock
pressureLockActive = false;
}
if (pressure >= 4.8)
{
// Winger - automatyczne wylaczanie malej sprezarki
// TODO: governor lock, disables usage until pressure drop below 3.8 (should really make compressor object we could reuse)
compressorRunning = false;
}
}
return false;
}
// for the tests: the reservoirs at the given pressure, with the pressure switch primed or not
void SetForTest(double const Value, bool const PressureSwitchPrimed)
{
pressure = Value;
pressureSwitchActive = PressureSwitchPrimed;
}
private:
double volume{0.48}; // so that the raised pantographs drop soon with the compressor off
double pressure{0.0};
bool compressorRunning{false};
bool connectedToMainReservoir{true};
bool pressureSwitchActive{false};
bool pressureLockActive{false};
};
} // namespace physics