## 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

## 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

2

PNachtwey (Electrical)
(OP)

If you do a search for CTM PID you will find many links that point to about the same data on different universities websites. The link I will use is this one

http://ctms.engin.umich.edu/CTMS/index.php?example...

They are similar with the layout changing a bit.

In previous posts I have made it clear I am not a fan of using Matlab to teach control theory because it really doesn't. The professors are lazy and seem to rely on that fact that one can get an answer easily with Matlab, but these exercises really don't teach control theory. Another complaint I have is that professor seem to just copy what has been done before without much thought about improving the material or knowledge level. This topic will make you think if you stick with it.

To start with the tutorial lists 5 functions that will be used. There is NO explanation as to how these functions work or why. I used learning MathCad. Mathcad doesn't have these built in function so I had to make them myself.

Stepping down the characteristics of the P, I and D Terms.

The description of the P term says that increasing the P term will cause the system to overshoot more but why?

The description of the derivative gain says that Kd adds to the ability to anticipate error. This is very wrong. The derivative term adds damping by trying to maintain the same error.

In the description of the integrator gain it a drawback to using the integrator error is that it makes the system sluggish. Why? It also mentions that the integrator may take time to unwind. This is true with incompetent design.

The table of controller gains and how they affect the response is only helpful in a naive way. Student do not get heavily in debt to learn this. One can find lots of documents that say this gain does this and that gain does that but these documents provide no real insight.

Step down to equation 6. This equation will be used a lot as the open loop transfer function for the various methods of control. A little Matlab code results in the plot of the response. OK. It is pretty and simple to obtain but so what? The document does not go into the why the response is the way it is. The document should go into that there are two real poles at -5+sqrt(5) and -5-sqrt(5). The pole at -5-sqrt(5) will decay relatively quickly leaving the poles at -5+sqrt(5) to decay slowly. Since the time constant is the inverse of the pole the time constant is 1/(5+sqrt(5))). It takes 5 time constants to get within 1% of the final value.

Work it out and compare with the plot.

Now step down to equation 7. A proportional gain is added. In the Matlab code the proportional gain was arbitrarily set to 300. This results in the poles being at -5+i*sqrt(295) and -5-i*sqrt(295). Obviously this

results in an oscillatory response. The real part of two poles is at -5 to the time constants are 0.2 seconds. You can the time it takes to get to steady state is more than 5 time constants. There is no mention of why. The best explanation is two cars waiting at a traffic light. Both will accelerate using a time constant of 0.2 seconds but the second car must wait for the first car to accelerate. If you want to simulate 10 cars accelerating at a traffic light use 10 FOPDT transfer functions in series.

In my Mathcad pdf I wanted a critically damped response so Kp = 5. This results in the characteristic equation being (s+5)^2. If Kp is over 5 the response will be under damped. The sqrt for the pole location will be imaginary. BTW, I computed the real part of the pole by dividing the 10 by 2 the real part pole location will be at -5. I computed the sqrt term by taking half of 10 and squaring it. This results in 25. In the CTM example Kp = 200 so Kp+300-25=295 since the this is more 25 the result is imaginary.

compare with my Mathcad P only. I provide a lot more detail. I show how to compute the controller gains by selecting the response I want. Everyone else does it the other way around.

https://deltamotion.com/peter/Mathcad/CTM/Mathcad%...

This is long enough. I will continue with the PD, PI and PID examples if anybody is interested. The proportional and derivative example can be enlightening but the CTM example doesn't provide much insight.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

http://ctms.engin.umich.edu/CTMS/index.php?example...

They are similar with the layout changing a bit.

In previous posts I have made it clear I am not a fan of using Matlab to teach control theory because it really doesn't. The professors are lazy and seem to rely on that fact that one can get an answer easily with Matlab, but these exercises really don't teach control theory. Another complaint I have is that professor seem to just copy what has been done before without much thought about improving the material or knowledge level. This topic will make you think if you stick with it.

To start with the tutorial lists 5 functions that will be used. There is NO explanation as to how these functions work or why. I used learning MathCad. Mathcad doesn't have these built in function so I had to make them myself.

Stepping down the characteristics of the P, I and D Terms.

The description of the P term says that increasing the P term will cause the system to overshoot more but why?

The description of the derivative gain says that Kd adds to the ability to anticipate error. This is very wrong. The derivative term adds damping by trying to maintain the same error.

In the description of the integrator gain it a drawback to using the integrator error is that it makes the system sluggish. Why? It also mentions that the integrator may take time to unwind. This is true with incompetent design.

The table of controller gains and how they affect the response is only helpful in a naive way. Student do not get heavily in debt to learn this. One can find lots of documents that say this gain does this and that gain does that but these documents provide no real insight.

Step down to equation 6. This equation will be used a lot as the open loop transfer function for the various methods of control. A little Matlab code results in the plot of the response. OK. It is pretty and simple to obtain but so what? The document does not go into the why the response is the way it is. The document should go into that there are two real poles at -5+sqrt(5) and -5-sqrt(5). The pole at -5-sqrt(5) will decay relatively quickly leaving the poles at -5+sqrt(5) to decay slowly. Since the time constant is the inverse of the pole the time constant is 1/(5+sqrt(5))). It takes 5 time constants to get within 1% of the final value.

Work it out and compare with the plot.

Now step down to equation 7. A proportional gain is added. In the Matlab code the proportional gain was arbitrarily set to 300. This results in the poles being at -5+i*sqrt(295) and -5-i*sqrt(295). Obviously this

results in an oscillatory response. The real part of two poles is at -5 to the time constants are 0.2 seconds. You can the time it takes to get to steady state is more than 5 time constants. There is no mention of why. The best explanation is two cars waiting at a traffic light. Both will accelerate using a time constant of 0.2 seconds but the second car must wait for the first car to accelerate. If you want to simulate 10 cars accelerating at a traffic light use 10 FOPDT transfer functions in series.

In my Mathcad pdf I wanted a critically damped response so Kp = 5. This results in the characteristic equation being (s+5)^2. If Kp is over 5 the response will be under damped. The sqrt for the pole location will be imaginary. BTW, I computed the real part of the pole by dividing the 10 by 2 the real part pole location will be at -5. I computed the sqrt term by taking half of 10 and squaring it. This results in 25. In the CTM example Kp = 200 so Kp+300-25=295 since the this is more 25 the result is imaginary.

compare with my Mathcad P only. I provide a lot more detail. I show how to compute the controller gains by selecting the response I want. Everyone else does it the other way around.

https://deltamotion.com/peter/Mathcad/CTM/Mathcad%...

This is long enough. I will continue with the PD, PI and PID examples if anybody is interested. The proportional and derivative example can be enlightening but the CTM example doesn't provide much insight.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

Is it possible for you to post the actual Mathcad sheets?

Cheers

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

I am trying to more in python. All the magazine articles will be using python.

https://deltamotion.com/peter/Mathcad/CTM/t0p2%20P...

https://deltamotion.com/peter/Mathcad/CTM/t0p2%20P...

https://deltamotion.com/peter/Mathcad/CTM/t0p2%20P...

https://deltamotion.com/peter/Mathcad/CTM/t0p2%20P...

The last one with the full PID will be most interesting. My pole placement technique is much better than what Matlab provided.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

Have you considered writing this information into an FAQ? That would keep the information near the top, since there's only one other FAQ in this forum.

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

<Hijack>

This sounds like the algorithm in the 737-Max8 MCAS system

</hijack>

Sorry for the mischief. I couldn't resist.

Thank you Natchwey, for this summary and your Mathcad sheets.

May I add my own voice, that this may be valuable as a FAQ? You can cut-and-paste this posting into a new FAQ if you choose to write it that way. If you need any more help with that process I'd be happy to.

No one believes the theory except the one who developed it. Everyone believes the experiment except the one who ran it.

STF

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

I have seen where I have a FAQ or archive area. Do I just copy and paste from this thread?

The people that have Mathcad get a preview of what is to come. I have been using Mathcad since version 3.

The techniques I use are shown on my YouTube channel "Peter Ponders PID".

I like symbolic solutions. There is a more numerical approach called Ackermann's method for calculating controller gains by placing poles. However, Ackermann's method is not as flexible as my symbolic approach. My symbolic approach also lets one see what goes into the equations. Multiply matrices jumbles everything up into numbers. It is hard to tell what affects what.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

No one believes the theory except the one who developed it. Everyone believes the experiment except the one who ran it.

STF

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

There is another thread that may interest the motion control guys.

http://www.plctalk.net/qanda/showthread.php?t=1198...

I am hoping people will have questions. I like questions. I have a lot to keep me busy. My H&P article finally got published on the web.

https://www.hydraulicspneumatics.com/controls-inst....

There will be a part two and probably a part 3 where we compare PLC control on real hydraulic systems.

I am also have the title of moderator on a Chinese hydraulic servo control forum. I am busy but....

Most of all I hate it when my info gets lost in the web some where so the blog is a good idea.

I also have my own forum.

I will work on the proportional-derivative part of the CTM-PID tomorrow and on the week end maybe.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

Look at equation 8 of

http://ctms.engin.umich.edu/CTMS/index.php?example...

also open my version at

http://ctms.engin.umich.edu/CTMS/index.php?example...

The CTM webpage doesn’t clearly show how T(s) is generated whereas I do in the top half of my pdf.

I used an extra variable K to represent the open loop gain. K is equal to 1 so it can be ignored. I also show the desired characteristic equation at mid page. I want to locate the two closed loop poles on the negative real axis in the s- domain so the response will not overshoot the set point or the steady state value. I then compared the coefficients of the characteristic equation and the desired characteristic equation to calculate Kp and Kd. Notice that this time I am solving for two gains so l λ can be changed within limits. At the low end, λ should not be changed so that Kp or Kd are below zero. There is no theoretical limit on the high end but in practice the feedback resolution will limit how high one can increase the Kd gain.

The CTM examples shows controller gains seem to be arbitrarily chosen. This is sad because this section is the section where people can learn the most about the relationship between gains. Increasing the derivative gain just a little allows the proportional gain to be increased a lot. If Kd=0 and Kp=5 the response will be critically damped just like the proportional only example. What one should realize is that if you want the characteristic equation to result in a critically damped response, there is a relationship between Kd and Kp. If λ=5 then Kd=0 and Kp=5. If λ=6 then Kd=2 and Kp=16. If λ=7 then Kd=4 and Kp=29. Basically ((10+Kd)/2)^2=(20+Kp) so increasing the derivative gain allows one to increase the proportional gain by a lot and still keep a critically damped response. I dispute the comment about the derivative gain’s effect on the rise time and settling time. It is easy to see that the derivative gain can decrease rise time by allowing the closed loop poles to become more negative so error decay more quickly. Yet increasing the derivative gain without increasing the proportional gain will cause the closed loop poles to be over damped and increase the rise time. In short it is not right to simply say this gain does this and that gain does that. It depends on where the closed loop poles are. My approach to tuning is the opposite of what is taught. I think about the type of response I want, then where the closed loop poles need to be to achieve that response. Finally, the controller gains are calculated all at once. Using this technique, I can be certain that the closed loop poles will be near the negative real axis even if my system identification is not quite right.

Now move down to page 4/5 of my document and compare the response I compute with the PD response of the CTM website. I chose a critically damped response to avoid overshoot. I adjusted the closed loop pole locations to -18 by setting λ=18 so my gains would be about the same as the CTM gains. Notice that the CTM response and my “actual velocity Laplace” response are approximately the same even though the gains I used are a little different. Notice that the blue “Actual Velocity Laplace” response overshoots when I placed two closed loop poles at -18?. Also notice that the red actual velocity that is calculated using state space and a PD control does not overshoot. This highlights one of my big pet peeves about Matlab but mostly how instructors use Matlab to get answers without understanding.

The reason for the overshoot is that the ‘perfect’ Laplace solution does not separate the controller from the actuator. The Laplace solution does not limit the controller output to +/- 100%. My PD controller has limits at +/- 100% so there is no overshoot. It is obvious that the Matlab simulation also does not consider the output of the controller is limited to +/- 100%.

There is also a possibility that the closed loop zero created by the P and D gains can cause overshoot but that is not the case in this example. The only reason I use Laplace transforms is to check if the closed loop zeros will cause overshoot. If the closed loop zero is going to cause overshoot I remove it by having the derivative gain act only on changes in the actual velocity. Motion controllers normally want closed loop zeros to extend bandwidth and don’t worry about overshooting because motion controllers normally do not make step changes in velocities or positions.

In short, people are using the wrong approach to optimize their controller gains. There should be lots of questions.

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/

## RE: 'Evaluating the CTM ( Control Tutorial for Matlab )- Introduction: PID Controller Design

my document is located at

https://deltamotion.com/peter/Mathcad/CTM/Mathcad%...

Peter Nachtwey

Delta Computer Systems

http://www.deltamotion.com

http://forum.deltamotion.com/