Fixing PID

Taylor Turner

Member
Join Date
Sep 2020
Location
Midwest
Posts
78
I am wanting to code PID control.

Thus far I have a functional PID without a ramp rate.
In examples that I've seen the time component in the term equations are just the time derivation between error calculations and not controlling the rate at which the control variable is increased. Not worried about decreasing the value yet.

I have seen where the set point is controlled by a theoretical value which increases at rate and a few units added above the process variable.
I'd like to get away from that if possible and have the rate directly factored with the PID.

I have made some open loop ramping profiles, used on VFDs and pressure control, by taking a time duration's accumulation divided by it's preset value.
The ratio of time can be scaled from it's 0-1 to an output span, pressure say 0-3000psi, for a linear ramp.
Also the ratio of time can be applied to the x component in a polynomial constrained from 0-1 resulting in an s-curve..
y = -2(dx/dt)^3 + 3(dx/dt)^2, accelerating.
y = 2(dx/dt)^3 - 3(dx/dt)^2, decelerating.
Then the y component scaled with what the span of your output set point, 0-3000psi.
For open loop motion control this is great, but it's not good enough.

My first attempt was to multiply the ratio of time directly to the PID terms.
Which would just increase the terms at a percentage proportional to the expected time duration.
It kind of made sense in the P term, but the I term runs away easily.
Increasing the terms as you're getting closer to the set point creates troubles too.
I know this is not correct, but at this point I'm plugging and chugging with minimal references.
I'd like to get it to where the ramp rate doesn't have to be linear and polynomial functions can be enabled.

Example code in brief:
//This is so the terms are multiplied by 1 when the time duration is complete. At half the the time the term will be half.
PID.tRamp.PRE := abs((PID.rSetpoint - PID.rProcessVariable))/PID.rRamp*60*1000; //Error/Degrees per minute*1000

PID.rProportionalTerm := PID.rProportionalGain * (PID.rSetpoint - PID.rProcessVariable) * (PID.tRamp.ACC/PID.tRamp.PRE);

PID.rIntegralTerm := PID.rIntegralGain * PID.rIntegrator * (PID.tRamp.ACC/PID.tRamp.PRE);

PID.rDerivativeTerm := (PID.rDerivativeGain * (PID.rDeviation - PID.rProcessVariable)) * (PID.tRamp.ACC/PID.tRamp.PRE);

Code in full:
https://github.com/TTControls/PIDDutyCycle/blob/master/PIDPWM
I know the use of timers sucks and an interrupt should be used, but one step at a time.
 
Last edited:
I don't think Proportional On Measurement is the answer to my question.
How do you apply a rate of change to PID?

>Edit
I suppose thinking out loud now. Just apply the time ratio to the set point and let the PID do its thing fundamentally.
 
Last edited:
Now you're getting it.

You would rather not mess with the actual PID filter dynamics since they are (presumably) already correctly matched to the plant. Modify the setpoint in such a way that allows the PID function to track it accurately and let the PID take it from there.

Keith
 

Similar Topics

Are the Siemens ET200SP family members immune to vibrations on a running machine? Some customers had some loosening after running for some time...
Replies
4
Views
1,436
I am hoping this post will prevent the hour of frustration and lost productivity I just endured. For several months I have been using RS Logix...
Replies
1
Views
1,480
Another newbie question from me.... My MLX1400 threw the following error code: Major Halt S:1/13 and S:6 = 08h. As you can tell, I am a newbie...
Replies
2
Views
1,772
Our PLC stopped working, can someone tell me how to fix it? The forktruck driver ran into the electrical cabinet it is in, should I open it up and...
Replies
19
Views
3,938
Hello, I am a Control Systems Intern for a company in the Western New York region. My job is to upgrade the safety features of a manufacturing...
Replies
18
Views
4,190
Back
Top Bottom