Designing a PID Controller Using the Root Locus Method

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to another video today I'd like to talk about how to design a linear PID controller to ensure that it meets specified requirements we'll see this technique is based on understanding the root locus of the closed-loop system and then manipulating it intelligently by modifying the controller this is a mathematically defensible approach that allows us to make guarantees about the system performance now what's so exciting about today's topic is that in fact this technique is applicable to any type of linear controller not just PID controllers so while we'll use PID controllers as a case study keep in the back of your head that this approach is generalizable to all linear controllers let's just pause a moment to let that sink in this technique is applicable to all linear controllers now that being said today's discussion is going to build on a lot of prior material so at minimum please make sure you've watched at least these five videos before continuing on links to all these videos are in the description below so to reiterate as long as you're dealing with a linear system the techniques that we're going to cover today will allow you to intelligently and effectively design a linear controller so in the discussion day we will apply this technique to PID controllers because as we've discussed before PID control is probably the most popular control scheme in the world once you know how to design one the world is your oyster it's gonna make you so happy that you might just want to do a little dance just be careful that when you're dancing you don't pull a muscle alright anyway um so if you're as excited as me about this topic then make like a seat belt and buckle up alright so let's get into the discussion of how to design or designing a PID controller using the root locus technique so this is how we're going to go about designing our PID controller so just to reiterate let's just draw our so the block diagram that we've seen several times before where you've got your plant G of s and it is trying to track a specific reference signal it's called R of T the difference between R of T and the output gives you the error and now the idea is this error signal is going to be broken up into a proportional component an integral component and a derivative component okay so let's just start with this as our general architecture right and this diagram here this portion was our controller and in this case it's a PID controller okay so what we did in one of our previous videos where we were discussing how to use actually the control system designer right that was one of our prerequisite videos that I talked about is we just focused on using the root locus technique to design a proportional control KP so lets how about walk before we run and for now let's get rid of this derivative section and maybe let's just consider designing a PI controller so maybe let's take off this D adjectives because we're not going to have a derivative component all I want to do here is design a p.i controller using this root locus technique okay so let's go ahead and state because the goal of this specific subsection here is to design a PI controller okay so what that basically means is you need to go ahead and choose these two degrees of freedom right I need to choose KP and ki those are the only two numbers you get to pick right that's your job as control systems engineer is to choose KP and ki to get reasonable performance so to go about this using the locus technique let's examine the controller a little bit more in fact let's figure out and write down the control of what is U of T given Y of T right what's the control signal given the error at the current time so that's pretty easy the control law is very simple in this case so the control law for a PI controller well the control at any given time it's just the proportional component right which was KP times e of T and now we're going to add on our integral component ki times integral from 0 to T of a of tau D tau right ok let's take the Laplace transform of this so I could write this as u of s is equal to KP e of s plus ki times 1 over s right ok so let's uh let's simplify this side I could also write this as KP plus ki oh sorry whoops I dropped the e of s over here whoops ki over s right this whole thing times e of s right ok so let's move this to the other side and we see that the transfer function between U of s to e of s right is KP plus ki over s right or what you could do is let's let's simplify this right you could also write this as KP s plus ki all over s right if you get yourself a common denominator right or the other way you could write this is once let's let's factor this one more way let's pull the KP out in the front so you can write this as KP times s plus K I over KP right all over s all right so this is effectively our transfer function let maybe let's write this one more time so the controller C of s right which is just the transformation of U of s over EMS is just this format you could write it like this KP plus s plus ki over KP all over s alright so let's box this up because this tells quite a lot about the PI controller if you look at this format this is in a traditional you know if we think about this in a MATLAB format sits in zpk or 0 pulque format if you look at this thing long enough this is basically what it's a first-order numerator so there's one real zero and the zero is located at negative ki over KP and there is a pole at the origin right so what's really fascinating about API controller is the other way you can think about it is a PI controller is nothing more than one real zero right at minus ki over KP right and then it's one pole at the origin right so from a pole 0 map perspective a p.i controller let me just sketch it over here where we've got a little bit of room is you just have a real pole at the origin right here and then you have a zero located at minus K I over KP ok so the other way you could think about this is earlier we said the goal here was to choose KP and K I right yeah the two degrees of freedom you can choose either one of these two the other way to think about this is you can you're free to move the location of this zero right because you get to play with these two and you can also change the constant gain here so the other way you could think of designing a PID controller one way is obviously is to choose KP and ki or the alternative way is you can say move the Z the real 0 and also change over all gain of the controller right so the degrees of freedom may be let's just circle those in green here right you can change this value and you can change this value right which basically gives you also another two degrees of freedom but I think these two degrees of freedom are a little bit more intuitive if we're thinking about root locus because you can clearly see where are the roots or sorry where are the poles and zeros that you're introducing via this controller so what we should do here is um let's go ahead and give me a second to erase the board and let's look at the same example we were doing earlier with our position control the DC motor with this framework in mind of how to design API controller for that plant alright so let's look at our example of controlling our DC motor the position of the DC motor so in this case the plant here I think we called this GP or for the positioning of the plants maybe we should call this GP here okay so we said the position giving the angle of the wheel over the armature voltage to the system here or the control signal was given by just a refresher memory again we did talk about this in our previous video one of those prerequisite videos so I'm not going to cover this in detail I'm just gonna flash it back up for convenience 10:21 s squared + 4 8 4 5 s ok great this was our example system that was our plant here and we said that some of the requirements in that previous video were things like the percent overshoot had to be less than 40 percent we needed the rise time to be less than 1 second we needed the settling time to be less than 3 seconds we needed a gain margin greater than 20 decibels and a phase margin of greater than 30 degrees and finally we wanted a bandwidth of greater than 5 radians per second ok and again in our last video we showed that our a1 way to get that performance here was just used proportional only and I think we showed that if you just use the KP is equal to 0.55 that was a system that actually satisfied all of those requirements so now you might be asking well if it ain't broke don't fix it why even bother adding this integrator right uh why don't we jump over to MATLAB and maybe jump over to the lab actually to see a does this work and is it actually broke in do we need to fix it all right so I've just started a very quick simple MATLAB script to get our transfer function set up and define our simple proportional gain so let's just run this and I also have a Simulink model pre-built which shows how this system we should respond at least theoretically in simulation so let's just run this with this proportional gain of KP of 55 and see what we get and here's the scope and look at that again like we saw earlier we designed this gain KP to be exactly right in the sense that it satisfies all the performance requirements so look at this the yellow line is obviously our commanded reference and the blue line is the actual position of the motor and this looks beautiful right you had you meet the settling time and the rise time and all the other requirements with this system but what happens if we try to take this idealize proportional controller which appears to look beautiful and simulation and maybe bring it over to the real DC motor let's see what happens when we try to implement this same proportional controller on the real DC motor with the same commanded step change magnitude of 90 degrees we see that this controller fails completely we see that we only get a little over 40 degrees of rotation before he gets stuck remember the linear simulation claimed it would be perfect and it would go to 90 degrees with 0 steady state error the problem gets worse if there are any external disturbances here I'm taping on some ball bearings to apply an approximate constant torque and we see that with each additional disturbance the steady-state error gets worse this illustrates some of the dangers of designing controller for a real system based on a linear model so in this case the linear system wasn't able to model the real friction and we didn't account for external disturbances so the controller looked great in theory but in practice it was not great all right so that just highlights the lack of robustness of a proportional control only I mean I guess if you want to say in more plain language this is just a piece of junk all right we need to add a couple of performance requirements because clearly this didn't capture everything so let's just cross this out this is junk and let's go ahead and add a couple of more requirements so let's put in a few additional recs okay so let's also say that we need to have 0 steady state error and also we should say that this thing is robust to external disturbances again we added this one because we saw that you know what actually that proportional control again in theory got you 0 steady state error but we saw in practice that's a different story so really the combination of these two additional requirements really does now make a case for adding the integral component to our controller so what I want to do now is let's go over to matlab and fire up the control system designer and see if we can design a PI controller using the root locus technique so again I'll stress again right now if you haven't watched the video on how to use the control system designer in MATLAB please please please take a moment to stop and make sure you review and understand and are very comfortable with the workflow that we discussed there because that's exactly what we're going to be doing here with our PI controller with a couple of epsilon tweaks so give me a second let's pause the video and jump over to MATLAB alright so let's go ahead and use the control system designer to design API controller so again please make sure you've watched that video where we did discuss how to use a control system designer because I'm just gonna blaze through and quickly gloss over the steps because I'm gonna assume that you've seen this before so step one is create a TF of the system slash plant alright so we're gonna say GP is transfer function of GP Noom and GP denne and then step two was start the app right so all we're gonna do is just a control system designer and pass in GP so we don't have to manually import this in the app so I'm gonna hit run and that is going to bring up our control system designer in our other window I will maximize it here so it's plotting okay so now what we're gonna do for step three is we're gonna add all of our design requirements and our additional plots so one of the plots that we may want is let's get a new bode plot which is a transfer function r2y right this is the closed-loop transfer function so we can understand the system bandwidth let's put the two of those two on top of one another the other one that might be helpful to look at during this process is let's make a new step response and now let's look hard to use so we can see how the control signal operates in this fashion here we go are - you are - y all right this looks good I think we've got the plots we want let's start adding our design requirement so I'm gonna come here to our step response of our to Y and I'm going to add a new design requirement where we said we need better than one second rise time less than three seconds of settling time and no more than 40% overshoot so I'll hit okay here we go let's also while we're at it look at what those actual values are right now so I'll add our settling time and also our characteristic on the rise time there we go okay so we think huh I guess if we can get all these to look nice there we go Oh for giggles we can also zoom in on our root locus editor we talked about this earlier that since our DC motor has very fast dynamics out here and very slow dynamics we probably care about the slow dynamics so let's let's zoom in a little bit here this is where all the action is going to occur and we could also add design requirements if we wanted to for example again our settling time of less than three seconds and we could also add our design requirement of less than 40% overshoot and again remember these are suggestions or they're not entirely accurate because we don't actually have a second order system and actually that's going to be important a little bit later so just keep that in mind where else do we have some design requirements oh here in our closed-loop OD plot we said we could add a new design requirement that I want the system to maintain we wanted above the 3 DB the negative 3 DB line because this was where we wanted the bandwidth to be so again let's maybe zoom into the area of action here where I want the bandwidth to be above 5 radians per second so again this system seemed to be doing great but like we just saw in the real application this is not actually great right everything looks great in simulation but we really need that integral control component to ensure that it's robust to external disturbances in steady-state error so we saw that to do that right now our compensator is very simple it's a static gain of value k1 and what you can do here is if you right-click on the root locus and you say edit compensator you'll get this other dialog box to pop up and let's change this back to 0.55 5 this is exactly what we were using earlier and you can see when I hit enter everything updates and we say ok this looks great but we know this doesn't work this is broken what we have to do is we want to make this instead of a proportional controller we wanted to make it a p.i controller and what we showed on the board is a PI controller is nothing more than an integrator basically I pulled the origin and a real 0 so when I come here to this dynamic section of the tool I can just click on right click on this and say add polar 0 look at this let's add an integrator and now look at this the controller structure has changed so now I have basically this is just an integral controller but if I want the P I portion of it I also have to add that 0 so I'm going to again right-click on this and say add real 0 re polar zero and click on real 0 and here you go now I have a PI controller right now so let me close this dialog and again come to the root locus and we'll zoom in a little bit to again this is where the actions occurring and what you can see is all of these magenta lines like we talked about magenta items are things that you can manipulate or move so this red X right here in the magenta X you're seeing that is the integrator so actually I don't want to move that that has to stay at the origin but this little zero here this can move right this is the zero that is associated with the p i-- controller and you'll notice there's some little weird rendering artifacts i guess in this tool like like right here this is whoops amount nope i guess it fixed itself but some of the times here we go this is super odd this is an artifact of the rendering you know a root locus has to look symmetrical about the real axis but just the way that matlab decides to use finite spacing when it's drawing the root locus it makes it look like it's not symmetrical but it actually is you can see that if you grab these line one of the closed-loop poles and you start moving it around now that will eventually be you know in see look here starts to connect the dots a little bit better and you do see that it is symmetrical maybe it's better if i grab this other one up here anyways a small anecdote here that this is just a rendering artifact you you can see here that clearly the root locus is symmetrical so the game now with designing the pi controller is instead of trying to blindly change KP + ki values i'm going to manipulate the poles and the zeros and the components of the controller to get the performance I want directly in the root locus so you can see as I move this around this is why the control system designer is so great we can see all of our performance metrics updating in real time so you can see here that the percent overshoot and the settling time and all these requirements are are displayed so you can see right now we are not meeting the settling time requirement we got five seconds of selling time so we need to play around with this until we get this to match so what I'm gonna do is you know I'll move the zero now I'm gonna move the closed-loop poles so and you can see in real time over here on the on the Left pane what since I have the C button clicked you can see what the compensator is or the controller that yields the root locus so you can see I am basically increasing this and we're increasing effectively the proportional gain is kind of what we're doing here okay so let's see here what are we doing this is a Oh actually this is actually maybe an interesting point - maybe maybe let's let's take it take a look at this I wanted to point this out because earlier I was trying to hammer home this idea that if you look at the root locus and you look at the regions of I guess feasible Nisour the allowable regions of the root locus for these design requirements remember this these diagonal lines we claim these design requirements were for the 40% or less overshoot notice here that the roots here they are well within the the 40% value here right there in the white area but look at the step response the step response claims you're over 40 percent so that clearly states that you know something is odd here and the reason why is because this is not a second-order system it's not even second-order dominant right there are three poles that are very similar in location to each other so this is actually well well technically it's a fourth order system right there is one pole that's way out there at minus a thousand dish or something like that we really don't care about that that one is is so fast that it really doesn't influence the dynamics its threes three that are interacting here and creating more complicated dynamics so again you cannot trust the regions of allowability in the complex plane where we have these lines here you can trust the step response right so ah just again to show the paradox right the root locus in the complex plane claims you have better than 40 percent overshoot but in reality you've got over 40 percent and in fact you you also see this with a settling time requirement right you see that the settling time we have one pole that the settling time it makes it look like it's worse than three seconds right because this vertical line was our three second settling time line and you got this pole that's that's to the right of that line so you might think if you looked up at this root locus or the the areas of the complex plane you might think hey this system is uh is meeting percent overshoot but not meeting settling time but if you look at the step response it's the exact opposite scenario right you are meeting the percent overshoot but you are meeting the settling time requirement so really we should be looking at this step response for all of those time domain responses okay so with that being said the game is continue playing around with this until you get something that you're happy with so again you can grab and drag the zeros grab and drag these poles or the other option here is you could right click and you know say edit compensator and you can directly change these values in here like for example point I can plug plug in point three six so 205 right and right here you can change the location of the zero so if you didn't want this at minus point oh nine you can move to like I don't know minus point eight six five four okay so for example now I hit OK and that updates the root locus and again you see this weird artifact show up but let's quickly do a scan on all of our performance metrics so yeah check it out we meet the settling time requirement we meet the percent overshoot we meet the rise time we meet the gain margin we meet the phase margin let's look at the closed loop bandwidth again this is the one that's harder to read here so here's one radians per second two three four five so yeah so again I think we meet yeah we meet the bandwidth requirement and lastly let's do a check here on the step response of the control signal and this is great less than half a volt in order to get this performance over this this experiment so this looks awesome so what we should probably do is let's go ahead and export the controller because that looks awesome so maybe let's export this as I will change the name to see how about p.i and we'll hit export and now that should be in our MATLAB workspace let's come back and we can see that we've got C P I so this is the compensator that we claim will work all right so now on to step 6 which was let's save our controller so maybe let's call this P I controller dot Matt and we'll save the thing we called CPI ok so we've got that and we could also go back to our control system designer and whoops where was our control system designer it was over here and let's go ahead and save this session just in case we want to come back to this so I'll give this the underscore RPI okay so now we've saved both the control system designer session and the controller I can go ahead and close the control system designer and maybe the next thing we want to do is uh this is our PI controller but I always like to think about what is the KP gain what's the ki gain if you remember from our discussion on the board we saw that the KP value is basically I want to write the numerator in a polynomial format and KP is just going to be the coefficient of s so you can easily see that in this case KP is going to be zero point four one six two three and then ki is going to be the constant in the numerator so in this case it's going to be zero point four stick so that number times what zero point eight six five four so these were our two gains so let me just go ahead and evaluate this selection so I can get both KP and ki in the in the the work space so here we go and now what we can easily do it so let's go ahead and augment our PID controller and let's just go ahead and add an integrator to this loop and whoops sorry and I will copy this and get myself another gain and this gain needs to be ki and now we've got our integral path and now let's go ahead and add a summing block and just simulate the system to verify that we get the appropriate functionality that we expect so again let's go ahead and run the simulation and hit the scope and here we go so this also looks great in simulation now remember the trick now would be to see if this controller that we designed now does any better on the real system so let's go ahead and run over to the lab with this set of KP + ki gains and give it a try let's use the same -90° step input we did before but now with API controller and we see that the PI controller works much better on the real system the system is still subject to these nonlinear friction forces which temporarily cause the motor to get stuck especially when it's near the setpoint when it's near the setpoint we know that that's a proportional control is doing very little because the error is small and since the control is proportional to that small error that yields a small control signal however as you can see here the integral component of the control starts to wind up and accumulate this small error and eventually it's enough to make a difference for some reason as I'm watching this the phrase death by a thousand paper cuts pops into my head here you know you've got this big bad friction that says hahaha I'm this difficult nonlinear phenomena that you can't account for with linear modeling and as such I have defeated your puny proportional control but then your integrator comes in and slowly accumulates this error until it overcomes this nonlinear phenomena so in the end it's the integral component of control that is enough to overcome the friction and eventually drive the system to 0 steady state error the controller does a great job with external disturbances as well so the system is still holding steady at the minus 90 degree location that we commanded earlier and now let's tape on a heavy ball bearing to introduce that approximate constant disturbance torque now if you recall the proportional only controller that we looked at earlier failed miserably in this scenario as the steady-state error just grew each time we added more disturbance torque but in this case we see that the PI controller can handle this unaccounted torque and eventually return the system to the setpoint so this really shows how an integral component of the controller really adds the robustness of the overall system notice that the constant control needed to maintain this minus 90 degree setpoint has changed from what it was originally which is to be expected because now there's a constant torque from the ball bearing that it needs to oppose furthermore note that when the systems at the desired setpoint there's actually no error so the proportional component of the controller is doing nothing 100 percent of the control needed to maintain this 0 steady state error comes from the integral component so if we let this run longer you'll eventually see that the system does achieve 0 steady state error but at this point this is kind of like watching grass grow or I guess to be more accurate it's watching integrator accumulation state grow so tell you what why don't you just take my word for it that it gets to zero and we'll move on to something bigger and better all right so that word great so why don't we keep on trucking and see if we can extend this concept to now a full PID control so let's add back our derivative branch so I'll add a KD followed by a let's start with a pure integrator if our derivative to start so now let's make this a pure PID controller ok so we play the exact same trick namely we need to write down what the control law for this system is and we've got as expected U of T is you know we still have the same KP e of T plus ki times integral 0 to T e of tau D tau and now we are adding our KD times d e of T DT right so taking the Laplace transform is again something very simple sorry of s plus ki over s plus KD s and again collecting oh gosh sorry and I keep forgetting to put the e terms here so this is our a of s plus KD se of s great so grouping and pulling out the e of s we get KP plus ki over s plus s KD and again getting a common denominator to make this look like a numerator polynomial or a denominator polynomial we end up with what we end up with KP s plus ki plus s squared KD right all over s this is equal to U of s over e of s right or I guess maybe maybe it'd be better to rewrite this in a standard form where you've got the s squared term at the top here's loads or the front s so KD s squared plus K PS plus ki all over s so this here is my C let's call it P I D of s right so again we see the same thing that a PID controller a pure PID maybe we should maybe make a note of this this is a pure PID right so all this is is a pure PID is nothing more than a transfer function here it's a with two zeros which could be potentially complex so the components that make up a pure PID controller is two zeros these have the potential to be complex potentially complex and it has a pole at origin right a single integrator so again we see we have the same issue that the game we're gonna play now is you've got yourself now a two zeros they could be complex I'll draw them as complex potentially and you've got a pole at the origin and again what you get to change here is we get to move the location of these zeros so these zeros can go you know you can move them here as long as they're symmetric obviously you can move them here heck you may move them all to the real axis and then what you can do is you can also change the overall gain of the system so same thing we still got three degrees of freedom to play with here you can move the the the Y component of the zeros the X component of the zeros and you can choose the overall gain so it's the same goal a PID controller is on one hand choosing the gains KP ki or KD or on the other hand it's just choosing the location of these two zeros and the overall gain of the system maybe before we jump back over to math or actually I don't want to jump over to MATLAB with this one because a couple of reasons but just to maybe mention take a look at this this is actually an improper transfer function so you can note here right there's more zeroes than there are poles so let's maybe make a quick side note here that this is a pure PID is improper right which during our discussion of practical implementation issues with the PID controller namely the video right over here you remember we discussed how this is a this is kind of non-causal right pure derivatives should be sending off red flags and klaxon should be going off in your head as control systems engineer that a pierre-pierre derivative it's a bad idea in your control system so this is a little bit on here all right but what I will say is that if you think about this when you're doing the root locus for this this combination of pure PID ax plus plant right so here is our plant over here if you remember what we're doing is we're doing the root locus of the combination right of the loop transfer functions so what I'm trying to get at is as the PID controller this could compensator it can be improper as long as the plant transfer function is proper right if the plant transfer function has more poles than zeros by the time you multiply something with more poles and zeros with something that has one more zero than a pole you should come out with at least a margin a proper system right there should be at least the same number of zeros and poles as there are for the overall system here right so when we're getting out here this is my long-winded way of saying as long as the plant has at least one more pole than zero by the time you combine it with this pure PID controller you could still do root low because you can still do everything we talked about all the rules apply because the overall combination of these two things in series is something where you have at least the same number of poles and zeros so with that being said you could go to the control system designer and design yourself a pure PID controller by doing the same techniques we did earlier but as we saw earlier in our practical discussion that's not a good idea so instead of wasting some time and trying to design a pure PID controller give me a moment to pause the and erase the board and let's talk about the actual form that is most implementable for controller namely a P I pseudo D controller okay so instead of the PID controller let's change this to API pseudo D let's maybe say API pseudo D controller and we remember and that the only difference here is we said that this was the problem here was this pure numerical derivative so instead what we're going to use is we are going to use a pseudo derivative of the form a s over s plus a write this here was your pseudo derivative which we saw was basically again a derivative chained to a low-pass filter of DC gain 1 ok so in this case with our new architecture we can easily see what the control law is so maybe let's go ahead and write that down again so the control law in the Laplace domain it's quite easy to see it's just gonna be what its gonna be KP plus ki over s plus KD a s all over s plus a all right this is your control law or the transfer function for our pseudo derivative now again let's play the exact same trick that we did earlier let's take this control law and basically get it into a numerator denominator format by getting a common denominator so to avoid me making multiple algebraic errors here you can see this is a real easy problem it's just an algebraic manipulation of getting a common denominator here and combining all these things together so what we can do is at the end of the day is you can show that alright if you do all of that you could write this in the form of a KD plus KP s squared plus a KP plus ki s plus a ki all over s plus a okay so this here is the transfer function what sorry C is our transfer function with the controller C let's call this the P I pseudo D right this was the equivalent transfer function representation of this controller and again we do the exact same game we did before you look at this thing long enough and you see okay another way to describe API pseudo d-- controller is it's nothing more than again you still have what a second-order numerator so you still got two zeros so there are two zeros and again depending on what those constants are the roots of that might be complex so again let's just write it's potentially complex and then what else components make up this thing well there's again a pole at the origin and then there is a real zero at minus a right that's this root down here and again maybe what we should note here is this real zero minus a came from the break frequency of the pseudo derivative right because you can see that a term is just right here and that is again the corner frequency or the break frequency of where do we start rolling off the the noise here where does that thing start not acting like a derivative effectively okay so this is great we see that we're going to do the exact same thing we did earlier is we're going to go over to the control system designer and basically design a root locus by manipulating these things manipulating the location of the two zeros we can't manipulate this pole at the origin and we are going to then manipulate this real zero at minus a so again maybe what we should do is we should draw the pole-zero map of this and we see that okay you've got the or you've got the integrator which you can't manipulate here but you've got these two zeros and now you also have this real zero at minus a we should maybe make a quick note of this typically you're going to choose this a value again the a value is the break frequency of where do we want to start filtering out the noise of this system typically that's higher so you want to get rid of high frequency noises so one thing you may want to do is choose this a to be a large enough magnitude so it doesn't influence the dynamics of the rest of your system so what I'm saying is maybe stick this zero further out here alright typically like I don't know if the like maybe minus 100 or something like that so basically you're saying any noise over 100 radians per second is what I want to start cutting off so the farther you put this out the better it is for not interacting with your dynamics as much here but that also requires faster sampling as well so there's a little bit of a trade-off you don't want to put this thing out at minus 8 million here because then you're really not cutting off any noise you're letting pretty much Eddy everything through but if you start pushing it too close here then you're going to start interacting the dynamics of this pseudo derivative are going to start influencing the rest of your root locus which you know may or may not be a good thing here so I think for our system we're going to use about minus 100 here just for our example but that's not terribly germane to the discussion right now I just wanted to just throw that quick note out here while we're drawing the the pole-zero map of the P I sued OD controller so again the things you get to manipulate here are the position of these two potentially complex zeros and the position of this real zero and the overall gain of the system so now there are four degrees of freedom for the system which again makes sense here because there's four degrees of freedom here you're going to choose KP ki KD and the a the break frequency of your system so what we're gonna do is maybe before we leave the white board let's quickly talk about when we go over to the control system designer what it's going to get us is it's going to get us we're going to design this this second order transfer function right so let me just write from the control system designer we obtained basically it's gonna give you a second order transfer function let's just call it C of s it's going to give you at the end of the days you know like an alpha s squared plus beta s plus gamma all over s s plus Delta right where all of these alpha beta gamma and Delta numbers are going to be what values we achieve from the control system designer by moving around all of those zeros and poles and the and gains and things like that so if you look at this and you look at that again I always like to think I want to know I don't care about alpha beta gamma and Delta I care about KP ki and KD because those seem to have some physical intuition and meaning to me so what I'm getting at here is you may want to think about solving this is what you get from control system designer right we obtained this from MATLAB I want to now compare this to this and solve for if someone gives me alpha beta gamma and Delta like MATLAB gives those to me what are the corresponding KP ki and KD and a values so you see it's actually just solving a system of four equations and four e'n nodes at the same time simultaneously so you look at this coefficient of s squared so maybe let's look at the s squared all right you see that alpha here had better equal the coefficient of S squared over here so that better equal a KD plus KP right you look at the coefficient of a s right in the numerator and you see okay beta had better equal coefficient of s in the numerator over here that has got equal a KP plus ki then you look at the constant like I guess you wanna call the s zero yeah as one's you're there something like that so you get gamma has got to equal the constant over here it's got equal a ki and then you look at this determinant in the denominator here and you see that okay Delta had better equal a right so here's the denominator term so here's equation one two three and four and basically what you want to do is just solve this for a KP ki and KD so if you solve those simultaneously if you go to Mathematica or some other symbolic package you're basically going to see that okay obviously well right off the bat you see a has got to be Delta alright and then KP is going to be minus gamma plus beta Delta all over Delta squared and then your ki is going to be gamma over Delta and KD is going to be this kind of ugly gamma minus beta Delta plus alpha delta squared all over Delta cubed okay so ah actually what might be handy now to help you with your workflows I've actually coded this up already into a MATLAB function so let me let me erase this to get a little bit more room so I boxed all of these equations up for you into a function that I called what did I call this thing I called it extract PID gains from second order transfer function gosh that was a ridiculous name sorry and I ran out of room here transfer function dot M okay so it's a MATLAB function it's an M file and I got a link to that M file here in the description of this video so you're free to download this if you want what you do here is you can pass this thing a transfer function right and as long as this is a second order transfer function of crud I just I just erased the format here maybe we should write this down here you know alpha s squared plus beta s plus gamma all over s S Plus Delta right you give it a transfer function of this form or you give it a zpk object of the you know of the equivalent form what it will do is it will run these calculations will extract the relevant information and then spit out for you k p ki k D and a just using these equations here so the reason I wanted to provide this is because this now makes the work flow a lot easier because where are we gonna get this C of s we are going to get this thing from the control system designer right this is what we're gonna do is we're gonna manipulate the root locus directly in the control system designer and make sure that we meet the performance requirements here we're going to export the controller from control system designer it's going to be in this ugly format which I have no freaking clue what the KPK ia KD and a values are but then I'm gonna pass it to this function that I wrote then it will pull out the KPK ikd and a and then we can go and simulate and implement this on our real system right so that's the game plan here why don't we uh let's jump over to my lab and and do this part right here and use our function here to get the KPK ikd values all right so to design our p i-- pseudo d-- controller all we need to do is let's come back to our control system designer and here's actually our p i-- controller that we designed a couple of minutes ago you know what might be interesting let's go ahead and store this design and now all we need to do is if we want to change this from api to api pseudo d-- controller i'll just come here to the root locus editor right click click on edit compensator and now we see that all we need to do is change this to add the poles and zeros as we just discussed so I'm gonna have to add one real pole and this pole is gonna have to be located at minus 100 right this was the break frequency of our pseudo derivative and finally we need to add one more zero although what we could also do is tell you what let me delete this zero because I don't want to real zeros I want a complex pair just for fun you could do either so let me delete this and now what I'll do is I will add a complex zero so now if you notice our compensator has the exact form that we had on the board namely it's a second-order numerator with a pole at the origin and a pole at minus a or minus 100 in the denominator so now the game becomes just doing the same we did earlier in the sense of just manipulating any magenta items which are basically controller parameters to get the closed-loop root locus to look the way we wanted to so uh you can see you just need to play with this it's it's a little bit of an iterative process at this point of moving the poles around the locations until you meet all of your design requirements you can quickly see that as the controller gets more and more complicated as you have more poles and more zeros there's gonna be a lot more degrees of freedom there's gonna be a lot more difficult to kind of get things to to move the way you want it to because as you move one thing it's probably going to change something else so sooner or later this is going to be a little bit cumbersome and we may need to look and difficult different techniques to design and synthesize more complicated controllers but for this purpose it seems to work great um one little trick that maybe I'll leave you with right now is zeros I like to think of zeros as sort of like they're like magnets right we talked about earlier when we were sketching the root locus how as you increase the gain of the avi control system the loop gain the open-loop poles I start excuse me the closed-loop poles will go to the open-loop zero so zero it relie act as sinks or magnets or places that will suck the root locus towards it so as you move this around so for example if I kind of zoom out a little bit let me see if I going to zoom out and maybe pan over that this example may not serve exactly the way I wanted to but I'm trying to get you to see that as you move this around you do change the pole you can kind of see there we go this would sort of sucked this pole towards it and all of the poles will sort of get pull some of the poles will get pulled towards zeros so this is one little trick that can help you if you need to kind of pull the root locus in certain directions you may want to think about adding zeros of course to keep your compensator a proper you may need to add poles at the same time so again root locus design is a little bit of a I don't want to say guess and check but it is definitely iterative so again we're just gonna keep playing with us until we get a compensator that we like you can either do this graphically by grabbing and dragging and moving the root locus around or show you another cool feature you could actually grab and drag other components like for example here in the in the bode plot editor here right so here's my bode plot for the loop game to give me gain and phase margin so you can see right here that I'm not meeting my gain margin at all so you can also just grab and drag items here in the bode plots let me grab this let me just pull this up literally to see if I can get more gain margin and there you go there we go so now I grab and drag it and well yeah I think we want a 20 mm 20 decibels so here we go this seemed to work but again I guess we have to we have to fight this this battle on multiple fronts so let's look yeah this is actually looking halfway reasonable so again you can either manipulate the root locus by moving the magenta items you can manipulate magenta items here in the bode plot editor or again you can just right click Edit on compensator and punch in numbers that you would like so for example I would like an overall gain of this and then we know we're not we could move this real pole but it won't matter too much but I could also change this complex zero I can make this at minus 3.0 no 7206 and an imaginary part of on an out point eight one five one one I'm just kind of using some numbers right now and hit enter hit closed and then hey actually look at this that seems to work right look at all of our look at here our settling time is good our overshoot is good our rise time is good our gain and phase margins are good our bandwidth is good so great this looks awesome tell you what let's come back here to my control system and I'm going to store this and again you can now use the compare if I wanted to look at both design one and design two you can kind of see how the the two fare against one of the other so it looks like we actually do a bit of an improvement as is hopefully expected when I add the derivative we make the controller more complicated hopefully it's able to do a little bit more so with that being said let's go ahead and clear this comparison and let's go ahead and do like we did earlier and whoops let me clear the comparison and let's export this controller that we've got and let's call this C I pseudo D right and I'll go ahead and export that to the MATLAB workspace okay so let me see where is a CPI pseudo D here it is and as we said it's this continuous or kind of odd format we claim this still is API pseudo D controller it's just in a polynomial format so what I'm going to do is again supply this function extract come on extract what did I call this thing here PID gains so again go go to the description of this video you can download this function and all you need to do is I'm going to pass it the controller that we just designed in the linear system editor or sorry in the control system designer and it will give me the KP ki and KD so let's just go ahead and try this let me copy the function call here and paste it down here and I need to give this what did I call this CPI pseudo D there we go and here we are here's the gains KP ki and KD and a for that system that we just made so the last thing we're going to want to do is come to our Simulink model which was here I believe yep and let's simulate and verify that that works so what we're gonna have to do is let's mint our system with a pseudo D component as well so this was KD and then what we're gonna need is a transfer function to represent the whoops excuse me I'm just gonna type here and click transfer function there it is okay and I need this to be my pseudo derivative okay so that thing looked like a coefficient of let me see we needed to be a s over s plus a there we go so if I hit OK there I think this is basically this should act as my pseudo derivative there it is AOS over s plus a I look guess we need a little bit more real estate here with our drawing okay let's put this over here and well I guess I didn't do this quite the best so I need another plus tell you what to keep this nice let's witches to be rectangular and here we go so now here's my pea I pseudo D controller using the gains that we designed so let's just go ahead and see now if this system performs the way we expect it to so I'll just go ahead and hit run and come here to the scope and yay look at that this controller seems to work great umm again everything looks beautiful here in theory so the real proof is if I take these games KPK ikd and a for my pseudo derivative and run over to the lab and let's Chuck this on the real DC motor to see if this system works so let's try the full pie pseudo D controller with the same step input and as I said with the original Nintendo Entertainment System now you're playing with power it would have been a little more impressive if it had just stopped there but the small amount of error combined with the nasty nonlinear behavior the friction makes this actually a much more challenging problem now keep in mind that this is not a fully optimized system we didn't spend an inordinate amount of time tuning the root locus I bet if we had spent more time we could have squeezed a bit more performance out of this controller for example note that during the majority of the time here the control signal is actually less than minus 2 volts however during the initial step change the system briefly saturated at minus 15 volts if we'd been willing to tolerate a little bit more controller saturation I bet we could have made a bit more aggressive controller that would regulate the error more quickly to zero and these types of changes are actually easy to design for it simply involves us going back to the root locus in the control system designer and retuning the controller now let's again add that disturbance torque to further illustrate the robustness of the system and look at this it seems to work so in summary the full PI pseudo D controller seems to perform even better than the PI system and definitely better than that garbage P only controller the system is able to meet linear performance requirements as well as handle nonlinear effects such as friction and disturbances now I don't know about you but I'm very pleased with these results and it's not just because we got a controller to work but more because of how we got here we started by modeling a real plant as a linear system and then use a mathematically defensible approach to design a controller to meet desired requirements we spent a lot of time building up to this point and this is one of the first examples where we've been able to see the full control design cycle yield a successful outcome with a real system all right so we've seen how we can use the root locus technique to design ap ie pseudo dpi dpi any type of controller so why don't we talk about generalizing this so now it's no longer just how to design a PID controller but how about how to design a linear controller using the root locus technique so again the concept is pretty simple instead of using a specific route load or a Pacific PID structure this controller can be anything of the form some gain let's call it K with an S Plus z1 s + z2 all the way s plus Z M writes just m0 s all over an S Plus p1 s + p2 all the way s plus P n so you got em zeros and poles so this doesn't have to be a PI controller this is really any linear controller and the process of designing intelligently this game K these Z's and these peas are exactly what we just talked about so the procedure is really straightforward so one step one is basically you know get a model of your plan and then go ahead and like we talked about earlier just import that in your control system designer or whatever tool you'd like for visualizing the root locus as well as visualizing step responses and bode plots and anything else you need to know to understand the behavior of the system and then all you're going to do here is manipulate by adding a manipulate the root locus by adding poles and zeros which correspond to the controller right so step two is really manipulate the root locus by adding appropriate poles slashes zeroes corresponding to your controller and you know what it's it's almost that simple there's almost like two steps sure there's all these bells and whistles of exporting the the controller extracting gains if you wanted in a different structure and all that stuff but at its heart this is all it is is all you're doing is you're making a controller by appropriately placing poles and zeros so that you can manipulate the root locus of the closed-loop system because really at the end of the day that's a lot of what linear classical control theory is right it's just placing the poles of the system of the closed-loop system in locations where you where you want them to go so with that being said I hope you enjoyed the discussion today and you can see why this is so powerful and why it's it's applicable to pretty much any linear controller of this structure so if you've been a subscriber of the channel for a while thanks for being with us if not please subscribe because we're going to be having lots of other videos on control systems engineering in the future I'm trying to organize all of this curriculum because you've seen I am a lot of different other videos related to systems and topics like this so check out the description of this video for a link to a more comprehensive summary of all the videos as well as sort of a curriculum slash syllabus so with that being said I think this is maybe a good spot to wrap it up and I hope to catch you at one of these future videos so until then I'll talk to you later bye
Info
Channel: Christopher Lum
Views: 44,950
Rating: undefined out of 5
Keywords: PID, PID control, PID controller, PID tuning, root locus, proportional integral derivative controller, proportional integral derivative control, PID implementation, pseudo-derivative, tuning PID using root locus, PID performance, PID with Matlab, Control Systems Designer
Id: Hk6YBO_A_PU
Channel Id: undefined
Length: 63min 59sec (3839 seconds)
Published: Tue May 21 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.