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

#include <discctrl.h>

Inheritance diagram for DAC_Process_Debug:
Collaboration diagram for DAC_Process_Debug:

Public Member Functions

 DAC_Process_Debug (integer iNumOut, integer iNumIn, integer iOrdA, integer iOrdB, ForgettingFactor *pf, GPCDesigner *pd, PersistentExcitation *px, DriveCaller *PTrig, std::vector< DriveCaller * > &vDesOut, const std::string &sf, unsigned f_proc)
 
virtual ~DAC_Process_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 Attributes

integer iNumOutputs
 
integer iNumInputs
 
integer iOrderA
 
integer iOrderB
 
integer iOrderMd
 
doublerealpdBase
 
doublerealpdTheta
 
doublerealpdA
 
doublerealpdY
 
doublerealpdB
 
doublerealpdU
 
unsigned f_proc
 
doublerealpdC
 
doublerealpdE
 
doublerealpdMd
 
doublerealpdYd
 
doublerealpdU0
 
integer iRefA
 
integer iRefB
 
integer iRefMd
 
IdentProcesspId
 
GPCDesignerpCD
 
PersistentExcitationpPx
 
DriveOwner Trigger
 
std::vector< DriveOwner * > vDesiredOut
 
const std::string outfile
 
std::ofstream out
 

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 211 of file discctrl.h.

Constructor & Destructor Documentation

DAC_Process_Debug::DAC_Process_Debug ( integer  iNumOut,
integer  iNumIn,
integer  iOrdA,
integer  iOrdB,
ForgettingFactor pf,
GPCDesigner pd,
PersistentExcitation px,
DriveCaller PTrig,
std::vector< DriveCaller * > &  vDesOut,
const std::string &  sf,
unsigned  f_proc 
)

Definition at line 363 of file discctrl.cc.

References ASSERT, DiscreteControlProcess::DISCPROC_ARMAX, DiscreteControlProcess::DISCPROC_ARX, DiscreteControlProcess::DISCPROC_MA, GPCDesigner::iGetPredHor(), GPCDesigner::iGetPredStep(), iNumInputs, iNumOutputs, iOrderA, iOrderB, iOrderMd, MBDYN_EXCEPT_ARGS, out, outfile, pCD, pdBase, pdE, pdTheta, pdU, pdU0, pdY, pdYd, pId, pPx, SAFENEWARR, SAFENEWWITHCONSTRUCTOR, and vDesiredOut.

