33 #include "TDeposito.h"
34 #include "TBloqueMotor.h"
52 FILE *fich = fopen(FileWAM,
"r");
53 fsetpos(fich, &filepos);
55 fscanf(fich,
"%d %d", &obj, &prm);
57 fscanf(fich,
"%d ", &FObjectID);
60 FObjectSensed = nmSensEjec;
63 FParameterSensed = nmTime;
66 std::cout <<
"ERROR: Parametro " << prm <<
"en el objeto " << obj <<
"no valido, sensor: " << FNumeroSensor <<
71 FObjectSensed = nmSensTubo;
72 fscanf(fich,
"%lf ", &FDistancia);
75 FParameterSensed = nmPressure;
78 FParameterSensed = nmTemperature;
81 FParameterSensed = nmMassFlow;
84 std::cout <<
"ERROR: Parametro " << prm <<
"en el objeto " << obj <<
"no valido, sensor: " << FNumeroSensor <<
89 FObjectSensed = nmSensDeposito;
92 FParameterSensed = nmPressure;
95 FParameterSensed = nmTemperature;
98 std::cout <<
"ERROR: Parametro " << prm <<
"en el objeto " << obj <<
"no valido, sensor: " << FNumeroSensor <<
103 FObjectSensed = nmSensMotor;
106 FParameterSensed = nmFuel;
109 FParameterSensed = nmEngSpeed;
112 std::cout <<
"ERROR: Parametro " << prm <<
"en el objeto " << obj <<
"no valido, sensor: " << FNumeroSensor <<
117 std::cout <<
"ERROR: Objeto " << obj <<
"no valido, sensor: " << FNumeroSensor << std::endl;
119 fscanf(fich,
"%lf %lf ", &FDelay, &FGain);
121 fgetpos(fich, &filepos);
129 FObjectPointer = Object;
130 if(FObjectSensed == nmSensTubo) {
131 tmp = (double)(((
TTubo*) FObjectPointer)->getNin() - 1) * FDistancia / ((
TTubo*) FObjectPointer)->getLongitudTotal();
134 FDelta = (FDistancia - (double) FNode0 * ((
TTubo*) FObjectPointer)->getXRef()) / ((
TTubo*) FObjectPointer)->getXRef();
139 return FCurrentValue;
143 double tmp0 = 0., tmp1 = 0.;
147 double TimeStep = Time - FTime0;
149 FPeriod = FPeriod + TimeStep;
151 if(FPeriod >= 0.001) {
157 if(Update || !FInicia) {
158 switch(FObjectSensed) {
160 switch(FParameterSensed) {
165 FCurrentValue = FRealValue;
168 switch(FParameterSensed) {
170 FRealValue = ((
TTubo*) FObjectPointer)->GetPresion(FNode0) * (1 - FDelta) + ((
TTubo*) FObjectPointer)->GetPresion(
174 tmp0 =
pow2(((
TTubo*) FObjectPointer)->GetAsonido(FNode0) * __cons::ARef) / ((
TTubo*) FObjectPointer)->GetGamma(
175 FNode0) / ((
TTubo*) FObjectPointer)->GetRMezcla(FNode0);
176 tmp1 =
pow2(((
TTubo*) FObjectPointer)->GetAsonido(FNode1) * __cons::ARef) / ((
TTubo*) FObjectPointer)->GetGamma(
177 FNode1) / ((
TTubo*) FObjectPointer)->GetRMezcla(FNode1);
178 FRealValue = tmp0 * (1 - FDelta) + tmp1 * FDelta;
181 tmp0 = ((
TTubo*) FObjectPointer)->GetDensidad(FNode0) * ((
TTubo*) FObjectPointer)->GetVelocidad(
182 FNode0) * __cons::ARef * ((
TTubo*) FObjectPointer)->GetArea(FNode0);
183 tmp1 = ((
TTubo*) FObjectPointer)->GetDensidad(FNode1) * ((
TTubo*) FObjectPointer)->GetVelocidad(
184 FNode1) * __cons::ARef * ((
TTubo*) FObjectPointer)->GetArea(FNode1);
185 FRealValue = tmp0 * (1 - FDelta) + tmp1 * FDelta;
190 switch(FParameterSensed) {
192 FRealValue = ((
TDeposito*) FObjectPointer)->getPressure();
195 FRealValue = ((
TDeposito*) FObjectPointer)->getTemperature();
200 switch(FParameterSensed) {
202 FRealValue = ((
TBloqueMotor*) FObjectPointer)->getMasaFuel();
205 FRealValue = ((
TBloqueMotor*) FObjectPointer)->getRegimen();
212 FPrevValue = FRealValue;
216 FCurrentValue = FPrevValue;
218 FCurrentValue = ((2 * FDelay - deltaT) * FPrevValue + deltaT * FGain * (FRealValue + FPrevRealValue)) /
219 (2 * FDelay + deltaT);
221 FPrevValue = FCurrentValue;
222 FPrevRealValue = FRealValue;
233 int nvars = 0, var = 0;
235 FILE *fich = fopen(FileWAM,
"r");
236 fsetpos(fich, &filepos);
238 fscanf(fich,
"%d ", &nvars);
239 for(
int i = 0; i < nvars; i++) {
240 fscanf(fich,
"%d ", &var);
243 FResMediosSensor.Output =
true;
246 FResMediosSensor.Input =
true;
249 std::cout <<
"Resultados medios en Controlador " << FNumeroSensor <<
" no implementados " << std::endl;
253 fgetpos(fich, &filepos);
255 }
catch(exception & N) {
256 std::cout <<
"ERROR: TPIDController::LeeResultadosMedSensor en el controlador " << FNumeroSensor << std::endl;
257 std::cout <<
"Tipo de error: " << N.what() << std::endl;
264 int nvars = 0, var = 0;
266 FILE *fich = fopen(FileWAM,
"r");
267 fsetpos(fich, &filepos);
269 fscanf(fich,
"%d ", &nvars);
270 for(
int i = 0; i < nvars; i++) {
271 fscanf(fich,
"%d ", &var);
274 FResInstantSensor.Output =
true;
277 FResInstantSensor.Input =
true;
280 std::cout <<
"Resultados instantaneos en Sensor " << FNumeroSensor <<
" no implementados " << std::endl;
284 fgetpos(fich, &filepos);
286 }
catch(exception & N) {
287 std::cout <<
"ERROR: TPIDController::LeeResultadosInsSensor en el Sensor " << FNumeroSensor << std::endl;
288 std::cout <<
"Tipo de error: " << N.what() << std::endl;
297 if(FResMediosSensor.Output) {
298 Label =
"\t" +
PutLabel(707) + std::to_string(FNumeroSensor) +
PutLabel(901);
299 medoutput << Label.c_str();
301 if(FResMediosSensor.Input) {
302 Label =
"\t" +
PutLabel(708) + std::to_string(FNumeroSensor) +
PutLabel(901);
303 medoutput << Label.c_str();
306 }
catch(exception & N) {
307 std::cout <<
"ERROR: TPIDController::CabeceraResultadosMedSensor en el Sensor " << FNumeroSensor << std::endl;
308 std::cout <<
"Tipo de error: " << N.what() << std::endl;
317 if(FResInstantSensor.Output) {
318 Label =
"\t" +
PutLabel(707) + std::to_string(FNumeroSensor) +
PutLabel(901);
319 insoutput << Label.c_str();
321 if(FResInstantSensor.Input) {
322 Label =
"\t" +
PutLabel(708) + std::to_string(FNumeroSensor) +
PutLabel(901);
323 insoutput << Label.c_str();
325 }
catch(exception & N) {
326 std::cout <<
"ERROR: TPIDController::CabeceraResultadosInsSensor en el Sensor " << FNumeroSensor << std::endl;
327 std::cout <<
"Tipo de error: " << N.what() << std::endl;
336 if(FResMediosSensor.Output) {
337 medoutput <<
"\t" << FResMediosSensor.OutputMED;
339 if(FResMediosSensor.Input) {
340 medoutput <<
"\t" << FResMediosSensor.InputMED;
343 }
catch(exception & N) {
344 std::cout <<
"ERROR: TPIDController::ImprimeResultadosMedSensor en el Sensor " << FNumeroSensor << std::endl;
345 std::cout <<
"Tipo de error: " << N.what() << std::endl;
354 if(FResInstantSensor.Output) {
355 insoutput <<
"\t" << FResInstantSensor.OutputINS;
357 if(FResInstantSensor.Input) {
358 insoutput <<
"\t" << FResInstantSensor.InputINS;
360 }
catch(exception & N) {
361 std::cout <<
"ERROR: TPIDController::CabeceraResultadosInsSensor en el Sensor " << FNumeroSensor << std::endl;
362 std::cout <<
"Tipo de error: " << N.what() << std::endl;
370 FResMediosSensor.OutputSUM = 0.;
371 FResMediosSensor.InputSUM = 0.;
372 FResMediosSensor.TiempoSUM = 0.;
373 FResMediosSensor.Tiempo0 = 0.;
375 }
catch(exception & N) {
376 std::cout <<
"ERROR: TPIDController::IniciaMedias en el Sensor: " << FNumeroSensor << std::endl;
385 if(FResMediosSensor.Output) {
386 FResMediosSensor.OutputMED = FResMediosSensor.OutputSUM / FResMediosSensor.TiempoSUM;
387 FResMediosSensor.OutputSUM = 0.;
389 if(FResMediosSensor.Input) {
390 FResMediosSensor.InputMED = FResMediosSensor.InputSUM / FResMediosSensor.TiempoSUM;
391 FResMediosSensor.InputSUM = 0.;
393 FResMediosSensor.TiempoSUM = 0;
395 }
catch(exception & N) {
396 std::cout <<
"ERROR: TPIDController::ResultadosMediosSensor en el eje: " << FNumeroSensor << std::endl;
406 double Delta = Actual - FResMediosSensor.Tiempo0;
408 if(FResMediosSensor.Output) {
409 FResMediosSensor.OutputSUM += FCurrentValue * Delta;
411 if(FResMediosSensor.Input) {
412 FResMediosSensor.InputSUM += FRealValue * Delta;
414 FResMediosSensor.TiempoSUM += Delta;
415 FResMediosSensor.Tiempo0 = Actual;
417 }
catch(exception & N) {
418 std::cout <<
"ERROR: TSensor::AcumulaResultadosMediosSensor en el eje: " << FNumeroSensor << std::endl;
426 if(FResInstantSensor.Output)
427 FResInstantSensor.OutputINS = FCurrentValue;
428 if(FResInstantSensor.Input)
429 FResInstantSensor.InputINS = FRealValue;
431 }
catch(exception & N) {
432 std::cout <<
"ERROR: TPIDController::ResultadosInstantSensor en el eje " << FNumeroSensor << std::endl;
433 std::cout <<
"Tipo de error: " << N.what() << std::endl;
443 #pragma package(smart_init)