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

#include <TTable1D.h>

Inheritance diagram for TTable1D:
[legend]
Collaboration diagram for TTable1D:
[legend]

Public Member Functions

 TTable1D (int i)
 
 ~TTable1D ()
 
double Output (double Time)
 
void LeeController (const char *FileWAM, fpos_t &filepos)
 
void AsignaObjetos (TSensor **Sensor, TController **Controller)
 
void LeeResultadosMedControlador (const char *FileWAM, fpos_t &filepos)
 
void LeeResultadosInsControlador (const char *FileWAM, fpos_t &filepos)
 
void CabeceraResultadosMedControlador (stringstream &medoutput)
 
void CabeceraResultadosInsControlador (stringstream &insoutput)
 
void ImprimeResultadosMedControlador (stringstream &medoutput)
 
void ImprimeResultadosInsControlador (stringstream &insoutput)
 
void IniciaMedias ()
 
void ResultadosMediosController ()
 
void AcumulaResultadosMediosController (double Actual)
 
void ResultadosInstantController ()
 
- Public Member Functions inherited from TController
 TController (nmControlMethod meth, int i)
 
 ~TController ()
 

Additional Inherited Members

- Protected Attributes inherited from TController
std::vector< TSensor * > FSensor
 Array with the pointers of the sensor inputs.
 
int FNumSensors
 Number of sensor input.
 
iVector FSensorID
 Array with the ID of the sensor inputs.
 
int FControllerID
 ID of this controller.
 
nmControlMethod FControl
 Type of controller.
 
stResMediosCtrl FResMediosCtrl
 Struct with the average results of the controllers.
 
stResInstantCtrl FResInstantCtrl
 Struct with the average results of the controllers.
 

Detailed Description

This object is use to generate one-dimensional map to simulate ECU maps

Definition at line 37 of file TTable1D.h.

Constructor & Destructor Documentation

◆ TTable1D()

TTable1D::TTable1D ( int  i)

One dimensional table constructor

Parameters
iIndex

Definition at line 35 of file TTable1D.cpp.

35  :
36  TController(nmCtlTable, i) {
37  fID = i + 1;
38  /* fError_ant=0;
39  fTime_ant=0;
40  fInicio=true; */
41 
42  fDimensiones = 1;
43  fDatos = NULL;
44 }

◆ ~TTable1D()

TTable1D::~TTable1D ( )

One dimensional table destructor

Definition at line 46 of file TTable1D.cpp.

46  {
47  delete fDatos;
48 }

Member Function Documentation

◆ AcumulaResultadosMediosController()

void TTable1D::AcumulaResultadosMediosController ( double  Actual)
virtual

Acumulate the average results

Parameters
ActualCurrent time

Implements TController.

Definition at line 282 of file TTable1D.cpp.

282  {
283  try {
284  /* Lo que se hace en esta funcion se realiza dentro del calculo del eje, para asi poder
285  llevar a cabo la salida de resultados medios por pantalla. */
286  double Delta = Actual - FResMediosCtrl.Tiempo0;
287 
288  if(FResMediosCtrl.Output) {
289  FResMediosCtrl.OutputSUM += fOutput * Delta;
290  }
291 
292  FResMediosCtrl.TiempoSUM += Delta;
293  FResMediosCtrl.Tiempo0 = Actual;
294 
295  } catch(exception & N) {
296  std::cout << "ERROR: TTable::AcumulaResultadosMediosController en el eje: " << fID << std::endl;
297  // std::cout << "Tipo de error: " << N.what() << std::endl;
298  throw Exception(N.what());
299  }
300 }

References TController::FResMediosCtrl.

Here is the caller graph for this function:

◆ AsignaObjetos()

void TTable1D::AsignaObjetos ( TSensor **  Sensor,
TController **  Controller 
)
virtual

Asign the controllers and the sensors

Parameters
SensorArray with sensors
ControllerArray with controllers

Implements TController.

Definition at line 123 of file TTable1D.cpp.

123  {
124 
125  FSensor.push_back(Sensor[FSensorID[0] - 1]);
126 
127  // fSetPointController=Controller[fSetPointControllerID-1];
128 
129 }

