source: flair-src/trunk/lib/FlairFilter/src/ControlLaw.cpp@ 214

Last change on this file since 214 was 214, checked in by Sanahuja Guillaume, 4 years ago

matrix

File size: 1.7 KB
Line 
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 <Matrix.h>
20#include <cvmatrix_descriptor.h>
21#include <DataPlot1D.h>
22#include <sstream>
23
24using std::string;
25using namespace flair::core;
26using namespace flair::gui;
27
28namespace flair {
29namespace filter {
30
31ControlLaw::ControlLaw(const Object *parent, string name, uint32_t nb_out)
32 : IODevice(parent, name) {
33 if (nb_out == 1) {
34 output = new Matrix(this, nb_out, 1, floatType, name);
35 } else {
36 cvmatrix_descriptor *desc = new cvmatrix_descriptor(nb_out, 1);
37 for (int i = 0; i < nb_out; i++) {
38 std::stringstream ss;
39 ss << i;
40 desc->SetElementName(i, 0, ss.str());
41 }
42 output = new Matrix(this, desc, floatType, name);
43 delete desc;
44 }
45
46 input = NULL;
47 AddDataToLog(output);
48}
49
50ControlLaw::~ControlLaw(void) {}
51
52void ControlLaw::Update(Time time) {
53 input->SetDataTime(time);
54 UpdateFrom(input);
55}
56
57float ControlLaw::Output(uint32_t index) const {
58 return output->Value(index, 0);
59}
60
61void ControlLaw::UseDefaultPlot(const LayoutPosition *position) {
62 if (output->Rows() != 1)
63 Warn("Output size is different from 1. Plotting only Output(1,1).\n");
64
65 DataPlot1D *plot = new DataPlot1D(position, ObjectName(), -1, 1);
66 plot->AddCurve(output->Element(0));
67}
68} // end namespace filter
69} // end namespace flair
Note: See TracBrowser for help on using the repository browser.