Fuzzy Logic Control

I'm doing a project on a Greenhouse whose temperature and humidity are controlled by a Fuzzy Logic Control. I used fuzzyTech to build my rule block and configured it accordingly now I'm using the arduinoUNO as the microprocessor for my system. The fuzzyTECH gave me the C code already. Is there a way to use this code on the arduino?

You might be able to use it as a basis for a sketch. If the output was not intended for a resource limited microcontroller, it might require too much memory. Post it and we can have a look.

OK i attatched but does it have a fuzzy logic library?

Ftrghouse2.cpp (5.72 KB)

I'm not aware of a fuzzy logic library. It doesn't support Microsoft Foundation Classes either. Does it have to output Visual C++ code, or are there any other options.

I got a few other formats. Check them out. Oh and thanks so much for helping me out

ghouse2.c (3.7 KB)

ghouse2.ftr (863 Bytes)

ghouse2.h (2.94 KB)

ghouse2.IO (1.76 KB)

Building an automated greenhouse where temperature and humidity are the variables being controlled. The arduino is the microprocessor and the method of conttol is fuzzy logic. I have my rule bases which were made on fuzzyTech but the only output in C and C++. Is there a way to input this on an Arduino?

I have my rule bases which were made on fuzzyTech but the only output in C and C++.

What a happy coincidence, then, that the Arduino is programmed in C++.

It is, but the code generated has libraries not familiar with the Arduino. :( Do I have to make the library or is there a way to bypass this?

It is, but the code generated has libraries not familiar with the Arduino.

Perhaps we could see it?

Do I have to make the library or is there a way to bypass this?

Yes. You either have to create a library or there is a workaround. 8)

OK I’ll post the code.

//---------------------------------------------------------------------------
//-------------------- fuzzyTECH 5.54 Professional Edition ------------------
//---------------------------------------------------------------------------
//---- Code Generator: Visual C++ Wrapper Class for fuzzyTECH Runtime DLL —
//-------------- Code Generation Date: Tue Mar 27 11:29:58 2012 -------------
//----------------------- Fuzzy Logic System: GREENHOU ----------------------
//---------------------------------------------------------------------------
//--------- (c) 1991-2003 INFORM GmbH, Pascalstr. 23, D-52076 Aachen --------
//------- Inform Software Corp., 2001 Midwest Rd., Oak Brook, IL 60523 ------
//---------------------------------------------------------------------------

//------ DEPENDENCIES -------------------------------------------
#include “stdafx.h”
#include “FtrGREENHOU.h”

//------ LOCAL DATA (STATIC) ------------------------------------
static LPCSTR ioNames = {
“Humidity”,
“Temperature”,
“Humidifier”,
“Ventilation”
};

//------ LOCAL FUNCTIONMS (STATIC) ------------------------------
static void CopyInputVariables(HFTRUN hftrLeft, HFTRUN hftrRight){
UINT uNumIn = ftrGetInfo(hftrRight, FTR_GETINCOUNT);
for (FTRIOI i = 0; i< (FTRIOI) uNumIn; i++){
double Value;
ftrGetShellValue(hftrRight, i, &Value, NULL);
ftrSetShellValue(hftrLeft, i, Value);
}
}

//------ IMPLEMENTATION -----------------------------------------
//constructors
CFtrGREENHOU::CFtrGREENHOU(){
m_ftrOk = FALSE;
}

CFtrGREENHOU::CFtrGREENHOU(const CFtrGREENHOU &old){
m_ftrOk = old.m_ftrOk;
m_strPathFtrFile = old.m_strPathFtrFile;
if (old.m_ftrOk){
m_ftrOk = ::ftrOpen(0, (LPSTR)(LPCTSTR)old.m_strPathFtrFile, &m_hftr);
if (m_ftrOk)
CopyInputVariables(m_hftr, old.m_hftr);
}
}

//destructor
CFtrGREENHOU::~CFtrGREENHOU(){
if (m_ftrOk)
ftrClose(m_hftr);
}

//operators
CFtrGREENHOU &CFtrGREENHOU::operator=(const CFtrGREENHOU &right){
if (this != &right){
if (m_ftrOk)
ftrClose(m_hftr);

m_ftrOk = right.m_ftrOk;
m_strPathFtrFile = right.m_strPathFtrFile;

if (right.m_ftrOk){
m_ftrOk = ::ftrOpen(0, (LPSTR)(LPCTSTR)right.m_strPathFtrFile, &m_hftr);
if (m_ftrOk)
CopyInputVariables(m_hftr, right.m_hftr);
}
}
return *this;
}

