Trimming a Simulink Model Using the Linear Analysis Tool

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 some tools in MATLAB and Simulink that will allow us to easily and quickly trim a model the majority of the time today is going to focus on the tools that allow us to do this trimming if you're interested in some of the background theory or discussion related to trimming a system or just would like to dig a little bit deeper feel free to check out our other video which will talk a little bit more about trimming a dynamic system using numerical optimization now that being said while I wouldn't consider this video to be necessarily a strict prereq to make sure we're all on the same page why don't we go ahead and recap a couple of the major points that we made in this discussion as it relates to trimming so the concept with trimming right is that you have some type of a dynamic system and typically this is described by a system of usually nonlinear ordinary differential equations now the idea here is that this system would have some input you which might be a vector so there might be multiple inputs and there might be multiple outputs as well now this thing also has an internal state which we'll call X right so again you've got inputs u outputs Y and internal state X now the concept with trimming or sometimes it's also referred to as finding an operating point is it's really simple all you would like to do in some cases is it might be desirable to find a pair of inputs and States which yield some type of desired behavior may be some desired output all right so maybe we should just write that down here that a trim point sometimes also known as an operating point right it's really just a pair of let's call it X naught and you not typically constant here that yields some type of desirable behavior so do desirable behavior or maybe a you know state trajectory or output however you like to look at it right so if the system is something like like an airplane right trimming it and the desired behavior might be something like finding the control inputs and the state vector that would yield straight and level steady-state flight right so obviously in order for this aircraft to fly straight level it has to be going at a certain velocity it has to have a certain angle of attack the engines have to be set to a certain propulsive force the elevator has to be set at a certain deflection angle to maintain this angle of attack etc etc right and you can kind of see that this is where that term trimming came from right we talked about this earlier it literally came from aircraft systems where a pilot would be the one that would manually be fidgeting with the control inputs here to try to manipulate the state so it got into the desired configuration so that you would have the desired trajectory and maybe the desired outputs like the aircraft was just flying straight and level all right so that's the idea with trimming maybe one other quick side note that I might want to make before we go on here trimming and operating points um sometimes people refer to these as equilibrium points as well but they're not all interchangeable remember in that other video we mentioned here that a trim point is not the same thing as an equilibrium point all right remember the equilibrium point idea was that if this system here was described by some X dot is equal to f of X and you write an equilibrium point is typically defined here as the set of x and u such that f of X and you maybe we should put the knots on them all these are knots right these are the location you're interested it is equal to zero in other words it yields zero State derivatives so meaning that if you stayed at that condition if you found this magical set of control inputs instead of States the system would stay there and it wouldn't move because X dot is equal to zero so you can clearly see them coming back to our example of the aircraft in straight and level flight as it's flying along yeah the mistakes do have state derivative is equal to but for sure the position is not the the position dot is not equal to zero right this thing has it can't hover right it's not a quadrotor so it needs to be moving at some velocity in order to obtain this trim point so some of the states like the position East or the position north is definitely changing as you move along alright so just another little small point that we may want to mention here that when we're talking about trimming a model we're talking about finding this operating point we're not necessarily finding an equilibrium point right you might want to find an equilibrium point which is which is a type of trim point but vice versa is not true right okay so that being said the discussion today now is with this background what we want to do is look at some MATLAB tools that will allow us to make constraints or specify certain controls or certain states and put restrictions on them so that we can try to find these operating points so maybe we should just quickly write that down here what we want to do here is we want a tool that can place restrictions or maybe constraints might be a better word on you might want to put a constraint on the state vector you might want to put a constraint on the control vector you might even want to put us constraint on the state vector derivatives here right so typically this is what's done right you specify I want the aircraft flying at a certain altitude at a certain speed and I want the ailerons to be 0 but I'll let the other ones be free and I want it to be a steady state in the sense that I don't want the some states like the acceleration which is the the derivative of velocity to be 0 all right so the idea now is to find these trim points you want to find operating points which satisfy any constraints that we place on a subset of either the state controls or the state derivative dots and also satisfies the dynamics of the system ok so as you can see doing this for a complicated system manually is very difficult right and then that's exactly like we talked about there that's what a trained pilot is doing ran a pilot trains for many years and they understand the dynamic system they're playing around with namely the aircraft they understand it so well that they know how to manipulate some of these controls and states to get to a trim point or to an operating point now if you have some other arbitrary model or is very very complex we need some mathematical tools that are gonna allow us to try to find an operating point which satisfies these constraints that we're going to put on the system okay so with that being said give me a second I'll erase the board let's look at a very simple example system that we can use as our concrete test case for these studies all right so the example I'd like to use for this case study is the planar vehicle that we actually derived in one of our previous videos so if you haven't seen our discussion on deriving the equations of motions for this simple planar vehicle please check that out because I'm going to assume that you've already seen this perform proceeding forward so you have a good understanding of how this model behaves and some of the dynamics we're gonna see that later on understanding the trim solutions it's very helpful to have a physical intuition on how the system should behave just so you can check to make sure the results are reasonable so that being said just to refresh your memory right it's a planar vehicle like a boat or I guess like that rocket ship from asteroids it's a system where you can actually move around in the plane right but the system can rotate independently it's got sort of these independent thrusters so it can spin on an axis if you want to all right that's how it's set up right it's got States like here you've got X Y position X Y velocity angular position and angular velocity and then you've got to throttle to control inputs one is a throttle for the axial force the other is a throttle setting for the the moment that you can exert on the vehicle again here's the equations of motion that we derived earlier and here's some of these intermediate variables okay so for this specific example what I'd like to look at is let's put some numerical values to some of these parameters and we saw this this model is parameterized pretty e pretty simply there aren't too many constants that go along with it so the constants I want to use here is let's use a mass of how about ten kilograms a moment of inertia here of five kilogram meters squared how about a maximum axial force that the system can exert is 10 Newton's so the engine is in the axial direction is 10 Newtons strong here and then the maximum moment that the axial thrusters KITT or the rotational thrusters can exert here is 0.5 Newton meters let's say that the coefficient of drag right we've lumped all of those the basically the the coefficient of drag to this this nonlinear drag term here is actually I don't want to call it coefficient of drag rate because we saw that that's all this stuff lumped together like the density of the medium the cross-sectional area all that it's just some constant let's pick something as just 1 over 40 which is above also 0.025 again remember the said units of Newton's second squared meters squared in our model and then let's pick a again our coefficient of rotational drag if you want to think about it that way as how about 0.75 units of Newton meters seconds okay and I think that was all the parameters we needed okay so now what I'd like to do is let's examine a couple of different scenarios so what we're gonna do now over the next couple of minutes here is look at trying to trim or find operating points of this planar vehicle in multiple cases so for case one what we're gonna look at here is how about if I want this thing to move in the positive y-direction at 15 meters per second okay and then maybe we'll contrast that to what about it in a case two what if I wanted instead of just going in the positive y-direction how about an arbitrary direction also at 15 meters per second okay and then maybe have a case three let's look at how about trying to do something like a a steady orbit where I want the the planar vehicle just spinning around in a circle and then finally let's look at case four here which would be how about let's repeat case one which was this positive y-direction but at a slower speed 10 meters a second okay so what we want to do now is let's go over and examine these and see if there's a way we can use Malaba mewling to a tane what are the operating points for these conditions so before we do that give me a second and let's let's dig a little bit deeper here into case one so I'm going to pause the video erase some of this stuff and let's look at this a little bit more closely Before we jump over to the tool alright so the first case we're going to look at is just positive y-direction travel at 15 meters a second basically that's saying I've got my planar vehicle it can be placed you know it can actually be placed anywhere in this plane and all I care about is that it is moving in the positive y-direction of 15 meters a second maybe it's going like this maybe you know maybe it we want is there is there a way that it could possibly go like this or maybe like this right so the question now becomes are there any constraints on any of these states to yield this operating condition right that are that to make it consistent with this operating condition or this trim point so let's just write down all of our states right so we had of six states and those corresponding to the x position the Y position the X dot the Y dot the theta and the theta dot okay so we just saw that the X&Y position it doesn't matter where you are in the plane you can still achieve upward travel here so x and y can be free right now that's not the true for X dot right in order to make sure that the vehicle is moving only in the positive y direction I got to make sure that this is zero right so here's one constraint x3 has got to be zero in order to be consistent with this operating condition similarly Y dot had better be exactly equal to 15 that's the velocity I want to be traveling at now how about theta well we know that the way this system operates here's where some of the physical intuition might be helpful is you know that the the axial thrust force right that's good is what's gonna get you this 50 meters a second right you're going to be basically cranking up the the engine the axial force engine so that it pushes the vehicles to a velocity where the thrust from the motor is basically equal to the drag right so we know that this thing has got to be aligned with the direction of travel in order to get us the motion we want so in this case we see that theta that had better be 90 degrees right remember that zero meant you're pointing in the positive x-axis so a theta of 90 degrees means are pointed in the positive y-axis so this has got to be PI over 2 okay yeah theta dot now we also know that in order to get consistent straight motion in this direction we better make sure that theta dot doesn't vary right so this has got to be 0 okay now maybe we should also ask ourselves how about state derivatives here right so these here if we put them maybe we'll circle these in green or box them up in green all right these are basically restrictions now on X or constraints on X okay not only we're basically saying are they what values do these these does this state vector have to have in order to be consistent with this operating condition now what about the X dot okay so how about X dot what about X 1 dot X 2 dot X 3 dot X 4 dot X 5 dot X 6 dot we should basically ask ourselves a question as do these have to be in steady state or not okay so here let's ask ourselves that so ok X 1 dot here what was X 1 dot well X 1 dot right isn't this according to us that is X dot right ok what is X 2 dot X 2 is this so this is y dot right what is X 3 dot X 3 dot is now X double dot right x4 dot is y double dot or Y acceleration X v dot is theta dot and X 6 dot is now theta double dot right so we should ask ourselves do any of these have to be in steady state well x1 dot yes that has to be in steady state because we said it has to be zero so this has to be in steady state so maybe I'll mark this as a as SS now Y dot is no it's Y naught is not equal to zero right so it's naughty not gonna be steady stay right because it's got to be at 15 meters a second so this is not going to be at steady state it's gonna be at 15 okay x double-dot now yes we do know that that acceleration should be as at zero again since X dot is gonna be at zero we also want X double dot to be zero so we need to make sure that this is at steady state okay similarly we need to know that y double dot is also equal to zero so there's no y acceleration there might be Y velocity but that we don't want it to be accelerating so this should also be at steady state okay and here we go how about theta dot well theta dot yeah actually is going to be at zero right so this is going to be at steady state okay and similarly theta double dot this should also be at steady state okay so let's also put these maybe I'll circle these in blue okay so here are basically a couple of our restrictions on or constraints on X dot right we're basically just denoting which of these variables need to be in steady state or not okay and then finally let's look at the use how about u 1 and u 2 right u 1 was our axial thrust right and then u2 was our moment right okay so we know that this is sort of what we're looking for this can be free all right because what we're asking the system to do is we want to find out effectively what is the throttle setting that will yield us this operating condition right so we want this to be free I know it can't be 0 it's got to be some nonzero value but how about the moment we know this has got to be 0 right because in order to make sure that the book that the vehicle stays pointing in this direction and doesn't doesn't turn alright I want really want to make sure I don't induce a moment on this to make it turn so if we circle these in red here are basically our constraints on you right so great what we've done now is we've narrowed down the state space to values which satisfy these constraints both the states and the controls right so what we want to do now is see if we understand we have a good understanding of what constraints need to be met we now want to go over to mal I'm assuming you can see if there's a tool that will allow us to find out what are some of these free variables okay that will allow us to get an operating point or a trim point which is consistent with what we're looking for right with this desired behavior okay all right so keep this in mind maybe write these down because what we're gonna do right now is let's run over to MATLAB Simulink and see how we can directly use a tool to input these different types of constraints into the system and basically have the system solve for the free variables for us to find our operating point all right so here we are on MATLAB and I've just gone ahead and typed up a little script that initializes all of the constants that we talked about as well as setting an initial condition for this model so like we said earlier the X and the y locations are free so I just randomly picked 10 and minus 10 it really doesn't matter but we said X thought had better be 0 Y dot should be 15 theta should be 90 degrees and theta dot should be 0 so let's just go ahead and run this to initialize all of these variables and then what I've done is I've also built a little Simulink model here of the planar vehicle so as we said you've got the thrust fraction going in you've got the torque fraction going in and then you've got although the states coming out on this side so maybe to start why don't we illustrate you know how might you iteratively tune this or trim this if you are a pilot or a operator this vehicle so what I would do is I would just start iteratively um guessing I guess and what is the appropriate thrust fraction that's needed to get me 15 meters a second so for example I'm starting here with 0.1 and if I go ahead and run this simulation and look at the scopes oh we see that's that's clearly not gonna work here because a thrust of 0.1 look we start at the right initial condition but we're we don't stay there right the boat the boat the vehicle starts slowing down as drag overtakes it so I don't loads bump this up point 4 and then let hit run again okay we're doing better we're staying closer to 15 but we're still not there I don't know how about 0.55 ok running again ok now we're really close here right what this is clothes maybe we can do a little bit better on it 0.56 maybe is that better there we go now what now we're getting out we're basically staying here but I think you can see that while this is easy to do for a single degree of freedom right in this case we really only had to try to iterate on this thrust fraction here if the system were more complicated and you had more knobs to tune or try to trim simultaneously this would be really cumbersome so we want to see can we use a MATLAB or simulating tool that will allow us to interactively do that and luckily the answer is yes so let's go ahead and look at that now all right so the first thing we're gonna do here is let's actually prepare this model a little so instead of me manually trying to iterate on the control inputs let's delete these constant blocks and we want the software or the tool to go ahead and try to find values that work for our operating point so to do that I'm going to basically open my simulated browser and I'm going to come here and find some of these imports and drag and drop them into the model okay so I'll maybe make two of these one for the thrust and one for the torque and maybe let's rename this one as thrust and we'll rename this one here as torque okay um in a similar fashion let's grab a couple of out ports and actually maybe just one in this case we'll grab an out port grab drag and drop it into the model and let's go ahead and hook this up to the signal we care about which is a wide dot okay alright and I will then rename this thing as Y dot okay so now what we've done is we've instrumented this model appropriately and what we're able to do next is let's open up a tool that is actually extremely powerful it's called the linear analysis tool if I come up here to analysis in my Simulink model come down to control design and say linear analysis what's going to open up is this other tool which is the linear analysis tool and this is incredibly powerful it's got a lot of functionality the functionality we care about is using it to trim the model like we talked about so to do that we come up here to the operating point click on this little drop down and we come down to trim model when we bring that up we get this dialogue which is effectively allowing us to make place constraints on the state the state vector dot as well as a control right so here's the control okay maybe the first things first let's look at this you see it's got state one two three four five six how do we know which states do these correspond to well if you look at this up here it says planar vehicle model planar vehicle integrator XY X dot y dot theta theta dot one question that's probably the back your mind is where did it get this information right how does it know that state one is going to be X state two is going to be Y state three is going to be X dot etc etc right well it's actually telling you here right in this dialogue it's saying go look in the this model in this block in this subsystem block and hopefully that's labeled so you know what let's just go ahead and check that for sanity I'll come in here and here's my model let's go ahead and look under the mask okay and here we go and if you look here there whoopsie sorry let me drag this down over here I'm trying to make this a little bigger and then zoom in all the way over to the integrator over here and I've gone ahead and named the integrator something very specific so I've gone ahead and listed which order the states are in this integrator so this is on my long winded way of saying when you're building your models instead of leaving these integrators just labeled as plain old integrator you may want to label exactly what is it integrating and if it's a vector what orders in integrating in because other tools like the linear analysis tool will make use of this annotation and it will be more helpful down the road okay so with that being said I'll just come up a level again and let's go ahead and minimize this because we don't need them simulate model we need the linear analysis tool okay so first off let's go ahead and uncheck all of these so we see here that what we can do is we can start placing these restrictions on the state like we talked about so we said earlier I think what we said is X dot has got to be constrained to be 0 Y dot is constrained to be 15 theta is constrained to be PI over 2 and theta dot is constrained to be 0 now which of these are in steady state we said ok X is to be in steady state why is not and then X dot is gonna be a steady state why Dutch be in steady state theta should be in steady state and theta dot should be in steady state okay so these are basically this first column is what we had circled earlier on the white board in green this second column is what we had circled in the white board in blue and now we come here to this input tabs again you'll see here are the two different inputs what's the here channel 1 and channel 2 and again you are sorry channel 1 and channel 1 right you might be asking what are those well look here that is why we labeled this thing thrust and torque so again coming back to the Simulink model we see that annotations start to make a lot more they're a lot more important right now so here you can see that we call this thing thrust and it shows up here as thrust and this thing we call torque and it shows up here in torque so now we know what we want to do is we said we know that the torque input or the fraction of the moment has got to be set here at 0 let's forget about the outputs for now but if you're interest you can just click over here in the output and you can see this corresponds to that one out port that we placed in the model over here at y dot you see here's the y dot and here's the y dot we're gonna make use of this a little bit later so let's come back here to the states and um let's see oh the other thing that maybe we should mention here is all of these things here in the value column you can click on these and change them so for example if we wanted to constraint instead of 15 meters a second to be like 10 meters a second you can go ahead and enter that here so again let's move this back to 15 this is what we were interested in okay so we basically got the system set up and ready to trim so all we need to do now is click on this start trimming button and unfortunately you see that we get a little bit of a hiccup if you read this here it says you couldn't find the the system was not able to find a solution that satisfies all the constraints relax the constraints to find a feasible set or to find a feasible solution okay so what that means is we've sort of while mathematically this should be feasible we've made the system a little bit too constrained for the numerical optimization and routine to find a solution so let's start relaxing some of these that maybe don't matter as much so for example let's relax this steady-state constraint on X okay and let's try again and we end up with the same thing so all right let's keep on relaxing constraints how about let's get rid of this constraint here of this was what X dot may be let's uh let's not say it has to be zero let's just take it off and see what happens okay and aha now we were able to successfully meet all of the constraints so after we relax those we actually were able to get the system to go and trim the model for us so to see what that trim point looks like what you can do is just come over here and click on OPM three and you get this other window popping up and maybe let's see I guess this is as big as it goes but look at this let's first take a look at the solution for the state so it said that the desired value I guess yeah we said we didn't care about X we didn't care about why we didn't care about X dot we cared about y dot we cared about theta and theta dot and here's the solution it found so it found a value here of okay X is 10 again who cares y is negative 10 who cares it did find that X dot has got to be really close to zero so that's great even though we didn't explicitly tell it to be zero right the numerical routine found the proper solution here of X dots got to be zero and it did find that X sorry y dot has got to be 15 theta has got to be 90 degrees and theta dot has got to be zero and now here's the other more interesting one which one of these did it find to be in steady state so again we see that X has got to be sorry X dot has got to be in steady state Y dot has got to be at 15 the X acceleration or X double dot is 0 y double dot is 0 theta dot is 0 and theta double dot is here so again it this looks beautiful right this X that we found and its state derivatives seem to match more importantly the thing that we care about is here on the input tab if you come here to the input tab it found that in order to get this velocity that we or this operating point that we want here's the true the trim of control that's needed so we need a frittata setting point five six to five so we were pretty close when we were in ER tively guessing and simulate but this is what should get us much much much closer okay so uh tell you what why don't we go back to the whiteboard real quick and just double check that this solution seems reasonable before moving on all right so the linear analysis tool found us a solution here for our operating point on our trim condition here so this was I think was 10 - 10 0 15 PI over 2 and 0 right that was our trim state and the trim control was 0.5 6 2 5 and 0 okay so again what we can do is maybe since the system is simple enough we might have a chance to maybe analytically verify that this is the appropriate operating condition so what we're trying to do here is we're starting here at 10 negative 10 right and the system is going straight up right so if the system is going straight up at 15 meters a second coming back to our Freebody diagram right we know that at that condition what's going on here is you have F you pushing on and the thing that's retarding the motion is just F drag all right that's the only thing that's going on in this operating condition right so at equilibrium one well not sorry I used the wrong word right when we talked about this is not an equilibrium point here but at steady-state right you have the the axial thrust equaling the drag so luckily with our equations of motion this is actually simple enough to kind of analytically solve so maybe what we can do real quickly is we see that ok in this case we need F u to be equal to F drag right that's what should happen at this operating condition so what is f u so the fu is just F max times u1 so this is F max times u1 and what is the drag force it's C T times V squared right so this is C T V squared so if you solve this for u1 this is basically CT over F max times V squared ok well I already know what CT is right I think we were using a value of Ct of 1 over 40 we know what F max was shucks I forgot what the actual constant number was for that let me just double check it we were using a 10 all right and then we know what V is in this case V is the velocity right V is x3 squared plus X 4 squared it's just the velocity of the vehicle so it's just 15 ok so you plug all these numbers into this expression and you exactly get 0.5 6 - 5 so again this is fascinating and that we can analytically verify the numerical solution that the linear analysis tool got for us so this is great the the solution sounds good so maybe let's jump back to MATLAB and take some next steps about maybe saving this operating point all right that's great so we verified that this solution for Opie trim 3 this is great this solved the system or or it gives us the proper trim point that we'd like so the next thing we want to do is make sure that we save this because if we did a little bit of work to get this this is the important thing that we want to keep safe so to do that what you want to do is let me drag some of these out of the way is coming back to the linear analysis tool and you kind of see that here in the linear analysis workspace it's created a couple of these variables now those variables only exist in the linear analysis tool workspace if we come back to main MATLAB and you look here in the workspace there's nothing called Opie trim one two or three ok so in order to get that back to the MATLAB workspace it's actually really simple all you do here is come click on Opie trim 3 this is the one we care about grab drag and drop it up here to the MATLAB workspace and it will copy this thing called Opie trim 3 to your workspace so now if I come back to MATLAB now there's this thing called Opie trim 3 and it's got all that information about the operating point that we talked about right so it's got the the X naught which is this column right here and it's got the U naught which is right here ok so it's got all that information so you might want to just go ahead and say save you know this is trim point 1 dot mat and let's call this Opie trim 3 right that's what ok great we've saved that as a mat file so that should be good to go the other thing you might want to consider saving let's come back to the linear analysis tool here is ok we just saved the solution but we may want to save the settings or the inputs or the constraints all right the constraints on all of the states the state derivatives and all the inputs we might want to save these as well so to save this so that we can recreate this later you may want to come over here and just click on export and we're gonna again export this to the MATLAB workspace and it's gonna be called something called open spec I don't know maybe to make it consistent maybe let's call it Opie spec 3 and I'll go ahead and export that to the workspace to the MATLAB workspace excuse me so when I come back to MATLAB now let me clear this we've got a variable called Opie spec 3 so Opie spec 3 and again these are all the constraints that we put on the states or their derivatives or the control inputs in order to use as an input to the trimming process so again maybe what we want to do here is go ahead and say save I'll call this maybe trim point O 1 inputs maybe dot matte or settings whatever you like and I'll save my Opie spec or op spec 3 ok great so we've saved both of those uh let me show you one other thing that's kind of interesting let's come back to the linear analysis tool over here and ok you might want to consider maybe simulating this right you we were able to analytically show that this was the right solution for this simple system but if your your simulation or your model was very very complicated you might not believe this you might need to go and take this trim pull sorry I'm looking at the wrong column this one right here this trim point right and take this trim control sorry over here this trim control and input it to your Simulink model and see if it works alright so the way you can do that is obviously you could come back to your Simulink model over here and replace this with in our case it should be Oh point five six to five and replaced this with a constant of zero and then change the initial condition wherever you've got that put up in your model to the initial condition that you solve for using the linear analysis tool right so you could manually do that and maybe that's good practice but the linear analysis tools actually got a kind of interesting feature that I'll show you real quick is you can actually sync this with the model or initialize the model with these variables okay so if I click on initialize model okay and I'm going to yeah let's put this here in the MATLAB workspace okay and actually it's already there but that's alright let's click on this again okay so what that will do now is if I come back to that same Simulink model and I go ahead and run this it actually is using that trim point that we had inputted so now if I come to this look at this the positioner or y dot that is bang-on at 15 and all the other states are in the appropriate locations here that we desire okay so the only thing that I maybe will point out is that this is a little bit I don't want to say insidious here but what Simulink is actually doing here is if you come in here to settings and come in here to data import/export when you click on that export to model or initialize model button what it does here is if you look here what it does is it says that when you're loading or you're running this thing it's trying to input and load this thing called Opie trim 3 and 4 for both the input and the initial state is trying to load that from the workspace so that's fine as long as this variable exists in your workspace right this Opie trim 3 but if it wasn't there you might have a slight problem so for example let's say you you you you run this script again right you come back the next day and you say ok I want to start over again here's my system I come over to my to my simulation and I try to hit run and it's going to yell at you because it has no clue what this Opie trim 3 variable is so you probably have to load that variable back in luckily that's exactly why we saved this so if I go ahead and load trim point a1 dot Matt right here I've got Opie trim 3 back in my MATLAB workspace so now the simulation should run and there we go and we're back to where we were so I don't know about you I personally don't like this because it makes this Simulink model dependent on this other variable that need to now load from the workspace so if you don't like this you can go ahead and just uncheck these two boxes so it's not going to try to find those any longer from the from the workspace and you'll basically be kind of back to where you were earlier so in this case I think we're just using 0 inputs so yeah it's slowing down and it's not doing anything super interesting so again something to be aware of that when you click on that button in the linear analysis tool where you want to this button right here where you want to initialize the variable or the model with this operating point just be careful that you create some dependencies that you might be a little bit difficult to find down the road if you weren't aware of it maybe the last thing I want to show before we move on to some other cases is really all of this GUI here in the linear analysis tool it's a wrapper for the function called find op in MATLAB so the way you can see that here is actually they have a button here that's really cool here in that says generate MATLAB script so if you click on this button here what it will do is will actually generate an am a live script which is the equivalent of trimming the model here so it the other way you could trim the model with all of the appropriate initial inputs here and which ones are known and which ones need to be at steady state all that kind of stuff is you could go ahead and now just save this this automatically generated script and you can see at the end here the majority of it right the the engine that's doing the optimization is this find op function so in this case when we're doing the trimming here or trying to find this operating point it's really this nice graphical user interface / - the find out function and again I think the linear analysis - is a much more user-friendly way to go about finding a trim point for a system alright and the last thing to maybe show is let's come back to the linear analysis tool um alright we did a lot of work in the linear analysis tool so you may want to consider saving your entire session here before you exit so to do that it's really simple just coming here to the save session button and I'll go ahead and call this I don't know how about trim point o one session dot mat and that will save so now we're free to go ahead and close the linear analysis tool and you get this notice here that you want to save the session which we just did so let's go ahead and no I don't need to save it again and now let's go ahead and pretend like we're coming back the next day so I'll go ahead and close all these I don't need to change save this auto-generated script here and what you can do is again let's try to get back to where we were here is our model here so one thing that you can do is you may want to come up here and come here and say control design linear analysis tool that's totally fine let's go ahead and start up a linear analysis tool now before you load the session though if I try right now it's gonna choke let's just show that so if I come here and click on the session that we had earlier I load this I get this dialog here asking if I want to save the current session that I'm working on well no because I never do anything so say no and we're gonna have a couple of issues because it doesn't know what all these variables like MIB all that kind of stuff was what was needed for this system so what you want to do before you load the session is make sure you have any of the appropriate variables that are needed for the session those should be defined in the MATLAB workspace so you see it's just sitting here hanging I think in the past it's given me errors saying oh actually here it's back in the command window right here all these errors all this stuff it doesn't know what X 0 is doesn't know what any of this stuff is so this clearly didn't work so to fix this problem let's just go ahead and kill this session of the linear analysis tool and again I will come here and run this script to initialize all these variables so those are now created here in the MATLAB workspace so now if I go ahead and come back to my Simulink model and launch the linear analysis tool here it is now I can go ahead and load the session that I was doing earlier hopefully with no problem and again we get this dialog telling me I should save and I want to say no I don't care about saving this in boring session but nothing in it and there we go everything is back to normal here so you got your Opie trim and you've got all of the we're back to basically where we were okay so that was a good discussion SARS a little bit long-winded but I think it's always that it takes a little while to get the first example running so tell you what let's run over to the whiteboard and talk quickly about example number two all right let's go ahead and switch this from trim case one to trim case two and now instead of moving in the positive y-direction let's just go in and how about an arbitrary direction so in other words instead of the vehicle going straight up here let's pick another direction I don't know how about this way something like this so maybe let's go ahead and choose a theta here of maybe like 135 degrees something like that okay so what I want to do now is let's modify our constraints on X X dot and you again these here are for the positive Y Direction how do we translate these into this case where we want a angle of 135 degrees so let's just walk down one at a time and see which of these we have to modify okay so again we know that x1 and or x and y can be free x dot this is not going to be 0 any longer right and similarly Y dot is not going to be 0 any longer right you could sit here and do the trigonometry and figure out yeah I know it's hundred thirty five degrees I know I want this to be 15 meters per second so you could do all of that here and figure out what does the X dot and the y dot need to be to make this vector sum but let's actually say let's pretend like we're not that smart and we want the tool to do this for us here so what we're gonna do here is let's say that these can be free and we're going to want the tool to figure out what is necessary X dot y dot components in order to get us the condition weren't asking for okay here theta this can't be this has the camping 90 degrees anymore this has to be basically what 135 times pi over 180 all right so this is 135 degrees in radians and against theta dot is 0 ok great how about constraints on X dot okay x1 dot which is X dot that is definitely not going to be 0 so this is no longer to be gonna be in steady state all right so we'll take that off y dot is also not going to be in steady state but the X acceleration Y acceleration should be 0 in other words steady state X dot or sorry theta dot should be a steady state and theta double dot also be at steady state so I get I think this is an appropriate set of constraints on X ok here we go back down here so our inputs u one here this is free and u 2 is going to be 0 again this is a similar situation we could actually use our knowledge of the previous system here and we know that this needs to be zero point five six to five in order to get us 15 m/s because you know it doesn't matter which direction you're heading right you're gonna need the same velocity to get that same speed in this condition here but again let's pretend we're not that smart we want the tool to go ahead and figure this out for us ok now the only other problem here is if you look at this nowhere here did we say it's got to be 15 meters a second right how are we gonna embed this this this constraint here that we need the vehicle moving 15 meters a second so this is where we're actually going to need to actually add some constraints on Y okay so let's add an output of this system like a y1 to be the velocity of the system as such here right and this needs to be 15 okay so this is not free this is a fixed value and unfortunate I don't have another color so I guess I'll box this up in black here so now what we're gonna do is we're gonna have a constraint on the output vector Y okay so what we're gonna need to do is we're gonna need to augment our model alright if you remember our Simulink model right now is just the plant itself right so you just had coming in and effectively there were internal states I think that we were outputting all the states what we now need to do is make some kind of a measurement box that will output Y so that we can specify and make a constraint on the output okay so what we're going to want to do is modify our Simulink model to have this extra functionality and then we'll be able to place this constraint on Y inside the linear analysis tool and now hopefully this set of constraints is conducive to allowing the numerical solution in the linear analysis tool to find art us the operating condition that were interested in here okay so let's go over to test Simulink and augment our model and run it through the linear analysis tool all right so here we are back at our Simulink model and now all we're going to do is add a sensor model so I actually already have that prepared so I made myself a little block here if you look under this mask here you see that it basically picks out X dot and Y dot and then what it does here is it just takes X dot squared plus y dot squared square root so it basically gives you velocity right so um and I guess for interesting I also pull out theta dot but we're not going to need that so what we can do is just simply go ahead and hook this up like such and now what I want to do is let's grab another one of these nub output numbers and maybe I'll right click and drag and get a second one this second output I'm going to call it V okay and now let's hook this up to the model this last one I don't need so I'm gonna go ahead and get a terminator and just hook this up because I don't need this output okay so now what we've got is we've got a model that is going to output both Y dot as well as V okay so now what I can do let's go ahead and save our Simulink model and now I will go ahead and start up the linear analysis tool again and we will go ahead and try to get this thing trimmed alright so let's just go ahead and start up the linear analysis tool and here we are and we're going to do the exact same thing we did earlier is let's just come up here to trim model and all we need to do now is set this up appropriately so again let's just go ahead clear everything all right and let's just start walking down what we did earlier so I think the only thing that we had constraints on everything else all these states were free except for theta and we said theta I really want to make sure that this is 135 times pi over 180 all right and then theta dot is 0 okay those were our two constraints on the states in terms of their if their state derivatives if they're in steady state or not I think all we said was yeah X dot it's got to be 0 Y dots got to be 0 theta dot has got to be or sorry I'm sorry this was a X double dot Y double dot theta dot and theta double dot those are all equal to 0 or it means their states are in steady state okay that should be a set up then let's come over here to inputs just like we did earlier the only constraint we're gonna put on is the torque here is going to be known to be a value of 0 and now let's come here to the output tab so this is the new portion so remember we put this out port number 2 here on the velocity and this is the signal that we want to be 15 meters a second so what I'm gonna do here is I'm going to click on known and I'm going to change this one which is the V signal to be 15 great so now this is set up and ready to run the only other thing maybe that I'll mention is that this first column right here is what the numerical algorithm uses as sort of an initial guess at a solution so you see it's going to place the system here at 10 minus 10 again nobody cares about that we know that this that x and y don't matter for this solution but here in terms of X dot and y dot it looks like it's starting with an initial vector or velocity vector pointing straight up in the positive y direction we know that's not actually going to be the solution so if anything it should be something closer to I'm gonna I'm gonna put this at something a little bit more reasonable how about minus 10 and positive 10 right this is now a better initial guess at a solution than what we had earlier so hopefully this will help us with our trimming and the optimization scheme so let's just go ahead and try it go ahead and hit start trimming hey there he goes an operating point was successfully met so here's Opie trim one and if we go ahead and look at it I'll go ahead and click on OPM one and again let's inspect the state and here we go so again nobody cares about X&Y here but ah look at this X dot is minus ten point six y dot is positive ten point six so good that sure looks about right to get us 135 degrees here's theta here's theta dot yep all of these are inappropriate steady-state right the first two are definitely not in steady state but the last four are all in steady state if we look at the input again what we see is yes this is the exact same answer we got earlier and that makes perfectly good sense right the system is still doing the same thing it's just pointing in a different direction so the thrust should still be the exact same and now let's come look at the output Hey look at that the output it does look like we indeed get 15 meters a second on the output so again to double-check this let's go ahead and hit this initialize model button that will write this Opie trim to the Simulink model we can simulate this to make sure it works so I'm going to go ahead and hit that and I'll go ahead and export Opie trim to the MATLAB workspace so it's available now to the Simulink model and maybe the last thing we'll do here is let's add maybe a scope here on V just to make sure that that is exactly what we want so I'll grab this yeah that one's got two inputs tell you what let's just go ahead and ask for a new scope hook this up to the V signal oops and again just to make sure we're all aware right as soon as I hit that initialize model button here what it did is it in data import/export it's going to load in that Opie trim for the inputs so that's gonna be the point five six to five here and the zero here that's where it's getting those numbers and then the initial state here for my system here will be also gotten from that Opie trim one variable so now if I go ahead and run this sucker and we inspect the first of all for here table let's look at the XY plane or trajectory of the vehicle that's here what I'm plotting X Y oops sorry where is that graph here it is hey look at that that looks perfect right the system starts here at 10 minus 10 and it sure looks like it's going off and minus in 135° and more importantly let's go look at V and yes the velocity is sitting here at 15 right and it's constant and all the other states are doing whatever they need to be in order to get us the condition we want so here again this second trim point looked awesome let's go ahead and move on to how about case number three all right so let's move on to how about case three so case three that I want to investigate is how about a 60 second orbit with u1 is equal to 0.75 so we're going to just going to set the axial thralls we're going to set the the the the axial engine here at 0.75 and what I want this thing doing is I want this thing going around in some kind of circle here where it's going to take 60 seconds to complete one rotation right so that's that's the goal so again that's the operating condition I want so we just need to translate this into States their derivatives controls and outputs any of those kind of constraints so okay let's think about this so again X&Y these can be free right or you can specify them and it really doesn't matter right x and y are arbitrary and in fact the same goes for theta right because in this case theta is changing here so this can be that this should be can be free as well you know and actually X dot and Y dot those we should also set to be free in the sense that again we should let the system decide what those need to be we know that they're gonna be changing right this V this thing is moving around and around and around so whoopsies so we definitely know that we should not specify these as certain values now that's not the true for theta dot right we know that if this thing is going to go around and complete one revolution in 60 seconds we know that the angular rate here or the heading rate change this better be 2pi over 60 okay so really we're only specifying a one constraint on the states okay now how about the state derivatives are any of these in steady state okay so X dot no this is this is varying right this is changing all the time right the X dot velocity is changing so that should not be steady-state this should not be steady-state this should not be steady say because again it's varying that's also varying theta dot here right what is theta dot theta dot is not zero it's this nonzero value so it is we don't want to say that this is a steady state how about theta double dot though that should be at steady state right because I want a constant orbit right I don't want this thing changing so it's the angular acceleration should be constant so the angular sorry they angular acceleration should be zero which means steady state right okay great so not a lot of constraints here what about down here okay the axial thrust we are going to constrain that here to 0.75 because we know that's what we want okay and then the YouTube this is what we don't know this is going to be free this is kind of one of the key points that we're looking for here I want the system to be able to solve for what is the appropriate control input or the you to input to get me this orbit all right and similarly here for the output here this should be free we should not specify anything and put any constraints on to this so hopefully if we put this into the system and we'll get us a solution that gets us this orbit so again let's run over to the linear analysis tool and see if that's what happens all right I think you're getting to be an old hat at this by now so let's go ahead and launch the linear analysis tool again and we'll come down and trim for condition number three is so again let's go ahead and clear everything we'll start from scratch so I think we owe the only thing we had a constraint on was theta dot here right so we said theta dot had better be what did we say it was 2pi over 60 right that was our rate okay and then I think that was the only thing that was also in steady state right so theta double dot was equal to zero so okay how about the inputs the inputs the only thing we wanted was we said we were gonna set the thrust here to 0.75 and we were gonna let the system try to solve for what's the necessary torque needed to hold that and four outputs let's just make sure that these are all cleared okay and I think we're almost ready to go the last thing we should maybe do is go ahead and set some initial conditions here or these are not in it sorry not initial conditions these are initial guesses for the numerical and routine so well we'll make a rough guess at what's the solution so let's go ahead and put 0 because again that was arbitrary for X arbitrary for y x dot and y dot we had no idea what these were gonna be so we can kind of make something up I don't know how about makeup how about minus 5 and positive 7 again and it doesn't really matter theta again this really doesn't matter it can be anything let's go ahead and make this 0 so again these ones don't matter since we haven't actually checked the known value these are all just initial guesses for the routine to start at all right so let's go and hit trim see what opened wow that was pretty quick no problem there so let's go ahead and inspect opie trim 1 and let's see what we get so here's the actuals yep it was able to define operating point at x equals 0 y equals 0 X dot is equal to minus 5 y dot is 7 here's theta of 0 and yep it did find the correct state for theta dot now the interesting thing to look at while we're on this tabby is look at the the the state derivatives here right since we said they're not in steady state many of these are not zero in fact the only one that zero is down at the bottom so this is definitely not an equilibrium point right because all of these numbers are our non-trivial and somewhat large we actually expect a little bit of transients right so this is not gonna settle into an orbit right away there's going to be some state movement here before we get the steady state behavior we're looking for okay let's go look at the inputs so again the 75 is expected but AHA this is the number we were looking for this is how much torque control is needed to maintain and obtain this orbit that takes a 60 seconds to complete so again looks like it takes about 16 percent of full throttle to do that in terms of the outputs this really doesn't matter at this point because this is just the initial output we're gonna see that that this may change so for example keep in mind here look V here it says initial is going to be eight point six pretty much guarantee the velocity is not going to be 8.6 when we are at steady-state in this orbit so let's go ahead and tell you what let's initialize the model with this value come back to our Simulink model again and just go ahead and run this thing so when we run it first off maybe we should do is let's go ahead and look at their trajectory and you can see well it's running off here and in fact I need that looks like I need to expand this the window so tell you what let's let's change the ranges here to be the X minimum let's make this how about minus 300 Y X max here of how about 50 Y min what was going to be reasonable yeah the C arrow is pretty good here and a Y max of yeah 600 is I think is going to help us okay so let's go ahead and run this again maybe and hopefully that XY graphed here we go this looks a little better so as you can see right you start down here at 0-0 but there's some initial transients right before the system starts settling into its its orbit so we can look at what the velocity is let's go ahead and open up this scope and you said it started at 8.6 but as you can see there's some serious transients until we initially settle out at a velocity of around looks like seven meters a second so this thing is going seven meters a second as it's spinning around in this this orbit and again here are the scopes the state trajectory again this is kind of hard to visualize right here I guess this XY graph helps a little bit but it really would it be a lot nicer if we could actually draw the vehicle here and visualize this a little bit more precisely so this is maybe a small plug for our upcoming video where we're going to talk about using simulate 3d animation to actually animate this scenario here and draw what's going on so we don't have to just stare at graphs to try to understand what the vehicle is doing in this scenario but that's for another discussion in the meantime it looks like we again were able to trim this thing to the appropriate operating point for example you can see here's the orbit limit cycle that were settling into and I think if you look at the time stamps here these are about 60 seconds apart you can see it's not the most precise thing in the world but I yeah it's about 60 seconds apart so great everything seems to be working like we expect all right so tell you what let's go on to our last example of case number 4 all right so the last case I want to look at is case 4 which is actually revisiting case 1 right this was the positive Y velocity but now I want this instead of 15 meters a second I want this at 10 meters a second ok so all of these constraints are basically the same as case 1 except the Y dot constraint alright so this one is now going to be 10 everything else is pretty much the same so I'll just leave all these like maybe I'll draw it like just an arrow to say this is all of these inputs are so the arrow means same as example 1 right and we're just going to load in what we had earlier doesn't make one modification again maybe while we're sitting up here at the whiteboard we could we can actually compute ahead of time what we are supposed to get just to make sure our trim solution comes out proper I think what we said earlier was we saw that the thrust needed for this u1 that was going to be it was CT V squared over F max so again plugging in all the numbers here and now V of 10 we should be getting a value of 0.25 so let's run over to the trim tool and again we'll just load in our results from case one modify one constraint to be 10 instead of instead of 15 and verify that we get a quarter all right so for the last time we will come here and launch the linear analysis tool and like usual come to trim the model and now let me go ahead and minimize the Simulink model and we'll note here that it's actually really handy now that we saved trim point O 1 inputs dot m80 earlier if you remember these were the operating specs needed to trim for case number 1 instead of me sitting here having to punch in all of these manually and hoping I don't make a mistake what I'll do here is let's come back to the MATLAB workspace I'll just go ahead and load trim point oh one inputs that creates up spec three here in the MATLAB workspace so now when I come back to the linear analysis tool what I can do is I can go ahead and import from the MATLAB workspace operating specification number three so if I hit import that should have all of the inputs necessary to trim for this case the only thing I want to do different for case four is I don't want 15 metres a second I want 10 meters a second the last thing that maybe note here is let's go bring up the Simulink model kind of up in the background and particularly I'm caring about this v2 here okay so if I come here two outputs notice here that we're missing this second out port if you remember we added the second out port during case two so operating spec that we generated in case one didn't have this so if I try to trim right now we get an error saying that the operating specifications that we have here are out of sync with the model that we are trying to basically trim okay well luckily it's got this it tells us to use this sync with model button so if I come back over here to the the trim inputs right let's just go ahead and hit sync with model and there we go so now we get this to be consistent and again we will come back and just double check everything is the way we wanted to yep still got our 10 meters and now what we can do is let's go ahead and start trimming and there we go and successfully met I guess I can get rid of this diagnostic viewer I don't need that error anymore here we go Oh P trim one has been created and let's go ahead and look at it and as expected we get all of yep these are all meeting the requirements we need more importantly check the inputs and yes here's that 0.25 that we calculated on the board all right and again like we did earlier what we should probably do at this point is save this trim point because we're actually going to make use of this a little bit later so again just refer sure memory what we're gonna do to save both the inputs maybe we should do that first let's go ahead and export up spec one to the MATLAB workspace okay and then I need to go ahead and move the trim point to the workspace okay so now back in the MATLAB workspace I've got Opie's spec 1 which is the operating specifications needed to generate this 10 meter a second trim and then we've got Opie trim 1 ok so what we should probably do here is let's go ahead and save as trim point o4 dot mat this is going to be Opie trim 1 and then we're also gonna save trim 0.04 what do we call this input dot mat and that was Opie spec or obspec one great ok so we've got all of those saved um and with that I think this is a good point place to leave it I hope you enjoyed the discussion here where all we talked about was mostly how to use the linear analysis tool to trim the Simulink model now the reason we actually saved these to case number one and case number four is the next step that's probably in the back of your head is now that I have this model trimmed and I know operating conditions at two different points maybe what we might want to do is linearize this nonlinear model about those two so that's actually our very next discussion is how to linearize a simulant model about an operating point using the linear analysis tool so I hope you'll join us at that future video and if you've been a longtime subscriber thanks so much for sticking with us if you're new to the channel please do consider subscribing because it helps me continue making these and we will have a lot more discussions on simulating MATLAB control systems engineering etc in the future so with that being said I hope to catch you at a future video until then I'll talk to you later bye
Info
Channel: Christopher Lum
Views: 19,680
Rating: undefined out of 5
Keywords: Trim point, trim model, trimming model, operating point, equilibrium point, non-linear model trim, Linear Analysis Tool, findop
Id: kypswO4RLkk
Channel Id: undefined
Length: 68min 45sec (4125 seconds)
Published: Fri May 31 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.