Implementing a PID
Implementing a PID
(OP)
Dear All,
I am a researcher scientist who knows nothing about PID except from what I did read on this forum and on a few sources from the web these past two weeks. For my research, I need to program a PID and I am seeking help to write the algorithm.
Here's what I am planning to do:
Variables
SP => requested output for A
PV => actual output of A measured by a sensor
MV => actual value applied to A's input
current_time => value of a timer at the start of the current loop
previous_time =>value of the timer a the start of the previous loop
Kp, Ki, Kd => pid configuration constants
integ => integration storage variable
Before starting the PID:
MV is set to 0 so the output of A is 0 and the measured value (PV) is also 0.
Kp, Ki, Kd are user-defined
Initialization
LOOP
According to you, could this be a functional implementation of a PID ?
Thanks for your replies,
Naotake
More informations on the process
I need to control a process (let's call it A) that has the usual characteristics. A takes an input (MV) and provides an output (PV) that should ideally be equal to MV. PV is measured by a sensor.
When changing MV, the response of A is immediate, but because of the sensor's characteristics, it can take from 1 to 30 seconds for PV to reach a stable value (30 seconds for really extreme changes on MV).
Unfortunately, thought the process's (A) response is immediate, there is a small decrease in time of its output after a change in MV (typically less than 10%). This evolution (drift) takes place over the course of 5-10 minutes and is proportional to the difference between the previous value of MV and the new one. So the moment this is the most noticeable is when the PID has just been started, and when the operator requests a new set point.
I am a researcher scientist who knows nothing about PID except from what I did read on this forum and on a few sources from the web these past two weeks. For my research, I need to program a PID and I am seeking help to write the algorithm.
Here's what I am planning to do:
Variables
SP => requested output for A
PV => actual output of A measured by a sensor
MV => actual value applied to A's input
current_time => value of a timer at the start of the current loop
previous_time =>value of the timer a the start of the previous loop
Kp, Ki, Kd => pid configuration constants
integ => integration storage variable
Before starting the PID:
MV is set to 0 so the output of A is 0 and the measured value (PV) is also 0.
Kp, Ki, Kd are user-defined
Initialization
CODE -->
SP is set to the desired value MV is set to a value that is expected to yield an a close result for PV previous_time is set to the current time Waiting for 1 second
LOOP
CODE -->
current_time is set to the current time PV is set to the value read on the sensor Error is set to (SP - PBV) dt is set to (current_time - previous_time) integ is set to (integ + Error*dt) MV is set to Kp*Error + Ki*integ + Kd*(Error / dt) previous_time is set to current_time Waiting 1 second Repeating the loop
According to you, could this be a functional implementation of a PID ?
Thanks for your replies,
Naotake
More informations on the process
I need to control a process (let's call it A) that has the usual characteristics. A takes an input (MV) and provides an output (PV) that should ideally be equal to MV. PV is measured by a sensor.
When changing MV, the response of A is immediate, but because of the sensor's characteristics, it can take from 1 to 30 seconds for PV to reach a stable value (30 seconds for really extreme changes on MV).
Unfortunately, thought the process's (A) response is immediate, there is a small decrease in time of its output after a change in MV (typically less than 10%). This evolution (drift) takes place over the course of 5-10 minutes and is proportional to the difference between the previous value of MV and the new one. So the moment this is the most noticeable is when the PID has just been started, and when the operator requests a new set point.
RE: Implementing a PID
RE: Implementing a PID
What is with this using crappy sensors that don't follow the process variable? And if your sensor is that crappy, how do you even know that the process response is "immediate," and why don't you use the sensor that tells you that the process is fast as the process sensor?
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Implementing a PID
Noway2, the document is really helpful, thank you very much. I still need to learn a lot more to fully understand it. My current concerns are about setting the PID right for my particular system, which is far from ideal.
IRstuff, I can assure you it's not a school project. As I mentioned, I am researcher scientist (Associate Professor to be more accurate). I need to develop this PID for my research.
The physical parameter that is tracked is not easy to follow… so, yes, I agree that the sensor's characteristics look crappy. The process's response time is near immediate, because physics dictate it. I really can't tell more whiteout disclosing too much. But I could tell you more by e-mail without the rest of the world reading it. But trust me, all the relevant details are exposed here.
I can however explain more about the drift in the process with an example.
For each MV, there is a PV which is reproducible and corresponds to an equilibrium of the process. However, changing MV changes this equilibrium and PV does drift during the time it takes for the system to reach an new equilibrium. That's the price to pay for having an immediate response.
Let's imagine that setting MV to 0 gives a PV of 0. Setting MV to 50 gives a PV of 40. Relationship is proportional. Then, we can guess that setting MV to 100 should give a PV of 80 (immediate). And that's what actually happens. However, during the next few minutes, there will be a drift occurring, because 80 is not the equilibrium value, and PV will eventually stabilize around 74.
Then, setting MV to 50 again, will give a PV of 37 (immediate) that will evolve to become 40 again.
I have also been considering removing P & I altogether because I can predict, with really decent accuracy which value of MV should be applied for a particular SP. So I could get there first, and then start regulating proportionally to compensate for any slow drift that may occur.
I am still experimenting with it and any thought is helpful to me.
Thank you again for your replies.
RE: Implementing a PID
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Implementing a PID