source: flair-src/trunk/demos/Sinus/src/Loop.cpp@ 26

Last change on this file since 26 was 16, checked in by Bayard Gildas, 9 years ago

Reformatting

File size: 3.4 KB
RevLine 
[14]1// created: 2013/06/26
2// filename: Loop.h
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9//
10//
11/*********************************************************************/
12
[16]13// include header of the class
[14]14#include "Loop.h"
[16]15// include only header of class declared in Loop.h (forward declaration)
[14]16#include "Sinus.h"
17#include "MeanFilter.h"
18#include <LowPassFilter.h>
19#include <ButterworthLowPass.h>
20#include <FrameworkManager.h>
21#include <Tab.h>
22#include <GridLayout.h>
23#include <SpinBox.h>
24#include <PushButton.h>
25#include <DataPlot1D.h>
26#include <cvmatrix.h>
27
28using namespace std;
29using namespace flair::core;
30using namespace flair::gui;
31using namespace flair::filter;
32using namespace flair::sensor;
33
[16]34Loop::Loop(FrameworkManager *parent, string name, int priority)
35 : Thread(parent, name, priority) {
36 Tab *mainTab = new Tab(parent->GetTabWidget(), ObjectName());
37 killButton = new PushButton(mainTab->NewRow(), "kill");
38 startLogButton = new PushButton(mainTab->NewRow(), "start_log");
39 stopLogButton = new PushButton(mainTab->LastRowLastCol(), "stop_log");
40 period = new SpinBox(mainTab->NewRow(), "period thread:", " ms", 10, 1000, 1);
[14]41
[16]42 sinus = new Sinus(parent, "sinus");
43 sinus->UseDefaultPlot();
[14]44
[16]45 // 1st order law pass filter on raw signal, its parent is the sinus
46 firstLowPass = new LowPassFilter(sinus, sinus->GetSetupLayout()->NewRow(),
47 "1st order lawpass filter");
48 sinus->GetPlot()->AddCurve(
49 firstLowPass->Matrix()->Element(0),
50 DataPlot::Blue); // add output of the filter to signal's graph
[14]51
[16]52 // 3rd order law pass filter on raw signal, its parent is the sinus
53 thirdLowPass = new ButterworthLowPass(
54 sinus, sinus->GetSetupLayout()->NewRow(), "3rd order lawpass filter", 3);
55 sinus->GetPlot()->AddCurve(
56 thirdLowPass->Matrix()->Element(0),
57 DataPlot::Yellow); // add output of the filter to signal's graph
[14]58
[16]59 // mean filter on raw signal, its parent is the sinus
60 mean =
61 new MeanFilter(sinus, sinus->GetSetupLayout()->NewRow(), "Mean filter");
62 sinus->GetPlot()->AddCurve(
63 mean->GetMatrix()->Element(0),
64 DataPlot::Green); // add output of the filter to signal's graph
[14]65
[16]66 // mean filter on 1st order law pass filter, its parent is the 1st order law
67 // pass filter
68 meanOnfirstLowPass =
69 new MeanFilter(firstLowPass, sinus->GetSetupLayout()->NewRow(),
70 "Mean filter on 1st order lawpass filter");
71 sinus->GetPlot()->AddCurve(
72 meanOnfirstLowPass->GetMatrix()->Element(0),
73 DataPlot::Black); // add output of the filter to signal's graph
[14]74
[16]75 // set ojects to be logged
76 // as the law pass filters and the mean filters have the sinus as parent, they
77 // are automatically logged
78 parent->AddDeviceToLog(sinus);
[14]79}
80
[16]81Loop::~Loop() {}
[14]82
[16]83// main loop of the Thread
[14]84void Loop::Run(void) {
[16]85 // warn if changing from primary to secondary mode when in real time
86 WarnUponSwitches(true);
[14]87
[16]88 sinus->Start();
[14]89
[16]90 SetPeriodMS(period->Value());
[14]91
[16]92 while (1) {
93 WaitPeriod();
[14]94
[16]95 if (period->ValueChanged())
96 SetPeriodMS(period->Value());
[14]97
[16]98 if (killButton->Clicked())
99 break;
100 if (startLogButton->Clicked())
101 getFrameworkManager()->StartLog();
102 if (stopLogButton->Clicked())
103 getFrameworkManager()->StopLog();
[14]104
[16]105 // nothing more to do
106 // this is a very simple example
[14]107
[16]108 // normaly, we should use results of filters to calculate a control law
109 }
[14]110
[16]111 WarnUponSwitches(false);
[14]112}
Note: See TracBrowser for help on using the repository browser.