Identify Autotune PID algorithm

Go To Last Post
78 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Edit: Noticed this strange relation between Detla controller PID values, not sure why is that so?

All calculated values of P are:

P = 2*[(+peak)  - (-peak) ]    i.e twice of difference between max and min values.

 

 

This holds true for all the graphs in post#50.

Delta PID controller have WPM timer period set = 20 seconds, tommorow will do more test on different times like 10,5,2 etc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

 

Maybe get a really good PID reference like:

https://books.google.com/books?id=edCcDwAAQBAJ&pg=PA99&lpg=PA99&dq=Magnitude+Optimum+Multiple+Integration+(MOMI)%E2%80%9D+method&source=bl&ots=1plDKLj0q_&sig=ACfU3U09-plKEJtGdea3enVV6ht1k7YhOA&hl=en&sa=X&ved=2ahUKEwi2pfXc4KnpAhWQbc0KHQzbDqwQ6AEwBnoECAkQAQ#v=onepage&q=Magnitude%20Optimum%20Multiple%20Integration%20(MOMI)%E2%80%9D%20method&f=false

 

Also, I found another source (different than above link), that gives all the calculations for the following auto tune diagram...however they do calculations quite differently to get the final PID values.  however, they give a long explanation of how they do it with an example.

This is the diagram they calculate from:

 

 

Is your " (an)other source (different than above link)" a secret?

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like in large oven, our formula some how fails.

Do you know what they do with the PID values?  Since the output is always full on/off it can only be emulating PID..are you assuming (or do you know) the PID is being converted to PWM?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Since the output is always full on/off it can only be emulating PID
54 posts and am I the only one who gets it?  The bang-bang approach is only used during the auto-tune phase.  Once PID values are derived, surely the system operates via PWM or similar.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once PID values are derived, surely the system operates via PWM or similar

That's a question...what does it do to get from PID values to its output since it can only be on/off...so any calcs are then transformed by some unstated method to some form of on/off. 

It's likely to be a simple linear conversion to duty cycle, but might have other factors, even stepping based on some discrete thresholds of some sort, possibly adding hysteresis, deadbands, etc. 

Any of these would  be part of the control "calcs".

Since the output is always full on/off it can only be emulating PID

I think this is a correct interpretation, if they are using a solid state relay.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. May 11, 2020 - 09:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ joeymorin yes, during autotuning it follow relay method( as pointed by @ N.Winterbottom ), once its done it gives variable PWM cycle and then maintain temperature to +-1C for heating.

 

We tested on 10second pulse also, proportional band still holds this formula for 2*[(+peak) - (-peak)]

i.e if during second cycle of tuning, max temerature goes to 94C & min is 87C, then P = 2[94-87] = 14

 

Although we are calcuating by Ku=4*d/(pi * a)

Today will try with our formula & check how far we are.

meanwhile sideways also try to understand abt Delta PID algorithm.

 

@ avrcandies can you point to your other source, might be this is what is being used in Delta controller PID?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



 once its done it gives variable PWM cycle 

Examin that in detail to determine exactly (mathematically) what it is outputting.  For example, it might display numbers scaled differently than some other system does. For all you know it could take the PID numbers, calc, apply them to some fuzzy logic & then you see some on/off patten coming out to drive the heating.   More than likely, it just varies the duty cycle linearly, but that is somewhat guessing as to what probably does. 

-------------

You need to find the article by 

It shows calculations and has many details.  Temperature Control in a Plastic Extruder Control System

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely you are "close enough" with your understanding of the Delta Electronics controller by now. You are probably wasting time now trying to exactly match the Pb, Ti, Td calculated by their PID Autotuner. Especially as you/we don't know the inner details of their PID controller algorithm, or any tweaks they may do to improve performance in a particular area.

 

I've forgotten what exactly the scope of your project is. Please re-iterate.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ N.Winterbottom

You are right , and i said in post#57 now i am trying to write PWM algo to maintain temperature with whatever we are getting at the moment. 

This is very good implementation with some improvement also mentioned.

Will see if i am able to maintain temperature.

 

1. First PID values are calculated manually & PWM algo is implemented to see how far i am to maintain temperature.

2. Once step 1 is succesful, write autotune code in c also 

 

Meanwhile will also try to test other PID controllers from OMRON also.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I tried to write code for calculating the output 0 to 100% from below function, but value is always greater than 100 to system is always clampled and high.

The code of lots of tweaks as mentioned in this blog:  http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/  

so its not only Kp,Ki ,kd multiplaction with error.

 

 

 

 

const float32_t c_output_max = 100.0f;
const float32_t c_output_min = 0.0f;

float32_t input_temperature;
float32_t setpoint_temperature;
float32_t output_duty_cycle;

float32_t i_term;
float32_t last_input;

//ku = 12.60633212609071966486208026713f;   units: per degree celsius
//tu = 820  seconds
float32_t kp = 7.563799f;   //kp = 0.6*Ku
float32_t ki = 0.018448f;  // ki = 1.2*Ku/Tu
float32_t kd = 775.289425f;    // ki = 0.075*Ku*Tu


float32_t sample_time = 1.0f;  // 1 second


//sample_time + derivative_kick + On-The-Fly Tuning Changes + integral windup +
void compute_pid_duty_cycle(void)
{  
    float32_t error;
    float32_t d_input;

    /* get error */    
    error = setpoint_temperature - input_temperature;

    /* integral error */
    i_term = i_term + (error * ki);
    if(i_term > c_output_max)
    {
        i_term = c_output_max;
    }    
    else if(i_term < c_output_min)
    {
        i_term = c_output_min;
    }    
    else
    {
    }    
        

/* differential error */    
    d_input = input_temperature - last_input;

/*Compute PID Output*/
    output_duty_cycle = (kp * error) + (i_term) - (kd * d_input);
    if(output_duty_cycle > c_output_max)
    {
        output_duty_cycle = c_output_max;
    }    
    else if(output_duty_cycle < c_output_min)
    {
        output_duty_cycle = c_output_min;
    }    
    else
    {
    }        

    /*Remember some variables for next time*/
    last_input = input_temperature;
    
} /* function ends here */

 

 

Parallel we have tested on another advanced Delta PID DTC1000, and below are tuning results.

Ti & Td match exactly as from DElta electronics PID now.

I was reading Pb is actual proportional band and not proportional gain Kp.

I am reading more on it how to calculate.

 

Another thing is this "I offset" which also calculate after autotuning, dont know what it is.

This Pb gives from 0 to 100%.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You will have a very long road if you are doing all this coding & hoping to simply compare waveforms.

Just one number or implementation differing slightly & means the switching cycle will differ a slight bit, which will propagate into the next cycle & cascade/buildup & effect the next cycle.

 

If you compare raindrops falling in two areas of the field you might say these waveforms of raindrops barely match at all, yet the same amount of rain fell in both areas & were delivered from the same cloud.

 

Ultimately, you just want to ensure that the temperature is maintained to your satisfaction....but it is not apparent you have defined what satisfactory is!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ avrcandies , I wrote code with whatever values of Kp,Ki and Kd we are getting. Issue is its always clampled to 100%.

Need to normalize this output in range 0-100%. Dont understand how to do it.

 

need to maintain temperature within +-1%.

Edit: First goal now is to get this running and see what we will get.

 

 

 

This Delta PID test is entirely separate, just to understand what is being done., Thats why in my post I wrote parallel.

 

 

 

Last Edited: Thu. May 14, 2020 - 03:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Need to normalize this output in range 0-100%. Dont understand how to do it.

The output stage is like a gas pedal, the PID makes it press more or less.  You might have some system where 0 to 25 driver input volts means zero to full power, some other system might use 0 to 4V, or 0 to 1V.   The PID adjusts itself & also the tuning takes into account the range (the pid values are just 3 more gain settings).  Of course all that means nothing if the output can only turn on/off....so you fake it using percent on.....for example, you might set it so a value of 5 means full on 100% of the time, then 2.5 cycles on/off 50% of the time, 1 means it's on 20% & off 80%...the freq is typically "slow", depending on the system (in some cases might want faster).  Or you might set things so 1 means on 100%.   The doesn't matter, per se,, it will just affect the scaling of the PID values---they work together to give the desired output.

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. May 14, 2020 - 06:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ avrcandies " The PID adjusts itself & also the tuning takes into account the range (the pid values are just 3 more gain settings).  "

 

This is not happening, my PID out is always more than 100 seems like.

We are keeping 5 second pulse, so if 100% pid output, then full 5 seconds on, 50% PID outout means 2.5second ssr on and 2.5second ssr off.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the temperature keeps climbing due to the heater being on all the time (too much), then the integrator term (too hot) will build & build towards infinity until you pass your turn off threshold...so it will turn off at some point, even if badly adjusted or your scaling is messed up.

You do have to have numeric polarities correct...if too hot it must turn off, if too cold turn must turn on.  If backwards it will lock up (you have positive feedback, want negative).    If you are driving too slow & get further off the gas you will go slower & get more off the gas & go slower yet....that is a backwards polarity.  Likewise, if you go too fast and apply more gas you go faster and apply more gas & crash.

  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Have written below code, but outout is very fluctating and then clamped to either zero or highest.

This is general three gains Kp, Ki and Kd.

 

I think one reason might be: dimensions dont match on both sides . Though i am not sure of this.

 

1. kp has unit : (change in output)/celsius.

since Kp is proportional to D/A  , where D= change in output which we take 0 to 100, since its relay method.

A= change in temperature.

 

2. ki = 1.2*Ku/Tu  so its units: (change in output)/(celsius * second).

 

3. ki = 0.075*Ku*Tu  so its units: (change in output * second)/(celsius).

4.While on left of equation , which is outout it is dimension less or percentage



I have checked another PID controller from another company they also used porportional band, ; https://web-material3.yokogawa.c...

 

But i dont get how to caculate it.

 

Defination sats: " It is amount of change in input (or deviation), as a percent of span, required to cause the control output to change from 0% to 100% "

For example in our test, with set point 70C, max goes to 78.6, minimum goes to 69.0, 

sensor span is -200C to  + 600C

How to calculate it? 

is it : (78.6-69.0)*100/(600+200C)  ??

 

 

 

void compute_pid_duty_cycle(void)
{  
    float32_t error;
    float32_t temp_integral;
    float32_t derivative;

/* get error */    
    error = setpoint_temperature - input_temperature;
    
    if(first_time)
    {
        first_time = 0U;
        previous_err = error;
    }    

/* integral error */
    integral = integral + error;   //dt = 1sec
    temp_integral = integral * ki;  
    
    if(temp_integral > c_output_max)  //integral windup up
    {
        temp_integral = c_output_max;
    }    
    else if(temp_integral < c_output_min)
    {
        temp_integral = c_output_min;
    }    
    else
    {
    }  

/* differential error */  
    derivative = error - previous_err;     //dt = 1seconds

/* Compute PID Output */
    output_duty_cycle = (kp * error) + (temp_integral) + (kd * derivative);
    if(output_duty_cycle > c_output_max)
    {
        output_duty_cycle = c_output_max;
    }    
    else if(output_duty_cycle < c_output_min)
    {
        output_duty_cycle = c_output_min;
    }    
    else
    {
    }        

/* Remember some variables for next time */
    previous_err = error;
    
} /* function ends here */

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Meanwhile will also try to test other PID controllers from OMRON also.

WHY??? You are supposed to be spending your time  making your controller work....Are you pretending to be quality control for Omron?   Just making your own control system work well seems to be enough of a task.

PID has been around for a long time, since opamps.  WIth a processor, you do not even need PID to control temperature, there are many ways to do it.

 

sensor span is -200C to  + 600C

How to calculate it? 

is it : (78.6-69.0)*100/(600+200C)  ??

After 67 posts now you say you're not sure about reading the sensor?  How much time is wasted!!.. Did you not verify the temperature readings before you started?

 

Now ask yourself why do you need to make this control in the first place?...can you just use the one(s) you have? 

 

Have written below code, but outout is very fluctating and then clamped to either zero or highest.

That means very little...what does the final temperature look like? Why forget to post your results??  

Turn your KD down to zero & make your KI very small...what temperature do you get 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. May 16, 2020 - 04:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


@ avrcandies 1. By reading different established products just trying to see what they are working on, almost all on them have Proprotional band , intergral time and derivative time

Parallel we are trying to get our code working with calculated values of Kp,Ki & Kd.

 

 

 

2. I know how to read temperature sensor reading, this is how to calculate proportional band. Different pdf give different answers on this.

Kp, proportional gains is know how to calculate.

 

 

3. I have kept set point at 40C, and sensor is connected, right now its not in oven, so reading only room temperature.

compute_pid_duty_cycle() is called every 1 second, and output is limited to -100 to +100. 

Since sensor is reading room temperature, so error is almost same. I recorded 100 reading and check "error" is same alsmost, while "output_duty_cycle" pid duty cycle vary a lot from 10% to 100% almost.

 

 

 

 

void compute_pid_duty_cycle(void)
{  
    float32_t error;
    float32_t temp_integral;
    float32_t derivative;

/* get error */    
    error = setpoint_temperature - input_temperature;
    
    if(first_time)
    {
        first_time = 0U;
        previous_err = error;
    }    

/* integral error */
    integral = integral + error;   //dt = 1sec
    temp_integral = integral * ki;  
    
    if(temp_integral > c_output_max)  //integral windup up
    {
        temp_integral = c_output_max;
    }    
    else if(temp_integral < c_output_min)
    {
        temp_integral = c_output_min;
    }    
    else
    {
    }  

/* differential error */  
    derivative = error - previous_err;     //dt = 1seconds

/* Compute PID Output */
    output_duty_cycle = (kp * error) + (temp_integral) + (kd * derivative);
    
    
    if(output_duty_cycle > c_output_max)
    {
        output_duty_cycle = c_output_max;
    }    
    else if(output_duty_cycle < c_output_min)
    {
        output_duty_cycle = c_output_min;
    }    
    else
    {
    }        

/* Remember some variables for next time */
    previous_err = error;
    
} /* function ends here */

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Proportional mean just what it says, proportional.

 

example:  Vout=300*err     the controller output is 300 time the present error, it is proportional

 

If the max 100% useable/allowable, Vout is 600, then err has a max allowable of 2

Or you could just talk about percentage out:   Vout (%) = 100/2 * err       so P=proportional band = 2

 

So looking at PWM  600V =100% PWM on at err=2

                

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I think you're getting confused by textbook examples versus real world practical examples of temperature controller.

 

In your post #31 you attached:

Resumo Alargado - Auto-tuning de Controladores PID pelo método Relay.pdf

In that, the author provides the discrete or digital form for PID:

Notice he calculates the differential using y which I think is the measured process value not the error.

 

Notice also, there is a Kp factor around each term. This effectively results in a Kp factor around the whole controller.

 

In my #24 I referred to the Wikipedia article: https://en.wikipedia.org/wiki/PID_controller . In that same article I find a section titled "Reciprocal gain, a.k.a. proportional band"

 

I shall copy & paste:

Reciprocal gain, a.k.a. proportional band

In many cases, the manipulated variable output by the PID controller is a dimensionless fraction between 0 and 100% of some maximum possible value, and the translation into real units (such as pumping rate or watts of heater power) is outside the PID controller. The process variable, however, is in dimensioned units such as temperature. It is common in this case to express the gain Kp not as "output per degree", but rather in the reciprocal form of a proportional band 100 / Kp, which is "degrees per full output": the range over which the output changes from 0 to 1 (0% to 100%). Beyond this range, the output is saturated, full-off or full-on. The narrower this band, the higher the proportional gain

I think this goes a long way to explain your problems.

 

BTW: A cycle time of 1s seems very fast for a standard temperature control loop. 10 or 20s seems more reasonable. Having said that; I have seen a 1s cycle time controller but that was on a laboratory temperature bath; a precision piece of equipment holding temperature to within 0.02°C. Obviously a specialised controller was used here.

 

 

Last Edited: Sun. May 17, 2020 - 09:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ N.Winterbottom You right,  lot of diff in textbook examples and real world practical examples. :)

1. why y(n) - y(n-1) is taken rather than error, here it is explained:  http://brettbeauregard.com/blog/2011/04/improving-the-beginner%e2%80%99s-pid-derivative-kick/

2. Kp factor with each term is there as it should be since ki=Kp/Ti & kd=KdTd

3. The wikipedia article is true when only P is used, so it mentions Pb=100/Kp

4. In most of reputed brand PID controller Delta, Omron and many others: they all have:

a) Pb with range : 0.1 to 999.9

b) Ti

c) Td

d) Some have offset also 

 

trying to figure this out.

 

We aredoing sampling every 1 second, store it in array for 10 samples i.e 10seconds, then avg it & then update the PWM width of10seconds. 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't get too hung up on the names or scaling, you simply have 3 weighted adjustments (variables) to make

 

For example, either of these can give the EXACT same effect

Y =Ae+Be+Ce           A=2, B=3,  C=4

Y= ABCe+BCe+Ce     C=4, B=3/4, A=2/3  

 

You simply have a certain amount of proportional gain, integral gain and derivative gain added together, perhaps with some filtering & limiting.

Why do you keep messing with PID, you can do a lot of other ways more effectively. Since you have a processor rather than fixed PID circuitry, you can make it adaptive to the situation.

 

https://www.sciencedirect.com/science/article/pii/S147466701641476X

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. May 17, 2020 - 04:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I want to understand what is proportional band in PID context?

We did some PID tuning test from Delta Electronics temperature controller, and after a test,  it gives Pb = 40 , Ti = 302 & Td=75

Pb has unit of degree as per manual.

 

So what does it mean that suppose at any given point, set point is 100C.

So PID formula will only apply during (100 - (40/2))  to (100 + (40/2))  . i.e 80C to 120C.

 

If measured temperature is current below 80C, then output is 100% on & if above 120C then output is off completey?

Is this it means?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

proportional band is defined as the amount of change in the controlled variable required to drive the loop output from 0 to 100%.    

We did some PID tuning test from Delta Electronic

So what, WHO CARES?  You seem to be going nowhere---are you having good luck when you run your program? How well does it perform?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

posted results in post #69.

PWM keeps on varying very significantly.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

posted results in post #69.

PWM keeps on varying very significantly.

You fail to show a graph of your temperature results--why?  Do it for several adjustments...what do you see.  Keep the derivative term low, add just a little integral....what do you get as a temperature result? 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. May 19, 2020 - 10:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
/* Compute PID Output */
    output_duty_cycle = (kp * error) + (temp_integral) + (kd * derivative);

So in your example the error stays constant therefore the derivative is zero. The integral should wind up to it's peak value and summed with

(kp * error) which is also constant.

 

This surely is a simple code debugging exercise.

 

Pages