References TController::FSensor, and TController::FSensorID.

◆ CabeceraResultadosInsControlador()

void TTable1D::CabeceraResultadosInsControlador ( stringstream &  insoutput)
virtual

Generate the header of the instantaneus results for the controller

Parameters
insoutputStringStream where the instantaneous results are stored

Implements TController.

Definition at line 203 of file TTable1D.cpp.

203  {
204  try {
205  std::string Label;
206 
207  if(FResInstantCtrl.Output) {
208  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
209  insoutput << Label.c_str();
210  }
211 
212  } catch(exception & N) {
213  std::cout << "ERROR: TTable::CabeceraResultadosInsControlador en el controlador " << fID << std::endl;
214  std::cout << "Tipo de error: " << N.what() << std::endl;
215  throw Exception(N.what());
216  }
217 }

References TController::FResInstantCtrl, and PutLabel().

Here is the call graph for this function:

◆ CabeceraResultadosMedControlador()

void TTable1D::CabeceraResultadosMedControlador ( stringstream &  medoutput)
virtual

Generate the header of the average results for the controller

Parameters
medoutputStringStream where the average results are stored

Implements TController.

Definition at line 187 of file TTable1D.cpp.

187  {
188  try {
189  std::string Label;
190 
191  if(FResMediosCtrl.Output) {
192  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
193  medoutput << Label.c_str();
194  }
195 
196  } catch(exception & N) {
197  std::cout << "ERROR: TTable::CabeceraResultadosMedControlador en el controlador " << fID << std::endl;
198  std::cout << "Tipo de error: " << N.what() << std::endl;
199  throw Exception(N.what());
200  }
201 }

References TController::FResMediosCtrl, and PutLabel().

Here is the call graph for this function:

◆ ImprimeResultadosInsControlador()

void TTable1D::ImprimeResultadosInsControlador ( stringstream &  insoutput)
virtual

Print the instantaneous results

Parameters
insoutputStringStream where the average results are stored

Implements TController.

Definition at line 234 of file TTable1D.cpp.

234  {
235  try {
236  std::string Label;
237 
238  if(FResInstantCtrl.Output) {
239  insoutput << "\t" << FResInstantCtrl.OutputINS;
240  }
241 
242  } catch(exception & N) {
243  std::cout << "ERROR: TTable::CabeceraResultadosInsControlador en el controlador " << fID << std::endl;
244  std::cout << "Tipo de error: " << N.what() << std::endl;
245  throw Exception(N.what());
246  }
247 }

References TController::FResInstantCtrl.

◆ ImprimeResultadosMedControlador()

void TTable1D::ImprimeResultadosMedControlador ( stringstream &  medoutput)
virtual

Print the average results

Parameters
medoutputStringStream where the average results are stored

Implements TController.

Definition at line 219 of file TTable1D.cpp.

219  {
220  try {
221  std::string Label;
222 
223  if(FResMediosCtrl.Output) {
224  medoutput << "\t" << FResMediosCtrl.OutputMED;
225  }
226 
227  } catch(exception & N) {
228  std::cout << "ERROR: TTable::ImprimeResultadosMedControlador en el controlador " << fID << std::endl;
229  std::cout << "Tipo de error: " << N.what() << std::endl;
230  throw Exception(N.what());
231  }
232 }

References TController::FResMediosCtrl.

◆ IniciaMedias()

void TTable1D::IniciaMedias ( )
virtual

Initialize average results

Implements TController.

Definition at line 249 of file TTable1D.cpp.

249  {
250  try {
251 
252  FResMediosCtrl.OutputSUM = 0.;
253  FResMediosCtrl.TiempoSUM = 0.;
254  FResMediosCtrl.Tiempo0 = 0.;
255 
256  } catch(exception & N) {
257  std::cout << "ERROR: TTable::IniciaMedias en el controlador: " << fID << std::endl;
258  // std::cout << "Tipo de error: " << N.what() << std::endl;
259  throw Exception(N.what());
260  }
261 }