374 : iNumOutputs(iNumOut),
375 iNumInputs(iNumIn),
376 iOrderA(iOrdA),
377 iOrderB(iOrdB),
378 iOrderMd(0),
379 pdBase(0),
380 pdTheta(0),
381 pdA(0),
382 pdY(0),
383 pdB(0),
384 pdU(0),
385 f_proc(f_proc),
386 pdC(0),
387 pdE(0),
388 pdMd(0),
389 pdYd(0),
390 pdU0(0),
391 iRefA(0),
392 iRefB(0),
393 iRefMd(0),
394 pId(0), pCD(pd), pPx(px), Trigger(pTrig),
395 outfile(sf)
396 {
397  /* The control model is handled as follows:
398  * the outputs and inputs are stored in two vector:
399  * Y = [y(k-1), ..., y(k-pa)], U = [u(k-1), ..., u(k-pb)]
400  * as soon as new y, u are available, the oldes values are replaced by
401  * the newest and the vector is used as a queue, i.e. it starts from
402  * a floating reference and goes back to the beginning when it's
403  * over.
404  * Mathices alpha, beta are stacked in two big matrtices:
405  * A = [alpha_1, ..., alpha_pa], B = [beta_1, ..., beta_pb]
406  * the input is calculated as A*Y + B*U
407  */
408 
409  /* At present at least one input and one output are required */
410  ASSERT(iNumInputs > 0);
411  ASSERT(iNumOutputs > 0);
412  ASSERT(iOrderA > 0);
413  ASSERT(iOrderB > 0);
414 
415  ASSERT(pCD != 0);
416  ASSERT(pPx != 0);
417 
419  ASSERT(iOrderMd > 0);
420 
421  /* Size of working area */
422  int iSize =
423  iNumOutputs*iOrderA // Vector Y
424  +iNumInputs*iOrderB // Vector U
425  +iNumOutputs*iOrderMd // Vector Yd
426  +iNumInputs // Vector u(k)
427  +iNumOutputs*(iNumOutputs*iOrderA + iNumInputs*(iOrderB + 1)); // Theta
428 
429  if ((f_proc & DISCPROC_MA) == DISCPROC_MA) {
430  iSize += iNumOutputs*iOrderA // Vector E
431  + iNumOutputs*iNumOutputs*iOrderA; // Theta e' piu' grande!
432  }
433 
434  SAFENEWARR(pdBase, doublereal, iSize);
435 
436  pdY = pdBase;
440  pdTheta = pdU0 + iNumInputs;
441 
442  if ((f_proc & DISCPROC_MA) == DISCPROC_MA) {
443  pdE = pdU0 + iNumInputs;
445  }
446 
447  for (int i = iSize; i-- > 0; ) {
448  pdBase[i] = 0.;
449  }
450 
451  /* In the input file, for human readability matrices are written as:
452  * alpha_1,
453  * alpha_2,
454  * ...
455  * alpha_p,
456  * beta_1,
457  * ...
458  * beta_p
459  */
460 
461  /* Si costruisce l'identificatore ARX */
462  switch (f_proc) {
463  case DISCPROC_ARX:
465  IdentARXProcess(iNumOut, iNumIn, iOrdA, iOrdB, pf));
466  break;
467 
468  case DISCPROC_ARMAX:
470  IdentARMAXProcess(iNumOut, iNumIn, iOrdA, iOrdB, pf));
471  break;
472 
473  default:
474  silent_cerr("DAC_Process_Debug: "
475  "unknown identification type " << f_proc
476  << std::endl);
478  }
479 
480  if (!vDesOut.empty()) {
481  vDesiredOut.resize(iNumOutputs);
482 
483  for (integer i = 0; i < iNumOutputs; i++) {
484  vDesiredOut[i] = 0;
486  DriveOwner,
487  DriveOwner(vDesOut[i]));
488  }
489  }
490 
491  // temporaneo ?!?
492  if (!outfile.empty()) {
493  out.open(outfile.c_str());
494  // mettere un test?
495  }
496 }
unsigned f_proc
Definition: discctrl.h:224
integer iNumOutputs
Definition: discctrl.h:213
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
IdentProcess * pId
Definition: discctrl.h:234
doublereal * pdU0
Definition: discctrl.h:229
doublereal * pdC
Definition: discctrl.h:225
std::vector< DriveOwner * > vDesiredOut
Definition: discctrl.h:239
integer iNumInputs
Definition: discctrl.h:214
doublereal * pdE
Definition: discctrl.h:226
GPCDesigner * pCD
Definition: discctrl.h:235
integer iOrderA
Definition: discctrl.h:215
integer iOrderB
Definition: discctrl.h:216
doublereal * pdTheta
Definition: discctrl.h:219
PersistentExcitation * pPx
Definition: discctrl.h:236
doublereal * pdBase
Definition: discctrl.h:218
doublereal * pdU
Definition: discctrl.h:223
const std::string outfile
Definition: discctrl.h:242
doublereal * pdY
Definition: discctrl.h:221
#define ASSERT(expression)
Definition: colamd.c:977
std::ofstream out
Definition: discctrl.h:243
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
DriveOwner Trigger
Definition: discctrl.h:237
doublereal * pdB
Definition: discctrl.h:222
integer iOrderMd
Definition: discctrl.h:217
doublereal * pdMd
Definition: discctrl.h:227
integer iRefMd
Definition: discctrl.h:232
doublereal * pdA
Definition: discctrl.h:220
integer iGetPredHor(void) const
Definition: gpc.h:219
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701
integer iGetPredStep(void) const
Definition: gpc.h:207
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
doublereal * pdYd
Definition: discctrl.h:228

Here is the call graph for this function:

DAC_Process_Debug::~DAC_Process_Debug ( void  )
virtual

Definition at line 499 of file discctrl.cc.

References out, outfile, pCD, pdBase, pId, pPx, SAFEDELETE, SAFEDELETEARR, and vDesiredOut.

500 {
501  // matrices and arrays come from one allocation only
502 
503  if (pdBase != 0) {
505  }
506 
507  if (pId != 0) {
508  SAFEDELETE(pId);
509  }
510 
511  if (pCD != 0) {
512  SAFEDELETE(pCD);
513  }
514 
515  if (pPx) {
516  SAFEDELETE(pPx);
517  }
518 
519  // can be null (no desired output
520  for (std::vector<DriveOwner *>::iterator i = vDesiredOut.begin();
521  i != vDesiredOut.end(); ++i)
522  {
523  SAFEDELETE(*i);
524  }
525 
526  // temporaneo ?!?
527  if (!outfile.empty()) {
528  out.close();
529  }
530 }
IdentProcess * pId
Definition: discctrl.h:234
std::vector< DriveOwner * > vDesiredOut
Definition: discctrl.h:239
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
GPCDesigner * pCD
Definition: discctrl.h:235
PersistentExcitation * pPx
Definition: discctrl.h:236
doublereal * pdBase
Definition: discctrl.h:218
const std::string outfile
Definition: discctrl.h:242
std::ofstream out
Definition: discctrl.h:243
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710

