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

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

sinus

File size: 3.3 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
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 <cvmatrix.h>
27
28
29using namespace std;
30using namespace flair::core;
31using namespace flair::gui;
32using namespace flair::filter;
33using namespace flair::sensor;
34
35Loop::Loop(FrameworkManager* parent,string name,int priority): 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(),"1st order lawpass filter");
47    sinus->GetPlot()->AddCurve(firstLowPass->Matrix()->Element(0),DataPlot::Blue);//add output of the filter to signal's graph
48
49    //3rd order law pass filter on raw signal, its parent is the sinus
50    thirdLowPass=new ButterworthLowPass(sinus,sinus->GetSetupLayout()->NewRow(),"3rd order lawpass filter",3);
51    sinus->GetPlot()->AddCurve(thirdLowPass->Matrix()->Element(0),DataPlot::Yellow);//add output of the filter to signal's graph
52
53    //mean filter on raw signal, its parent is the sinus
54    mean=new MeanFilter(sinus,sinus->GetSetupLayout()->NewRow(),"Mean filter");
55    sinus->GetPlot()->AddCurve(mean->GetMatrix()->Element(0),DataPlot::Green);//add output of the filter to signal's graph
56
57    //mean filter on 1st order law pass filter, its parent is the 1st order law pass filter
58    meanOnfirstLowPass=new MeanFilter(firstLowPass,sinus->GetSetupLayout()->NewRow(),"Mean filter on 1st order lawpass filter");
59    sinus->GetPlot()->AddCurve(meanOnfirstLowPass->GetMatrix()->Element(0),DataPlot::Black);//add output of the filter to signal's graph
60
61    //set ojects to be logged
62    //as the law pass filters and the mean filters have the sinus as parent, they are automatically logged
63    parent->AddDeviceToLog(sinus);
64}
65
66Loop::~Loop() {
67
68}
69
70//main loop of the Thread
71void Loop::Run(void) {
72    //warn if changing from primary to secondary mode when in real time
73    WarnUponSwitches(true);
74
75    sinus->Start();
76
77    SetPeriodMS(period->Value());
78
79    while(1) {
80        WaitPeriod();
81
82        if(period->ValueChanged()) SetPeriodMS(period->Value());
83
84        if(killButton->Clicked()) break;
85        if(startLogButton->Clicked()) getFrameworkManager()->StartLog();
86        if(stopLogButton->Clicked()) getFrameworkManager()->StopLog();
87
88        //nothing more to do
89        //this is a very simple example
90
91        //normaly, we should use results of filters to calculate a control law
92    }
93
94    WarnUponSwitches(false);
95}
Note: See TracBrowser for help on using the repository browser.