OpenWAM
Public Member Functions | List of all members
TSensor Class Reference

#include <TSensor.h>

Public Member Functions

 TSensor (int i)
 
 ~TSensor ()
 
void ReadSensor (const char *FileWAM, fpos_t &filepos)
 
void AsignaObjeto (TObject *Object)
 
double Output ()
 
void ActualizaMedida (double Time)
 
nmObjectSensed ObjectSensed ()
 
int ObjectID ()
 
void LeeResultadosMedSensor (const char *FileWAM, fpos_t &filepos)
 
void LeeResultadosInsSensor (const char *FileWAM, fpos_t &filepos)
 
void CabeceraResultadosMedSensor (std::stringstream &medoutput)
 
void CabeceraResultadosInsSensor (std::stringstream &insoutput)
 
void ImprimeResultadosMedSensor (std::stringstream &medoutput)
 
void ImprimeResultadosInsSensor (std::stringstream &insoutput)
 
void IniciaMedias ()
 
void ResultadosMediosSensor ()
 
void AcumulaResultadosMediosSensor (double Actual)
 
void ResultadosInstantSensor ()
 

Detailed Description

This object is used to get information from some objects and provides it to controllers

Definition at line 42 of file TSensor.h.

Constructor & Destructor Documentation

◆ TSensor()

TSensor::TSensor ( int  i)

Contructor of the class TSensor

Parameters
iIndex of the sensor

Definition at line 38 of file TSensor.cpp.

38  {
39  FNumeroSensor = i;
40  FInicia = false;
41  FPeriod = 0.;
42  FTime0 = 0.;
43 }

◆ ~TSensor()

TSensor::~TSensor ( )

Destructor of the class TSensor

Definition at line 45 of file TSensor.cpp.

45  {
46 
47 }

Member Function Documentation

◆ ActualizaMedida()

void TSensor::ActualizaMedida ( double  Time)

Update the sensor output value

Parameters
TimeCurrent tiem

Definition at line 142 of file TSensor.cpp.

142  {
143  double tmp0 = 0., tmp1 = 0.;
144  bool Update = false;
145  double deltaT = 0.;
146 
147  double TimeStep = Time - FTime0;
148 
149  FPeriod = FPeriod + TimeStep;
150 
151  if(FPeriod >= 0.001) {
152  Update = true;
153  deltaT = FPeriod;
154  FPeriod = 0;
155  }
156 
157  if(Update || !FInicia) {
158  switch(FObjectSensed) {
159  case nmSensEjec:
160  switch(FParameterSensed) {
161  case nmTime:
162  FRealValue = Time;
163  break;
164  }
165  FCurrentValue = FRealValue;
166  break;
167  case nmSensTubo:
168  switch(FParameterSensed) {
169  case nmPressure:
170  FRealValue = ((TTubo*) FObjectPointer)->GetPresion(FNode0) * (1 - FDelta) + ((TTubo*) FObjectPointer)->GetPresion(
171  FNode1) * FDelta;
172  break;
173  case nmTemperature:
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;
179  break;
180  case nmMassFlow:
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;
186  break;
187  }
188  break;
189  case nmSensDeposito:
190  switch(FParameterSensed) {
191  case nmPressure:
192  FRealValue = ((TDeposito*) FObjectPointer)->getPressure();
193  break;
194  case nmTemperature:
195  FRealValue = ((TDeposito*) FObjectPointer)->getTemperature();
196  break;
197  }
198  break;
199  case nmSensMotor:
200  switch(FParameterSensed) {
201  case nmFuel:
202  FRealValue = ((TBloqueMotor*) FObjectPointer)->getMasaFuel();
203  break;
204  case nmEngSpeed:
205  FRealValue = ((TBloqueMotor*) FObjectPointer)->getRegimen();
206  break;
207  }
208  }
209  }
210 
211  if(!FInicia) {
212  FPrevValue = FRealValue;
213  FInicia = true;
214  }
215  if(!Update) {
216  FCurrentValue = FPrevValue;
217  } else {
218  FCurrentValue = ((2 * FDelay - deltaT) * FPrevValue + deltaT * FGain * (FRealValue + FPrevRealValue)) /
219  (2 * FDelay + deltaT);
220  }
221  FPrevValue = FCurrentValue;
222  FPrevRealValue = FRealValue;
223  FTime0 = Time;
224 
226 
227  // out=FCurrentValue;
228  // return out;
229 }

