31 #include "TValvulaContr.h"
32 #include "TBloqueMotor.h"
36 TValvulaContr::TValvulaContr() :
45 TValvulaContr::~TValvulaContr() {
52 TValvulaContr::TValvulaContr(
TValvulaContr *Origen,
int Valvula) :
55 FTipoContr = Origen->FTipoContr;
56 FLimiteInf1 = Origen->FLimiteInf1;
57 FLimiteInf2 = Origen->FLimiteInf2;
58 FLimiteSup1 = Origen->FLimiteSup1;
59 FLimiteSup2 = Origen->FLimiteSup2;
60 FCDInicial = Origen->FCDInicial;
61 FCDFinal = Origen->FCDFinal;
62 FAngle0 = Origen->FAngle0;
68 FNumeroOrden = Origen->FNumeroOrden;
75 void TValvulaContr::LeeDatosIniciales(
const char *FileWAM, fpos_t &filepos,
int norden,
bool HayMotor,
80 FILE *fich = fopen(FileWAM,
"r");
81 fsetpos(fich, &filepos);
83 FNumeroOrden = norden;
87 fscanf(fich,
"%d %lf %lf %lf %lf %lf %lf ", &Ctrl, &FLimiteInf1, &FLimiteInf2, &FLimiteSup1, &FLimiteSup2, &FCDInicial,
92 FTipoContr = nmContrAngulo;
95 FTipoContr = nmContrFuel;
99 fgetpos(fich, &filepos);
102 }
catch(exception &N) {
103 std::cout <<
"ERROR: LeeDatosIniciales ValvulaContr" << std::endl;
113 void TValvulaContr::CalculaCD(
double AnguloActual,
double Mf) {
115 double xx = 0., acoef = 0., bcoef = 0.;
117 if(FTipoContr == nmContrAngulo)
119 else if(FTipoContr == nmContrFuel)
122 printf(
"ERROR: This type of controlled valve is not implemented");
123 throw Exception(
"ERROR: This type of controlled valve is not implemented");
125 if(FLimiteSup1 == FLimiteSup2) {
126 if(xx >= FLimiteSup1) {
127 FCDTubVol = FCDFinal;
128 FCDVolTub = FCDFinal;
130 }
else if(FLimiteSup1 < FLimiteSup2) {
131 if(xx >= FLimiteSup1 && xx < FLimiteSup2) {
132 acoef = (FCDFinal - FCDInicial) / (FLimiteSup2 - FLimiteSup1);
133 bcoef = FCDInicial - acoef * FLimiteSup1;
134 FCDTubVol = acoef * xx + bcoef;
135 FCDVolTub = acoef * xx + bcoef;
137 if(xx >= FLimiteSup2) {
138 FCDTubVol = FCDFinal;
139 FCDVolTub = FCDFinal;
142 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
143 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
145 if(FLimiteInf1 == FLimiteInf2) {
146 if(xx <= FLimiteInf1) {
147 FCDTubVol = FCDInicial;
148 FCDVolTub = FCDInicial;
150 }
else if(FLimiteInf1 > FLimiteInf2) {
151 if(xx <= FLimiteInf1 && xx > FLimiteInf2) {
152 acoef = (FCDInicial - FCDFinal) / (FLimiteInf2 - FLimiteInf1);
153 bcoef = FCDInicial - acoef * FLimiteInf2;
154 FCDTubVol = acoef * xx + bcoef;
155 FCDVolTub = acoef * xx + bcoef;
157 if(xx <= FLimiteInf2) {
158 FCDTubVol = FCDInicial;
159 FCDVolTub = FCDFinal;
162 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
163 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
165 }
catch(exception &N) {
166 std::cout <<
"ERROR: CalculaCD ValvulaContr" << std::endl;
173 void TValvulaContr::GetCDin(
double Time) {
175 double xx = 0., acoef = 0., bcoef = 0.;
177 if(FTipoContr == nmContrAngulo) {
178 double DeltaT = Time - FTime0;
180 double DeltaA = 6 * FEngine->getRegimen() * DeltaT;
181 xx = DeltaA + FAngle0;
183 }
else if(FTipoContr == nmContrFuel) {
184 xx = FEngine->getMasaFuel();
186 printf(
"ERROR: This type of controlled valve is not implemented");
187 throw Exception(
"ERROR: This type of controlled valve is not implemented");
189 if(FLimiteSup1 == FLimiteSup2) {
190 if(xx >= FLimiteSup1) {
191 FCDTubVol = FCDFinal;
193 }
else if(FLimiteSup1 < FLimiteSup2) {
194 if(xx >= FLimiteSup1 && xx < FLimiteSup2) {
195 acoef = (FCDFinal - FCDInicial) / (FLimiteSup2 - FLimiteSup1);
196 bcoef = FCDInicial - acoef * FLimiteSup1;
197 FCDTubVol = acoef * xx + bcoef;
199 if(xx >= FLimiteSup2) {
200 FCDTubVol = FCDFinal;
203 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
204 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
206 if(FLimiteInf1 == FLimiteInf2) {
207 if(xx <= FLimiteInf1) {
208 FCDTubVol = FCDInicial;
210 }
else if(FLimiteInf1 > FLimiteInf2) {
211 if(xx <= FLimiteInf1 && xx > FLimiteInf2) {
212 acoef = (FCDInicial - FCDFinal) / (FLimiteInf2 - FLimiteInf1);
213 bcoef = FCDInicial - acoef * FLimiteInf2;
214 FCDTubVol = acoef * xx + bcoef;
216 if(xx <= FLimiteInf2) {
217 FCDTubVol = FCDInicial;
220 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
221 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
225 void TValvulaContr::GetCDout(
double Time) {
226 double xx = 0., acoef = 0., bcoef = 0.;
228 if(FTipoContr == nmContrAngulo) {
229 double DeltaT = Time - FTime0;
231 double DeltaA = 6 * FEngine->getRegimen() * DeltaT;
232 xx = DeltaA + FAngle0;
234 }
else if(FTipoContr == nmContrFuel) {
235 xx = FEngine->getMasaFuel();
237 printf(
"ERROR: This type of controlled valve is not implemented");
238 throw Exception(
"ERROR: This type of controlled valve is not implemented");
240 if(FLimiteSup1 == FLimiteSup2) {
241 if(xx >= FLimiteSup1) {
242 FCDVolTub = FCDFinal;
244 }
else if(FLimiteSup1 < FLimiteSup2) {
245 if(xx >= FLimiteSup1 && xx < FLimiteSup2) {
246 acoef = (FCDFinal - FCDInicial) / (FLimiteSup2 - FLimiteSup1);
247 bcoef = FCDInicial - acoef * FLimiteSup1;
248 FCDVolTub = acoef * xx + bcoef;
250 if(xx >= FLimiteSup2) {
251 FCDVolTub = FCDFinal;
254 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
255 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
257 if(FLimiteInf1 == FLimiteInf2) {
258 if(xx <= FLimiteInf1) {
259 FCDVolTub = FCDInicial;
261 }
else if(FLimiteInf1 > FLimiteInf2) {
262 if(xx <= FLimiteInf1 && xx > FLimiteInf2) {
263 acoef = (FCDInicial - FCDFinal) / (FLimiteInf2 - FLimiteInf1);
264 bcoef = FCDInicial - acoef * FLimiteInf2;
265 FCDVolTub = acoef * xx + bcoef;
267 if(xx <= FLimiteInf2) {
268 FCDVolTub = FCDFinal;
271 printf(
"ERROR: in hysteresis valve (EGR,Swirl...");
272 throw Exception(
"ERROR: in hysteresis valve (EGR,Swirl...)");
276 #pragma package(smart_init)