MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
DiscreteControlARXProcess_Debug Class Reference

#include <discctrl.h>

Inheritance diagram for DiscreteControlARXProcess_Debug:
Collaboration diagram for DiscreteControlARXProcess_Debug:

Public Member Functions

 DiscreteControlARXProcess_Debug (integer iNumOut, integer iNumIn, integer iOrdA, integer iOrdB, const std::string &infile)
 
virtual ~DiscreteControlARXProcess_Debug (void)
 
void GetInput (std::vector< doublereal > &dIn)
 
void PutOutput (const std::vector< doublereal > &dOut, const std::vector< doublereal > &dIn, const std::vector< doublereal > &dDesiredOut)
 
- Public Member Functions inherited from DiscreteControlProcess
virtual ~DiscreteControlProcess (void)
 

Protected Member Functions

int ReadMatrix (std::istream &In, doublereal *pd, unsigned int iRows, unsigned int iCols, unsigned int iNumSubMats, const char *sMatName)
 

Protected Attributes

integer iNumOutputs
 
integer iNumInputs
 
integer iOrderA
 
integer iOrderB
 
doublerealpdA
 
doublerealpdY
 
doublerealpdB
 
doublerealpdU
 
doublerealpdU0
 
integer iRefA
 
integer iRefB
 
const std::string infile
 

Additional Inherited Members

- Public Types inherited from DiscreteControlProcess
enum  {
  DISCPROC_UNKNOWN = -1, DISCPROC_AR = 0x1U, DISCPROC_MA = 0x2U, DISCPROC_X = 0x4U,
  DISCPROC_ARX = (DISCPROC_AR | DISCPROC_X), DISCPROC_ARMA = (DISCPROC_AR | DISCPROC_MA), DISCPROC_ARMAX = (DISCPROC_AR | DISCPROC_MA | DISCPROC_X), DISCPROC_LAST
}
 

Detailed Description

Definition at line 131 of file discctrl.h.

Constructor & Destructor Documentation

DiscreteControlARXProcess_Debug::DiscreteControlARXProcess_Debug ( integer  iNumOut,
integer  iNumIn,
integer  iOrdA,
integer  iOrdB,
const std::string &  infile 
)

Definition at line 95 of file discctrl.cc.

References ASSERT, iNumInputs, iNumOutputs, iOrderA, iOrderB, MBDYN_EXCEPT_ARGS, pdA, pdB, pdU, pdU0, pdY, ReadMatrix(), and SAFENEWARR.

100 : iNumOutputs(iNumOut),
101 iNumInputs(iNumIn),
102 iOrderA(iOrdA),
103 iOrderB(iOrdB),
104 pdA(0),
105 pdY(0),
106 pdB(0),
107 pdU(0),
108 pdU0(0),
109 iRefA(0),
110 iRefB(0)
111 {
112  /* The control model is handled as follows:
113  * the outputs and inputs are stored in two vector:
114  * Y = [y(k-1), ..., y(k-pa)], U = [u(k-1), ..., u(k-pb)]
115  * as soon as new y, u are available, the oldes values are replaced by
116  * the newest and the vector is used as a queue, i.e. it starts from
117  * a floating reference and goes back to the beginning when it's
118  * over.
119  * Mathices alpha, beta are stacked in two big matrtices:
120  * A = [alpha_1, ..., alpha_pa], B = [beta_1, ..., beta_pb]
121  * the input is calculated as A*Y + B*U
122  */
123 
124  // At present at least one input and one output are required
125  ASSERT(iNumInputs > 0);
126  ASSERT(iNumOutputs > 0);
127  ASSERT(iOrderA > 0);
128  ASSERT(iOrderB > 0);
129 
130  // Size of working area
131  int iSize = iNumInputs*iNumOutputs*iOrderA // Matrix A
132  + iNumInputs*iNumInputs*iOrderB // Matrix B
133  + iNumOutputs*iOrderA // Vector Y
134  + iNumInputs*iOrderB // Vector U
135  + iNumInputs; // Vector u(k)
136 
137  doublereal *pd = 0;
138  SAFENEWARR(pd, doublereal, iSize);
139 
140  pdA = pd;
141  pd += iNumInputs*iNumOutputs*iOrderA;
142 
143  pdB = pd;
144  pd += iNumInputs*iNumInputs*iOrderB;
145 
146  pdY = pd;
147  pd += iNumOutputs*iOrderA;
148 
149  pdU = pd;
150  pd += iNumInputs*iOrderB;
151 
152  pdU0 = pd;
153 
154  for (int i = iSize; i-- > 0; ) {
155  pdA[i] = 0.;
156  }
157 
158  /* In the input file, for human readability matrices are written as:
159  * alpha_1,
160  * alpha_2,
161  * ...
162  * alpha_p,
163  * beta_1,
164  * ...
165  * beta_p
166  */
167 
168  std::ifstream In(infile.c_str());
169  if (!In) {
170  silent_cerr("DiscreteControlARXProcess_Debug: "
171  "unable to open control data file \"" << infile << "\""
172  << std::endl);
174  }
175 
176  ReadMatrix(In, pdA, iNumInputs, iNumOutputs, iOrderA, "alpha");
177  ReadMatrix(In, pdB, iNumInputs, iNumInputs, iOrderB, "beta");
178 }
const std::string infile
Definition: discctrl.h:145
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define ASSERT(expression)
Definition: colamd.c:977
int ReadMatrix(std::istream &In, doublereal *pd, unsigned int iRows, unsigned int iCols, unsigned int iNumSubMats, const char *sMatName)
Definition: discctrl.cc:56
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