Member Function Documentation

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

Implements DiscreteControlProcess.

Definition at line 533 of file discctrl.cc.

References PersistentExcitation::AddInput(), iNumInputs, pdU0, and pPx.

534 {
535  // control input
536  for (int i = iNumInputs; i-- > 0; ) {
537  dIn[i] = pdU0[i];
538  }
539 
540  // persistent excitation
541  pPx->AddInput(&dIn[0]);
542 }
doublereal * pdU0
Definition: discctrl.h:229
integer iNumInputs
Definition: discctrl.h:214
PersistentExcitation * pPx
Definition: discctrl.h:236
virtual void AddInput(doublereal *pd) const =0

Here is the call graph for this function:

void DAC_Process_Debug::PutOutput ( const std::vector< doublereal > &  dOut,
const std::vector< doublereal > &  dIn,
const std::vector< doublereal > &  dDesiredOut 
)
virtual

Implements DiscreteControlProcess.

Definition at line 545 of file discctrl.cc.

References ASSERT, GPCDesigner::DesignControl(), DriveOwner::dGet(), IdentProcess::dGetForgettingFactor(), DiscreteControlProcess::DISCPROC_MA, f_proc, IdentProcess::GetErr(), IdentProcess::GetTheta(), IdentProcess::iGetNumOutput(), IdentProcess::iGetSize(), iNumInputs, iNumOutputs, iOrderA, iOrderB, iOrderMd, iRefA, iRefB, iRefMd, out, outfile, pCD, pdA, pdB, pdC, pdE, pdMd, pdTheta, pdU, pdU0, pdY, pdYd, pId, Trigger, IdentProcess::Update(), and vDesiredOut.