References pow2().

Here is the call graph for this function:

◆ AcumulaResultadosMediosSensor()

void TSensor::AcumulaResultadosMediosSensor ( double  Actual)

Acumulate the average results

Parameters
ActualCurrent time

Definition at line 402 of file TSensor.cpp.

402  {
403  try {
404  /* Lo que se hace en esta funcion se realiza dentro del calculo del eje, para asi poder
405  llevar a cabo la salida de resultados medios por pantalla. */
406  double Delta = Actual - FResMediosSensor.Tiempo0;
407 
408  if(FResMediosSensor.Output) {
409  FResMediosSensor.OutputSUM += FCurrentValue * Delta;
410  }
411  if(FResMediosSensor.Input) {
412  FResMediosSensor.InputSUM += FRealValue * Delta;
413  }
414  FResMediosSensor.TiempoSUM += Delta;
415  FResMediosSensor.Tiempo0 = Actual;
416 
417  } catch(exception & N) {
418  std::cout << "ERROR: TSensor::AcumulaResultadosMediosSensor en el eje: " << FNumeroSensor << std::endl;
419  // std::cout << "Tipo de error: " << N.what() << std::endl;
420  throw Exception(N.what());
421  }
422 }

◆ AsignaObjeto()

void TSensor::AsignaObjeto ( TObject Object)

Asign the pointer of the object sensed

Parameters
ObjectPointer to the object sensed

Definition at line 125 of file TSensor.cpp.

125  {
126  int nin = 0;
127  double tmp = 0.;
128 
129  FObjectPointer = Object;
130  if(FObjectSensed == nmSensTubo) {
131  tmp = (double)(((TTubo*) FObjectPointer)->getNin() - 1) * FDistancia / ((TTubo*) FObjectPointer)->getLongitudTotal();
132  FNode0 = floor(tmp);
133  FNode1 = ceil(tmp);
134  FDelta = (FDistancia - (double) FNode0 * ((TTubo*) FObjectPointer)->getXRef()) / ((TTubo*) FObjectPointer)->getXRef();
135  }
136 }

◆ CabeceraResultadosInsSensor()

void TSensor::CabeceraResultadosInsSensor ( std::stringstream &  insoutput)

Generate the header of the instantaneous results

Parameters
insoutputStringStream where the instantaneous results are stored

Definition at line 313 of file TSensor.cpp.

313  {
314  try {
315  std::string Label;
316 
317  if(FResInstantSensor.Output) {
318  Label = "\t" + PutLabel(707) + std::to_string(FNumeroSensor) + PutLabel(901);
319  insoutput << Label.c_str();
320  }
321  if(FResInstantSensor.Input) {
322  Label = "\t" + PutLabel(708) + std::to_string(FNumeroSensor) + PutLabel(901);
323  insoutput << Label.c_str();
324  }
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;
328  throw Exception(N.what());
329  }
330 }

References PutLabel().

Here is the call graph for this function:

◆ CabeceraResultadosMedSensor()

void TSensor::CabeceraResultadosMedSensor ( std::stringstream &  medoutput)

Generate the header of the average results

Parameters
medoutputStringStream where the average results are stored

Definition at line 293 of file TSensor.cpp.

293  {
294  try {
295  std::string Label;
296 
297  if(FResMediosSensor.Output) {
298  Label = "\t" + PutLabel(707) + std::to_string(FNumeroSensor) + PutLabel(901);
299  medoutput << Label.c_str();
300  }
301  if(FResMediosSensor.Input) {
302  Label = "\t" + PutLabel(708) + std::to_string(FNumeroSensor) + PutLabel(901);
303  medoutput << Label.c_str();
304  }
305 
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;
309  throw Exception(N.what());
310  }
311 }

References PutLabel().

Here is the call graph for this function:

◆ ImprimeResultadosInsSensor()

void TSensor::ImprimeResultadosInsSensor ( std::stringstream &  insoutput)

Print the instantaneous results of the sensor

Parameters
insoutputStringStream where the instantaneous results are stored

Definition at line 350 of file TSensor.cpp.

350  {
351  try {
352  std::string Label;
353 
354  if(FResInstantSensor.Output) {
355  insoutput << "\t" << FResInstantSensor.OutputINS;
356  }
357  if(FResInstantSensor.Input) {
358  insoutput << "\t" << FResInstantSensor.InputINS;
359  }
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;
363  throw Exception(N.what());
364  }
365 }

