Changeset 16 in flair-src for trunk/demos/Sinus/src/Loop.cpp
- Timestamp:
- Apr 8, 2016, 3:48:40 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/demos/Sinus/src/Loop.cpp
r14 r16 11 11 /*********************************************************************/ 12 12 13 // include header of the class13 // include header of the class 14 14 #include "Loop.h" 15 // include only header of class declared in Loop.h (forward declaration)15 // include only header of class declared in Loop.h (forward declaration) 16 16 #include "Sinus.h" 17 17 #include "MeanFilter.h" … … 26 26 #include <cvmatrix.h> 27 27 28 29 28 using namespace std; 30 29 using namespace flair::core; … … 33 32 using namespace flair::sensor; 34 33 35 Loop::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); 34 Loop::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 41 42 sinus=new Sinus(parent,"sinus");43 42 sinus = new Sinus(parent, "sinus"); 43 sinus->UseDefaultPlot(); 44 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 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 48 51 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 // 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 52 58 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 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 56 65 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 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 60 74 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); 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); 64 79 } 65 80 66 Loop::~Loop() { 81 Loop::~Loop() {} 67 82 83 // main loop of the Thread 84 void 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); 68 112 } 69 70 //main loop of the Thread71 void Loop::Run(void) {72 //warn if changing from primary to secondary mode when in real time73 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 do89 //this is a very simple example90 91 //normaly, we should use results of filters to calculate a control law92 }93 94 WarnUponSwitches(false);95 }
Note:
See TracChangeset
for help on using the changeset viewer.