José Claudio / Mbed 2 deprecated QuadCopter-Sensor-Serial

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FuzzyIO.cpp Source File

FuzzyIO.cpp

00001 #include "FuzzyIO.h"
00002 
00003 FuzzyIO::FuzzyIO(float rangeMin, float rangeMax)
00004 {
00005     this->rangeMin = rangeMin;
00006     this->rangeMax = rangeMax;
00007 
00008     mfs = NULL;
00009     mfsLenght = 0;
00010 }
00011 
00012 FuzzyIO::~FuzzyIO(void)
00013 {
00014 }
00015 
00016 void FuzzyIO::addMF(MembershipFunction* mf)
00017 {
00018     mfs = (MembershipFunction**) realloc(mfs, sizeof(MembershipFunction*) * (mfsLenght + 1));
00019     
00020     mfs[mfsLenght] = mf;
00021     
00022     mfsLenght++;
00023 }
00024 
00025 void FuzzyIO::addAutoMFs(int amount, mfType type, float rangeMin, float rangeMax)
00026 {
00027     if (amount <= 1)
00028     {
00029         MembershipFunction* mf = new MembershipFunction(type);
00030         mf->setValues(rangeMin, (rangeMin - rangeMax) / 2, rangeMax);
00031         
00032         this->addMF(mf);
00033         
00034         return;
00035     }
00036     
00037     float rangeDt = (rangeMax - rangeMin) / (amount - 1);
00038     float startPoint = rangeMin - rangeDt;
00039     
00040     for (int i = 0; i < amount; i++)
00041     {
00042         MembershipFunction* mf = new MembershipFunction(type);
00043         mf->setValues(startPoint, startPoint + rangeDt, startPoint + rangeDt * 2);
00044         
00045         startPoint = startPoint + rangeDt;
00046         
00047         this->addMF(mf);
00048     }
00049 }
00050 
00051 void FuzzyIO::addAutoMFs(int amount, mfType type)
00052 {
00053     this->addAutoMFs(amount, type, this->rangeMin, this->rangeMax);
00054 }
00055 
00056 MembershipFunction* FuzzyIO::getMFs(int index)
00057 {
00058     return mfs[index];
00059 }
00060 
00061 int FuzzyIO::getMFsLenght()
00062 {
00063     return this->mfsLenght;
00064 }