548 {
549  /* At present dDesiredOutput is not used;
550  * it will be when the system is controlled
551  * and ID'd at the same time */
552 
553  ASSERT(pId != 0);
554  ASSERT(pCD != 0);
555 
556  pId->Update(&dOut[0], &dIn[0]);
557 
558  if (!outfile.empty()) {
559  pId->GetTheta(pdTheta);
560 
561  for (integer i = 0; i < pId->iGetSize()*pId->iGetNumOutput(); i++) {
562  out << std::setw(16) << pdTheta[i];
563  }
564  out << std::setw(16) << pId->dGetForgettingFactor() << std::endl;
565  }
566 
567  if (Trigger.dGet()) {
568  pCD->DesignControl(pdTheta, &pdA, &pdB, &pdMd, &pdC);
569  }
570 
571  // Moves reference backwards
572  if (iRefA == 0) {
573  iRefA = iOrderA;
574  }
575  iRefA--;
576 
577  doublereal* pdOff = pdY + iNumOutputs*iRefA;
578  for (int i = iNumOutputs; i-- > 0; ) {
579  pdOff[i] = dOut[i];
580  }
581 
582  if ((f_proc & DISCPROC_MA) == DISCPROC_MA) {
583  pdOff = pdE + iNumOutputs*iRefA;
584  pId->GetErr(pdOff);
585  }
586 
587  /* Moves reference backwards */
588  if (iRefB == 0) {
589  iRefB = iOrderB;
590  }
591  iRefB--;
592 
593  pdOff = pdU + iNumInputs*iRefB;
594  for (int i = iNumInputs; i-- > 0; ) {
595  /* dIn contiene la somma dell'ingresso esogeno e dell'ingresso
596  * di controllo, ovvero l'ingresso totale applicato al sistema;
597  * pdU0 contiene il solo ingresso generato dal controllore */
598  pdOff[i] = dIn[i];
599  pdU0[i] = 0.;
600  }
601 
602  // Moves reference backwards
603  if (!vDesiredOut.empty()) {
604  if (iRefMd == 0) {
605  iRefMd = iOrderMd;
606  }
607  iRefMd--;
608 
609  doublereal* pdOff = pdYd + iNumOutputs*iRefMd;
610  for (int i = iNumOutputs; i-- > 0; ) {
611  pdOff[i] = vDesiredOut[i]->dGet();
612  }
613 
614  if (!dDesiredOut.empty()) {
615  for (int i = iNumOutputs; i-- > 0; ) {
616  pdOff[i] += dDesiredOut[i];
617  }
618  }
619  }
620 
621  if (pdB == 0) {
622  return;
623  }
624 
625  // Matrices are row-oriented
627  // Y shiftato di iRefA
628  doublereal* pdVecOff = pdY + iRefA*iNumOutputs;
629  for (int i = iNumInputs; i-- > 0; ) {
630  for (int j = iRefA*iNumOutputs; j-- > 0; ) {
631  pdMatOff--;
632  pdU0[i] += pdMatOff[0]*pdY[j];
633  }
634  for (int j = (iOrderA-iRefA)*iNumOutputs; j-- > 0; ) {
635  pdMatOff--;
636  pdU0[i] += pdMatOff[0]*pdVecOff[j];
637  }
638  }
639 
640  pdMatOff = pdB + iOrderB*iNumInputs*iNumInputs;
641  pdVecOff = pdU + iRefB*iNumInputs;
642  for (int i = iNumInputs; i-- > 0; ) {
643  for (int j = iRefB*iNumInputs; j-- > 0; ) {
644  pdMatOff--;
645  pdU0[i] += pdMatOff[0]*pdU[j];
646  }
647  for (int j = (iOrderB - iRefB)*iNumInputs; j-- > 0; ) {
648  pdMatOff--;
649  pdU0[i] += pdMatOff[0]*pdVecOff[j];
650  }
651  }
652 
653  if ((f_proc & DISCPROC_MA) == DISCPROC_MA) {
654  pdMatOff = pdC + iOrderA*iNumOutputs*iNumInputs;
655  // E shiftato di iRefA
656  pdVecOff = pdE + iRefA*iNumOutputs;
657  for (int i = iNumInputs; i-- > 0; ) {
658  for (int j = iRefA*iNumOutputs; j-- > 0; ) {
659  pdMatOff--;
660  pdU0[i] += pdMatOff[0]*pdE[j];
661  }
662  for (int j = (iOrderA - iRefA)*iNumOutputs; j-- > 0; ) {
663  pdMatOff--;
664  pdU0[i] += pdMatOff[0]*pdVecOff[j];
665  }
666  }
667  }
668 
669  if (!vDesiredOut.empty()) {
670  pdMatOff = pdMd + iOrderMd*iNumOutputs*iNumInputs;
671  // Yd shiftato di iRefMd
672  pdVecOff = pdYd + iRefMd*iNumOutputs;
673  for (int i = iNumInputs; i-- > 0; ) {
674  for (int j = iRefMd*iNumOutputs; j-- > 0; ) {
675  pdMatOff--;
676  pdU0[i] += pdMatOff[0]*pdYd[j];
677  }
678  for (int j = (iOrderMd - iRefMd)*iNumOutputs; j-- > 0; ) {
679  pdMatOff--;
680  pdU0[i] += pdMatOff[0]*pdVecOff[j];
681  }
682  }
683  }
684 }
unsigned f_proc
Definition: discctrl.h:224
integer iGetNumOutput(void) const
Definition: id.h:115
integer iNumOutputs
Definition: discctrl.h:213
IdentProcess * pId
Definition: discctrl.h:234
virtual doublereal dGetForgettingFactor(void)
Definition: id.h:108
doublereal * pdU0
Definition: discctrl.h:229
doublereal * pdC
Definition: discctrl.h:225
std::vector< DriveOwner * > vDesiredOut
Definition: discctrl.h:239
integer iNumInputs
Definition: discctrl.h:214
doublereal * pdE
Definition: discctrl.h:226
GPCDesigner * pCD
Definition: discctrl.h:235
integer iOrderA
Definition: discctrl.h:215
integer iOrderB
Definition: discctrl.h:216
doublereal * pdTheta
Definition: discctrl.h:219
doublereal * pdU
Definition: discctrl.h:223
const std::string outfile
Definition: discctrl.h:242
doublereal * pdY
Definition: discctrl.h:221
virtual void Update(const doublereal *pdY, const doublereal *pdU)=0
#define ASSERT(expression)
Definition: colamd.c:977
virtual void GetTheta(doublereal *pdTheta)=0
std::ofstream out
Definition: discctrl.h:243
DriveOwner Trigger
Definition: discctrl.h:237
virtual integer iGetSize(void) const =0
doublereal * pdB
Definition: discctrl.h:222
integer iOrderMd
Definition: discctrl.h:217
doublereal * pdMd
Definition: discctrl.h:227
virtual void GetErr(doublereal *pdE)
Definition: id.cc:191
doublereal dGet(const doublereal &dVar) const
Definition: drive.cc:664
integer iRefMd
Definition: discctrl.h:232
doublereal * pdA
Definition: discctrl.h:220
virtual void DesignControl(const doublereal *, doublereal **ppda=NULL, doublereal **ppdb=NULL, doublereal **ppdm=NULL, doublereal **ppdc=NULL)
Definition: gpc.cc:818
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
doublereal * pdYd
Definition: discctrl.h:228

