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

Last change on this file since 146 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 1.7 KB
RevLine 
[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"
19#include <cvmatrix.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
[15]31ControlLaw::ControlLaw(const Object *parent, string name, uint32_t nb_out)
32 : IODevice(parent, name) {
33 if (nb_out == 1) {
34 output = new cvmatrix(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());
[7]41 }
[15]42 output = new cvmatrix(this, desc, floatType, name);
43 }
[7]44
[15]45 input = NULL;
46 AddDataToLog(output);
[7]47}
48
[15]49ControlLaw::~ControlLaw(void) {}
[7]50
51void ControlLaw::Update(Time time) {
[15]52 input->SetDataTime(time);
53 UpdateFrom(input);
[7]54}
55
56float ControlLaw::Output(uint32_t index) const {
[15]57 return output->Value(index, 0);
[7]58}
59
[15]60void ControlLaw::UseDefaultPlot(const LayoutPosition *position) {
61 if (output->Rows() != 1)
62 Warn("Output size is different from 1. Plotting only Output(1,1).\n");
[7]63
[15]64 DataPlot1D *plot = new DataPlot1D(position, ObjectName(), -1, 1);
65 plot->AddCurve(output->Element(0));
[7]66}
67} // end namespace filter
68} // end namespace flair
Note: See TracBrowser for help on using the repository browser.