Changeset 16 in flair-src for trunk/demos/Sinus/src
- Timestamp:
- Apr 8, 2016, 3:48:40 PM (9 years ago)
- Location:
- trunk/demos/Sinus/src
- Files:
-
- 7 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 } -
trunk/demos/Sinus/src/Loop.h
r14 r16 14 14 #define LOOP_H 15 15 16 // necessary include, as Thread is a base of our class16 // necessary include, as Thread is a base of our class 17 17 #include <Thread.h> 18 18 19 // forward declaration for other classes19 // forward declaration for other classes 20 20 namespace flair { 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 21 namespace core { 22 class FrameworkManager; 23 } 24 namespace gui { 25 class PushButton; 26 class SpinBox; 27 } 28 namespace sensor { 29 class Sinus; 30 } 31 namespace filter { 32 class LowPassFilter; 33 class ButterworthLowPass; 34 class MeanFilter; 35 } 36 36 } 37 37 38 class Loop : public flair::core::Thread { 39 public: 40 /*! 41 * \brief Constructor 42 * 43 * Builds main loop 44 * 45 * \param parent the FrameworkManager to use 46 * \param name object name 47 * \param priority Thread priority, 51 by default (1:mini, 99:maxi) 48 */ 49 Loop(flair::core::FrameworkManager *parent, std::string name, 50 int priority = 51); 38 51 39 class Loop : public flair::core::Thread 40 { 41 public: 42 /*! 43 * \brief Constructor 44 * 45 * Builds main loop 46 * 47 * \param parent the FrameworkManager to use 48 * \param name object name 49 * \param priority Thread priority, 51 by default (1:mini, 99:maxi) 50 */ 51 Loop(flair::core::FrameworkManager* parent,std::string name,int priority=51); 52 /*! 53 * \brief Destructor 54 */ 55 ~Loop(); 52 56 53 /*! 54 * \brief Destructor 55 */ 56 ~Loop(); 57 private: 58 void Run(void); 57 59 58 private: 59 void Run(void); 60 61 flair::sensor::Sinus *sinus; 62 flair::filter::LowPassFilter *firstLowPass; 63 flair::filter::ButterworthLowPass *thirdLowPass; 64 flair::filter::MeanFilter *mean,*meanOnfirstLowPass; 65 flair::gui::PushButton *startLogButton,*stopLogButton,*killButton; 66 flair::gui::SpinBox *period; 60 flair::sensor::Sinus *sinus; 61 flair::filter::LowPassFilter *firstLowPass; 62 flair::filter::ButterworthLowPass *thirdLowPass; 63 flair::filter::MeanFilter *mean, *meanOnfirstLowPass; 64 flair::gui::PushButton *startLogButton, *stopLogButton, *killButton; 65 flair::gui::SpinBox *period; 67 66 }; 68 67 -
trunk/demos/Sinus/src/MeanFilter.cpp
r14 r16 22 22 using namespace flair::gui; 23 23 24 namespace flair { namespace filter { 24 namespace flair { 25 namespace filter { 25 26 26 MeanFilter::MeanFilter(const IODevice* parent,const LayoutPosition* position,string name): IODevice(parent,name) { 27 //interface initialisation 28 groupBox=new GroupBox(position,name); 29 numberOfElements=new SpinBox(groupBox->NewRow(),"numberOfElements:",1,MAX_NUMBER_OF_ELEMENTS,1);//saturated to MAX_NUMBER_OF_ELEMENTS 27 MeanFilter::MeanFilter(const IODevice *parent, const LayoutPosition *position, 28 string name) 29 : IODevice(parent, name) { 30 // interface initialisation 31 groupBox = new GroupBox(position, name); 32 numberOfElements = new SpinBox(groupBox->NewRow(), "numberOfElements:", 1, 33 MAX_NUMBER_OF_ELEMENTS, 34 1); // saturated to MAX_NUMBER_OF_ELEMENTS 30 35 31 //init storage 32 for(int i=0; i<MAX_NUMBER_OF_ELEMENTS; i++) previousValues[i]=0; 36 // init storage 37 for (int i = 0; i < MAX_NUMBER_OF_ELEMENTS; i++) 38 previousValues[i] = 0; 33 39 34 //1*1 output matrix 35 cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1); 36 desc->SetElementName(0,0,"mean filter");//name will be used for graphs and logs 37 output=new cvmatrix(this,desc,floatType,name); 40 // 1*1 output matrix 41 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1); 42 desc->SetElementName(0, 0, 43 "mean filter"); // name will be used for graphs and logs 44 output = new cvmatrix(this, desc, floatType, name); 38 45 39 46 AddDataToLog(output); 40 47 } 41 48 42 MeanFilter::~MeanFilter() { 43 } 49 MeanFilter::~MeanFilter() {} 44 50 45 cvmatrix *MeanFilter::GetMatrix() const { 46 return output; 47 } 51 cvmatrix *MeanFilter::GetMatrix() const { return output; } 48 52 49 float MeanFilter::GetValue(void) const { 50 return output->Value(0,0); 51 } 53 float MeanFilter::GetValue(void) const { return output->Value(0, 0); } 52 54 53 //UpdateFrom, where we implement the filter 54 //this method is automatically called when the parent IODevice calls ProcessUpdate 55 //in our case it is the sinus or the 1st orde law pass filter 55 // UpdateFrom, where we implement the filter 56 // this method is automatically called when the parent IODevice calls 57 // ProcessUpdate 58 // in our case it is the sinus or the 1st orde law pass filter 56 59 //(see in Sinus::Run the call to ProcessUpdate) 57 60 void MeanFilter::UpdateFrom(const io_data *data) { 58 61 59 float result=0;60 //get input argument in a cvmatrix61 cvmatrix *input=(cvmatrix*)data;62 float result = 0; 63 // get input argument in a cvmatrix 64 cvmatrix *input = (cvmatrix *)data; 62 65 63 //simple (and not efficent!) implementation of the filter 64 previousValues[numberOfElements->Value()-1]=input->Value(0,0); 65 for(int i=0; i<numberOfElements->Value(); i++) result+=previousValues[i]; 66 for(int i=1; i<numberOfElements->Value(); i++) previousValues[i-1]=previousValues[i]; 66 // simple (and not efficent!) implementation of the filter 67 previousValues[numberOfElements->Value() - 1] = input->Value(0, 0); 68 for (int i = 0; i < numberOfElements->Value(); i++) 69 result += previousValues[i]; 70 for (int i = 1; i < numberOfElements->Value(); i++) 71 previousValues[i - 1] = previousValues[i]; 67 72 68 //put the result in output matrix69 output->SetValue(0,0,result/numberOfElements->Value());70 //put corresponding time71 73 // put the result in output matrix 74 output->SetValue(0, 0, result / numberOfElements->Value()); 75 // put corresponding time 76 output->SetDataTime(data->DataTime()); 72 77 73 //ProcessUpdate is very important74 //we must call it after updating the output matrix75 //it allows:76 77 78 78 // ProcessUpdate is very important 79 // we must call it after updating the output matrix 80 // it allows: 81 // -to save value in the logs 82 // -to automatically call the next filter UpdateFrom method 83 ProcessUpdate(output); 79 84 } 80 } // end namespace filter81 } // end namespace flair85 } // end namespace filter 86 } // end namespace flair -
trunk/demos/Sinus/src/MeanFilter.h
r14 r16 15 15 #define MEANFILTER_H 16 16 17 // we fix the max number of elements to compute the mean18 // this is a simple example, it should be dynamical17 // we fix the max number of elements to compute the mean 18 // this is a simple example, it should be dynamical 19 19 #define MAX_NUMBER_OF_ELEMENTS 200 20 20 21 // necessary include, as IODevice is a base of our class21 // necessary include, as IODevice is a base of our class 22 22 #include <IODevice.h> 23 23 24 // forward declaration for other classes24 // forward declaration for other classes 25 25 namespace flair { 26 27 28 29 30 31 32 33 26 namespace core { 27 class cvmatrix; 28 } 29 namespace gui { 30 class LayoutPosition; 31 class GroupBox; 32 class SpinBox; 33 } 34 34 } 35 35 36 // MeanFilter is a class computing a mean36 // MeanFilter is a class computing a mean 37 37 // based on a parametrizable number of elements 38 38 // it derives on IODevice as it as an input and an output 39 39 // it is a filter, we extend the namespace 40 namespace flair { namespace filter { 41 class MeanFilter : public core::IODevice { 40 namespace flair { 41 namespace filter { 42 class MeanFilter : public core::IODevice { 42 43 43 public: 44 /*! 45 * \brief Constructor 46 * 47 * Builds a mean filter. \n 48 * After calling this function, position will be deleted as it is no longer usefull. \n 49 * 50 * \param parent IODevice to use as parent 51 * \param position where to place settings 52 * \param name name of the object 53 */ 54 MeanFilter(const core::IODevice* parent,const gui::LayoutPosition* position,std::string name); 44 public: 45 /*! 46 * \brief Constructor 47 * 48 * Builds a mean filter. \n 49 * After calling this function, position will be deleted as it is no longer 50 *usefull. \n 51 * 52 * \param parent IODevice to use as parent 53 * \param position where to place settings 54 * \param name name of the object 55 */ 56 MeanFilter(const core::IODevice *parent, const gui::LayoutPosition *position, 57 std::string name); 55 58 56 57 58 59 59 /*! 60 * \brief Destructor 61 */ 62 ~MeanFilter(); 60 63 61 /*! 62 * \brief Output matrix 63 * 64 * allows to access output matrix, to get signal value or to put it in a graph. \n 65 * 66 * \return pointer to the output matrix 67 */ 68 core::cvmatrix *GetMatrix(void) const; 64 /*! 65 * \brief Output matrix 66 * 67 * allows to access output matrix, to get signal value or to put it in a graph. 68 *\n 69 * 70 * \return pointer to the output matrix 71 */ 72 core::cvmatrix *GetMatrix(void) const; 69 73 70 71 72 73 74 75 76 77 74 /*! 75 * \brief Value 76 * 77 * this method is equivalent to GetMatrix()->Value(0,0) 78 * 79 * \return actual mean value 80 */ 81 float GetValue(void) const; 78 82 79 private: 80 //UpdateFrom method from base class IODevice 81 void UpdateFrom(const core::io_data *data); 82 gui::GroupBox *groupBox; 83 gui::SpinBox *numberOfElements; 84 core::cvmatrix *output; 85 float previousValues[MAX_NUMBER_OF_ELEMENTS];//previous values storage 86 87 }; 88 }// end namespace filter 89 }// end namespace flair 83 private: 84 // UpdateFrom method from base class IODevice 85 void UpdateFrom(const core::io_data *data); 86 gui::GroupBox *groupBox; 87 gui::SpinBox *numberOfElements; 88 core::cvmatrix *output; 89 float previousValues[MAX_NUMBER_OF_ELEMENTS]; // previous values storage 90 }; 91 } // end namespace filter 92 } // end namespace flair 90 93 #endif // MEANFILTER_H -
trunk/demos/Sinus/src/Sinus.cpp
r14 r16 30 30 using namespace flair::gui; 31 31 32 namespace flair { namespace sensor { 32 namespace flair { 33 namespace sensor { 33 34 34 Sinus::Sinus(const FrameworkManager* parent,string name,int priority) : IODevice(parent,name),Thread(parent,name,priority) { 35 Sinus::Sinus(const FrameworkManager *parent, string name, int priority) 36 : IODevice(parent, name), Thread(parent, name, priority) { 35 37 36 plot=NULL;38 plot = NULL; 37 39 38 //1*1 output matrix39 cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);40 desc->SetElementName(0,0,"value");//name will be used for graphs and logs41 output=new cvmatrix((IODevice*)this,desc,floatType,name);42 output->SetValue(0,0,0);40 // 1*1 output matrix 41 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1); 42 desc->SetElementName(0, 0, "value"); // name will be used for graphs and logs 43 output = new cvmatrix((IODevice *)this, desc, floatType, name); 44 output->SetValue(0, 0, 0); 43 45 46 AddDataToLog(output); 44 47 45 AddDataToLog(output); 48 // interface initialisation 49 mainTab = new Tab(parent->GetTabWidget(), name); 50 tabWidget = new TabWidget(mainTab->NewRow(), name); 46 51 47 //interface initialisation 48 mainTab=new Tab(parent->GetTabWidget(),name); 49 tabWidget=new TabWidget(mainTab->NewRow(),name); 52 Tab *settingsTab = new Tab(tabWidget, "Settings"); 53 GroupBox *sinusGroupBox = new GroupBox(settingsTab->NewRow(), name); 54 frequency = new DoubleSpinBox(sinusGroupBox->NewRow(), "frequence:", " Hz", 0, 55 100, 1); 56 amplitude = new DoubleSpinBox(sinusGroupBox->LastRowLastCol(), "amplitude:", 57 0, 10, 1); 58 offset = 59 new DoubleSpinBox(sinusGroupBox->LastRowLastCol(), "offset:", 0, 10, 1); 60 period = 61 new SpinBox(settingsTab->NewRow(), "period thread:", " ms", 1, 1000, 1); 50 62 51 Tab* settingsTab=new Tab(tabWidget,"Settings"); 52 GroupBox* sinusGroupBox=new GroupBox(settingsTab->NewRow(),name); 53 frequency=new DoubleSpinBox(sinusGroupBox->NewRow(),"frequence:"," Hz",0,100,1); 54 amplitude=new DoubleSpinBox(sinusGroupBox->LastRowLastCol(),"amplitude:",0,10,1); 55 offset=new DoubleSpinBox(sinusGroupBox->LastRowLastCol(),"offset:",0,10,1); 56 period=new SpinBox(settingsTab->NewRow(),"period thread:"," ms",1,1000,1); 57 58 setupLayout=new GridLayout(settingsTab->NewRow(),"setup");//layout sui servira à placer des filtres par exemple 63 setupLayout = new GridLayout( 64 settingsTab->NewRow(), 65 "setup"); // layout sui servira à placer des filtres par exemple 59 66 } 60 61 67 62 68 Sinus::~Sinus() { 63 69 64 65 70 SafeStop(); 71 Join(); 66 72 67 //main_tab has the FrameworkManager as parent; it will be destroyed when FrameworkManager is destroyed 68 //it is cleaner to delete it manually, because main_tab is unnecessary when Sinus is deleted 69 delete mainTab; 73 // main_tab has the FrameworkManager as parent; it will be destroyed when 74 // FrameworkManager is destroyed 75 // it is cleaner to delete it manually, because main_tab is unnecessary when 76 // Sinus is deleted 77 delete mainTab; 70 78 } 71 79 72 80 void Sinus::UseDefaultPlot(void) { 73 Tab* plotTab=new Tab(tabWidget,"Graph");74 plot=new DataPlot1D(plotTab->NewRow(),"Sinus",-10,10);75 plot->AddCurve(output->Element(0),DataPlot::Red);81 Tab *plotTab = new Tab(tabWidget, "Graph"); 82 plot = new DataPlot1D(plotTab->NewRow(), "Sinus", -10, 10); 83 plot->AddCurve(output->Element(0), DataPlot::Red); 76 84 } 77 85 78 GridLayout* Sinus::GetSetupLayout(void) const { 79 return setupLayout; 86 GridLayout *Sinus::GetSetupLayout(void) const { return setupLayout; } 87 88 DataPlot1D *Sinus::GetPlot(void) const { 89 if (plot == NULL) 90 Printf("Sinus::Plot, plot not yet defined, call UseDefaultPlot first\n"); 91 return plot; 80 92 } 81 93 82 DataPlot1D* Sinus::GetPlot(void) const { 83 if(plot==NULL) Printf("Sinus::Plot, plot not yet defined, call UseDefaultPlot first\n"); 84 return plot; 85 } 94 cvmatrix *Sinus::GetMatrix(void) const { return output; } 86 95 87 cvmatrix *Sinus::GetMatrix(void) const { 88 return output; 89 } 96 float Sinus::GetValue(void) const { return output->Value(0, 0); } 90 97 91 float Sinus::GetValue(void) const { 92 return output->Value(0,0); 93 } 94 95 //main function, where we compute the signal 98 // main function, where we compute the signal 96 99 void Sinus::Run(void) { 97 100 98 101 SetPeriodMS(period->Value()); 99 102 100 //warn if changing from primary to secondary mode when in real time101 103 // warn if changing from primary to secondary mode when in real time 104 WarnUponSwitches(true); 102 105 103 Time initTime=GetTime();106 Time initTime = GetTime(); 104 107 105 while(!ToBeStopped()) {106 108 while (!ToBeStopped()) { 109 WaitPeriod(); 107 110 108 if(period->ValueChanged()==true) SetPeriodMS(period->Value()); 111 if (period->ValueChanged() == true) 112 SetPeriodMS(period->Value()); 109 113 110 //compute sinus 111 Time actualTime=GetTime(); 112 float value=offset->Value()+amplitude->Value()*sinf(2*PI*frequency->Value()*(actualTime-initTime)/1000000000.);//les temps sont en nanosecondes 114 // compute sinus 115 Time actualTime = GetTime(); 116 float value = 117 offset->Value() + 118 amplitude->Value() * 119 sinf(2 * PI * frequency->Value() * (actualTime - initTime) / 120 1000000000.); // les temps sont en nanosecondes 113 121 114 //put the result in output matrix115 output->SetValue(0,0,value);116 //put corresponding time117 122 // put the result in output matrix 123 output->SetValue(0, 0, value); 124 // put corresponding time 125 output->SetDataTime(actualTime); 118 126 119 //ProcessUpdate is very important120 //we must call it after updating the output matrix121 //it allows:122 123 124 125 127 // ProcessUpdate is very important 128 // we must call it after updating the output matrix 129 // it allows: 130 // -to save value in the logs 131 // -to automatically call the next filter UpdateFrom method 132 ProcessUpdate(output); 133 } 126 134 } 127 } // end namespace sensor128 } // end namespace flair135 } // end namespace sensor 136 } // end namespace flair -
trunk/demos/Sinus/src/Sinus.h
r14 r16 15 15 #define SINUS_H 16 16 17 // necessary includes, as IODevice and Thread are bases of our class17 // necessary includes, as IODevice and Thread are bases of our class 18 18 #include <IODevice.h> 19 19 #include <Thread.h> 20 20 21 // forward declaration for other classes21 // forward declaration for other classes 22 22 namespace flair { 23 24 25 26 27 28 29 30 31 32 33 34 23 namespace core { 24 class FrameworkManager; 25 class cvmatrix; 26 } 27 namespace gui { 28 class Tab; 29 class TabWidget; 30 class GridLayout; 31 class DoubleSpinBox; 32 class SpinBox; 33 class DataPlot1D; 34 } 35 35 } 36 36 37 // sinus is a class generating a sinus signal38 // in this example, it emulates a sensonr, so we extend the namespace sensor39 // it derives frome37 // sinus is a class generating a sinus signal 38 // in this example, it emulates a sensonr, so we extend the namespace sensor 39 // it derives frome 40 40 // IODevice: as it has an ouput 41 41 // Thread: is it a thread 42 namespace flair { namespace sensor { 43 class Sinus : public core::IODevice, public core::Thread { 44 public: 45 /*! 46 * \brief Constructor 47 * 48 * Builds a sinus generator 49 * 50 * \param parent the FrameworkManager to use 51 * \param name object name 52 * \param priority Thread priority, 50 by default (1:mini, 99:maxi) 53 */ 54 Sinus(const core::FrameworkManager* parent,std::string name,int priority=50); 42 namespace flair { 43 namespace sensor { 44 class Sinus : public core::IODevice, public core::Thread { 45 public: 46 /*! 47 * \brief Constructor 48 * 49 * Builds a sinus generator 50 * 51 * \param parent the FrameworkManager to use 52 * \param name object name 53 * \param priority Thread priority, 50 by default (1:mini, 99:maxi) 54 */ 55 Sinus(const core::FrameworkManager *parent, std::string name, 56 int priority = 50); 55 57 56 57 58 59 58 /*! 59 * \brief Destructor 60 */ 61 ~Sinus(); 60 62 61 /*! 62 * \brief Output matrix 63 * 64 * allows to access output matrix, to get signal value or to put it in a graph. \n 65 * 66 * \return un pointeur vers la matrice de sortie 67 */ 68 core::cvmatrix *GetMatrix(void) const; 63 /*! 64 * \brief Output matrix 65 * 66 * allows to access output matrix, to get signal value or to put it in a graph. 67 *\n 68 * 69 * \return un pointeur vers la matrice de sortie 70 */ 71 core::cvmatrix *GetMatrix(void) const; 69 72 70 71 72 73 74 75 76 77 73 /*! 74 * \brief Value 75 * 76 * this method is equivalent to GetMatrix()->Value(0,0) 77 * 78 * \return actual signal value 79 */ 80 float GetValue(void) const; 78 81 79 80 81 82 83 84 85 82 /*! 83 * \brief Use defautl plot 84 * 85 * this method put a graph in a specific tab 86 * 87 */ 88 void UseDefaultPlot(void); 86 89 87 88 89 90 91 92 93 94 90 /*! 91 * \brief SetupLayout 92 * 93 * this method allows to add other widgets in the sinus tab. 94 * 95 * \return the GridLayout 96 */ 97 gui::GridLayout *GetSetupLayout(void) const; 95 98 96 97 98 99 100 101 102 103 99 /*! 100 * \brief Plot 101 * 102 * this method allows to add other curves in the graph 103 * 104 * \return the DataPlot1D 105 */ 106 gui::DataPlot1D *GetPlot(void) const; 104 107 105 private: 106 //UpdateFrom method from base class IODevice 107 //sinus is like a sensor, so it does not have input; we define an empty method 108 void UpdateFrom(const core::io_data *data){}; 109 void Run(void); 108 private: 109 // UpdateFrom method from base class IODevice 110 // sinus is like a sensor, so it does not have input; we define an empty 111 // method 112 void UpdateFrom(const core::io_data *data){}; 113 void Run(void); 110 114 111 112 gui::Tab*mainTab;113 gui::TabWidget*tabWidget;114 gui::DataPlot1D*plot;115 gui::DoubleSpinBox *frequency,*amplitude,*offset;116 117 gui::GridLayout*setupLayout;118 119 } // end namespace sensor120 } // end namespace flair115 core::cvmatrix *output; 116 gui::Tab *mainTab; 117 gui::TabWidget *tabWidget; 118 gui::DataPlot1D *plot; 119 gui::DoubleSpinBox *frequency, *amplitude, *offset; 120 gui::SpinBox *period; 121 gui::GridLayout *setupLayout; 122 }; 123 } // end namespace sensor 124 } // end namespace flair 121 125 #endif // SINUS_H -
trunk/demos/Sinus/src/main.cpp
r14 r16 16 16 #include <stdio.h> 17 17 18 // we use namespace std, to avoid writing for examlpe std::string18 // we use namespace std, to avoid writing for examlpe std::string 19 19 using namespace std; 20 // idem for TCLAP20 // idem for TCLAP 21 21 using namespace TCLAP; 22 // idem for flair22 // idem for flair 23 23 using namespace flair::core; 24 24 25 // global variables for the command line arguments26 string logPath; //path for logs27 string address; //address for FlairGCS28 int port; //port for FlairGCS29 string xmlFile; //setup xml file30 string name; //name25 // global variables for the command line arguments 26 string logPath; // path for logs 27 string address; // address for FlairGCS 28 int port; // port for FlairGCS 29 string xmlFile; // setup xml file 30 string name; // name 31 31 32 void parseOptions(int argc, char **argv);32 void parseOptions(int argc, char **argv); 33 33 34 int main(int argc, char *argv[]) {35 //get command line arguments (name,port,xml_file,log_path)36 parseOptions(argc,argv);34 int main(int argc, char *argv[]) { 35 // get command line arguments (name,port,xml_file,log_path) 36 parseOptions(argc, argv); 37 37 38 //creation of FrameworkManager39 40 manager= new FrameworkManager(name);41 manager->SetupConnection(address,port);42 43 38 // creation of FrameworkManager 39 FrameworkManager *manager; 40 manager = new FrameworkManager(name); 41 manager->SetupConnection(address, port); 42 manager->SetupUserInterface(xmlFile); 43 manager->SetupLogger(logPath); 44 44 45 //creation of the46 Loop* example=new Loop(manager,"Loop");45 // creation of the 46 Loop *example = new Loop(manager, "Loop"); 47 47 48 //start loop49 48 // start loop 49 example->Start(); 50 50 51 //wait for loop ends (with kill button)52 51 // wait for loop ends (with kill button) 52 example->Join(); 53 53 54 54 delete manager; 55 55 } 56 56 57 void parseOptions(int argc, char **argv) { 58 try { 59 CmdLine cmd("Command description message", ' ', "0.1"); 57 60 58 void parseOptions(int argc, char** argv) { 59 try { 60 CmdLine cmd("Command description message", ' ', "0.1"); 61 // name of the FrameworkManager, Sinus by default 62 ValueArg<string> nameArg("n", "name", "program name", false, "Sinus", 63 "string"); 64 cmd.add(nameArg); 61 65 62 //name of the FrameworkManager, Sinus by default 63 ValueArg<string> nameArg("n","name","program name",false,"Sinus","string"); 64 cmd.add( nameArg ); 66 // setup xml file, ./Sinus.xml by default 67 ValueArg<string> xmlArg("x", "xml", "xml file", false, "./Sinus.xml", 68 "string"); 69 cmd.add(xmlArg); 65 70 66 //setup xml file, ./Sinus.xml by default67 ValueArg<string> xmlArg("x","xml","xml file",false,"./Sinus.xml","string");68 cmd.add( xmlArg);71 // log path, ./ by defaults 72 ValueArg<string> logArg("l", "log", "log path", false, "/tmp", "string"); 73 cmd.add(logArg); 69 74 70 //log path, ./ by defaults 71 ValueArg<string> logArg("l","log","log path",false,"/tmp","string"); 72 cmd.add( logArg ); 75 // address for FlairGCS 76 ValueArg<string> addressArg("a", "address", 77 "address for FlairGCS station sol", false, 78 "127.0.0.1", "string"); 79 cmd.add(addressArg); 73 80 74 //address for FlairGCS75 ValueArg<string> addressArg("a","address","address for FlairGCS station sol",false,"127.0.0.1","string");76 cmd.add( addressArg);81 // port for FlairGCS, 9000 by default 82 ValueArg<int> portArg("p", "port", "port for FlairGCS", false, 9000, "int"); 83 cmd.add(portArg); 77 84 78 //port for FlairGCS, 9000 by default 79 ValueArg<int> portArg("p","port","port for FlairGCS",false,9000,"int"); 80 cmd.add( portArg ); 85 cmd.parse(argc, argv); 81 86 82 cmd.parse( argc, argv ); 87 // Get the value parsed by each arg. 88 logPath = logArg.getValue(); 89 port = portArg.getValue(); 90 xmlFile = xmlArg.getValue(); 91 name = nameArg.getValue(); 92 address = addressArg.getValue(); 83 93 84 // Get the value parsed by each arg. 85 logPath = logArg.getValue(); 86 port=portArg.getValue(); 87 xmlFile = xmlArg.getValue(); 88 name=nameArg.getValue(); 89 address=addressArg.getValue(); 90 91 } catch (ArgException &e) { // catch any exceptions 92 cerr << "error: " << e.error() << " for arg " << e.argId() << endl; 93 } 94 } catch (ArgException &e) { // catch any exceptions 95 cerr << "error: " << e.error() << " for arg " << e.argId() << endl; 96 } 94 97 }
Note:
See TracChangeset
for help on using the changeset viewer.