◆ ImprimeResultadosMedSensor()

void TSensor::ImprimeResultadosMedSensor ( std::stringstream &  medoutput)

Print the average results of the sensor

Parameters
medoutputStringStream where the average results are stored

Definition at line 332 of file TSensor.cpp.

332  {
333  try {
334  std::string Label;
335 
336  if(FResMediosSensor.Output) {
337  medoutput << "\t" << FResMediosSensor.OutputMED;
338  }
339  if(FResMediosSensor.Input) {
340  medoutput << "\t" << FResMediosSensor.InputMED;
341  }
342 
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;
346  throw Exception(N.what());
347  }
348 }

◆ IniciaMedias()

void TSensor::IniciaMedias ( )

Initailize the average results

Definition at line 367 of file TSensor.cpp.

367  {
368  try {
369 
370  FResMediosSensor.OutputSUM = 0.;
371  FResMediosSensor.InputSUM = 0.;
372  FResMediosSensor.TiempoSUM = 0.;
373  FResMediosSensor.Tiempo0 = 0.;
374 
375  } catch(exception & N) {
376  std::cout << "ERROR: TPIDController::IniciaMedias en el Sensor: " << FNumeroSensor << std::endl;
377  // std::cout << "Tipo de error: " << N.what() << std::endl;
378  throw Exception(N.what());
379  }
380 }

◆ LeeResultadosInsSensor()

void TSensor::LeeResultadosInsSensor ( const char *  FileWAM,
fpos_t &  filepos 
)

Read de instantaneous results selected for the sensor

Parameters
FileWAMFilename of the input data
fileposSpecify a position within the input file.

Definition at line 262 of file TSensor.cpp.

262  {
263  try {
264  int nvars = 0, var = 0;
265 
266  FILE *fich = fopen(FileWAM, "r");
267  fsetpos(fich, &filepos);
268 
269  fscanf(fich, "%d ", &nvars);
270  for(int i = 0; i < nvars; i++) {
271  fscanf(fich, "%d ", &var);
272  switch(var) {
273  case 0:
274  FResInstantSensor.Output = true;
275  break;
276  case 1:
277  FResInstantSensor.Input = true;
278  break;
279  default:
280  std::cout << "Resultados instantaneos en Sensor " << FNumeroSensor << " no implementados " << std::endl;
281  }
282  }
283 
284  fgetpos(fich, &filepos);
285  fclose(fich);
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;
289  throw Exception(N.what());
290  }
291 }

◆ LeeResultadosMedSensor()

void TSensor::LeeResultadosMedSensor ( const char *  FileWAM,
fpos_t &  filepos 
)

Read the average results selected for the sensor

Parameters
FileWAMFilename of the input data
fileposSpecify a position within the input file.

Definition at line 231 of file TSensor.cpp.

231  {
232  try {
233  int nvars = 0, var = 0;
234 
235  FILE *fich = fopen(FileWAM, "r");
236  fsetpos(fich, &filepos);
237 
238  fscanf(fich, "%d ", &nvars);
239  for(int i = 0; i < nvars; i++) {
240  fscanf(fich, "%d ", &var);
241  switch(var) {
242  case 0:
243  FResMediosSensor.Output = true;
244  break;
245  case 1:
246  FResMediosSensor.Input = true;
247  break;
248  default:
249  std::cout << "Resultados medios en Controlador " << FNumeroSensor << " no implementados " << std::endl;
250  }
251  }
252 
253  fgetpos(fich, &filepos);
254  fclose(fich);
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;
258  throw Exception(N.what());
259  }
260 }

◆ ObjectID()

int TSensor::ObjectID ( )

Return the ID numbero of the sensor

Definition at line 438 of file TSensor.cpp.

438  {
439  return FObjectID;
440 }

◆ ObjectSensed()

nmObjectSensed TSensor::ObjectSensed ( )
inline

Return the type of the object sensed

Definition at line 101 of file TSensor.h.

101  {
102  return FObjectSensed;
103  }

◆ Output()

double TSensor::Output ( )

Return the current value of the sensor output

Definition at line 138 of file TSensor.cpp.

138  {
139  return FCurrentValue;
140 }

◆ ReadSensor()

void TSensor::ReadSensor ( const char *  FileWAM,
fpos_t &  filepos 
)

Read from the input data the sensor information

