Changeset 16 in flair-src for trunk/demos/Sinus/src/Loop.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:48:40 PM (5 years ago)
Author:
Bayard Gildas
Message:

Reformatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/Sinus/src/Loop.cpp

    r14 r16  
    1111/*********************************************************************/
    1212
    13 //include header of the class
     13// include header of the class
    1414#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)
    1616#include "Sinus.h"
    1717#include "MeanFilter.h"
     
    2626#include <cvmatrix.h>
    2727
    28 
    2928using namespace std;
    3029using namespace flair::core;
     
    3332using namespace flair::sensor;
    3433
    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);
     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);
    4141
    42     sinus=new Sinus(parent,"sinus");
    43     sinus->UseDefaultPlot();
     42  sinus = new Sinus(parent, "sinus");
     43  sinus->UseDefaultPlot();
    4444
    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
    4851
    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
    5258
    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
    5665
    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
    6074
    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);
    6479}
    6580
    66 Loop::~Loop() {
     81Loop::~Loop() {}
    6782
     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);
    68112}
    69 
    70 //main loop of the Thread
    71 void 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 TracChangeset for help on using the changeset viewer.