DiscreteControlARXProcess_Debug::~DiscreteControlARXProcess_Debug ( void  )
virtual

Definition at line 180 of file discctrl.cc.

References pdA, and SAFEDELETEARR.

181 {
182  /* It must be non-null;
183  * matrices and arrays come from one allocation only */
184  if (pdA != 0) {
186  }
187 }
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713

Member Function Documentation

void DiscreteControlARXProcess_Debug::GetInput ( std::vector< doublereal > &  dIn)
virtual

Implements DiscreteControlProcess.

Definition at line 190 of file discctrl.cc.

References iNumInputs, and pdU0.

191 {
192  for (int i = iNumInputs; i-- > 0; ) {
193  dIn[i] = pdU0[i];
194  }
195 }
void DiscreteControlARXProcess_Debug::PutOutput ( const std::vector< doublereal > &  dOut,
const std::vector< doublereal > &  dIn,
const std::vector< doublereal > &  dDesiredOut 
)
virtual

Implements DiscreteControlProcess.

Definition at line 198 of file discctrl.cc.

References iNumInputs, iNumOutputs, iOrderA, iOrderB, iRefA, iRefB, pdA, pdB, pdU, pdU0, and pdY.

201 {
202  /* At present dDesiredOutput is not used;
203  * it will be when the system is controlled
204  * and ID'd at the same time */
205 
206  // Moves reference backwards
207  if (iRefA == 0) {
208  iRefA = iOrderA;
209  }
210  iRefA--;
211 
212  doublereal* pdOff = pdY + iNumOutputs*iRefA;
213  for (int i = iNumOutputs; i-- > 0; ) {
214  pdOff[i] = dOut[i];
215  }
216 
217  // Moves reference backwards
218  if (iRefB == 0) {
219  iRefB = iOrderB;
220  }
221  iRefB--;
222 
223  pdOff = pdU + iNumInputs*iRefB;
224  for (int i = iNumInputs; i-- > 0; ) {
225  /* dIn contiene la somma dell'ingresso esogeno e dell'ingresso
226  * di controllo, ovvero l'ingresso totale applicato al sistema;
227  * pdU0 contiene il solo ingresso generato dal controllore */
228  pdOff[i] = dIn[i];
229  pdU0[i] = 0.;
230  }
231 
232  // Matrices are row-oriented
234  // Y shiftato di iRefA
235  doublereal* pdVecOff = pdY + iRefA*iNumOutputs;
236  for (int i = iNumInputs; i-- > 0; ) {
237  for (int j = iRefA*iNumOutputs; j-- > 0; ) {
238  pdMatOff--;
239  pdU0[i] += pdMatOff[0]*pdY[j];
240  }
241  for (int j = (iOrderA-iRefA)*iNumOutputs; j-- > 0; ) {
242  pdMatOff--;
243  pdU0[i] += pdMatOff[0]*pdVecOff[j];
244  }
245  }
246 
247  pdMatOff = pdB + iOrderB*iNumInputs*iNumInputs;
248  pdVecOff = pdU + iRefB*iNumInputs;
249  for (int i = iNumInputs; i-- > 0; ) {
250  for (int j = iRefB*iNumInputs; j-- > 0; ) {
251  pdMatOff--;
252  pdU0[i] += pdMatOff[0]*pdU[j];
253  }
254  for (int j = (iOrderB-iRefB)*iNumInputs; j-- > 0; ) {
255  pdMatOff--;
256  pdU0[i] += pdMatOff[0]*pdVecOff[j];
257  }
258  }
259 }
double doublereal
Definition: colamd.c:52
int DiscreteControlARXProcess_Debug::ReadMatrix ( std::istream &  In,
doublereal pd,
unsigned int  iRows,
unsigned int  iCols,
unsigned int  iNumSubMats,
const char *  sMatName 
)
protected

