16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 22:09:19 +02:00

basic motor blowers implementation

This commit is contained in:
tmj-fstate
2018-10-04 02:39:55 +02:00
parent 044e3c921a
commit 682514fe7b
14 changed files with 609 additions and 144 deletions

View File

@@ -166,6 +166,7 @@ enum class start_t {
manual,
automatic,
manualwithautofallback,
converter,
battery
};
// recognized vehicle light locations and types; can be combined
@@ -619,107 +620,122 @@ struct TCoupling {
int sounds { 0 }; // sounds emitted by the coupling devices
};
// basic approximation of a fuel pump
// TODO: fuel consumption, optional automatic engine start after activation
struct fuel_pump {
bool is_enabled { false }; // device is allowed/requested to operate
bool is_disabled { false }; // device is requested to stop
bool is_active { false }; // device is working
start_t start_type { start_t::manual };
};
// basic approximation of a fuel pump
// TODO: fuel consumption, optional automatic engine start after activation
struct oil_pump {
bool is_enabled { false }; // device is allowed/requested to operate
bool is_disabled { false }; // device is requested to stop
bool is_active { false }; // device is working
start_t start_type { start_t::manual };
float resource_amount { 1.f };
float pressure_minimum { 0.f }; // lowest acceptable working pressure
float pressure_maximum { 0.65f }; // oil pressure at maximum engine revolutions
float pressure_target { 0.f };
float pressure_present { 0.f };
};
struct water_pump {
bool breaker { true }; // device is allowed to operate
bool is_enabled { false }; // device is requested to operate
bool is_disabled { false }; // device is requested to stop
bool is_active { false }; // device is working
start_t start_type { start_t::manual };
};
struct water_heater {
bool breaker { true }; // device is allowed to operate
bool is_enabled { false }; // device is requested to operate
bool is_active { false }; // device is working
bool is_damaged { false }; // device is damaged
struct heater_config_t {
float temp_min { -1 }; // lowest accepted temperature
float temp_max { -1 }; // highest accepted temperature
} config;
};
struct heat_data {
// input, state of relevant devices
bool cooling { false }; // TODO: user controlled device, implement
// bool okienko { true }; // window in the engine compartment
// system configuration
bool auxiliary_water_circuit { false }; // cooling system has an extra water circuit
double fan_speed { 0.075 }; // cooling fan rpm; either fraction of engine rpm, or absolute value if negative
// heat exchange factors
double kw { 0.35 };
double kv { 0.6 };
double kfe { 1.0 };
double kfs { 80.0 };
double kfo { 25.0 };
double kfo2 { 25.0 };
// system parts
struct fluid_circuit_t {
struct circuit_config_t {
float temp_min { -1 }; // lowest accepted temperature
float temp_max { -1 }; // highest accepted temperature
float temp_cooling { -1 }; // active cooling activation point
float temp_flow { -1 }; // fluid flow activation point
bool shutters { false }; // the radiator has shutters to assist the cooling
} config;
bool is_cold { false }; // fluid is too cold
bool is_warm { false }; // fluid is too hot
bool is_hot { false }; // fluid temperature crossed cooling threshold
bool is_flowing { false }; // fluid is being pushed through the circuit
} water,
water_aux,
oil;
// output, state of affected devices
bool PA { false }; // malfunction flag
float rpmw { 0.0 }; // current main circuit fan revolutions
float rpmwz { 0.0 }; // desired main circuit fan revolutions
bool zaluzje1 { false };
float rpmw2 { 0.0 }; // current auxiliary circuit fan revolutions
float rpmwz2 { 0.0 }; // desired auxiliary circuit fan revolutions
bool zaluzje2 { false };
// output, temperatures
float Te { 15.0 }; // ambient temperature TODO: get it from environment data
// NOTE: by default the engine is initialized in warm, startup-ready state
float Ts { 50.0 }; // engine temperature
float To { 45.0 }; // oil temperature
float Tsr { 50.0 }; // main circuit radiator temperature (?)
float Twy { 50.0 }; // main circuit water temperature
float Tsr2 { 40.0 }; // secondary circuit radiator temperature (?)
float Twy2 { 40.0 }; // secondary circuit water temperature
float temperatura1 { 50.0 };
float temperatura2 { 40.0 };
};
class TMoverParameters
{ // Ra: wrapper na kod pascalowy, przejmujący jego funkcje Q: 20160824 - juz nie wrapper a klasa bazowa :)
private:
// types
// basic approximation of a generic device
// TBD: inheritance or composition?
struct basic_device {
// config
start_t start_type { start_t::manual };
// ld inputs
bool is_enabled { false }; // device is allowed/requested to operate
bool is_disabled { false }; // device is requested to stop
// TODO: add remaining inputs; start conditions and potential breakers
// ld outputs
bool is_active { false }; // device is working
};
struct cooling_fan : public basic_device {
// config
float speed { 0.f }; // cooling fan rpm; either fraction of parent rpm, or absolute value if negative
// ld outputs
float revolutions { 0.f }; // current fan rpm
};
// basic approximation of a fuel pump
struct fuel_pump : public basic_device {
// TODO: fuel consumption, optional automatic engine start after activation
};
// basic approximation of an oil pump
struct oil_pump : public basic_device {
// config
float pressure_minimum { 0.f }; // lowest acceptable working pressure
float pressure_maximum { 0.65f }; // oil pressure at maximum engine revolutions
// ld inputs
float resource_amount { 1.f }; // amount of affected resource, compared to nominal value
// internal data
float pressure_target { 0.f };
// ld outputs
float pressure { 0.f }; // current pressure
};
// basic approximation of a water pump
struct water_pump : public basic_device {
// ld inputs
// TODO: move to breaker list in the basic device once implemented
bool breaker { true }; // device is allowed to operate
};
struct water_heater {
// config
struct heater_config_t {
float temp_min { -1 }; // lowest accepted temperature
float temp_max { -1 }; // highest accepted temperature
} config;
// ld inputs
bool breaker { true }; // device is allowed to operate
bool is_enabled { false }; // device is requested to operate
// ld outputs
bool is_active { false }; // device is working
bool is_damaged { false }; // device is damaged
};
struct heat_data {
// input, state of relevant devices
bool cooling { false }; // TODO: user controlled device, implement
// bool okienko { true }; // window in the engine compartment
// system configuration
bool auxiliary_water_circuit { false }; // cooling system has an extra water circuit
double fan_speed { 0.075 }; // cooling fan rpm; either fraction of engine rpm, or absolute value if negative
// heat exchange factors
double kw { 0.35 };
double kv { 0.6 };
double kfe { 1.0 };
double kfs { 80.0 };
double kfo { 25.0 };
double kfo2 { 25.0 };
// system parts
struct fluid_circuit_t {
struct circuit_config_t {
float temp_min { -1 }; // lowest accepted temperature
float temp_max { -1 }; // highest accepted temperature
float temp_cooling { -1 }; // active cooling activation point
float temp_flow { -1 }; // fluid flow activation point
bool shutters { false }; // the radiator has shutters to assist the cooling
} config;
bool is_cold { false }; // fluid is too cold
bool is_warm { false }; // fluid is too hot
bool is_hot { false }; // fluid temperature crossed cooling threshold
bool is_flowing { false }; // fluid is being pushed through the circuit
} water,
water_aux,
oil;
// output, state of affected devices
bool PA { false }; // malfunction flag
float rpmw { 0.0 }; // current main circuit fan revolutions
float rpmwz { 0.0 }; // desired main circuit fan revolutions
bool zaluzje1 { false };
float rpmw2 { 0.0 }; // current auxiliary circuit fan revolutions
float rpmwz2 { 0.0 }; // desired auxiliary circuit fan revolutions
bool zaluzje2 { false };
// output, temperatures
float Te { 15.0 }; // ambient temperature TODO: get it from environment data
// NOTE: by default the engine is initialized in warm, startup-ready state
float Ts { 50.0 }; // engine temperature
float To { 45.0 }; // oil temperature
float Tsr { 50.0 }; // main circuit radiator temperature (?)
float Twy { 50.0 }; // main circuit water temperature
float Tsr2 { 40.0 }; // secondary circuit radiator temperature (?)
float Twy2 { 40.0 }; // secondary circuit water temperature
float temperatura1 { 50.0 };
float temperatura2 { 40.0 };
};
public:
double dMoveLen = 0.0;
@@ -1040,6 +1056,7 @@ public:
water_heater WaterHeater;
bool WaterCircuitsLink { false }; // optional connection between water circuits
heat_data dizel_heat;
std::array<cooling_fan, 2> MotorBlowers;
int BrakeCtrlPos = -2; /*nastawa hamulca zespolonego*/
double BrakeCtrlPosR = 0.0; /*nastawa hamulca zespolonego - plynna dla FV4a*/
@@ -1126,7 +1143,7 @@ public:
bool StLinSwitchOff{ false }; // state of the button forcing motor connectors open
bool ResistorsFlag = false; /*!o jazda rezystorowa*/
double RventRot = 0.0; /*!s obroty wentylatorow rozruchowych*/
bool UnBrake = false; /*w EZT - nacisniete odhamowywanie*/
bool UnBrake = false; /*w EZT - nacisniete odhamowywanie*/
double PantPress = 0.0; /*Cisnienie w zbiornikach pantografow*/
bool PantPressSwitchActive{ false }; // state of the pantograph pressure switch. gets primed at defined pressure level in pantograph air system
bool PantPressLockActive{ false }; // pwr system state flag. fires when pressure switch activates by pantograph pressure dropping below defined level
@@ -1343,6 +1360,8 @@ public:
bool FuelPumpSwitchOff( bool State, range_t const Notify = range_t::consist ); // fuel pump state toggle
bool OilPumpSwitch( bool State, range_t const Notify = range_t::consist ); // oil pump state toggle
bool OilPumpSwitchOff( bool State, range_t const Notify = range_t::consist ); // oil pump state toggle
bool MotorBlowersSwitch( bool State, side const Side, range_t const Notify = range_t::consist ); // traction motor fan state toggle
bool MotorBlowersSwitchOff( bool State, side const Side, range_t const Notify = range_t::consist ); // traction motor fan state toggle
bool MainSwitch( bool const State, range_t const Notify = range_t::consist );/*! wylacznik glowny*/
bool ConverterSwitch( bool State, range_t const Notify = range_t::consist );/*! wl/wyl przetwornicy*/
bool CompressorSwitch( bool State, range_t const Notify = range_t::consist );/*! wl/wyl sprezarki*/
@@ -1353,6 +1372,7 @@ public:
void WaterHeaterCheck( double const Timestep );
void FuelPumpCheck( double const Timestep );
void OilPumpCheck( double const Timestep );
void MotorBlowersCheck( double const Timestep );
bool FuseOn(void); //bezpiecznik nadamiary
bool FuseFlagCheck(void) const; // sprawdzanie flagi nadmiarowego
void FuseOff(void); // wylaczenie nadmiarowego

View File

@@ -1438,6 +1438,8 @@ void TMoverParameters::compute_movement_( double const Deltatime ) {
SetFlag( SoundFlag, sound::relay );
}
}
// traction motors
MotorBlowersCheck( Deltatime );
// uklady hamulcowe:
ConverterCheck( Deltatime );
if (VeselVolume > 0)
@@ -1534,6 +1536,11 @@ void TMoverParameters::WaterPumpCheck( double const Timestep ) {
// water heater status check
void TMoverParameters::WaterHeaterCheck( double const Timestep ) {
WaterHeater.is_damaged = (
( true == WaterHeater.is_damaged )
|| ( ( true == WaterHeater.is_active )
&& ( false == WaterPump.is_active ) ) );
WaterHeater.is_active = (
( false == WaterHeater.is_damaged )
&& ( true == Battery )
@@ -1545,11 +1552,6 @@ void TMoverParameters::WaterHeaterCheck( double const Timestep ) {
&& ( dizel_heat.temperatura1 > WaterHeater.config.temp_max ) ) {
WaterHeater.is_active = false;
}
WaterHeater.is_damaged = (
( true == WaterHeater.is_damaged )
|| ( ( true == WaterHeater.is_active )
&& ( false == WaterPump.is_active ) ) );
}
// fuel pump status update
@@ -1592,20 +1594,57 @@ void TMoverParameters::OilPumpCheck( double const Timestep ) {
true == OilPump.is_active ? std::min( minpressure + 0.1f, OilPump.pressure_maximum ) : // slight pressure margin to give time to switch off the pump and start the engine
0.f );
if( OilPump.pressure_present < OilPump.pressure_target ) {
if( OilPump.pressure < OilPump.pressure_target ) {
// TODO: scale change rate from 0.01-0.05 with oil/engine temperature/idle time
OilPump.pressure_present =
OilPump.pressure =
std::min<float>(
OilPump.pressure_target,
OilPump.pressure_present + ( enrot > 5.0 ? 0.05 : 0.035 ) * Timestep );
OilPump.pressure + ( enrot > 5.0 ? 0.05 : 0.035 ) * Timestep );
}
if( OilPump.pressure_present > OilPump.pressure_target ) {
OilPump.pressure_present =
if( OilPump.pressure > OilPump.pressure_target ) {
OilPump.pressure =
std::max<float>(
OilPump.pressure_target,
OilPump.pressure_present - 0.01 * Timestep );
OilPump.pressure - 0.01 * Timestep );
}
OilPump.pressure = clamp( OilPump.pressure, 0.f, 1.5f );
}
void TMoverParameters::MotorBlowersCheck( double const Timestep ) {
// activation check
for( auto &blower : MotorBlowers ) {
blower.is_active = (
// TODO: bind properly power source when ld is in place
( blower.start_type == start_t::battery ? Battery :
blower.start_type == start_t::converter ? ConverterFlag :
Mains ) // power source
// breaker condition disabled until it's implemented in the class data
// && ( true == blower.breaker )
&& ( false == blower.is_disabled )
&& ( ( true == blower.is_active )
|| ( blower.start_type == start_t::manual ? blower.is_enabled : true ) ) );
}
// update
for( auto &fan : MotorBlowers ) {
auto const revolutionstarget { (
fan.is_active ?
( fan.speed > 0.f ? fan.speed * static_cast<float>( enrot ) * 60 : fan.speed * -1 ) :
0.f ) };
if( std::abs( fan.revolutions - revolutionstarget ) < 0.01f ) {
fan.revolutions = revolutionstarget;
continue;
}
if( revolutionstarget > 0.f ) {
auto const speedincreasecap { std::max( 50.f, fan.speed * 0.05f * -1 ) }; // 5% of fixed revolution speed, or 50
fan.revolutions += clamp( revolutionstarget - fan.revolutions, speedincreasecap * -2, speedincreasecap ) * Timestep;
}
else {
fan.revolutions *= std::max( 0.0, 1.0 - Timestep );
}
}
OilPump.pressure_present = clamp( OilPump.pressure_present, 0.f, 1.5f );
}
@@ -2608,6 +2647,60 @@ bool TMoverParameters::OilPumpSwitchOff( bool State, range_t const Notify ) {
return ( OilPump.is_disabled != initialstate );
}
bool TMoverParameters::MotorBlowersSwitch( bool State, side const Side, range_t const Notify ) {
auto &fan { MotorBlowers[ Side ] };
if( ( fan.start_type != start_t::manual )
&& ( fan.start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
return false;
}
bool const initialstate { fan.is_enabled };
fan.is_enabled = State;
if( Notify != range_t::local ) {
SendCtrlToNext(
( Side == side::front ? "MotorBlowersFrontSwitch" : "MotorBlowersRearSwitch" ),
( fan.is_enabled ? 1 : 0 ),
CabNo,
( Notify == range_t::unit ?
coupling::control | coupling::permanent :
coupling::control ) );
}
return ( fan.is_enabled != initialstate );
}
bool TMoverParameters::MotorBlowersSwitchOff( bool State, side const Side, range_t const Notify ) {
auto &fan { MotorBlowers[ Side ] };
if( ( fan.start_type != start_t::manual )
&& ( fan.start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
return false;
}
bool const initialstate { fan.is_disabled };
fan.is_disabled = State;
if( Notify != range_t::local ) {
SendCtrlToNext(
( Side == side::front ? "MotorBlowersFrontSwitchOff" : "MotorBlowersRearSwitchOff" ),
( fan.is_disabled ? 1 : 0 ),
CabNo,
( Notify == range_t::unit ?
coupling::control | coupling::permanent :
coupling::control ) );
}
return ( fan.is_disabled != initialstate );
}
// *************************************************************************************************
// Q: 20160713
// włączenie / wyłączenie obwodu głownego
@@ -6022,7 +6115,7 @@ bool TMoverParameters::dizel_StartupCheck() {
}
// test the oil pump
if( ( false == OilPump.is_active )
|| ( OilPump.pressure_present < OilPump.pressure_minimum ) ) {
|| ( OilPump.pressure < OilPump.pressure_minimum ) ) {
engineisready = false;
if( OilPump.start_type == start_t::manual ) {
// with manual pump control startup procedure is done only once per starter switch press
@@ -8208,59 +8301,54 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) {
}
extract_value( ConverterStartDelay, "ConverterStartDelay", line, "" );
// devices
std::map<std::string, start_t> starts {
{ "Manual", start_t::manual },
{ "Automatic", start_t::automatic },
{ "Mixed", start_t::manualwithautofallback },
{ "Battery", start_t::battery },
{ "Converter", start_t::converter } };
// compressor
{
std::map<std::string, start_t> starts {
{ "Manual", start_t::manual },
{ "Automatic", start_t::automatic }
};
auto lookup = starts.find( extract_value( "CompressorStart", line ) );
CompressorStart =
lookup != starts.end() ?
lookup->second :
start_t::manual;
}
// fuel pump
{
std::map<std::string, start_t> starts {
{ "Manual", start_t::manual },
{ "Automatic", start_t::automatic },
{ "Mixed", start_t::manualwithautofallback }
};
auto lookup = starts.find( extract_value( "FuelStart", line ) );
FuelPump.start_type =
lookup != starts.end() ?
lookup->second :
start_t::manual;
}
// oil pump
{
std::map<std::string, start_t> starts {
{ "Manual", start_t::manual },
{ "Automatic", start_t::automatic },
{ "Mixed", start_t::manualwithautofallback }
};
auto lookup = starts.find( extract_value( "OilStart", line ) );
OilPump.start_type =
lookup != starts.end() ?
lookup->second :
start_t::manual;
}
// water pump
{
std::map<std::string, start_t> starts {
{ "Manual", start_t::manual },
{ "Battery", start_t::battery }
};
auto lookup = starts.find( extract_value( "WaterStart", line ) );
WaterPump.start_type =
lookup != starts.end() ?
lookup->second :
start_t::manual;
}
// traction motor fans
{
auto lookup = starts.find( extract_value( "MotorBlowersStart", line ) );
MotorBlowers[side::front].start_type =
MotorBlowers[side::rear].start_type =
lookup != starts.end() ?
lookup->second :
start_t::manual;
}
}
void TMoverParameters::LoadFIZ_Blending(std::string const &line) {
@@ -8513,6 +8601,10 @@ void TMoverParameters::LoadFIZ_Engine( std::string const &Input ) {
extract_value( WaterHeater.config.temp_min, "HeaterMinTemperature", Input, "" );
extract_value( WaterHeater.config.temp_max, "HeaterMaxTemperature", Input, "" );
}
// traction motors
extract_value( MotorBlowers[ side::front ].speed, "MotorBlowersSpeed", Input, "" );
MotorBlowers[ side::rear ] = MotorBlowers[ side::front ];
}
void TMoverParameters::LoadFIZ_Switches( std::string const &Input ) {
@@ -9289,7 +9381,39 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if (Command == "MainSwitch")
else if( Command == "MotorBlowersFrontSwitch" ) {
if( ( MotorBlowers[ side::front ].start_type != start_t::manual )
&& ( MotorBlowers[ side::front ].start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
MotorBlowers[side::front].is_enabled = ( CValue1 == 1 );
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if( Command == "MotorBlowersFrontSwitchOff" ) {
if( ( MotorBlowers[ side::front ].start_type != start_t::manual )
&& ( MotorBlowers[ side::front ].start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
MotorBlowers[side::front].is_disabled = ( CValue1 == 1 );
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if( Command == "MotorBlowersRearSwitch" ) {
if( ( MotorBlowers[ side::rear ].start_type != start_t::manual )
&& ( MotorBlowers[ side::rear ].start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
MotorBlowers[side::rear].is_enabled = ( CValue1 == 1 );
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if( Command == "MotorBlowersRearSwitchOff" ) {
if( ( MotorBlowers[ side::rear ].start_type != start_t::manual )
&& ( MotorBlowers[ side::rear ].start_type != start_t::manualwithautofallback ) ) {
// automatic device ignores 'manual' state commands
MotorBlowers[side::rear].is_disabled = ( CValue1 == 1 );
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if (Command == "MainSwitch")
{
if (CValue1 == 1) {