References TController::FResMediosCtrl.

◆ LeeController()

void TTable1D::LeeController ( const char *  FileWAM,
fpos_t &  filepos 
)
virtual

Read data information of the controller

Parameters
FileWAMFilename of the input data file
fileposPosition within the input data file to read

Implements TController.

Definition at line 61 of file TTable1D.cpp.

61  {
62 
63  int xnum = 0, tip = 0, fromfile = 0;
64 
65  FILE *fich = fopen(FileWAM, "r");
66  fsetpos(fich, &filepos);
67 
68  fscanf(fich, "%d ", &fromfile);
69 
70  if(fromfile == 1) {
71  char *InputFile;
72  fscanf(fich, "%s ", &InputFile);
73 
74  FILE *fichdata = fopen(InputFile, "r");
75 
76  double X_tmp = 0., Y_tmp = 0.;
77  dVector X_vec, Y_vec;
78  while(!feof(fichdata)) {
79  fscanf(fichdata, "%lf %lf ", &X_tmp, &Y_tmp);
80  X_vec.push_back(X_tmp);
81  Y_vec.push_back(Y_tmp);
82  }
83  fX_map = X_vec;
84  fY_map = Y_vec;
85  } else if(fromfile == 0) {
86  // fscanf(fich,"%d ",&fDimensiones);
87  fscanf(fich, "%d ", &xnum);
88  fX_map.resize(xnum);
89  fY_map.resize(xnum);
90  for(int i = 0; i < xnum; i++) {
91  fscanf(fich, "%lf %lf ", &fX_map[i], &fY_map[i]);
92  }
93  } else {
94 
95  }
96 
97  fscanf(fich, "%lf ", &fPeriod);
98 
99  fscanf(fich, "%d ", &tip);
100  switch(tip) {
101  case 0:
102  fTipo = nmLineal;
103  fDatos = new Linear_interp(fX_map, fY_map);
104  break;
105  case 1:
106  fTipo = nmHermite;
107  fDatos = new Hermite_interp(fX_map, fY_map);
108  break;
109  case 2:
110  fTipo = nmSteps;
111  fDatos = new Step_interp(fX_map, fY_map);
112  break;
113  }
114 
115  FSensorID.resize(1);
116  fscanf(fich, "%d ", &FSensorID[0]);
117 
118  fgetpos(fich, &filepos);
119  fclose(fich);
120 
121 }

References TController::FSensorID.

◆ LeeResultadosInsControlador()

void TTable1D::LeeResultadosInsControlador ( const char *  FileWAM,
fpos_t &  filepos 
)
virtual

Read the instantaneous results selected for the controller

Parameters
FileWAMFilename of the input data file
fileposPositon within the input data file to read

Implements TController.

Definition at line 159 of file TTable1D.cpp.

159  {
160  try {
161  int nvars = 0, var = 0;
162 
163  FILE *fich = fopen(FileWAM, "r");
164  fsetpos(fich, &filepos);
165 
166  fscanf(fich, "%d ", &nvars);
167  for(int i = 0; i < nvars; i++) {
168  fscanf(fich, "%d ", &var);
169  switch(var) {
170  case 0:
171  FResInstantCtrl.Output = true;
172  break;
173  default:
174  std::cout << "Resultados instantaneos en Controlador " << fID << " no implementados " << std::endl;
175  }
176  }
177 
178  fgetpos(fich, &filepos);
179  fclose(fich);
180  } catch(exception & N) {
181  std::cout << "ERROR: TTable::LeeResultadosInsControlador en el controlador " << fID << std::endl;
182  std::cout << "Tipo de error: " << N.what() << std::endl;
183  throw Exception(N.what());
184  }
185 }

References TController::FResInstantCtrl.

◆ LeeResultadosMedControlador()

void TTable1D::LeeResultadosMedControlador ( const char *  FileWAM,
fpos_t &  filepos 
)
virtual

Read the average results selected for the controller

Parameters
FileWAMFilename of the input data file
fileposPosition within the input data file to read

Implements TController.

Definition at line 131 of file TTable1D.cpp.

