| 1 | // created: 2014/04/30
|
---|
| 2 | // filename: ControlLaw.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Guillaume Sanahuja
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: Base class for control law
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | /*********************************************************************/
|
---|
| 13 |
|
---|
| 14 | #include "ControlLaw.h"
|
---|
| 15 | #include <cvmatrix.h>
|
---|
| 16 | #include <cvmatrix_descriptor.h>
|
---|
| 17 | #include <DataPlot1D.h>
|
---|
| 18 | #include <sstream>
|
---|
| 19 |
|
---|
| 20 | using std::string;
|
---|
| 21 | using namespace flair::core;
|
---|
| 22 | using namespace flair::gui;
|
---|
| 23 |
|
---|
| 24 | namespace flair {
|
---|
| 25 | namespace filter {
|
---|
| 26 |
|
---|
| 27 | ControlLaw::ControlLaw(const Object* parent,string name,uint32_t nb_out) : IODevice(parent,name) {
|
---|
| 28 | if(nb_out==1) {
|
---|
| 29 | output=new cvmatrix(this,nb_out,1,floatType,name);
|
---|
| 30 | } else {
|
---|
| 31 | cvmatrix_descriptor* desc=new cvmatrix_descriptor(nb_out,1);
|
---|
| 32 | for(int i=0;i<nb_out;i++) {
|
---|
| 33 | std::stringstream ss;
|
---|
| 34 | ss << i;
|
---|
| 35 | desc->SetElementName(i,0,ss.str());
|
---|
| 36 | }
|
---|
| 37 | output=new cvmatrix(this,desc,floatType,name);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | input=NULL;
|
---|
| 41 | AddDataToLog(output);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | ControlLaw::~ControlLaw(void) {
|
---|
| 45 |
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void ControlLaw::Update(Time time) {
|
---|
| 49 | input->SetDataTime(time);
|
---|
| 50 | UpdateFrom(input);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | float ControlLaw::Output(uint32_t index) const {
|
---|
| 54 | return output->Value(index,0);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | void ControlLaw::UseDefaultPlot(const LayoutPosition* position) {
|
---|
| 58 | if(output->Rows()!=1) Warn("Output size is different from 1. Plotting only Output(1,1).\n");
|
---|
| 59 |
|
---|
| 60 | DataPlot1D *plot=new DataPlot1D(position,ObjectName(),-1,1);
|
---|
| 61 | plot->AddCurve(output->Element(0));
|
---|
| 62 | }
|
---|
| 63 | } // end namespace filter
|
---|
| 64 | } // end namespace flair
|
---|