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