mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 16:19:19 +02:00
control for alerter, doors, vehicle lights. support for multiple logs. fixes for relaytype 45, 46
This commit is contained in:
@@ -416,37 +416,30 @@ struct TPowerParameters
|
||||
struct
|
||||
{
|
||||
_mover__3 RHeater;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
_mover__2 RPowerCable;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TCurrentCollector CollectorParameters;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
_mover__1 RAccumulator;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TEngineTypes GeneratorEngine;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
double InputVoltage;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TPowerType PowerType;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
@@ -670,10 +663,18 @@ public:
|
||||
/*nastawniki:*/
|
||||
int MainCtrlPosNo = 0; /*ilosc pozycji nastawnika*/
|
||||
int ScndCtrlPosNo = 0;
|
||||
int LightsPosNo = 0; // NOTE: values higher than 0 seem to break the current code for light switches
|
||||
int LightsPosNo = 0;
|
||||
int LightsDefPos = 1;
|
||||
bool LightsWrap = false;
|
||||
int Lights[2][17]; // pozycje świateł, przód - tył, 1 .. 16
|
||||
enum light {
|
||||
|
||||
headlight_left = 0x01,
|
||||
redmarker_left = 0x02,
|
||||
headlight_upper = 0x04,
|
||||
headlight_right = 0x10,
|
||||
redmarker_right = 0x20,
|
||||
};
|
||||
bool ScndInMain = false; /*zaleznosc bocznika od nastawnika*/
|
||||
bool MBrake = false; /*Czy jest hamulec reczny*/
|
||||
double StopBrakeDecc = 0.0;
|
||||
@@ -1173,6 +1174,10 @@ extract_value( _Type &Variable, std::string const &Key, std::string const &Input
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
bool
|
||||
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
|
||||
|
||||
inline
|
||||
std::string
|
||||
extract_value( std::string const &Key, std::string const &Input ) {
|
||||
|
||||
@@ -1814,8 +1814,9 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
|
||||
LastRelayTime = 0;
|
||||
|
||||
if ((OK) && (EngineType == ElectricInductionMotor))
|
||||
// NOTE: round() already adds 0.5, are the ones added here as well correct?
|
||||
if ((Vmax < 250))
|
||||
ScndCtrlActualPos = Round(Vel + 0.5f);
|
||||
ScndCtrlActualPos = Round(Vel + 0.5);
|
||||
else
|
||||
ScndCtrlActualPos = Round(Vel * 1.0 / 2 + 0.5);
|
||||
|
||||
@@ -2031,10 +2032,12 @@ void TMoverParameters::SecuritySystemCheck(double dt)
|
||||
(Battery)) // Ra: EZT ma teraz czuwak w rozrządczym
|
||||
{
|
||||
// CA
|
||||
if (Vel >=
|
||||
SecuritySystem
|
||||
.AwareMinSpeed) // domyślnie predkość większa od 10% Vmax, albo podanej jawnie w FIZ
|
||||
{
|
||||
if( ( SecuritySystem.AwareMinSpeed > 0.0 ?
|
||||
( Vel >= SecuritySystem.AwareMinSpeed ) :
|
||||
( ActiveDir != 0 ) ) ) {
|
||||
// domyślnie predkość większa od 10% Vmax, albo podanej jawnie w FIZ
|
||||
// with defined minspeed of 0 the alerter will activate with reverser out of neutral position
|
||||
// this emulates behaviour of engines like SM42
|
||||
SecuritySystem.SystemTimer += dt;
|
||||
if (TestFlag(SecuritySystem.SystemType, 1) &&
|
||||
TestFlag(SecuritySystem.Status, s_aware)) // jeśli świeci albo miga
|
||||
@@ -4087,106 +4090,152 @@ double TMoverParameters::TractionForce(double dt)
|
||||
if ((MainCtrlPos == 0) || (ShuntMode))
|
||||
ScndCtrlPos = 0;
|
||||
|
||||
else if (AutoRelayFlag)
|
||||
switch (RelayType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if ((Im <= (MPTRelay[ScndCtrlPos].Iup * PosRatio)) &&
|
||||
(ScndCtrlPos < ScndCtrlPosNo))
|
||||
++ScndCtrlPos;
|
||||
if ((Im >= (MPTRelay[ScndCtrlPos].Idown * PosRatio)) && (ScndCtrlPos > 0))
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if ((MPTRelay[ScndCtrlPos].Iup < Vel) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
++ScndCtrlPos;
|
||||
if ((MPTRelay[ScndCtrlPos].Idown > Vel) && (ScndCtrlPos > 0))
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if ((MPTRelay[ScndCtrlPos].Iup < Vel) && (ScndCtrlPos < ScndCtrlPosNo) &&
|
||||
(EnginePower < (tmp * 0.99)))
|
||||
++ScndCtrlPos;
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im) && (ScndCtrlPos > 0))
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 41:
|
||||
{
|
||||
if ((MainCtrlPos == MainCtrlPosNo) &&
|
||||
(tmpV * 3.6 > MPTRelay[ScndCtrlPos].Iup) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
{
|
||||
++ScndCtrlPos;
|
||||
enrot = enrot * 0.73;
|
||||
}
|
||||
if ((Im > MPTRelay[ScndCtrlPos].Idown) && (ScndCtrlPos > 0))
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 45:
|
||||
{
|
||||
if ((MainCtrlPos > 11) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
if ((ScndCtrlPos == 0))
|
||||
if ((MPTRelay[ScndCtrlPos].Iup > Im))
|
||||
++ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos].Iup < Vel))
|
||||
++ScndCtrlPos;
|
||||
else {
|
||||
if( AutoRelayFlag ) {
|
||||
|
||||
// malenie
|
||||
if ((ScndCtrlPos > 0) && (MainCtrlPos < 12))
|
||||
if ((ScndCtrlPos == ScndCtrlPosNo))
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im))
|
||||
--ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos].Idown > Vel))
|
||||
--ScndCtrlPos;
|
||||
if ((MainCtrlPos < 11) && (ScndCtrlPos > 2))
|
||||
ScndCtrlPos = 2;
|
||||
if ((MainCtrlPos < 9) && (ScndCtrlPos > 0))
|
||||
ScndCtrlPos = 0;
|
||||
}
|
||||
case 46:
|
||||
{
|
||||
// wzrastanie
|
||||
if ((MainCtrlPos > 9) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
if ((ScndCtrlPos) % 2 == 0)
|
||||
if ((MPTRelay[ScndCtrlPos].Iup > Im))
|
||||
++ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos - 1].Iup > Im) &&
|
||||
(MPTRelay[ScndCtrlPos].Iup < Vel))
|
||||
++ScndCtrlPos;
|
||||
switch( RelayType ) {
|
||||
|
||||
// malenie
|
||||
if ((MainCtrlPos < 10) && (ScndCtrlPos > 0))
|
||||
if ((ScndCtrlPos) % 2 == 0)
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im))
|
||||
case 0: {
|
||||
|
||||
if( ( Im <= ( MPTRelay[ ScndCtrlPos ].Iup * PosRatio ) ) &&
|
||||
( ScndCtrlPos < ScndCtrlPosNo ) )
|
||||
++ScndCtrlPos;
|
||||
if( ( Im >= ( MPTRelay[ ScndCtrlPos ].Idown * PosRatio ) ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos + 1].Idown < Im) &&
|
||||
(MPTRelay[ScndCtrlPos].Idown > Vel))
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) && ( ScndCtrlPos < ScndCtrlPosNo ) )
|
||||
++ScndCtrlPos;
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown > Vel ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
if ((MainCtrlPos < 9) && (ScndCtrlPos > 2))
|
||||
ScndCtrlPos = 2;
|
||||
if ((MainCtrlPos < 6) && (ScndCtrlPos > 0))
|
||||
ScndCtrlPos = 0;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) && ( ScndCtrlPos < ScndCtrlPosNo ) &&
|
||||
( EnginePower < ( tmp * 0.99 ) ) )
|
||||
++ScndCtrlPos;
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown < Im ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 41:
|
||||
{
|
||||
if( ( MainCtrlPos == MainCtrlPosNo )
|
||||
&& ( tmpV * 3.6 > MPTRelay[ ScndCtrlPos ].Iup )
|
||||
&& ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
++ScndCtrlPos;
|
||||
enrot = enrot * 0.73;
|
||||
}
|
||||
if( ( Im > MPTRelay[ ScndCtrlPos ].Idown )
|
||||
&& ( ScndCtrlPos > 0 ) ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 45:
|
||||
{
|
||||
if( ( MainCtrlPos >= 10 ) && ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
if( ScndCtrlPos == 0 ) {
|
||||
if( Im < MPTRelay[ ScndCtrlPos ].Iup ) {
|
||||
++ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( Vel > MPTRelay[ ScndCtrlPos ].Iup ) {
|
||||
++ScndCtrlPos;
|
||||
}
|
||||
// check for cases where the speed drops below threshold for level 2 or 3
|
||||
if( ( ScndCtrlPos > 1 )
|
||||
&& ( Vel < MPTRelay[ ScndCtrlPos - 1 ].Idown ) ){
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
// malenie
|
||||
if( ( ScndCtrlPos > 0 ) && ( MainCtrlPos < 10 ) ) {
|
||||
if( ScndCtrlPos == 1 ) {
|
||||
if( Im > MPTRelay[ ScndCtrlPos - 1 ].Idown ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( Vel < MPTRelay[ ScndCtrlPos ].Idown ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3rd level drops with master controller at position lower than 10...
|
||||
if( MainCtrlPos < 10 ) {
|
||||
ScndCtrlPos = std::min( 2, ScndCtrlPos );
|
||||
}
|
||||
// ...and below position 7 field shunt drops altogether
|
||||
if( MainCtrlPos < 7 ) {
|
||||
ScndCtrlPos = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 46:
|
||||
{
|
||||
// wzrastanie
|
||||
if( ( MainCtrlPos >= 10 )
|
||||
&& ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
if( ( ScndCtrlPos ) % 2 == 0 ) {
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup > Im ) ) {
|
||||
++ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( ( MPTRelay[ ScndCtrlPos - 1 ].Iup > Im )
|
||||
&& ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) ) {
|
||||
++ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
// malenie
|
||||
if( ( MainCtrlPos < 10 )
|
||||
&& ( ScndCtrlPos > 0 ) ) {
|
||||
if( ( ScndCtrlPos ) % 2 == 0 ) {
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown < Im ) ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( ( MPTRelay[ ScndCtrlPos + 1 ].Idown < Im )
|
||||
&& ( MPTRelay[ ScndCtrlPos ].Idown > Vel ) ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( MainCtrlPos < 10 ) {
|
||||
ScndCtrlPos = std::min( 2, ScndCtrlPos );
|
||||
}
|
||||
if( MainCtrlPos < 7 ) {
|
||||
ScndCtrlPos = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
} // switch RelayType
|
||||
}
|
||||
} // switch RelayType
|
||||
}
|
||||
break;
|
||||
} // DieselElectric
|
||||
|
||||
case ElectricInductionMotor:
|
||||
{
|
||||
if ((Mains)) // nie wchodzić w funkcję bez potrzeby
|
||||
if ((abs(Voltage) < EnginePowerSource.CollectorParameters.MinV) ||
|
||||
(abs(Voltage) > EnginePowerSource.CollectorParameters.MaxV + 200))
|
||||
{
|
||||
MainSwitch(false);
|
||||
if( ( Mains ) ) {
|
||||
// nie wchodzić w funkcję bez potrzeby
|
||||
if( ( abs( Voltage ) < EnginePowerSource.CollectorParameters.MinV )
|
||||
|| ( abs( Voltage ) > EnginePowerSource.CollectorParameters.MaxV + 200 ) ) {
|
||||
MainSwitch( false );
|
||||
}
|
||||
tmpV = abs(nrot) * (PI * WheelDiameter) *
|
||||
3.6; //*DirAbsolute*eimc[eimc_s_p]; - do przemyslenia dzialanie pp
|
||||
}
|
||||
tmpV = abs(nrot) * (PI * WheelDiameter) * 3.6; //*DirAbsolute*eimc[eimc_s_p]; - do przemyslenia dzialanie pp
|
||||
if ((Mains))
|
||||
{
|
||||
|
||||
@@ -7915,3 +7964,22 @@ double TMoverParameters::ShowCurrentP(int AmpN)
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
bool
|
||||
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
|
||||
|
||||
auto value = extract_value( Key, Input );
|
||||
if( false == value.empty() ) {
|
||||
// set the specified variable to retrieved value
|
||||
Variable = ( ToLower( value ) == "yes" );
|
||||
return true; // located the variable
|
||||
}
|
||||
else {
|
||||
// set the variable to provided default value
|
||||
if( false == Default.empty() ) {
|
||||
Variable = ( ToLower( Default ) == "yes" );
|
||||
}
|
||||
return false; // supplied the default
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,23 +72,11 @@ double Min0R(double x1, double x2)
|
||||
// TODO: replace with something sensible
|
||||
std::string Now() {
|
||||
|
||||
std::time_t timenow = std::time( nullptr );
|
||||
std::tm tm = *std::localtime( &timenow );
|
||||
std::stringstream converter;
|
||||
converter << std::put_time( &tm, "%c" );
|
||||
std::time_t timenow = std::time( nullptr );
|
||||
std::tm tm = *std::localtime( &timenow );
|
||||
std::stringstream converter;
|
||||
converter << std::put_time( &tm, "%c" );
|
||||
return converter.str();
|
||||
|
||||
/* char buffer[ 256 ];
|
||||
sprintf( buffer,
|
||||
"%d-%02d-%02d %02d:%02d:%02d.%03d",
|
||||
st.wYear,
|
||||
st.wMonth,
|
||||
st.wDay,
|
||||
st.wHour,
|
||||
st.wMinute,
|
||||
st.wSecond,
|
||||
st.wMilliseconds );
|
||||
*/
|
||||
}
|
||||
|
||||
bool TestFlag(int Flag, int Value)
|
||||
|
||||
@@ -62,7 +62,7 @@ inline double Sign(double x)
|
||||
return x >= 0 ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
inline long Round(float f)
|
||||
inline long Round(double const f)
|
||||
{
|
||||
return (long)(f + 0.5);
|
||||
//return lround(f);
|
||||
|
||||
Reference in New Issue
Block a user