forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTractionPower.cpp
170 lines (153 loc) · 5.42 KB
/
TractionPower.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
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/.
*/
/*
MaSzyna EU07 locomotive simulator component
Copyright (C) 2004 Maciej Czapkiewicz and others
*/
#include "system.hpp"
#include "classes.hpp"
#pragma hdrstop
#include "Mover.h"
#include "mctools.hpp"
#include "Timer.h"
#include "Globals.h"
#include "TractionPower.h"
#include "Usefull.h"
#include "Ground.h"
//---------------------------------------------------------------------------
TTractionPowerSource::TTractionPowerSource()
{
NominalVoltage = 0;
VoltageFrequency = 0;
InternalRes = 0.2;
MaxOutputCurrent = 0;
FastFuseTimeOut = 1;
FastFuseRepetition = 3;
SlowFuseTimeOut = 60;
Recuperation = false;
TotalAdmitance = 1e-10; // 10Mom - jakaœ tam up³ywnoœæ
TotalPreviousAdmitance = 1e-10; // zero jest szkodliwe
OutputVoltage = 0;
FastFuse = false;
SlowFuse = false;
FuseTimer = 0;
FuseCounter = 0;
psNode[0] = NULL; // sekcje zostan¹ pod³¹czone do zasilaczy
psNode[1] = NULL;
bSection = false; // sekcja nie jest Ÿród³em zasilania, tylko grupuje przês³a
};
TTractionPowerSource::~TTractionPowerSource(){};
void TTractionPowerSource::Init(double u, double i)
{ // ustawianie zasilacza przy braku w scenerii
NominalVoltage = u;
VoltageFrequency = 0;
MaxOutputCurrent = i;
};
bool TTractionPowerSource::Load(cParser *parser)
{
std::string token;
// AnsiString str;
// str= Parser->GetNextSymbol()LowerCase();
// asName= str;
parser->getTokens(5);
*parser >> NominalVoltage >> VoltageFrequency >> InternalRes >> MaxOutputCurrent >>
FastFuseTimeOut;
parser->getTokens();
*parser >> FastFuseRepetition;
parser->getTokens();
*parser >> SlowFuseTimeOut;
parser->getTokens();
*parser >> token;
if (token.compare("recuperation") == 0)
Recuperation = true;
else if (token.compare("section") == 0) // od³¹cznik sekcyjny
bSection = true; // nie jest Ÿród³em zasilania, a jedynie informuje o pr¹dzie od³¹czenia
// sekcji z obwodu
parser->getTokens();
*parser >> token;
if (token.compare("end") != 0)
Error("tractionpowersource end statement missing");
// if (!bSection) //od³¹cznik sekcji zasadniczo nie ma impedancji (0.01 jest OK)
if (InternalRes < 0.1) // coœ ma³a ta rezystancja by³a...
InternalRes = 0.2; // tak oko³o 0.2, wg
// http://www.ikolej.pl/fileadmin/user_upload/Seminaria_IK/13_05_07_Prezentacja_Kruczek.pdf
return true;
};
bool TTractionPowerSource::Render()
{
return true;
};
bool TTractionPowerSource::Update(double dt)
{ // powinno byæ wykonane raz na krok fizyki
if (NominalVoltage * TotalPreviousAdmitance >
MaxOutputCurrent) // iloczyn napiêcia i admitancji daje pr¹d
{
FastFuse = true;
FuseCounter += 1;
if (FuseCounter > FastFuseRepetition)
{
SlowFuse = true;
ErrorLog("Power overload: \"" + gMyNode->asName + "\" disabled for " +
AnsiString(SlowFuseTimeOut) + "s");
}
else
ErrorLog("Power overload: \"" + gMyNode->asName + "\" disabled for " +
AnsiString(FastFuseTimeOut) + "s");
FuseTimer = 0;
}
if (FastFuse || SlowFuse)
{ // jeœli któryœ z bezpieczników zadzia³a³
TotalAdmitance = 0;
FuseTimer += dt;
if (!SlowFuse)
{ // gdy szybki, odczekaæ krótko i za³¹czyæ
if (FuseTimer > FastFuseTimeOut)
FastFuse = false;
}
else if (FuseTimer > SlowFuseTimeOut)
{
SlowFuse = false;
FuseCounter = 0; // dajemy znów szansê
}
}
TotalPreviousAdmitance = TotalAdmitance; // u¿ywamy admitancji z poprzedniego kroku
if (TotalPreviousAdmitance == 0.0)
TotalPreviousAdmitance = 1e-10; // przynajmniej minimalna up³ywnoœæ
TotalAdmitance = 1e-10; // a w aktualnym kroku sumujemy admitancjê
return true;
};
double TTractionPowerSource::CurrentGet(double res)
{ // pobranie wartoœci pr¹du przypadaj¹cego na rezystancjê (res)
// niech pamiêta poprzedni¹ admitancjê i wg niej przydziela pr¹d
if (SlowFuse || FastFuse)
{ // czekanie na zanik obci¹¿enia sekcji
if (res < 100.0) // liczenie czasu dopiero, gdy obci¹¿enie zniknie
FuseTimer = 0;
return 0;
}
if ((res > 0) || ((res < 0) && (Recuperation)))
TotalAdmitance +=
1.0 / res; // po³¹czenie równoleg³e rezystancji jest równowa¿ne sumie admitancji
TotalCurrent = (TotalPreviousAdmitance != 0.0) ?
NominalVoltage / (InternalRes + 1.0 / TotalPreviousAdmitance) :
0.0; // napiêcie dzielone przez sumê rezystancji wewnêtrznej i obci¹¿enia
OutputVoltage = NominalVoltage - InternalRes * TotalCurrent; // napiêcie na obci¹¿eniu
return TotalCurrent / (res * TotalPreviousAdmitance); // pr¹d proporcjonalny do udzia³u (1/res)
// w ca³kowitej admitancji
};
void TTractionPowerSource::PowerSet(TTractionPowerSource *ps)
{ // wskazanie zasilacza w obiekcie sekcji
if (!psNode[0])
psNode[0] = ps;
else if (!psNode[1])
psNode[1] = ps;
// else ErrorLog("nie mo¿e byæ wiêcej punktów zasilania ni¿ dwa");
};
//---------------------------------------------------------------------------
#pragma package(smart_init)