131  {
132  try {
133  int nvars = 0, var = 0;
134 
135  FILE *fich = fopen(FileWAM, "r");
136  fsetpos(fich, &filepos);
137 
138  fscanf(fich, "%d ", &nvars);
139  for(int i = 0; i < nvars; i++) {
140  fscanf(fich, "%d ", &var);
141  switch(var) {
142  case 0:
143  FResMediosCtrl.Output = true;
144  break;
145  default:
146  std::cout << "Resultados medios en Controlador " << fID << " no implementados " << std::endl;
147  }
148  }
149 
150  fgetpos(fich, &filepos);
151  fclose(fich);
152  } catch(exception & N) {
153  std::cout << "ERROR: TTable::LeeResultadosControlador en el controlador " << fID << std::endl;
154  std::cout << "Tipo de error: " << N.what() << std::endl;
155  throw Exception(N.what());
156  }
157 }

References TController::FResMediosCtrl.

◆ Output()

double TTable1D::Output ( double  Time)
virtual

Return the output of this controller

Parameters
TimeCurrent time

Implements TController.

Definition at line 50 of file TTable1D.cpp.

50  {
51 
52  double X = FSensor[0]->Output();
53 
54  fOutput = fDatos->interp(X);
55 
57 
58  return fOutput;
59 }

References AcumulaResultadosMediosController(), and TController::FSensor.

Here is the call graph for this function:

◆ ResultadosInstantController()

void TTable1D::ResultadosInstantController ( )
virtual

Calculate the instantaneous results

Implements TController.

Definition at line 302 of file TTable1D.cpp.

302  {
303  try {
304  if(FResInstantCtrl.Output)
305  FResInstantCtrl.OutputINS = fOutput;
306 
307  } catch(exception & N) {
308  std::cout << "ERROR: TTable::ResultadosInstantController en el eje " << fID << std::endl;
309  std::cout << "Tipo de error: " << N.what() << std::endl;
310  throw Exception(N.what());
311  }
312 }

References TController::FResInstantCtrl.

◆ ResultadosMediosController()

void TTable1D::ResultadosMediosController ( )
virtual

Calculate average Results

Implements TController.

Definition at line 263 of file TTable1D.cpp.

263  {
264  try {
265 
266  if(FResMediosCtrl.Output && FResMediosCtrl.TiempoSUM > 0) {
267  FResMediosCtrl.OutputMED = FResMediosCtrl.OutputSUM / FResMediosCtrl.TiempoSUM;
268  FResMediosCtrl.OutputSUM = 0.;
269  } else {
270  FResMediosCtrl.OutputMED = 0.;
271  }
272 
273  FResMediosCtrl.TiempoSUM = 0;
274 
275  } catch(exception & N) {
276  std::cout << "ERROR: TTable::ResultadosMediosController en el eje: " << fID << std::endl;
277  // std::cout << "Tipo de error: " << N.what() << std::endl;
278  throw Exception(N.what());
279  }
280 }

References TController::FResMediosCtrl.


The documentation for this class was generated from the following files:
Step_interp
Definition: Math_wam.h:325
TController::TController
TController(nmControlMethod meth, int i)
Definition: TController.cpp:38
TTable1D::AcumulaResultadosMediosController
void AcumulaResultadosMediosController(double Actual)
Definition: TTable1D.cpp:282
Hermite_interp
Definition: Math_wam.h:311
TController::FSensorID
iVector FSensorID
Array with the ID of the sensor inputs.
Definition: TController.h:43
TController::FResMediosCtrl
stResMediosCtrl FResMediosCtrl
Struct with the average results of the controllers.
Definition: TController.h:49
Linear_interp
Definition: Math_wam.h:301
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39
TController::FResInstantCtrl
stResInstantCtrl FResInstantCtrl
Struct with the average results of the controllers.
Definition: TController.h:50
dVector
std::vector< double > dVector
Double vector.
Definition: Math_wam.h:70
TController::FSensor
std::vector< TSensor * > FSensor
Array with the pointers of the sensor inputs.
Definition: TController.h:40