Linearizing a Simulink Model Using the Linear Analysis Tool and ‘linmod’

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to another video today I'd like to continue our discussion on MATLAB and Simulink tools that can help you work with nonlinear models in our last video we discussed how to use the linear analysis tool to generate trim and operating points for a nonlinear system please make sure you've watched this video because we're going to build off a lot of the results we generated in our discussion today now that we have these trim points the natural next question is how do I build a linear model of this nonlinear system about these trim points in today's video we're going to look at two different ways to go about doing this first we'll use the linear analysis tool again and second will use the Lin mod command so if all of this sounds like a lot of fun let's jump over to the whiteboard and get started all right so let's use the same planner vehicle model that we developed actually in this previous video so again if you're interested in the dynamics of this vehicle please check out this vehicle for the full derivation of the equations of motion but to refresh your memory right it was just this simple vehicle you could think of it as like a boat which had both an axial thruster as well as rotational thrusters so it could almost float around and spin on its axis if necessary or desired so again here were the dynamics and what we did in our last video discussing trim points was we found four different trim points for this vehicle or four different operating points what I want to do now is look at two of them I want to look at case number one or trim point number one and trim point number four and these two are very very simple trim points right the first one was the vehicle just heading in the positive Y direction at 15 meters a second and we saw that here's the trim point that is consistent with this operating condition right we said the X&Y position really didn't matter we just arbitrarily set them to 10 and minus 10 but the X dot was 0 y dot was 15 the heading angle was 90 degrees and the theta dot was zero and in order to get that it took point five six to five throttle setting I guess on the axial thruster in order to get that and it took zero throttle setting in the moment okay now if you wanted to go slower at 10 meters a second we on a second operating condition here our second trim point for that can for that system and we see that they are virtually identical the only difference here is the y dot are obviously different and since you're going slower here you need less throttle right in order to achieve that okay so what I want to consider now is now that we have these two operating points really that's all we need we just need theoretically mathematically right all we need is the equations of motion right your nonlinear set of differential equations that's right here right this is X dot is equal to f of X U and then I need to think about where do I want to linearize this function about i want to linearize it about this x naught and this u not that's all we need to do the process at least theoretically right so before we jump over to matlab let's think about what do we want to try to achieve out of this linearization process so again our planar vehicle model if you remember earlier we had our nonlinear planar vehicle alright and we said there were two inputs to this it was a u 1 and a u - ok and coming out of this was an entire state vector I think in our simulation and then what we did is we hooked up like a another block that would be able to compute some secondary parameters like like the velocity right if you notice the velocity is not one of the states you have to compute the velocity by basically squaring this adding it to this thing squared taking the square root of the two in order to get the the velocity of the vehicle so then we had another block here which computed something like velocity okay so this was our nonlinear system right so this was our dynamics over here here was a small little extra block to compute some secondary parameters and now we have an operating point for this nonlinear system ok so now what I want to investigate is how are we going to go ahead and let's start simple let's get ourselves a transfer function maybe let's call it G V of s right just between u 1 and V ok so what I want to do is I want to isolate how are the inputs or the the effects of the axial thruster affect the velocity right so what we're going to do is we want to go from a non linear system to our linear system okay and the process obviously is this process of linearization okay now the question is are there malliband simulate tools that will help us do this process now that we've done the work and we have a nonlinear Simulink model and in our last video we discussed how to get the trim point we should have enough to perform the linearization process so that's the next step let's focus on just getting this transfer function between u1 and velocity okay so let's go ahead and first focus on maybe trim point one where we were trying to go 15 meters a second so again maybe you want to write down this trim point here to keep it in the back of your head because we're actually gonna run over to MATLAB right now and put this into a script and see what are the tools that we can use to perform this linearization process alright so here we are in MATLAB and I've just started a little script and you'll notice this looks almost identical to the script that we use when we were trying to trim the model except now what we're trying to do is we're trying to linearize this model using both the linear analysis tool and Lin mod functions so to get that going all we're gonna do here is obviously define all the constants for my model and then next let's go ahead and define the trim point that we're interested in so I think we said the trim point or the trim state was 10 - 10 0 15 PI over 2 and 0 and the trim control as we just said was 5 6 - 5 and 0 right ok so if we go ahead and run this we should have all of our constants as well as the trim state X naught and the trim control unit now all we're gonna need to do next is come to our VR Simulink model okay so whoops where that's the that one there we go so here's the Simulink model that we set up last time now what we need to do is get this thing ready to run using the trim state and the trim control as the initial condition and the input respectively so I'm just gonna go ahead and start with the initial condition so I'll double click on my plane or vehicle model and I will plug in wherever I need for the initial condition and I'm gonna use X naught right that was what we defined over here okay so now I have the initial conditions set up and now I need the trim input to this system so that's over here so I'll go ahead and delete these two out blocks we don't need these let's go ahead and say delete and now what I'm gonna do is I'm gonna grab a constant okay and the constant value is gonna be you not okay that was our trim input and now I just need to hook it up here so I'm just gonna grab myself maybe Adam ox and let's hook this up like such and hook up the d-max to the rest of the system okay so at this point here we go I think the system should be ready to run at this point so if I go ahead and hit play on this we should be able to look at the scope and we see yeah this looks beautiful the system stays at an X of 10 y just starts linearly increasing X dot stays at 0 Y dot stays at a perfect 15 theta stays at exactly 90 degrees and theta dot is at 0 so right now the system is running using the trim state and the trim control as the initial condition and the input respectively and I'm just showing the inputs just to make sure we're all on the same page right the the axial thrust stays at 0.5 6 to 5 and we got 0 for the moment so the model is set up and ready to run or actually it is running with these trim points so let's go ahead and take the next steps and figure out how can i linearize this system to get the transfer function between the thrust fraction here and the velocity of the vehicle down here so to do that what I'm going to do is I'm going to find the signal that I want to use as the input so here it is this is u1 and I'm gonna right click on this and I'm gonna come down here to linear analysis points and I'm going to set this as an input perturbation because this is the input of the transfer function or the linear system that I'm interested in so when I click on this you'll notice that Simulink will give this the signal this little annotation or this little icon here to show you that this is going to be used for linearization eventually as an input point similarly to get the output of the linear system or the transfer function I'm interested I just come down to this signal right I want the velocity as to be the output of the system and I will again right click on that signal linear analysis point now this is going to be an output measurement because that's the output of the system that I'm interested in measuring and again you see that icon come up alright so that's pretty much all we need to do to get the Simulink model ready let's go ahead and hit save and now all we need to do is we are going to launch again the linear analysis tool to perform the linearization so I'll come up here to my Simulink model click on analysis control design linear analysis and again the linear analysis tool is gonna pop up in another window let me drag it over alright so what we can do now is first let's go ahead and come up here to analysis iOS and we're gonna first click on this little drop down and make sure that it's set to model iOS because that's what we want to use as input outputs are these little signals that we are the little annotations that we placed on the different signals so again yep that's set and just to kind of triple check you can come down here and say edit model iOS and what will show up is this little dialog which will show you all of the available model inputs and outputs that you can use for input perturbations or output measurements and you can see here that yep it's the thrust fraction as the input and the output is the velocity so that's exactly the transfer function I want I want the transfer function between U 1 and vehicle velocity okay that's great the other thing that we may want to double check now is let's also double check that the initial condition in the model is the actual trim point that we're interested in so what I can do here is come here to operating point and I'll just click on the drop down and come down here and say view model initial condition and what that's gonna give you is again a 90 little dialog that will say here's the point where we're thinking about linearizing about so you can see this looks exactly correct and yeah actually this doesn't have any inputs here but it does have inputs in the Simulink model right here right it says you've got you not coming into the system so we've got the trim point correctly input to the system so we are going to be going forward at 15 meters a second with the rest of these states as listed so this is exactly the place that we want to linearize this system about so to linearize this it's actually really simple you come up here and you can click on any of these here you can see it says linearized you click on any of these and it will linearize the system and give you either a step a bloating plot and impulse nyquist whatever you're interested in so or if you kind of click down here you can kind of find this button that says linearize with no plot so if you don't want a plot you feel free to just click this button I think the plots are kind of nice so let's just go ahead and click this button and you're gonna see that we're gonna get a variable showing up here there it is Lince this one and then we're gonna get a plot showing that linear systems step response and here we go so this is beautiful you can see that this is the step response from thrust fraction which was u1 to velocity this is exactly what I'm looking for so this linzess one is the linear system that I'm interested in the system has gone ahead or seemingly has gone ahead and linearized the system for me so again you can just double click on this if you really want to see a little bit more information about it huh this is fascinating it looks like it's just the first-order system we'll take a look at that in a second to make sure that makes sense but assuming that this looks reasonable what we can do is let's go ahead and drag and drop this again we see that it's here in the linear analysis workspace I want it back in the MATLAB workspace so I can save it so I'll grab drag drop it into the MATLAB workspace and now when I come back to MATLAB and I look at Linds this one here it is here's the linearized system so again let's go ahead and maybe save this I'll call it linear system a 1 dot mat and I'll save the Lynn sis one variable great so it's saved here what we may want to do is let's go ahead and get the transfer function of this system so let's come here to our MATLAB script and say obtain the transfer function for the system and actually let me make this a cell okay and what I'll do here is let's go ahead and get the a matrix it's just going to be Lin sis 1 dot the B matrix is going to be obviously Lin sis one dot BCD so we're gonna do all of these we're gonna get all the a B C and D matrices out of this thing okay and then what we can do is let's go ahead and use our good ol friend SS two TF to take this state space representation and turn it into a transfer function numerator denominator and then we can go ahead and obtain the transfer function we want which was GV we called it is transfer function of Noom den okay and again in this case i don't think we're gonna need to but I always like to wrap these things in a min real command again if you need to refresh your memory on what min real did please check out this video here where we talked a little bit about pole-zero cancellation and using the min real function in matlab i'll assume you've watched that you know what this is doing so I think we should be good to go so let's just go ahead and evaluate this cell so I can just go ahead and where is it I know it shift here it is evaluate current section let's go ahead control enter here we go so here's theoretically what the linearized system is between u1 and velocity it's a first-order system with a pull and minus point oh seven five so maybe what we should do before we go any further is let's go back to the whiteboard and double check that this is reasonable and if it is reasonable we'll look at another way to numerically linearize this system alright so we just saw how you could use the linear analysis tool in MATLAB Simulink to perform this linearization operation and we saw that at this operating pointer at this trim point the linearized system was supposedly one over s plus zero point zero seven five right that was the answer we got from MATLAB steve minich it was this first order system now let's go ahead and check if that makes sense so let's see if we can linearize this system analytically so at this trim point luckily the system is simple enough that we actually don't need a ton of whom machinery in place to perform this linearization so what we can do here is let's basically realize that in this offer in condition it's effectively a a one-dimensional system right theta is constant at PI over 2 right because theta down to 0 X is 0 X dot is 0 so there's not a lot of dynamics going on the only dynamics is in the Y direction here right so basically let's just take our equation for y dot so here is XY X dot y dot so here's the only place where there's any action occurring right so this was effectively saying y double dot right is equal to 1 over m f u sine of X 5 minus FD sine of ky right that was our equation now we can make a note here that ok again at this operating condition X 5 right well we'll know here what is X 5 X 5 was theta right and this is constant at 90 degrees right it's always going up at 90 degrees so this is PI over 2 right similarly Chi right the course angle is the same thing as a heading angle in this case so Chi is also equal to PI over 2 so both these sine terms just go to 1 right so this gets a lot more simple so we end up with again 1 over m times fu minus FD right ok let's remember what was the axial force so if you recall a few was F max times u 1 right times the first control input right that was how our model worked and finally what was drag F drag right that was CT times V squared that's what we ended up ok we can make one more substitution and if you notice V is basically Y dot in this case alright so this is the same thing as C T times y dot squared okay so we can plug this in and we end up with 1 over m times F max times u1 minus CT y dot squared all right okay all right why don't we go ahead and distribute this one over em through we can get this to look like basically Y double dot is equal to F max over m times u1 minus CT over m y dot squared okay so you can see that this is basically a second order differential equation in Y or you know what we can maybe do why don't we consider the state to be just Y dot to be the velocity right because that I get in that way I can basically turn this into a first order differential equation so in other words let's go ahead and say let the state let's call the state how about Z be Y dot okay so if that's the case you can rewrite this as we're kind of running out of space maybe what I should do here is let's let's erase this up on the boat top we'll start all over okay so what I want to do is rewrite this using this state so we end up with Z dot alright is just F max over m times u1 minus CT over m Z squared great so now this is a first order but still nonlinear differential equation here okay so what I want to do now is let's go ahead and linearize this about a given operating point so to linearize analytically right we talked about this actually in one of our other videos where we talked about performing linearization via a Taylor series you're basically doing a Taylor series expansion of this differential equation about the operating point that you're interested in so the a matrix in this case was just your good old friend the Jacobian right so this was partial of if we call this function f of Z right this is now F of Z this is partial of F with respect to Z evaluated at the point of interest right evaluated at Zeenat and you not right so this was just fancy words for partial with respect to Z of this thing right F max over m times u1 minus CT over m Z squared and you evaluate the result here at Z is equal to Z naught and U is equal to u naught right about the expansion point that you're interested in so taking this partial it's pretty easy to see this doesn't contribute but here the two comes out so we end up with this partial here is basically two CT over m times Z evaluated at Z naught so turns into this right so here's your a matrix it's really simple okay so your a matrix in this case is a oh sorry I'd be careful careful I dropped a minus sign right there should be a minus there okay here make sure it should be negative to CT over MZ not right so again this is an interesting point but also it's probably expected we notice here that the a matrix is a function of the trim point in this case this is our trim velocity so in this case we want Z naught to be equal to what's 15 right that's the velocity that we're trimming about right that's our trim trim speed so in this case with Z naught is equal to 15 and then all of these other constants I think if you remember CT the value we're using for that is I think wasn't it 1 over 40 or something yeah 140th and the mass we were using in this case was was 10 right so you can plug all of this in and tell you what let's let's let's wait to plug in all of these values here well we'll do it let's get the B matrix as well so let's go ahead and erase this okay so our B matrix in this case it was a very similar expression right it was partial F but now it's R with respect to u right Z naught u naught right that's how you get the B matrix so again it's just taking the partial of this thing but now with respect to U and now you can see this is actually pretty simple this comes out to just F max over m right so your B matrix in this case your B matrix doesn't change it's not it's constant it's not a function of the trim point either the trim state nor the trim control because you don't see Z naught or you not show up here so here's your B matrix okay and again the only other difference we need here what the only constant we need is F max right so I think F max what were we using in this case it was also 10 there okay so now we can get the transfer function between Z which is velocity right and you won here okay so the way we get that right is the transfer function GV it's just our good old friend si si minus a inverse B plus D right and we're going to make a note here in this case your C matrix is just 1 right because the output of the system that I care about is just the state Z where was it I guess yeah z well Z naught the velocity right we said that was our fancy word for velocity and then our D matrix is zero so you plug in here's your a matrix here's your B matrix here's your C matrix use your DMH plug it into your expression and what we'll end up with at the end of the day is G's where am i I'm running out of space here let's see maybe I can erase this picture we don't need this picture anymore okay so what we end up with is G V of s is going to be F max over em all over s plus 2 C T over m times Z not great so now we're ready to go ahead and plug in all of these constants over here right just plug in all these numbers into our expression over here and lo and behold what you end up with is 1 over s plus 0.075 so analytically this is what the transfer function between u1 and velocity should be right which is beautiful because if we compare this with what the linear analysis tool gave us their their bang-on in this case right there perfect so that gives us confidence in what the linear analysis tool is doing let's go back over to my lab and see is there another way or another set of tools we can use to also linearize it and see if it gives us this exact same answer all right so to linearize the system using Lin mod let's go back to our Simulink model and I'm actually gonna save this as a second model here just to illustrate that they are two different methods so I'm gonna call this planer vehicle model maybe underscore Lin mod okay so let's go ahead and clear these annotations just so we're not confused so I'll go ahead and take away this okay and then let's also take away this linear analysis point so again just click on it again to get rid of it okay now what we want to do with Lin mod is we are gonna go ahead and grab some of these input and output blocks so first let's grab an import block and in block drag and drop it and what I'm gonna do here is we're gonna use this as kind of the equivalent input perturbation signal so what I want to do here is I'm going to let's go ahead and delete this MUX and I'm gonna stick this here okay so now this is almost acting like that input perturbation annotation was in our previous method so this is where we are going to input something and now I want to make sure that the output is proper as well so in this case instead of it being a two by one I need to make sure I get the dimensions right so this is now the second trim point for the second input okay so at this point I think we're fairly set up on the inputs let's do a similar thing for the output so now actually a look at this we already have these two outputs let me go ahead and actually disconnect this cuz uh and delete this and I will disconnect and I'm gonna hook this up like this just just so everything is consistent again let's call this V okay so now what we've got is we've got a system where this is the input and this is the output okay so obviously this is not going to run right now because right now I don't know you've got something very odd coming and I actually don't know what Simulink decides to use here but I think it I think it uses zero so if you run this you can quickly see that we're not at equilibrium right the inputs we're not sitting here at the trim condition right that these inputs are both zero and as such the system responds like both of those are zero but we're not trying to simulate the system we're trying to linearize the system so in order to do that we've got the models set up and ready to go I'll go ahead and hit save let's come back to our script and now what I'm gonna do is let's comment out this entire section here okay and let's see if we can get the transfer function using another method so we're gonna go ahead and use the Lin mod command to do this so I'm gonna say help Lin mod and you can see that what Lin mod does is it basically obtains linear models of systems of ordinary differential equations that's exactly what we want to do so what we're gonna do is actually this version of Lin mod where we're gonna tell it where the Simulink model is or where the nonlinear system of ordinary differential equations are and we're gonna tell them what is the state and control input or the trim point that we want to linearize about so the call is real simple I just need to say Lin mod and then what do we call this thing planer vehical I think I spelled that wrong V hick Cole model underscore Lin mod okay dot SLX I can tell you well let's take off the a file extension I think there's some times where this thing doesn't like it okay and then what is the trim input it's X naught and what does the trim are sorry what does a trim state that's X naught and what does a trim input U naught however you got to be a little careful with you not here because u naught is basically the trim input to the system if we come back to our planar vehicle model right we see there's only one input here right this is the only thing I want to perturb so actually this right now u naught is a two by one I only want the first entry right I want you not sub 1 this is the point this is the trim point that I'm interested in linearizing about and if it does this is this should give me a B C and D right great and actually you know what maybe let me cut this and we'll move this further down because we're still gonna want to do the exact same thing that's just a different way of getting a B C and D matrices for this system right instead of using the linear analysis tool we're gonna just use the call to Lin mod so it's really this simple now if we do go ahead and run this well oh haha yep I need this call too because I need to turn those a B and C and D matrices into a numerator denominator so let's go and run this again and here we go we get the exact same result so we see that Lin mod gives us a very similar where actually gives us the exact same result all right so we just saw that both the linear analysis tool and Lin mod gave the same results in this case so you might be asking yourself is there any real differences well I'm glad you thought about that and you know what math works also is glad you thought about this because they already have some documentation on some of the differences so if you come to this URL I'll leave a link to this in the description of this video you can see that they discuss some of the differences between using the linear analysis tool which is effectively what they're calling simulant control design linearization versus what they're calling Simulink linearization which is basically Lin mod so a little bit more if you're interested in digging a little bit deeper about linearization there's also an excellent video by uh by Brian Douglas I'll link that as well where he talks a little bit more about the inner workings about Simulink linearization okay so with that being said let's see if this changes if we look at the other trim point all right so to do the other trim point I think we call that case number four right where all we need to do now is just change the trim point so instead of going ten meet 50 meters a second we want to go 10 meters a second and now the control input dropped down to 25 or 0.25 so again let's go ahead and do the exact same operation so what we can do is let's go ahead and maybe tell you let's put it let's put a breakpoint here and we're just going to run this first bit because all I need again is I just need the trim point and the sorry the trim state and the trim control and now let me exit out of the debugger let's go ahead and open up our Simulink model again we already have our input perturbation and our output perturbation are ready to go so we're just gonna go ahead and again start the linear analysis tool and maybe what I should do is let's go and check the model initial conditions make sure those are appropriate oh and actually look at this they're not because this is the same session that I had loaded up earlier let's go and hit the refresh button now we're talking so as soon as I hit refresh it got the new trim values from the model so now I think what we're ready to do is trim again so I can again come here and click on one of these or you know what let's just come here and linearize and don't do the step response so I'll just click linearize and here we go we get Lin sis 2 and again I'll grab drag and drop this into the MATLAB workspace where we can inspect it Lin sis - here we go it's a little bit different so let's go ahead and again do this portion of the script I'll uncomment this and I guess I have to make this Lin sis - now right and everything else is the same so it's just a new ABCD matrix and if I evaluate this section we should I guess sorry I've got a breakpoint set up here let me exit out of this try this again value 8 this section oh sorry you know why I don't haven't saved it there we go save this I'm just trying to execute all these commands there we go here we go we get a different transfer function so again this is interesting it says that the transfer function changes or the linearization changes depending on the operating condition again let's go back to the board and double check that that makes sense all right so I left most of this up because really the only difference between trim point one and trim point four was really the trim velocity here right so now this was 10 and this was 0.25 right okay so all of this analysis basically computing the jacobians everything was the same the only difference was where do you evaluate that Jacobian right instead of 15 you're evaluating this at a velocity of 10 so everything changes and if you run this again you plug in all these numbers you do indeed come up with the same thing that we got in the linear analysis - oh yeah I guess I should change this down here right this is what the linear analysis tool gave us right so everything is the same and again this is actually fascinating that this system is dynamics change depending on the operating point which makes good sense if you think about the way this system is set up right we had this nonlinear term of drag right that's actually what's coming into play in this one-dimensional case where the vehicle is just going straight right we talked about this earlier that the picture that went along with it or where did my little boat go oh here's here's my vehicle right when it was going straight up we had the situation that add trim that the force from the axial control has going to have to equal the drag force right when this boat was moving at some sort of velocity V right so what's coming into play here is that this drag force right is nonlinear if we were to plot F drag versus velocity I think we're using a square function right a quadratic so it looks something like this and what we're doing now is trim point one was over here at 15 meters a second and trim point number four is down here at 10 meters a second so you can clearly see that the drag it's slope is effectively kind of what we're computing here we're computing a linear model of the system at different locations so because this slope changes depending on trim point therefore your transfer function or your linear model changes with the trim point which is clearly reflected in our Jacobian right here because you see that terms show up in your a matrix so again all of this checks out the analysis as well as the numerical tool seemed to make sense so just to close out this discussion on this this single input single output system let's go back to the MATLAB and verify that Lin mod gives us the same result all right so to verify that Lin mod gives us the same result again it's really simple we just need to get used Lin mod to get our a B and C D matrices instead of the linear analysis tool so I'll just go ahead and uncomment this line and you know what we can just run this again because our planar vehicle model underscore Lin mod this is already set up so let's just go ahead and right-click and well I guess now I'm going to learn let's save the script and right-click and evaluate this section and again here we go we get the exact same result so this is perfect uh we were able to show that the system is able to linearize about different operating conditions or different trim points now we looked at just a C so or a single input single output case but you know what multiple input multiple output is just as easy let's uh let's quickly jump back to the white board maybe and identify what type of inputs and what type of outputs we might be interested so a multi input multi output system is just as easy so I'm just going ahead and erase the board and and move to our diagram up to the top where we'd have a little bit more room this is what we were looking at earlier right getting the linear system between axial throttle and velocity right now to give an operating point well we can actually just add in more inputs and more outputs so for example what if we said I want to understand how does the axial input force affect the the heading angle of the vehicle or theta so you can just come in here and get yourself a D mocs right and there's a one two three four five six here right so I think we want number five right this is theta right so what we could do now is we could start asking ourselves questions of well how does the axial thrust affect this output right and we could also look at different combinations for example like what if we wanted to understand how does the second input right the second input which was this moment throttle setting right about how much moment is being applied to the vehicle we could designate this as being an input so now in this case we've got two inputs and two outputs so the linear system I would expect to try to obtain either a single state space representation or for transfer functions right this would now be I guess maybe a better name or another name for this this would be like a g1 one right and then we could also be asking ourselves what is the transfer function between U 1 and theta this would be something like a g1 2 right or I could be looking at the transfer function between you 2 and velocity right this would be like a g2 1 and then finally what is u 2 2 theta right this would be like a g2 2 so we could be thinking about trying to generate now four separate transfer functions or again I guess one linear state space representation however you like to think about it but it's really simple to do this using the linear analysis tool so why don't we go back to MATLAB and see how can we expand our seaso system into a MIMO system so it's quite easy to actually modify our system to have multiple inputs and multiple outputs for the linearization process again let's just open up our Simulink model and then we will just go ahead and designate this as a second input perturbation and then we will designate theta here as a second output measurement great there we go so let's go ahead and save this and bring up our linear analysis tool and let's go ahead and double check here that those were updated so I'll come here and analysis iOS and edit model iOS and there we go this looks great looks like we've got both the u1 which was the thrust fraction and u2 as the torque fraction as input perturbations and then we have both velocity and theta as output measurements and you could hit refresh I guess if you want to be very keraton that this did update and is synced up with the model but it looked like this work so maybe let's also check that our initial conditions are proper and yeah it looks like we're still at the 10 meter per second condition here so this was trim point number 4 I believe all right so I think we're ready to linearize here's kind of an odd error if we go ahead and click on this bun to try to reel in your eyes we're going get a little bit of an error here saying that the plot size is basically incorrect which is right instead of having just a single input in a single output now we've got two inputs and two outputs so now this single input single output step graph we have here is not sufficient so to get around this all you got to do is just close this thing and then hit step again and here we go now we've got multiple inputs and multiple outputs and here's what's actually a little bit interesting it looks like here the one one is actually between the thrust and theta so as expected this is kind of like a big zero here so it looks like it switched the numbering of the inputs in the output so it looks like the first input is thrust the second input is torque but the first output is actually theta and the second output is velocity here so when we go ahead and take this lin says 4 and move it to the MATLAB workspace we can see that's the case so if we come here to the MATLAB workspace and look at Lin sis 4 let's take a look at this alright so maybe it's not as easy to see or not immediately obvious by just looking at the a B and C matrices because we actually don't know which way it was set up but I think we can figure that out if we were to go ahead and modify our script down here where we are going to now let's go ahead and get all of those transfer functions that we listed on the board so I'll uncomment this section and we'll comment this section out ok so this is now change Lin says 4 ok and now what we want to do is let's get all of those the 1 1 transfer function which is between the first input and the first output and I guess the d matrix needs to be appropriate right and then let's get the 1 2 which is between let me see the one - that should be the first output second input there we go something like that whoops ok then let's get the the 2 1 so that is going to be these between the second output and the first input and then let's get the 2-2 element which is between the second input and the second output okay great so let's go ahead and maybe rename this as g11 great and let's do this for all of them will get G 1 1 will get G 1 2 and then we'll get G 2 1 and G 2 2 okay all right great so now if we go ahead and save and run this section here what we'll see is those different transfer functions and indeed it looks like yeah G 1 1 is 0 but G 1 2 this looks like the transfer function now between the two of them the moment throttle setting and theta here so we can see it's a second-order system and again if we went through the same process on the board that we did earlier where we tried to analytically linearize the system again the system is simple enough and decoupled enough that you would get exactly this result now G 2 1 this is what we got earlier so here is the transfer function between the torque or sorry the axial thrust throttle setting and the velocity of the system and then finally this is zero so we actually see that this these two inputs and two outputs they're completely decoupled from each other at this operating condition so again we got to be a little bit careful that it looks like we weren't able to explicitly set the numbering of in terms of which was the first input which was the second input which was the first output and which was the second output so these numbering here are in Malibu is a little bit different from what we numbered on the whiteboard a second ago but the results are the same ok let's do the same thing for Lin mod all right so to do a similar thing for Lin mod again let's go ahead and open up our Lin mod model ok and all we're gonna do is again make a similar modification now I'm going to delete this constant and we're gonna go ahead and grab another one of these input ports and hook it up so now there's two inputs both the thrust fraction and the torque fraction and similarly I'm gonna grab another one of these output ports copy pasted here this is now going to be theta and I'll just hook it up to the theta signal like such save the model and I think we're ready to go so I will go ahead and come back to our Mallove's crypt and maybe we will go ahead and comment this out and then we will uncomment the Lin mod call and now we're gonna get our a B and C and D matrices using that other model and the Lin mod function so again let's save the script and I'll right-click and run this selection and whoops oh whoops oh yeah here we go I messed up the Lin mod command here write the Lin mod command again if we look at our system weight whoops that's the wrong Simulink model sorry let's open up the Lin mod model here we go this is the Lin mod model here's what the error is there are two inputs to this right so when I specify the trim point about which I want to linearize the system I gotta give it the proper state vector and then a control vector which has two inputs which correspond to these two okay so in this case the trim point I want is like this right so you not here it is yep this is the proper setting so now let's go ahead and save again and rerun this section and there we go so now here interestingly now we've got the numbering correct so again if you bring up the Simulink model we are able to explicitly as soon as I bring up the Simulink model right we can clearly see that input one is a thrust fraction input two is the torque fraction and output one is the velocity and output two is theta so in this case it looks like yeah g11 yes this is between the first input in the first output or the thrust fraction to velocity G one two is the one two let me see this is the first output so this is velocity to moment fraction so yep it's decoupled similarly here decoupled and then g22 is the transfer function between the moment fraction and the angle theta so again this looks great and it's a couple of different ways now to get a linear system alright so we saw we got to be a little bit careful on the numbering here about which inputs and which outputs the system decides to call first second third etc etc but we basically saw that at the end of the day the transfer function that we obtained between the throttle input or the actual axial thrust throttle and velocity right at the condition here of I think we were using this was trim point four right where the velocity was 10 meters per second right at this condition this transfer function turned out to be one over s plus 0.05 this guy between you won this was a big zero there was no relationship there this one also turned out to be a zero and now the transfer function between the moment throttle setting here and theta was actually a second-order system of 0.1 all over s squared plus 0.15 s okay so that's what we obtained both through the numerical linearization process aka the linear analysis tool and Lin mod as well as analytically right we showed that these are exactly what they should be so the next question I'm sure you're asking is alright great the tool gave us some linearize models are they actually accurate right do they represent the real system so in order to do that what we should maybe do is let's go ahead and subject the nonlinear system to some inputs here maybe some some simple step inputs in these two commands and then we will generate the same or equivalent step inputs to the linear systems and just make sure that these two systems give us reasonable results as long as the system is operating near this trim point here of Y I guess that's not the whole trim point but you get what I'm saying right the condition of straight-up at 10 meters per second all right so to check the reasonableness of these linearizations I've just slightly modified the system we were using to linearize using the linear analysis tool so I've added these green blocks and as you can see the green blocks are basically just the linear transfer functions that we computed using the linearization process so here's G V and here's G theta again these are for the trim condition of U naught of U naught and X naught corresponding to the 10 meter per second case or that case number 4 so in the first case let's just make sure yeah I'm where we're using a Delta u Delta u 2 of 0 so let's only perturb the thrust fraction and see what happens so we'll feed the same perturbation to the linear model as well as to the non linear model and again keep in mind that I am accounting here properly for the difference between Delta U and absolute U and Delta X and absolute x so again if you want details on these discussions here make sure you watch our video discussing analytical linearization but long story short these should be comparable so what we're gonna do right now is at time equals 1 let's just bump up the fraction the throttle by 2 percent here okay so if we run this and I go here and look at this scope and I'll drag it over here to this side you can see that these two are fairly reasonable the yellow is the nonlinear simulation and the blue is the linear simulation so you can see they both agree fairly nicely however we do see that as the velocity increases right as you start moving away from that trim point the nonlinear and the linear systems start to diverge we can see this effect to be even more exaggerated if for example if we increase instead of just a 2% bomb how about a 50% increase in throttle so we'll go from a throttle setting of 25% up to a throttle setting of 75% and again we'll hit run and check out the scope and again the linear simulation which was the blue again looks like this nice first order response but the second but the nonlinear simulation which is a yellow line right that quadratic drag starts to real start influencing the system so we see that the nonlinear system diverges significantly from the linear system showing again that these systems are our only reasonable in small regions near the operating point or the trim point how about let's do the same for G theta so again let's turn off the Delta U and let's go ahead and turn on the bump in Delta u2 which was the moment to the system so here we're gonna increase this by 10% okay so here if we go ahead and hit run and now look at the theta component let's go ahead and look at those here's what the transfer function says and look at this they're both right on top of each other that's because actually this system is already linear in theta in in this dimension here so the dynamics here between the u2 control input and the theta are actually already linear so these two come out exactly correct or exactly one on top of the other and again if we changed this now to go up by I don't know point 75% of giant jump in in throttle setting we see here that again they're still right on top of each other thus showing that the system is is pretty much linear in this condition so that's great I think what this shows is both of these systems seem to work well so these two linearizations that the linear analysis tool computed for us work very well again be a little bit cautious here because this system was simple enough that there was actually no cross coupling in the sense that GV and g theta at this at this operating point linearly they are not coupled but we know that they definitely are coupled in some sense so for example we can illustrate that real quick for or let's go back to our small input of just just 10% or you know we could even make this smaller 0.05 something small like like yeah 0.05 here so let's do this wait is sorry what did I yeah there okay at 0.05 and let's go ahead and I'll turn both of these on so let's do both of these at the same time and now again I'll make this back to something small like point one in throttle okay and now if we hit run again the theta is exactly perfect right because those are linear dynamics but now the velocity if you look at this this is very very different right again the linear system predicts just nice first-order dynamics but the nonlinear system we see clearly see some of the coupling between the states in a nonlinear sense coming in to give us this very interesting behavior of the nonlinear system so again you got to be a little bit careful about these linearizations and the areas in which they're accurate but uh with that being said I think this is a good spot to leave it so just to recap what we talked about today we looked at how to use two ways to linearize this nonlinear system right we started out with a nonlinear plant model and we tried to now linearize it using both the linear analysis tool as well as the Lin mod function and both give us very reasonable approximations and linearizations of the system about a specific operating point now the next step in the process is now that we have these linear systems is obviously to try to build a controller using all of our linear system theory the nice thing about these linear transfer functions or the linear state-space representation is all of these tools that we built up can be brought to bear on this problem we can do root locus we can do full state feedback we can do lqr we can do any other types of number of control architectures and have guaranteed performance for the linear system and then try to port that controller to control the nonlinear system so that's where we're gonna be heading next so I hope I will catch you at one of these future discussions if you've been a longtime subscriber to the channel thanks so much for sticking with us if you're new please go ahead and consider subscribing because we'll have lots of other discussions on control engineering in the future and I hope to see you at one of these videos see you later bye
Info
Channel: Christopher Lum
Views: 34,295
Rating: undefined out of 5
Keywords: Linearization, linearize, linearize dynamic system, linear ordinary differential equation, Linear Analysis Tool, linmod
Id: M6FQfLmir0I
Channel Id: undefined
Length: 55min 14sec (3314 seconds)
Published: Sat Jun 01 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.