Definition at line 56 of file discctrl.cc.

References DEBUGLCOUT, MBDYN_EXCEPT_ARGS, and MYDEBUG_INIT.

Referenced by DiscreteControlARXProcess_Debug().

62 {
63  // Matrices alpha_i
64 
65  // for every k + 1 = 1->p (every matrix)
66  for (unsigned int k = 0; k < iNumSubMats; k++) {
67  int iShift = iNumCols*k;
68 
69  // for every row
70  for (unsigned int i = 0; i < iNumRows; i++) {
71  doublereal* pdTmp = pd + iShift + iNumSubMats*iNumCols*i;
72 
73  // for every column
74  for (unsigned int j = 0; j < iNumCols; j++) {
75  In >> pdTmp[j];
76  if (!In) {
77  silent_cerr("Error: unexpected end of stream while reading "
78  << sMatName << '_' << k + 1
79  << '(' << i + 1 << ',' << j + 1 << ')'
80  << std::endl);
81 
83  }
84 
85  DEBUGLCOUT(MYDEBUG_INIT, sMatName << '_' << k + 1
86  << "(" << i << "," << j << ") = " << pdTmp[j]
87  << std::endl);
88  }
89  }
90  }
91 
92  return 0;
93 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
double doublereal
Definition: colamd.c:52
#define DEBUGLCOUT(level, msg)
Definition: myassert.h:244

Member Data Documentation

const std::string DiscreteControlARXProcess_Debug::infile
protected

Definition at line 145 of file discctrl.h.

integer DiscreteControlARXProcess_Debug::iNumInputs
protected

Definition at line 134 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), GetInput(), and PutOutput().

integer DiscreteControlARXProcess_Debug::iNumOutputs
protected

Definition at line 133 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().

integer DiscreteControlARXProcess_Debug::iOrderA
protected

Definition at line 135 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().

integer DiscreteControlARXProcess_Debug::iOrderB
protected

Definition at line 136 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().

integer DiscreteControlARXProcess_Debug::iRefA
protected

Definition at line 142 of file discctrl.h.

Referenced by PutOutput().

integer DiscreteControlARXProcess_Debug::iRefB
protected

Definition at line 143 of file discctrl.h.

Referenced by PutOutput().

doublereal* DiscreteControlARXProcess_Debug::pdA
protected
doublereal* DiscreteControlARXProcess_Debug::pdB
protected

Definition at line 139 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().

doublereal* DiscreteControlARXProcess_Debug::pdU
protected

Definition at line 140 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().

doublereal* DiscreteControlARXProcess_Debug::pdU0
protected

Definition at line 141 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), GetInput(), and PutOutput().

doublereal* DiscreteControlARXProcess_Debug::pdY
protected

Definition at line 138 of file discctrl.h.

Referenced by DiscreteControlARXProcess_Debug(), and PutOutput().


The documentation for this class was generated from the following files: