PID - Velocity control of a mass on a spring.

Join Date
Apr 2002
Location
No income tax, no capital gains tax. Freedom!
Posts
8,351
The is the first system that uses complex or imaginary poles. Complex poles oscillate. RLC circuits, masses on springs, pendulums, masses on shafts and hydraulic cylinders are examples of systems with complex poles. I designed this spread sheet to be more challenging yet, but I know there will be some that do quite well.

If you notice the damping factor is set to .1. This is very low and I would have strong words with a mechanical designer that designed a system like this. If you get stuck you may increase the damping factor to about .7 until you get the feel for tuning the system. Then gradually move the damping factor back down.

These systems that oscillate can be quite challenging when the desired actual profile is not allowed to overshoot the target profile.

After you get the system tuned you should try doubling the frequency and halving the amplitude. Notice that it is impossible to tune the system if the target frequency is higher than the natural frequency of the system. Too many times I see systems where the controller is to control an actuator above the natural frequency. This is impossible many times because the system gain drops and the controller can only output +/- 10 volts. Notice that the frequency of the target generator is double the natural frequency of the system. This system is on the edge, but that is why it will be a challenge.

There are three graphs on this sheet. One where the target velocity is doing a sine waving, one where it makes step jumps and the last is just to show you how much the system rings in open loop.

I can get the ISE to 153 for the sine wave and the ITAE to 44.69 for the ITAE with out cheating. Have fun.

Tuning a PID Controlling a Mass on a Spring
 
Peter,

Just so I don't screw this up when I simulate the system in the program of my choice, could you post the transfer function (either in s or z domain) for the systems that you are defining when you initially post them?

Thanks.
 
Transfer functions that will make your head hurt.

Just so I don't screw this up when I simulate the system in the program of my choice, could you post the transfer function (either in s or z domain) for the systems that you are defining when you initially post them?

Good idea. I will do that. The z transform function can be determined from the calculations part of the spread sheet by looking at the constants. My question is how are you going to screw this up? Everyone else is going to do this using the graphs and the ISE and ITAE. So what are you going to do with this information?

Here are this weeks transfer functions. I will update the other spread sheets.

T(s)=(G*omega^2)/(s^2+2*zeta*omega*s+omega^2)

T(z)= g*(B(n-1)*z+B(n-2))/(Z^2+A(n-1)z+A(n-2)

Where

G is the gain
omega is the natural frequency in radians per second.
zeta is the damping factor
a:=zeta*omega
b:=omega*sqrt(1-zeta^2)

A(n-1):=-2*exp(-a*T)*cos(b*T)
A(n-2):=exp(-2*a*T)
B(n-1):=1-exp(-a*T)*(cos(b*T)+(a/b)*sin(b*T)
B(n-2):=exp(-2*a*T)+exp(-a*T)*((a/b)sin(b*T)-cos(b/T))

The difference equation is:

v(n):=-A(n-1)*v(n-1)-A(n-2)*v(n-2)+B(n-1)*u(n-1)+B(n-2)*u(n-2)
where v is the resulting velocity and u is the conrol

One can see that calculating v(n) is easy once you know the coefficients A and B. The trick is in finding the values for the As and Bs. The simulation is multiplies and adds and the PID is multiplies and adds.

Have fun!!
 
Re: PID

Thomas Sullens said:
Peter are those formulas in english?

No, they are math. :) Math is its own language. Engineers and mathematicians in Germany, Japan, China and India can understand these formulas.

Your tuning looks pretty good. How long did it take?

Thomas Sullens said:
open loop looks really bad unless the
Damping to .7 🔨

That is the point. This system is miserable and you tuned it!
Trying reducing the natural frequency to .9 and then .8. You will notice that as the ratio between the target frequency and natural frequency increases the greater the output is required to control. Eventually the control is limited at +/- 10 volts and the system is out of control.

Reduce the damping factor to 0. This system will oscillate like a perpetual motion machine.
 
pid

When you change the damping to 1 is the red
line under the blue or is it gone?
I`m not sure probably 2 hrs. but I had to stop
and read one of Terry Woods post to clear
my head a little. You know once you get top
lines acting right you can change the p & i
quite a bit and it doesn`t seem to make much
difference. Why does the derivetive make so
much difference?
 
I thought I was doing pretty good with
P=30
I=300
D=1.0

ISE=71.7
ITAE=28.3 (but a little messy on the graph).

But Thomas's ISE=61.3 Came in better.

Now... combining my
P&I with the 0.6 D gives ISE=58.8...
See, two heads are better than one :D

Peter, why did you have to post the transfer functions? Now I'm going to have to get out my controls book đź“š and brush up on the math again...(but not til tomorrow since it's at work :) )
 
A limitation!!!

Thomas Sullens said:
When you change the damping to 1 is the red
line under the blue or is it gone?

This formula is not valid for damping factors greater or equal to 1. A damping factor of 1 means the system is critically damped, this means the two poles are real, not complex. Real poles are usually just negative numbers like -3. Complex poles are number like -3+2j and -3-2j. The j means the number is imaginary.

The -3 determines how fast the oscilations decay to steady state values. The more negative the faster. Faster is usually better.
The +/-2j indicates the frequency in radians per second that the system oscillates.

Thomas Sullens said:
I`m not sure probably 2 hrs. but I had to stop
and read one of Terry Woods post to clear
my head a little.

You did well and probably ruined it for everyone else. I think I should have had every wait and post their results on Wednesday. It is hard to beat a bulls eye on the first shot. People will naturally compete.

Back in 1997 I went to a steel mill in the middle of India to help with setup. While I was tuning the systems I had an audience. The Indian technicians soon caught how I was tuning the system using the ISE and soon they were standing in line to tune the system so they could get the lowest ISE. Between the 8 to 10 technicians they spent hours tuning the system. They beat my lowest ISE by quite a bit however I did need to back off their gains a little because they were too hot. Needless to say they have never called about tuning problems.

Thomas Sullens said:
You know once you get top
lines acting right you can change the p & i
quite a bit and it doesn`t seem to make much
difference. Why does the derivetive make so
much difference?

RSDoran posted this link a long time ago. I used it for training our technicians and engineers at Delta

PID Tutorial

This covers the system we are tuning this week. This is the mathematical explaination your question. However, I have some serve problems with this page. They only get the results they do because they don't limit the output of the PID controller to +/- 10 volts.

Now for a an electrians explaination of damping and PID in general.

Think of a servo motor with all the PID gains set to 0. You should be able to freely turn the shaft will little resistance. If I barely increase the P gain then I should feel the shaft try to move back to the original position when I twist the shaft. I should feel the force increase as I twist the shaft farther from its original position.

Now set the P gain back to 0 and increase the I gain. Now when the shaft is turned one can feel the force build up at a rate proportional to how far the shaft is twisted from the orginal position. Even if the shaft is only twisted a small amount from the orignal position it will eventually build up enough torque to force the shaft back to the original position or trip on a current overload trying.

Now set the gains back to 0 and increase the D gain. Now the shaft doen't twist as freely as it did with all the gains a 0. It feel like some is grabing the other end of the shaft and trying to keep you from moving it. As the D gain is increased one finds it harder to twist the shaft. It feel like some one is really gripping the other end trying to keep it from turn. Note, this does not mean moving back to the original position. It means keeping it from turning or moving. Once the shaft is turned the D gain will try to keep it there. As the gain is increased it will feel like a 800 lb gorilla has a grip on the shaft and is keeping it from moving. This gripping force really feels like friction and it is. How often have you played the part of the 800 lbs gorilla and grabbed something to keep it from oscillating? When you did you were doing the same thing as the differentiator.

I said when you changed the damping factor to 0, it would oscillate like a perpetual motion machine. Adding D gains does the same as adding friction or damping to the system. That is why the D gain is so important with most systems that have complex poles ( that oscillate). D gain is the 800 lbs gorilla that stabilizes your system. In this case the gorilla is keeping the mass from oscillating. Think about it. If mass was sliding on ice, it would oscillate for a long time with out the D gain.

BTW, don't try this unless you have a fractional horse power motor or the motor may twist you hand off. At Delta we have small motors that we let trainees twist to feel what I just described. They can easily get the motor to trip on a over current fault because the motors are so small.
 
Last edited:
Knowledge that is timeless.

ndzied1 said:
Peter, why did you have to post the transfer functions? Now I'm going to have to get out my controls book đź“š and brush up on the math again...(but not til tomorrow since it's at work :) )[/COLOR]

Excellent!!!!!!!! (y) I have said many times that the tools we used today will be gone or change tomorrow, but math and physics are enduring. Math and Physics are the same yesterday, today and tomorrow. I am always giving our windows programmer grief about this because programming windows changes from version to version. (n) Every time a new version of windows is release I tell them I am glad I didn't waste time learning the old version.
I know that someone’s brain must be sacrificed and forced to program windows, but it isn't going to be mine. (y)
 
Last edited:
pid

Peter thanks for the good explaination that really
makes sense,but I don`t completely understand the
numbers that are not imaginary, much less
'Complex poles are number like -3+2j and -3-2j. The j means the number is imaginary.' I probably shouldn`t ask this ,BUT HOW in the
world can a number be IMAGINARY????? This
stuff starts to make sense once you know what some of the
terms mean. THANKS Believe this site beats ebay
 
Why not?

