This is my first 'big' mbed program so far, it is an implementation of fuzzy logic, the main.cpp is kind off a debugging program, to show how it works, I still have planned some enhancements, but any comment is well recieved, i\'m still learning What i'm looking forward in publishing this, is ways to improve the code, some general advices that may help write better code. Any comment post it here: http://mbed.org/users/Yo_Robot/notebook/fuzzy_logic/

Dependencies:   mbed

Committer:
Yo_Robot
Date:
Sun Mar 20 04:20:47 2011 +0000
Revision:
0:252f423535e5
v0.1 - still under test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yo_Robot 0:252f423535e5 1 #include "mbed.h"
Yo_Robot 0:252f423535e5 2
Yo_Robot 0:252f423535e5 3 /* ===================- STRUCTURES -=========================================== */
Yo_Robot 0:252f423535e5 4
Yo_Robot 0:252f423535e5 5 struct limitStr /* Limits of each Fuzzy Member */
Yo_Robot 0:252f423535e5 6 {
Yo_Robot 0:252f423535e5 7 float low_; /* Lower limit of the Member /\ */
Yo_Robot 0:252f423535e5 8 float mid_; /* Center of the Member / \ */
Yo_Robot 0:252f423535e5 9 float high_; /* Higher limit of the Member / | \ */
Yo_Robot 0:252f423535e5 10 /* low / mid \ high */
Yo_Robot 0:252f423535e5 11 }; /* */
Yo_Robot 0:252f423535e5 12 /* */
Yo_Robot 0:252f423535e5 13 struct areaStr
Yo_Robot 0:252f423535e5 14 {
Yo_Robot 0:252f423535e5 15 float left_; /* values of the areas of each member */
Yo_Robot 0:252f423535e5 16 float center_;
Yo_Robot 0:252f423535e5 17 float right_;
Yo_Robot 0:252f423535e5 18 };
Yo_Robot 0:252f423535e5 19
Yo_Robot 0:252f423535e5 20 enum limitEnum // public enum constructor
Yo_Robot 0:252f423535e5 21 {
Yo_Robot 0:252f423535e5 22 limit_low1,
Yo_Robot 0:252f423535e5 23 limit_mid1,
Yo_Robot 0:252f423535e5 24 limit_low2,
Yo_Robot 0:252f423535e5 25 limit_mid2,
Yo_Robot 0:252f423535e5 26 limit_high
Yo_Robot 0:252f423535e5 27 };
Yo_Robot 0:252f423535e5 28
Yo_Robot 0:252f423535e5 29 /* ===================- FUZZY CLASS -=========================================== */
Yo_Robot 0:252f423535e5 30 class Fuzzy
Yo_Robot 0:252f423535e5 31 {
Yo_Robot 0:252f423535e5 32 public:
Yo_Robot 0:252f423535e5 33
Yo_Robot 0:252f423535e5 34 void setMember( float low1, float mid1, float low2, float mid2, float hi );
Yo_Robot 0:252f423535e5 35 limitEnum limit; // Enumerated names of the limits
Yo_Robot 0:252f423535e5 36 float read( limitEnum element );
Yo_Robot 0:252f423535e5 37 float getValue ( float x, Fuzzy Output );
Yo_Robot 0:252f423535e5 38 float getValue ( float x, float y, Fuzzy memberX, Fuzzy memberY, Fuzzy output );
Yo_Robot 0:252f423535e5 39 void printArt();
Yo_Robot 0:252f423535e5 40
Yo_Robot 0:252f423535e5 41 private:
Yo_Robot 0:252f423535e5 42
Yo_Robot 0:252f423535e5 43 limitStr left, center, right; // Holds the values
Yo_Robot 0:252f423535e5 44 areaStr Area; //
Yo_Robot 0:252f423535e5 45
Yo_Robot 0:252f423535e5 46 float fuzz( float value, limitStr member );
Yo_Robot 0:252f423535e5 47 /* ****************************************************************************** *
Yo_Robot 0:252f423535e5 48 * Fuzzifier (Fusificador): *
Yo_Robot 0:252f423535e5 49 * This Function calculates the degree of membership of the 'value' passed in the *
Yo_Robot 0:252f423535e5 50 * 'member' function it belongs to. *
Yo_Robot 0:252f423535e5 51 * *
Yo_Robot 0:252f423535e5 52 * 'value' = any float form 'low1' to 'hi' of that particular member *
Yo_Robot 0:252f423535e5 53 * ****************************************************************************** */
Yo_Robot 0:252f423535e5 54
Yo_Robot 0:252f423535e5 55 float min( float x1, float x2 );
Yo_Robot 0:252f423535e5 56 /* *************************************************************************** *
Yo_Robot 0:252f423535e5 57 * Calculates the minimum value of the two arguments *
Yo_Robot 0:252f423535e5 58 * *************************************************************************** */
Yo_Robot 0:252f423535e5 59
Yo_Robot 0:252f423535e5 60 float max( float x1, float x2, float x3 );
Yo_Robot 0:252f423535e5 61 /* *************************************************************************** *
Yo_Robot 0:252f423535e5 62 * Calculates the maximum value of the three arguments *
Yo_Robot 0:252f423535e5 63 * *************************************************************************** */
Yo_Robot 0:252f423535e5 64
Yo_Robot 0:252f423535e5 65 void calculateArea( float n, float z, float p , Fuzzy Output );
Yo_Robot 0:252f423535e5 66 /* *************************************************************************** *
Yo_Robot 0:252f423535e5 67 * Calculates the area of the given value to the Output Membership *
Yo_Robot 0:252f423535e5 68 * 'n' Negative Function
Yo_Robot 0:252f423535e5 69 * 'z' Zero Function
Yo_Robot 0:252f423535e5 70 * 'p' Positive Function
Yo_Robot 0:252f423535e5 71 * *************************************************************************** */
Yo_Robot 0:252f423535e5 72
Yo_Robot 0:252f423535e5 73 float defuzz( Fuzzy Output );
Yo_Robot 0:252f423535e5 74 /* *************************************************************************** *
Yo_Robot 0:252f423535e5 75 * This function calculates the final output to return, The object already *
Yo_Robot 0:252f423535e5 76 * the values defined, it needs an Oputput membership to generate a return *
Yo_Robot 0:252f423535e5 77 * value *
Yo_Robot 0:252f423535e5 78 * *************************************************************************** */
Yo_Robot 0:252f423535e5 79 };