Here is the call graph for this function:

Member Data Documentation

unsigned DAC_Process_Debug::f_proc
protected

Definition at line 224 of file discctrl.h.

Referenced by PutOutput().

integer DAC_Process_Debug::iNumInputs
protected

Definition at line 214 of file discctrl.h.

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

integer DAC_Process_Debug::iNumOutputs
protected

Definition at line 213 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

integer DAC_Process_Debug::iOrderA
protected

Definition at line 215 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

integer DAC_Process_Debug::iOrderB
protected

Definition at line 216 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

integer DAC_Process_Debug::iOrderMd
protected

Definition at line 217 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

integer DAC_Process_Debug::iRefA
protected

Definition at line 230 of file discctrl.h.

Referenced by PutOutput().

integer DAC_Process_Debug::iRefB
protected

Definition at line 231 of file discctrl.h.

Referenced by PutOutput().

integer DAC_Process_Debug::iRefMd
protected

Definition at line 232 of file discctrl.h.

Referenced by PutOutput().

std::ofstream DAC_Process_Debug::out
protected

Definition at line 243 of file discctrl.h.

Referenced by DAC_Process_Debug(), PutOutput(), and ~DAC_Process_Debug().

const std::string DAC_Process_Debug::outfile
protected

Definition at line 242 of file discctrl.h.

Referenced by DAC_Process_Debug(), PutOutput(), and ~DAC_Process_Debug().

GPCDesigner* DAC_Process_Debug::pCD
protected

Definition at line 235 of file discctrl.h.

Referenced by DAC_Process_Debug(), PutOutput(), and ~DAC_Process_Debug().

doublereal* DAC_Process_Debug::pdA
protected

Definition at line 220 of file discctrl.h.

Referenced by PutOutput().

doublereal* DAC_Process_Debug::pdB
protected

Definition at line 222 of file discctrl.h.

Referenced by PutOutput().

doublereal* DAC_Process_Debug::pdBase
protected

Definition at line 218 of file discctrl.h.

Referenced by DAC_Process_Debug(), and ~DAC_Process_Debug().

doublereal* DAC_Process_Debug::pdC
protected

Definition at line 225 of file discctrl.h.

Referenced by PutOutput().

doublereal* DAC_Process_Debug::pdE
protected

Definition at line 226 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

doublereal* DAC_Process_Debug::pdMd
protected

Definition at line 227 of file discctrl.h.

Referenced by PutOutput().

doublereal* DAC_Process_Debug::pdTheta
protected

Definition at line 219 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

doublereal* DAC_Process_Debug::pdU
protected

Definition at line 223 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

doublereal* DAC_Process_Debug::pdU0
protected

Definition at line 229 of file discctrl.h.

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

doublereal* DAC_Process_Debug::pdY
protected

Definition at line 221 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

doublereal* DAC_Process_Debug::pdYd
protected

Definition at line 228 of file discctrl.h.

Referenced by DAC_Process_Debug(), and PutOutput().

IdentProcess* DAC_Process_Debug::pId
protected

Definition at line 234 of file discctrl.h.

Referenced by DAC_Process_Debug(), PutOutput(), and ~DAC_Process_Debug().

PersistentExcitation* DAC_Process_Debug::pPx
protected

Definition at line 236 of file discctrl.h.

Referenced by DAC_Process_Debug(), GetInput(), and ~DAC_Process_Debug().

DriveOwner DAC_Process_Debug::Trigger
protected

Definition at line 237 of file discctrl.h.

Referenced by PutOutput().

std::vector<DriveOwner*> DAC_Process_Debug::vDesiredOut
protected

Definition at line 239 of file discctrl.h.

Referenced by DAC_Process_Debug(), PutOutput(), and ~DAC_Process_Debug().


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