CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

single water tank using Fuzzy PID

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Whc



Joined: 19 Sep 2011
Posts: 3

View user's profile Send private message

single water tank using Fuzzy PID
PostPosted: Mon Sep 19, 2011 6:24 am     Reply with quote

i'm doing a prototype project. Do you guys know how to program the fuzzy PID to the water flow to the tank depend to the water level in the tank. Is urgent. Can u guys give me a similar coding. so that i can study. Thx
Whc



Joined: 19 Sep 2011
Posts: 3

View user's profile Send private message

PostPosted: Mon Sep 19, 2011 6:30 am     Reply with quote

// Define rule base
struct rule_set {
float lowlimit; // low limit, membership 0.0
float highlimit; // high limit, membership 1.0
float weighting; // weighting factor for inference combination
} ;
typedef struct rule_set rule;

// Membership bounds on input and output levels
#define P_LIMIT 20000.0
#define I_LIMIT 400000.0
#define D_LIMIT 5000.0
#define O_LIMIT 20000.0

// Weighting factors for inference
#define P_RULE_WEIGHT 10.000
#define I_RULE_WEIGHT 0.040
#define D_RULE_WEIGHT 0.120

static rule P_rule = { -P_LIMIT, P_LIMIT, P_RULE_WEIGHT };
static rule I_rule = { -I_LIMIT, I_LIMIT, I_RULE_WEIGHT };
static rule D_rule = { -D_LIMIT, D_LIMIT, D_RULE_WEIGHT };
static rule O_rule = { -O_LIMIT, O_LIMIT, 1.0f };

// Evaluate "is member" and "is not member" of input value, given rule
// to apply. Accumulates results with previous results. Takes advantage
// of special complementation properties of this rule set.
void evaluate_support(
float variable, rule *pRule, float *isMember, float *isNotMember )
{
float in_set;
if ( variable >= pRule->highlimit )
in_set = 1.0;
else if ( variable <= pRule->lowlimit )
in_set = 0.0;
else
in_set = (variable - pRule->lowlimit) /
(pRule->highlimit - pRule->lowlimit);
*isMember += in_set * pRule->weighting ;
*isNotMember += (1.0 - in_set) * pRule->weighting ;
}

// Normalize and evaluate output
float defuzzify( rule *pRule, float isMember, float isNotMember )
{
float output;
output = (isMember * pRule->highlimit) + (isNotMember * pRule->lowlimit);
if (output>pRule->highlimit) output=pRule->highlimit;
if (output>pRule->lowlimit) output=pRule->lowlimit;
return output;
}

float compute_fuzzy_PID ( float Err, float AccumErr, float Speed )
{
float isMember = 0.0;
float isNotMember = 0.0;
evaluate_support( Err, &P_rule, &isMember, &isNotMember );
evaluate_support( AccumErr, &I_rule, &isMember, &isNotMember );
evaluate_support( Speed, &D_rule, &isMember, &isNotMember );
return defuzzify( &O_rule, isMember, isNotMember );
}
i get the coding but dont understand.Can someone explain to me?thx.
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 19, 2011 1:24 pm     Reply with quote

I gave up on 'fuzzy' logic over 20 years ago once I found how to get Matlab's 'Simulink' to run in true realtime. Since then I've never seen a fuzzy PID controller that had better response(speed and/or accuracy) that a properly tuned analog PID controller.The test was to control a 3DOF helicopter via the Net in realtime with 2 other applications open and running.

The 'fuzzy' concept is just that 'fuzzy',nothing more than a HUGE collection of if-then-else statements tested one after another after another ad naueum.... Microchip does have some good(?) examples of it
in the embedded applications handbook(1st or 2nd edition ?).

The classic example is in home heating..again..a series of if..then..else statements.Find one of them..your water tank level is very, very similar,easy enough to modify.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Sep 19, 2011 3:42 pm     Reply with quote

I thought the fuzzy logic fad passed a few years (many software generations) ago. Is there some outdated spec that reqires you to use fuzzy logic? It is like requiring you to use object oriented programming. That fad is getting a little long in the tooth too.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Whc



Joined: 19 Sep 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Sep 20, 2011 4:34 am     Reply with quote

is it use series if else can get similar result with fuzzy PID coding(posted)?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group