18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 21:07:06 +01:00
Files
maszyna/physics/components/lowvoltage.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

130 lines
4.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 low voltage supply and the train heating of a vehicle, held by physics::Vehicle as lowVoltage and trainHeating.
// as the parts of the main circuit (maincircuit.h): the definition in `config`, the state behind queries and operations
#pragma once
#include "physics/vehicletypes.h"
namespace physics
{
// the battery and the low voltage circuits
class LowVoltageSupply
{
public:
struct Config
{
float nominalBatteryVoltage{0.f};
start_t batteryStart{start_t::manual};
// the battery switch of the cab
bool batteryButtonImpulse{false}; // the switch works as a single button
bool batteryButtonHeld{false}; // the button has to be held to switch the battery on or off
float batteryButtonHoldTime{1.f}; // how long it has to be held [s]
};
Config config;
// the battery of the definition (LMaxVoltage), charged
void SetBattery(double const Value)
{
batteryVoltage = Value;
config.nominalBatteryVoltage = static_cast<float>(Value);
}
bool IsBatteryOn() const { return batteryOn; }
// the battery switch, where the battery is switched by hand; returns whether that changed it
bool SwitchBattery(bool const State)
{
auto const initialstate{batteryOn};
if (config.batteryStart == start_t::manual)
{
batteryOn = State;
}
return batteryOn != initialstate;
}
// the battery cut off whatever its switch, as for a vehicle prepared for hauling
void DisconnectBattery() { batteryOn = false; }
// the battery as the vehicle is placed: on, unless the vehicle has none
void ResetBattery() { batteryOn = config.batteryStart != start_t::disabled; }
// for the tests: the battery on or off, whatever its switch
void SetBatteryOnForTest(bool const State) { batteryOn = State; }
double BatteryVoltage() const { return batteryVoltage; }
// the battery drained by the given amount [V]; returns whether its voltage fell too low for the line breaker to hold.
// it neither charges above its nominal voltage nor drops to nothing
bool DrainBattery(double const Drain)
{
batteryVoltage -= Drain;
auto const toolow{config.nominalBatteryVoltage / batteryVoltage > 1.57};
if (batteryVoltage > config.nominalBatteryVoltage)
{
batteryVoltage = config.nominalBatteryVoltage; // wstrzymanie ładowania pow. 110V
}
if (batteryVoltage < 0.01)
{
batteryVoltage = 0.01;
}
return toolow;
}
// the battery kept at its nominal voltage, where its drain isn't modelled
void KeepBatteryCharged() { batteryVoltage = config.nominalBatteryVoltage; }
// the low voltage circuits, as the last step found them
bool const &Is24vAvailable() const { return power24vAvailable; }
bool const &Is110vAvailable() const { return power110vAvailable; }
// either of them
bool IsAvailable() const { return power24vAvailable || power110vAvailable; }
// 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 Volts24, bool const Available110v)
{
power24vVoltage = Volts24;
power24vAvailable = power24vVoltage > 0;
power110vAvailable = Available110v;
}
// for the tests of the parts the circuits feed: the power of a circuit as given, whatever the voltage
void Set24vAvailableForTest(bool const State) { power24vAvailable = State; }
void Set110vAvailableForTest(bool const State) { power110vAvailable = State; }
private:
bool batteryOn{false};
double batteryVoltage{0.0};
bool power110vAvailable{false};
bool power24vAvailable{false};
double power24vVoltage{0.0};
};
// the heating of the train fed by the vehicle
class TrainHeating
{
public:
struct Config
{
bool switchImpulse{false}; // the switch springs back to its middle position
double power{0.0};
double engineRpm{0.0}; // the revolutions of the engine guaranteed with the heating on
};
Config config;
bool IsOn() const { return on; }
void SetOn(bool const State) { on = State; }
// the heating switch. TODO: wrap the heating in a basic device
bool IsAllowed() const { return allow; }
void Allow(bool const State) { allow = State; }
private:
bool on{false};
bool allow{false};
};
} // namespace physics