[10] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[10] | 4 | // %flair:license}
|
---|
[7] | 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"
|
---|
[214] | 19 | #include <Matrix.h>
|
---|
[318] | 20 | #include <MatrixDescriptor.h>
|
---|
[7] | 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 |
|
---|
[15] | 31 | ControlLaw::ControlLaw(const Object *parent, string name, uint32_t nb_out)
|
---|
| 32 | : IODevice(parent, name) {
|
---|
| 33 | if (nb_out == 1) {
|
---|
[214] | 34 | output = new Matrix(this, nb_out, 1, floatType, name);
|
---|
[15] | 35 | } else {
|
---|
[318] | 36 | MatrixDescriptor *desc = new MatrixDescriptor(nb_out, 1);
|
---|
[15] | 37 | for (int i = 0; i < nb_out; i++) {
|
---|
| 38 | std::stringstream ss;
|
---|
| 39 | ss << i;
|
---|
| 40 | desc->SetElementName(i, 0, ss.str());
|
---|
[7] | 41 | }
|
---|
[214] | 42 | output = new Matrix(this, desc, floatType, name);
|
---|
[148] | 43 | delete desc;
|
---|
[15] | 44 | }
|
---|
[7] | 45 |
|
---|
[15] | 46 | input = NULL;
|
---|
| 47 | AddDataToLog(output);
|
---|
[7] | 48 | }
|
---|
| 49 |
|
---|
[15] | 50 | ControlLaw::~ControlLaw(void) {}
|
---|
[7] | 51 |
|
---|
| 52 | void ControlLaw::Update(Time time) {
|
---|
[15] | 53 | input->SetDataTime(time);
|
---|
| 54 | UpdateFrom(input);
|
---|
[7] | 55 | }
|
---|
| 56 |
|
---|
| 57 | float ControlLaw::Output(uint32_t index) const {
|
---|
[15] | 58 | return output->Value(index, 0);
|
---|
[7] | 59 | }
|
---|
| 60 |
|
---|
[15] | 61 | void ControlLaw::UseDefaultPlot(const LayoutPosition *position) {
|
---|
| 62 | if (output->Rows() != 1)
|
---|
| 63 | Warn("Output size is different from 1. Plotting only Output(1,1).\n");
|
---|
[7] | 64 |
|
---|
[15] | 65 | DataPlot1D *plot = new DataPlot1D(position, ObjectName(), -1, 1);
|
---|
| 66 | plot->AddCurve(output->Element(0));
|
---|
[7] | 67 | }
|
---|
| 68 | } // end namespace filter
|
---|
| 69 | } // end namespace flair
|
---|