source: flair-src/branches/sanscv/demos/Sinus/src/Loop.cpp@ 411

Last change on this file since 411 was 324, checked in by Sanahuja Guillaume, 5 years ago

removing opencv dependency

File size: 3.5 KB
RevLine 
[324]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
13// include header of the class
14#include "Loop.h"
15// include only header of class declared in Loop.h (forward declaration)
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 <Matrix.h>
27
28using namespace std;
29using namespace flair::core;
30using namespace flair::gui;
31using namespace flair::filter;
32using namespace flair::sensor;
33
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);
41
42 sinus = new Sinus(parent, "sinus");
43 sinus->UseDefaultPlot();
44
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->GetMatrix()->Element(0),
50 DataPlot::Blue); // add output of the filter to signal's graph
51
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->GetMatrix()->Element(0),
57 DataPlot::Yellow); // add output of the filter to signal's graph
58
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
65
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
74
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);
79}
80
81Loop::~Loop() {}
82
83// main loop of the Thread
84void Loop::Run(void) {
85 // warn if changing from primary to secondary mode when in real time
86 WarnUponSwitches(true);
87
88 sinus->Start();
89
90 SetPeriodMS(period->Value());
91
92 while (1) {
93 WaitPeriod();
94
95 if (period->ValueChanged())
96 SetPeriodMS(period->Value());
97
98 if (killButton->Clicked())
99 break;
100 if (startLogButton->Clicked())
101 getFrameworkManager()->StartLog();
102 if (stopLogButton->Clicked())
103 getFrameworkManager()->StopLog();
104
105 // nothing more to do
106 // this is a very simple example
107
108 // normaly, we should use results of filters to calculate a control law
109 }
110
111 WarnUponSwitches(false);
112}
Note: See TracBrowser for help on using the repository browser.