Parameters
FileWAMFilename of the input data
fileposSpecify a position within the input file.

Definition at line 49 of file TSensor.cpp.

49  {
50  int obj = 0, prm = 0;
51 
52  FILE *fich = fopen(FileWAM, "r");
53  fsetpos(fich, &filepos);
54 
55  fscanf(fich, "%d %d", &obj, &prm);
56  if(obj != 0)
57  fscanf(fich, "%d ", &FObjectID);
58  switch(obj) {
59  case 0:
60  FObjectSensed = nmSensEjec;
61  switch(prm) {
62  case 0:
63  FParameterSensed = nmTime;
64  break;
65  default:
66  std::cout << "ERROR: Parametro " << prm << "en el objeto " << obj << "no valido, sensor: " << FNumeroSensor <<
67  std::endl;
68  }
69  break;
70  case 1:
71  FObjectSensed = nmSensTubo;
72  fscanf(fich, "%lf ", &FDistancia);
73  switch(prm) {
74  case 1:
75  FParameterSensed = nmPressure;
76  break;
77  case 2:
78  FParameterSensed = nmTemperature;
79  break;
80  case 3:
81  FParameterSensed = nmMassFlow;
82  break;
83  default:
84  std::cout << "ERROR: Parametro " << prm << "en el objeto " << obj << "no valido, sensor: " << FNumeroSensor <<
85  std::endl;
86  }
87  break;
88  case 2:
89  FObjectSensed = nmSensDeposito;
90  switch(prm) {
91  case 1:
92  FParameterSensed = nmPressure;
93  break;
94  case 2:
95  FParameterSensed = nmTemperature;
96  break;
97  default:
98  std::cout << "ERROR: Parametro " << prm << "en el objeto " << obj << "no valido, sensor: " << FNumeroSensor <<
99  std::endl;
100  }
101  break;
102  case 3:
103  FObjectSensed = nmSensMotor;
104  switch(prm) {
105  case 4:
106  FParameterSensed = nmFuel;
107  break;
108  case 5:
109  FParameterSensed = nmEngSpeed;
110  break;
111  default:
112  std::cout << "ERROR: Parametro " << prm << "en el objeto " << obj << "no valido, sensor: " << FNumeroSensor <<
113  std::endl;
114  }
115  break;
116  default:
117  std::cout << "ERROR: Objeto " << obj << "no valido, sensor: " << FNumeroSensor << std::endl;
118  }
119  fscanf(fich, "%lf %lf ", &FDelay, &FGain);
120 
121  fgetpos(fich, &filepos);
122  fclose(fich);
123 }

◆ ResultadosInstantSensor()

void TSensor::ResultadosInstantSensor ( )

Calculate the instantaneous results

Definition at line 424 of file TSensor.cpp.

424  {
425  try {
426  if(FResInstantSensor.Output)
427  FResInstantSensor.OutputINS = FCurrentValue;
428  if(FResInstantSensor.Input)
429  FResInstantSensor.InputINS = FRealValue;
430 
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;
434  throw Exception(N.what());
435  }
436 }

◆ ResultadosMediosSensor()

void TSensor::ResultadosMediosSensor ( )

Calculate the average results

Definition at line 382 of file TSensor.cpp.

382  {
383  try {
384 
385  if(FResMediosSensor.Output) {
386  FResMediosSensor.OutputMED = FResMediosSensor.OutputSUM / FResMediosSensor.TiempoSUM;
387  FResMediosSensor.OutputSUM = 0.;
388  }
389  if(FResMediosSensor.Input) {
390  FResMediosSensor.InputMED = FResMediosSensor.InputSUM / FResMediosSensor.TiempoSUM;
391  FResMediosSensor.InputSUM = 0.;
392  }
393  FResMediosSensor.TiempoSUM = 0;
394 
395  } catch(exception & N) {
396  std::cout << "ERROR: TPIDController::ResultadosMediosSensor en el eje: " << FNumeroSensor << std::endl;
397  // std::cout << "Tipo de error: " << N.what() << std::endl;
398  throw Exception(N.what());
399  }
400 }

The documentation for this class was generated from the following files:
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TDeposito
Definition: TDeposito.h:44
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39
TBloqueMotor
Definition: TBloqueMotor.h:43
TSensor::AcumulaResultadosMediosSensor
void AcumulaResultadosMediosSensor(double Actual)
Definition: TSensor.cpp:402
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88