Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

single water tank using Fuzzy PID

Status
Not open for further replies.
Ron or carl
Is the VB6 can direct burn the coding inside the PIC(i have no experience for VB6)?can u guy give some example coding about fuzzy PID? cause i had no idea how to write a program which contain fuzzy PID characteristics.

No, VB6 or any form of Microsoft Visual Basic is not used with PICs.

To program a PIC you would use a language designed for a PIC. PIC Basic is one of several. PIC Basic is not the same as or anything like Visual Basic.

Now from the beginning. Your assignment is to design a system to maintain a water level in a tank correct? I assume this is just a school assignment. As water flows out of the tank at different rates you need to add water to the tank.

So, you will need a sensor to measure the level of water in the tank. There is likely a dozen ways to do this. You can do as Carl suggested and place three sensors (maybe conductive probes) at three levels in the tank as low, medium and high. You can use a pressure sensor as I suggest at the bottom of the tank and measure pressure or as stranor points out you can use a ultrasonic sensor at the top of the tank that measures the distance between the sensor and water level. Those are just three possibles. Stranor introduced a new method.

The sensor used will output a signal. That signal will be proportional to the water level in the tank. It can be Carl's method giving a 1 or 0 for each level or it can be an analog signal like a voltage or current. This all depends on the sensor used. If you are the project engineer you make the decision based on cost, environment, equipment and a collection of variables. The end result is the output of the sensor(s) will provide a signal directly proportional to the water level in the tank. The signal may or may not require signal conditioning.

Later I will continue with a full example. Just remember you need to start at the beginning. :)

Ron
 
Continued.... :)

The following will be US measurements as I am not about to do the conversions. Using a pressure sensor. One PSI = 27.27 inches of water column. Lets say my tank is 60 inches tall so a full tank = 60 / 27.27 = 2.2 PSI of pressure. A logical choice would be a 3 PSI pressure sensor. Since my first choice is to use a PID with a 0 to 5 volt ADC input pin I want my pressure transducer to output 0 to 5 volts for 0 to 3 PSI. If my PIC is an 8 bit ADC then I have 0 to 5 volts = 0 to 255 counts. That works out to be 85 counts per PSI. However, I will never exceed 2.2 PSI for my tank or 2.2 * 85 = 187 counts.

My PIC will have one ADC input and three DIO outputs.

From there you write your program code. As Carl mentioned the code for fuzzy logic would consist of mostly IF statements.

If analog input <= 150 then
Out1 = 1
If analog input <=100 then
Out1 & Out2 = 1

Get the idea? That is not code but a general idea.

Ron
 
I use one of these almost every time I install or replace an ultrasonic sensor. I like them because they are super easy to calibrate, have 0-10V and 4-20mA output and they are easily wired for inverse output. Also I have never had one go bad. They are pricey though; not a problem for me because my company pays, but I assume you are on a student budget. You could find a cheaper sensor that does the same thing on ebay or one of the "maker"-type hobby websites.
 
Last edited:
Ron
about the coding. Is it not need to calculate the plant(transfer function) and put the result inside the coding? just use IF statements?I'm confuse on that problem.
 
All you are doing in the code is telling the PIC what to do. For example you have a PIC with 1 AnalogInput and 3 DigitalOut pins. A voltage between 0 and 5 volts is supplied to the PIC AnalogInput. That voltage is proportional to the level of water in the tank. The voltage is represented by bits. If for example the PIC has an 8 bit ADC (Analog to Digital Converter) then 0 to 5 volts in equals 0 to 255 counts. What I gave you above is a very, very generic example of what the code would resemble. If you go about this project using a PIC you will need to learn some programming language to program the PIC. There are several family's of PICs out there to choose from and several programming languages that can be used with them. You need to get with your teacher and see exactly what they expect from you.

This project could also be built using discrete comparator ICs and no programming. It's a matter of what you want or the teacher expects.

Ron
 
carl
// Fuzzy PID example code

// 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 );
}
this one i get from internet. why it different from your one?
 
I didn't show you any code, just a suggestion on using Fuzzy Logic.

I don't really understand your posted code. I'm not that familiar with the C language.
 
Status
Not open for further replies.

Latest threads

Back
Top