Re: implementing matlab fuzzy logic toolbox models to microcontrollers



Hello,

You do not say it explicitly, but I assume that, if you are using a
microprocessor, you are doing some sort of control application.
If this is the case, you must have the following software modules:
1) a kernel managing all activities of the micro
2) an input task manager
3) a fuzzy inference engine
4) an output task manager
5) other, depending on your application

At
http://www.mathworks.com/access/helpdesk/help/toolbox/fuzzy/fp571.html,
"Stand-Alone C Code Fuzzy Inference Engine", you can read "In the
fuzzy/fuzzy directory of the toolbox, you can find two C files,
fismain.c and fis.c, which are provided as the source codes for a
stand-alone fuzzy inference engine. The stand-alone C code fuzzy
inference engine can read an FIS file and an input data file to perform
fuzzy inference directly, or it can be embedded in other external
applications.". They tell you how to compile the code. Then, they
tell you about the usage of this code ("Usage: fismain data_file
fis_file"). The page closes with the differences between MATLAB and
the standalone application that you create by compiling fismain.c

//////////////////////////////////////////////////////////////
///////////// START OF QUOTED TEXT ////////
//////////////////////////////////////////////////////////////
http://www.mathworks.com/access/helpdesk/help/toolbox/fuzzy/fp571.html
//////////////////////////////////////////////////////////////
"There are several things you should know about this stand-alone
executable:
It is ANSI C compatible.
Customized functions are not allowed in the stand-alone executable, so
you are limited to the 11 membership functions that come with the
toolbox, as well as other factory settings for AND, OR, IMP, and AGG
functions.
fismain.c contains only the main() function and it is heavily
documented for easy adaptation to other applications.
To add a new membership function or new reasoning mechanism into the
stand-alone code, you need to change the file fis.c, which contains all
the necessary functions to perform the fuzzy inference process."

//////////////////////////////////////////////////////////////
///////////// END OF QUOTED TEXT ///////////
//////////////////////////////////////////////////////////////

If you look at the source code you realize that in most cases
it will need to be changed quite a bit to fit into an 8-bit or 16-bit
microprocessor with limited on-chip memory. At this point, probably,
the effort of customizing the existing, MATLAB provided, source
code, will be comparable to designing, coding, and testing your
own inference engine. Of course the work with MATLAB will not
be wasted. First, by using MATLAB, you will have modeled your
fuzzy logic algorithm, you will have checked carefully the output
surfaces for each couple of inputs. Second, probably you will
have used Simulink to simulate your entire system, including
the non fuzzy parts. From your MATLAB work, you can read
all the information about the input variables & output variables
membership functions, the fuzzification & defuzzification
algorithms employed, and the rule evaluation block, and you
will be able to code it, optimized for your microprocessor.

I would suggest that, instead of C you use C++ that normally
results in less embedded code to be stored in firmware. Often
the difference between C and C++ is the difference between
having to use an external (E)PROM and just the on-chip
EPROM/Flash.

Of course, if you tell us more, we (either I or somebody else)
could advice you in a more practical way. For instance, why
don't you post your *.fis file or files? It makes quite a bit of
difference to know how complex or not complex things are.
Also, if you have a design spec of what you are doing,
why don't you post it? If this is part of a thesis, why don't
you post the general description of what you are doing. If
you want to get help, you must put people in a position
to help you. The longer number of responses that you got
depends in part on the scarcity of details that you provided.
The other factor is the fact that in the Northern emisphere
this is top vacation time.

Best regards

Bruno Di Stefano

PS
==
By the way, if you live within driving distance from Toronto
(Ontario, Canada), you may consider attending the technical
talks of the local CIS chapter of the IEEE. I am the chapter
chair (http://toronto.ieee.ca/chapters/s_ci.htm ).
I organise a number of technical talks every year. You may
come to the meetings, network after the meetings, and discuss
your work with others. You will find that a lot of people are
willing to pull out paper and pencil and explain things. If you
are elsewhere, let us know where you are and I can check
if there is a CIS chapter in your area.

I will cross-post this answer to the Google Fuzzy Logic
Newsgroup. See:
- http://groups.google.com/
- http://groups.google.com/group/fuzzy

I suggest that you post your messages related to Fuzzy
Logic also on the Fuzzy Logic Google Group,
http://groups.google.com/group/fuzzy. It is a moderated
newsgroup without the spam that normally characterizes
the USENET newgroups. There is a small audience, but
they are all professionals & academics. I suggest that
you post all future messages of this type also on
http://groups.google.com/group/fuzzy
You can also e-mail your posting to fuzzy@xxxxxxxxxxxxxxxx

--
-- Bruno Di Stefano
---------------------------------------------------------------------------------------
b.distefano@xxxxxxxx
Bruno.DiStefano@xxxxxxxxx
http://bruno.distefano.googlepages.com/home
nuptek@xxxxxxxxxxxx www3.sympatico.ca/nuptek


Zubair wrote:
hello again,

I am interested in designing and implementing the fuzzy system on a
micro-controller such as Atmel or AVRs. I am doing the designing of a
charge controller (for pv arrays), so the micro-controller will be
dealing with inputs from ADCs and outputs to DACs. I am a student so
there are real secrects to hide, infact i would love if someone comes
and works with me or atleast help me :)

I have designed the system in MATLAB fuzzy toolbox, and it is working
great. Somewhere i have read about the implementation of the matlab
fuzzy system in C.

If you go into the matlab\toolbox\fuzzy\fuzzy directory, you will find
two files; names are probably fis.h
and fismain.c (find the two files.. one is .h and other is .c).
As you were talking about finding the class implementation of fuzzy in
c, so matlab has provided. But there is the problem of mapping inputs
and outputs of the microcontroller to this class. Is there any way
out???

So precisely speaking, i need to convert that matlab model to C, and
then make it compatible to work with my microcontroller (Atmel 8052
most probably)!



regards
zubair

--
-- Bruno Di Stefano
---------------------------------------------------------------------------------------
b.distefano@xxxxxxxx
Bruno.DiStefano@xxxxxxxxx
http://bruno.distefano.googlepages.com/home
nuptek@xxxxxxxxxxxx www3.sympatico.ca/nuptek

.



Relevant Pages

  • Comunication Between fuzzy toolbox and c#
    ... i create a dll with matlab combuilder. ... in this file i use a "FIS" file for fuzzy logic purpose. ... and i read all of matlab compiler document. ...
    (comp.soft-sys.matlab)
  • A BIG PROBLEM FOR ME!!!
    ... i create a dll with matlab combuilder. ... in this file i use a "FIS" file for fuzzy logic purpose. ... and i read all of matlab compiler document. ...
    (comp.soft-sys.matlab)
  • Comunication Between fuzzy toolbox and c#
    ... i create a dll with matlab combuilder. ... in this file i use a "FIS" file for fuzzy logic purpose. ... and i read all of matlab compiler document. ...
    (comp.soft-sys.matlab)
  • Comunication Between fuzzy toolbox and c#
    ... i create a dll with matlab combuilder. ... in this file i use a "FIS" file for fuzzy logic purpose. ... and i read all of matlab compiler document. ...
    (comp.soft-sys.matlab)
  • Comunication Between fuzzy toolbox and c#
    ... i create a dll with matlab combuilder. ... in this file i use a "FIS" file for fuzzy logic purpose. ... and i read all of matlab compiler document. ...
    (comp.soft-sys.matlab)