//methods
BOOL CFtrGREENHOU::ftrOpen(LPCSTR lpFtrFileName)
{
m_strPathFtrFile = lpFtrFileName;
if (m_ftrOk)
ftrClose(m_hftr);
m_ftrOk = ::ftrOpen(0, (LPSTR) lpFtrFileName, &m_hftr);
if (m_ftrOk){
CString strErr[5];
UINT uNumIn = ftrGetInfo(m_hftr, FTR_GETINCOUNT);
UINT uNumOut = ftrGetInfo(m_hftr, FTR_GETOUTCOUNT);
UINT uDataType = ftrGetInfo(m_hftr, FTR_GETDATATYPE);
if (uNumIn != 2){
strErr[1].Format(" … %u instead of %u input variables\n", 2, uNumIn);
m_ftrOk = FALSE;
}
if (uNumOut != 2){
strErr[2].Format(" … %u instead of %u output variables\n", 2, uNumOut);
m_ftrOk = FALSE;
}
if (uDataType != FTR_INFO_DOUBLE){
strErr[3] = " … i/o data type ‘double’ instead of ‘FUZZY’\n";
m_ftrOk = FALSE;
}
for (FTRIOI i = 0; m_ftrOk && i < (FTRIOI)(uNumIn+uNumOut); i++){
char chName[34];
ftrGetIONameByIndex(m_hftr, i, sizeof(chName), chName);
m_ftrOk &= lstrcmp(chName, ioNames*) == 0;*

  • if (!m_ftrOk){*
  • strErr[4] = " … different names and/or order of i/o variables\n";*
  • break;*
  • }*
  • }*
  • if (!m_ftrOk){*
  • strErr[0].Format (“The Ftrun wrapper class ‘CFtrGREENHOU’ does not match with the file ‘%s’.\n\nThe wrapper class expects…\n”, lpFtrFileName);*
  • strErr[0] += strErr[1] + strErr[2] + strErr[3] + strErr[4];*
  • strErr[0] += “\nMake sure that you are running a matching pair of wrapper class and Ftr file.”;*
  • MessageBox(NULL, strErr[0], “Ftrun Wrapper Class CFtrGREENHOU”, MB_OK|MB_TASKMODAL|MB_ICONSTOP);*
  • ftrClose(m_hftr);*
  • }*
  • }*
  • return m_ftrOk;*
    }
    void CFtrGREENHOU::SetHumidity(double Value){
  • if (m_ftrOk)*
  • ftrSetShellValue(m_hftr, 0, Value);*
    }
    double CFtrGREENHOU::GetHumidity(BOOL *pDefaultValueFlag){
  • return GetValue(0, pDefaultValueFlag);*
    }
    double CFtrGREENHOU::GetHumidity(double &RangeMin, double &RangeMax){
  • return GetValue(0, RangeMin, RangeMax);*
    }
    void CFtrGREENHOU::SetTemperature(double Value){
  • if (m_ftrOk)*
  • ftrSetShellValue(m_hftr, 1, Value);*
    }
    double CFtrGREENHOU::GetTemperature(BOOL *pDefaultValueFlag){
  • return GetValue(1, pDefaultValueFlag);*
    }
    double CFtrGREENHOU::GetTemperature(double &RangeMin, double &RangeMax){
  • return GetValue(1, RangeMin, RangeMax);*
    }
    double CFtrGREENHOU::GetHumidifier(BOOL *pDefaultValueFlag){
  • return GetValue(2, pDefaultValueFlag);*
    }
    double CFtrGREENHOU::GetHumidifier(double &RangeMin, double &RangeMax){
  • return GetValue(2, RangeMin, RangeMax);*
    }
    double CFtrGREENHOU::GetVentilation(BOOL *pDefaultValueFlag){
  • return GetValue(3, pDefaultValueFlag);*
    }
    double CFtrGREENHOU::GetVentilation(double &RangeMin, double &RangeMax){
  • return GetValue(3, RangeMin, RangeMax);*
    }
    double CFtrGREENHOU::GetValue(FTRIOI ioIndex, BOOL *pDefaultValueFlag){
    double Value;
  • if (m_ftrOk)*
  • ftrGetShellValue(m_hftr, ioIndex, &Value, pDefaultValueFlag);*
  • else*
  • Value = 0;*
  • return Value;*
    }
    double CFtrGREENHOU::GetValue(FTRIOI ioIndex, double &RangeMin, double &RangeMax){
    double Value;
    double dMin, dMax;
  • if (m_ftrOk){*
  • ftrGetShellValue(m_hftr, ioIndex, &Value, NULL);*
  • ftrGetIORange(m_hftr, ioIndex, &dMin, &dMax);*
  • RangeMin = (double) dMin;*
  • RangeMax = (double) dMax;*
  • }*
  • else*
  • Value = 0;*
  • return Value;*
    }

That's the Visual C++ one. There were others posted in http://arduino.cc/forum/index.php/topic,98623.msg739757.html#msg739757. They needed an 'ftlibc.h'.

Yes sorry. Those 4 files were all i got from the fuzzyTECH. If i have to make a library can someone guide me?

Are the rules defined in any human-readable form? The .ftr (fuzzyTech Rules?) file is a binary file so it’s not of much use outside the fuzzyTech library.

Unfortunately not.

how about if write a c program like this?
if((a>b) && (a<c) )
then (the output)
from what i learn, in fuzzy we cannot put the exact value. maybe by doing range of value (a>b) && (a<c) can show the fuzzy

SvenJagz: OK I'll post the code. [...]

You might be better off using the code as a basis for your own code, but writing it from scratch. Translating or porting code, even C++, is just trading off one problem for another.

The Fuzzytech solution just emits code that is a tree of ranges. You can easily do that yourself.

Hey,

I don't know if you're still working on your project, but the guys over at MAKEPROTO have created a system that automatically builds fuzzy systems for the arduino from MATLAB fuzzy files. C code that you drop into your Arduino sketch.

http://makeproto.com/blog/