[/B]
I probably shouldn`t ask this ,BUT HOW in the
world can a number be IMAGINARY?????[/B]

First, I don't like the term imaginary either. We have both seen things that oscillate and it isn't our imaginations.

I will try to make an explanation this evening.
See this thread

I knew this was coming! I don't think I can make a movie though; an explanation will have to do. I think its time.

Maybe this will do.

Will will try to relate this to what we are doing.
 
Last edited:
Thomas,

At the most basic level, an imaginary number includes some factor of the square root of a negative 1. Harkoning back to high school math, you may remember the 'quadratic equation'

Code:
[size=4]
-b +/- sqrt((b^2-(4*a*c))/2*a)
[/size]

This is the general form for finding the answers (there are two) to the an equation of the form:
Code:
[size=4]
0 = a*x^2 + b*x + c
[/size]

so, whenever 4*a*c is larger than b^2 you get a negative number under the square root. In grade school, they told us this just wasn't a number. In hight school they sometimes fluff by this with a cursory explanation of "imaginary" numbers. In college you learn that there can be many uses for these types of numbers.

I'm sure Peter will be able to detail more exactly how they relate to controls but you seemed to be looking for some basic information.
 
thanks

Norman thank you for the help, but the closest I`ve come
to High Level Math in the last 30 years was making a
mark on conduit to bend an offset. We`re not on the same
wave length I`ll just try to tune the loops. Looked at
'Dave Short Trig Coarse' will start there. As for as remembering
school-----I loved grade school especially the 4th grade
it was 3 of the best years of my life!
đź“š
 
Tuning the loop

Peter made me do it! Note that I didn't have the benefit of reading the previous posts before Peter had me download and tune the simulation on his spreadsheet. I spent about twenty minutes playing with it and came up with the following numbers:

Kp = 30
Ki = 325
Kd = 0.75

ISE = 59.560
ITAE = 26.754

This was a nice little exercise with a "perfect" system model. This model allows you to get a feel for how the gains really work without having to worry about noise in the feedback being amplified by the differentiator and system non-linearities like curvilinear valves and supply pressure fluctuations etc.
 
Imaginary and Complex Numbers

All of you are familiar with real numbers. They go from negative to position infinity. Complex numbers are just a little more complex that real numbers. Think of complex numbers as two dimensional numbers whereas real numbers are just one dimentional. One of the dimensions of the complex number is the real number dimension. The other is the imaginary dimension. Try to picture an graph with a horizontal real axis and a veritical imaginary axis. Real numbers can only be on the x axis whereas complex numbers can be anywhere.

In control the real part of a complex pole describes how the system will decay or not. The more negative the real part of the complex number, the faster the system will approach steady state. If the real part is positive then the system oscillates in with exponentially increasing amplitude. That is not good this means we want the poles to negative real part or be on the left hand side of the graph.

The imaginary part describes how the system oscillates. The larger the imaginary number the faster the system will oscillate. If the imaginary part is negative the oscillation rotates in a clockwise direction and if the imaginary part is positive then the oscillation rotates in the counter clockwise direction.

Download this spread sheet.

Complex Response Spread Sheet

The spread sheet shows graphically how complex numbers can define how a system responds. The response allways starts at 1+j0 or 1,0 and decays toward 0,0 if the real part is less than 0. The Real and Imaginary part define this response .Try these numbers:

Real Imag
-2 20 The real part is negative the response decays toward 0
-4 20 The real part is more negative and the response decay toward 0,0 faster.
-4 10 The impaginary part defines the frequency. Notice that the response does not rotate around 0,0 as quickly as when the imaginary part is 20.
-4 0 The imaginary part is 0 si the response does not oscillate around the center. It just decays directly toward zero. This is how a negative real pole decays.

1 10 Notice that the real part is postive and does not decay toward 0. In fact the amplitude of the response gets bigger.

So in summary. The real part of a complex number describes how amplitude ( the distance between the point and zero ) will change. Negative real parts make the amplutude get smaller. More negative real part make the system reach steady state very quickly. Positive real parts make the amplitude increase with time which is not desirable. The imaginary part determines the frequency at which the system will oscillate. The larget the number the faster. The imaginary part actually specifies the frequency response in radians per second. Radians per second = 2 * pi * hz.
 

Similar Topics

Hello All, This is more of a sanity check then anything. I have a project that I need to control the velocity of a fan based on the pressure...
Replies
65
Views
20,462
So you thought you would take the weekend off! No way. The link below is saying download me! Give me a try! The link is to a spreadsheet that...
Replies
15
Views
23,428
Hello, I have a reactor with a cascaded PID control for control of the batch and jacket inlet temperature. We throw in all the required...
Replies
6
Views
1,713
Hi folks, I am upgrading a SLC to a ControlLogix platform. The goal of the project isn't simply to get the same program to run on different...
Replies
7
Views
2,771
I'm using a three term equation to control position, but the velocity profile from point A to B is failing expectation. I'm assuming the...
Replies
3
Views
1,410
Back
Top Bottom