Model Aircraft Design Optimization with MATLAB
From the series: Aerospace
Guilherme and Connell go through the “Aircraft Design Optimization with the Fixed-Wing Object” example shipped with Aerospace Toolbox in R2022b. The example uses the rules for the Regular Class aircraft of the 2020–2021 Society of Automotive Engineers (SAE®) Aero Design competition and optimizes for the highest possible flight score. You can easily modify the code to fit your design, and once it is set up you can adapt it to rule changes and new competition objectives in future years.
They start with an overview of optimization in the context of model aircraft design and describe the usual workflow student teams go through when designing their aircraft. Optimization is a powerful technique that will help you reduce guesswork during the design process, leading to a mathematically optimal design and ultimately better results at competition. By using MATLAB® to optimize your design, you can achieve faster design iterations and more freedom to experiment by doing away with manual trade studies and hand calculations.
To use optimization with MATLAB, you first need to translate your design parameters, competition objectives, and constraints into an optimization problem. Doing so with a problem-based approach simplifies the setup and using Optimization Toolbox™ lets you solve both linear and nonlinear problems without any prior knowledge of optimization techniques. The Fixed-Wing object from Aerospace Toolbox automatically calculates the static stability derivatives at every step of the optimization and includes them as design constraints to guarantee a stable aerodynamic configuration. You can use the same object to initialize a Simulink® model for more detailed analysis via simulation.
Published: 6 Dec 2022
Hello, and welcome to a video on model aircraft design optimization in MATLAB. My name is Connell D'Souza, and I work on the student programs team here at the MathWorks. Joining me today, we've got Guilherme, who works in our marketing development group.
Hello, Guilherme. Welcome to this video. Can you tell us a little bit about why you are the expert to talk about model aircraft optimization in MATLAB?
Sure, yeah. Hi, Cornell. Thanks for having me. Well, two things-- one, I work with especially the Simulink products. I worked with the aerospace toolbox in the past, but more importantly, I was a student just some years back. And I spent four years in my undergrad degree in student design teams working specifically with model aircraft competitions.
I worked in the SAE Aero Design competition and also in the AUVSI autonomous aircraft competition. So I've had a lot of time doing this on the other side. And I know what the experience is like.
Awesome. So we've definitely got an expert in the house today. OK. So moving forward, what's on the agenda today? So Guilherme is going to cover a little bit of basics about what optimization is.
We're going to talk a little bit about what the design process is for model aircrafts. And when we talk about model aircrafts, we mean remote-controlled aero modeling airplanes that have been built by students for competitions like SA Aero, Aero design will fly. We're also going to cover some of the benefits of optimization and how it can help you. And we're going to take a little bit of a software demonstration with how design optimization works in MATLAB.
We're going to talk about this new fixed-wing object that we've just introduced into the aerospace toolbox. And then we're going to do a quick software demonstration and then some key takeaways to get you started. So without wasting too much time, Guilherme, take it away.
All right. Yeah. It's sort of answering the simple question what is optimization. So I want to start by highlighting the optimization consists of three basic points here.
Right.
The first one is an objective that we want to minimize and maximize. This is really what evaluates our performance. It's what you care about.
Right.
The next thing is we're going to have to be subject to some constraints. So this optimization problem we're solving, there are some constraints on it. There's what we call a solution space that's allowable, and we want to work within that. Make sure we're following the rules, we're making things that work.
And finally, we're going to do all that with respect to some variables. Now, these variables are what define the optimization problem. This is what we're optimizing over. They're kind of like knobs, or in this case of this graphic, sort of vertical sliders.
The sliders. Yeah. OK.
Right? That actually control our design, and we're going to be iterating over them. And this is what defines what the objective value actually is.
OK. Awesome.
Let's look a little more in detail about how the model aircraft design process works.
Right.
So the first thing you're going to start with is an initial guess. If you've never designed an aircraft before, you're just going to have to start picking some numbers. If you've done it in the past, you might have some original numbers, say, your aircraft from last year. You can start there.
Once you have your initial guess, then we go to the design parameters. Right? Those little knobs. So these, again, will define your design, and you're going to start there. Sort of add numbers to them. And once you have numbers, you can evaluate the aircraft performance.
So you're going to do all your calculations, and figure out how your aircraft behaves, what the aerodynamic characteristics are, for example, or how much mass it has.
Right.
From there, we go to the constraints. So we want to make sure we're not violating any constraints. So we're going to do those calculations and make sure a design is feasible. And after that, we're going to compute an objective. Right?
So this is what we really care about, and this is what we're going to use to evaluate how good our design is. Now, if you do it once, you get a final result. But we sort of initial guess, right? We can probably do better.
Right.
So we're going to do-- here we're going to go back. This is actually a pretty hard step in this whole process. We're going to go back and pick new design parameters, reevaluate aircraft performance, check the constraint violations once again, make sure our new design is also feasible, and then we're going to compute another objective, a new objective. And then we compared this new one with the old one. We see which one is better--
Right.
--and we stick with that. And really we want to do this in a loop, right? We want to keep doing it. We call this the design loop. You go back.
So if I'm getting this right, this seems like a lot of iteration. And the fact that you're starting out from an initial guess means that your starting point is always not the best. So you really have to spend-- it's a pretty manual process. Right? This--
Yes, it's manual. It's time-intensive.
Right.
And you can choose when to stop but generally you want to keep going for many, many iterations because you want to do well in the competition. Right? So actually to handle that, that's why we introduce optimization. Right? That's what we're going to optimization with aircraft design and while we use MATLAB specifically to do it.
So let's just talk about some of the benefits here, what it brings to the table. The first one is exactly what we are talking about. So it reduces guesswork.
Yeah.
We don't want to use this initial guess. So there's guesswork there, but there's also a lot of guesswork when we're going from computing our objective and you're picking your design parameters.
Mhm.
Right?
I see.
If we have one or two variables, it might be easier to do. But once you get a lot of variables, it becomes hard.
Right.
A optimization problem is going to handle a multivariable problem.
Yep.
Right? You'll see later we're going to look at an aircraft, very simplified aircraft. It still has 12 design variables.
Right.
And trying to tune each one of those individually would take so much.
And then the other thing is that because they're all variables on the same aircraft, messing around with one of them starts a domino effect and affects a bunch of other ones as well.
Absolutely.
Right.
That's exactly right.
Yeah. I can only imagine how hard that would be to do that with a paper and a pen.
Yeah. You spend weeks in a big team, and you're still not going to be satisfied with the end result. Right.
Also, what the optimization does here going to the constraint side is it's going to automatically account for constraints. This is great because when you get an optimized result you know that your design works. It's feasible with your constraints. And finally, you're going to get improved performance. Right?
Eventually, you're going to give up-- like, the manual work is so tedious. It's so repetitive.
Right.
Eventually, you're going to give up, and you're not really going to get to a mathematical optimal. Right? Versus with the optimization, we can guarantee the algorithm is going to get you like an optimal one.
All right. So let's talk about how this looks like specifically with MATLAB. Now, this is going to be an overview. We're going to look at code later, right? But let's just do a quick overview of what this looks like.
So again, first step is to define the optimization variables. And here's the aircraft we're going to work with. There's also the definitions for the variables, and it's a very simplified aircraft. This is just a box for the fuselage, but, again, this is already enough to have 12 variables and be fairly tedious to optimize by hand.
And this is just to show you-- have an idea of what these variables mean that we're going to use later. Now, the next step is to formulate your objective function. And space sort of alluded this earlier. We're going to use the flight score equation here. That's what FS stands for, and it's for the SAE, so the Society of Automotive Engineers aero design competition specifically for the regular class aircraft.
Right.
I believe this is taken from the 2020 to 2021 competition year.
And I'm actually seeing the vision now because if you keep the flight score as your objective, you want to maximize that. That should be the end game, and I guess that's what optimization going to help us with, right?
Exactly.
OK.
Yeah.
Cool.
We want to do well in the competition.
Yes.
We want to win. So--
We want to win.
--let's optimize our score.
So a maximum score wins, right? I like that.
Exactly.
[CHUCKLES] All right. Cool. Let's move on.
Yeah. So next step is optimization constraints, and these are going to come from multiple sources. Here's just an example. I'm not going to read this out, but these are some of the restrictions for the astro class.
And then the last step-- well, we solve the optimization.
Right.
On the right, you have what the graph looks like. I'm going to talk more about this when we get to the code, but eventually we're going to produce a plot like this that's going to give us an optimal value. This is what optimization looks like with MATLAB.
Now I want to talk a little bit more about the fixed-wing object. So this is a really useful object that we're going to use. It's really the Aero.FixedWing class from the aerospace toolbox. We're going to use this to model and analyze a fixed-wing aircraft. And we're going to do that because it helps us calculate static stability characteristics.
Ooh.
Right? It's going to produce a nice table like this. Also gives us the numbers, right? Not just if it's stable or unstable.
Right.
And this is really useful because calculating static stability is complicated. And there's a lot of different methods. We want to make sure we're doing something that's powerful and--
Right.
--gives us good results.
I mean, and you want your aircraft to be stable. Right?
Exactly.
Or your pilot's going to have a real hard time trying to fly that. You know?
That's exactly right. So we want to make sure it's stable. And actually to do that, we need to use the static stability parameters as optimization constraints.
Oh. Interesting.
And we need a solver to really know that our aircraft has to be stable. It has to include that in the optimization.
Right.
So it's really important, as you're saying. We want to make sure our aircraft is stable. So that's it for this part of the presentation. We're going to go to the software now.
All right. So let's go and get the example. So I'm here at the MathWorks documentation page, specifically the examples for the aerospace toolbox. So here's where you can get a lot of different examples.
This one is here as well. Let me scroll down a little bit, and here it is. So once I'm here, I could open this on my desktop on our R2022b, but it's just easy if you don't have it installed. And so I'm going to open this in MATLAB Online.
I just wanted to point out a quick thing. So it says that this example needs the aerospace toolbox and the optimization toolbox. If any of you students out there taking part in a student competition and you don't have access to these toolboxes, I'm going to drop a link in the description below to where you can request licenses for your team. So you should have access to these tools, if needed.
All right. So here's the example. It starts with some of the things we already talked about, right? It's going to start with the design objective, same equation we're talking about.
Right.
Then it goes on to the optimizational strengths. So the first three, there is the ones I showed in the slide. Another one that I want to highlight I think important because we mentioned-- it is that the aircraft must be statically stable.
There's also some assumptions that are going to come in. Again, we want to simplify this design. We don't want to make the example too complicated.
Right.
And then we're going to formulate the problem. And this is the first function I want to highlight here, which is initialize aircraft.
OK.
So let me open that up. All right, so here we are with initialized aircraft. And here we can see how some of the variables are defined. It's really quite simple.
We're going to start with the optimvar function, right? So on line 10 I'm saying wing.HalfSpan is this optimization variable. I'm going to give it a name, b_w, and then I'm going to give it a lower bound.
It's a length, right? So it has to be positive.
Right, right.
And an upper bound of 1.5. So this comes with one of my requirements from the competition that says that the wingspan cannot be greater than 3 meters.
3 meters. Yeah.
So half span, 1 and 1/2 meters. And really--
I can see the reason why you have so much code is because you are-- essentially, you have three lines of code setting up each variable. Right? And just because you've got 12 optimization variables, that's a lot of lines of code. Right?
Exactly.
But it doesn't look like complicated code. It's just you need to set it up, right?
That's right.
OK.
So this is actually really simple to do. That's the great thing of using what is called a problem-based approach with the optimization toolbox is what we were doing in this example. And then the other thing I want to highlight is I'm also setting up an initial value. Right?
Right.
So that's like my initial guess that I was talking about earlier. All right, so back to this file. So the first step here is to set up the optimization problem.
It's going to be an empty problem, right? There's nothing in it, or we're going to say, hey, the objective sense is to maximize. Right? Again, we want to win the competition. We're going to maximize the flight score.
Make sense. [CHUCKLES]
Yeah. So the first step is to add the aerodynamics, and there's going to be a couple of functions like this, where I'm adding more information. Right? So let's look at addAerodynamics first.
OK. So here we are with addAerodynamics. Now, all this function is doing is I'm using it to do some calculations on aerodynamic coefficients. I'm using it to estimate drag, for instance, and I'm also defining some constraints. So let's look at what one of these constraints looks like.
OK.
So here I have a constraint for the wing aspect ratio. And this is not a requirement for the competition. It's mostly because I'm using the Prandtl lifting-line theory.
Right.
Should do this. It's not a complicated method, but it sort of requires a minimum aspect ratio to work, physically speaking.
OK.
So I set a minimum of 6, but you can see it's super simple to define constraints as well.
So it's just designprob.Constraints, and then you set up a structure that does that. That seems very simple.
Exactly, and all of them are going to be set up in this exact same way.
Right. So essentially you'll have, I guess, three structures-- one for constraints, one for variables, and one for your objective. Right?
That's exactly right.
Right.
Yeah.
OK. Cool.
All right. Yeah. Let's go back. The next function I really want to highlight is addStability.
OK.
So add-stability is where I'm going to be incorporating those stability constraints. So let me open that file as well. All right. So here on add-stability, much like a lot of the other files here, it's pretty long. But all I'm doing is I'm adding the equations, right? All the equations from textbooks.
Right.
I'm just adding these equations to the problem. All right. So at the end of the file is when I'm actually going to define my constraints.
Mhm.
Before we talk about them, I want to talk about this function here. It's FCN, so function to optim expression. What this function is doing is generally under the hood the optimization algorithm uses powerful tools like automatic differentiation. Right? But it depends on some functionality-supported operations for this to work.
Right.
However, because I'm using the aero fixed-wing object, I don't really have that. So I have to use this function to optim expression to convert my functions that are not supported into things I can actually use with the optimization.
It looks more complicated than it is. All it's really doing is I have-- computeDerivatives is another function that I have defined. And I'm giving it as a handle, and everything else is just the inputs to the function. And then it's going to return to me the stability derivative constraints.
Right. And then you're just storing the stability derivatives, outputs, into your constraint structure that you've got over there.
That's exactly right. In this, I have 10, and you're right. They're all going into my constraint struct. And I need to do this to make sure that my aircraft design is going to come out stable at the end.
Right, right. So if we back up a second and we go back to that design process that we saw, this is essentially that spot where you're saying is my aircraft stable before I make that next guess. Right?
That's right. Yeah. Next, we're going to define our objective. So as you mentioned earlier, it's very simple as well.
You do design problem dot objective, and this is exactly the same equation we had above, just written with the variables we've defined.
Right.
Right, so very simple. Next step is to set up some options. These are not required, but they can give you a little more control over what the optimization is doing. So--
There's also something that you as the audience can play around with and see what works best for your particular design.
Exactly. So here all I'm telling you to do is run for as long as you need. But if the difference between optimization objectives is less than 1 or 10 to the negative 4 on every step, just stop.
Just assume that it's converged and move forward. Yeah.
Exactly.
OK.
And then the final step is to solve, and this is where we get this final result. Now, I haven't run this yet. We can run this right now.
So the beautiful thing about a live script is not only is it a nice way to present the code. It also runs. All right. So here we have the result. It's the same plot we have down there.
In this case here, because we're using malleable line, we actually don't have parallel. But this ran pretty quickly, and all it's doing here-- so let's talk about what this plot is showing us.
Right.
On the top, we have constraint violations. It's a metric of how bad our design is in terms of our constraints. We want to, of course, have a constraint violation of 0. That's what tells us that our constraints are being met and our design is valid.
So that's what the top plot shows, and in the bottom it's the function value. Now, you'll see that it's going negative, and that's just because of the way the optimization solver is set up.
Right.
Right. We get a final flight score of 18.75.
Essentially, if you go into some of the workspace variables, you'll see the actual values of different parameters in your aircraft. Right? So we can actually pull that up real quick.
Yeah, that's right. So one of the outputs of the solve function is going to be these final values. And that's going to be a struct, and each element of the struct is one of those design novels. We have one of the design variables and what its value actually is.
Right.
Yeah. I can pull that up in the workspace. Can double-click the struct to see what's inside, and you can see here the value of our different variables. Actually, let me scroll up to that table, and we can sort of see what each one of these means, right? And this is sort of giving us information on our design.
And I can also see-- so I'm trying to think as a student team, right? Because, again, this is a lot of code to put together. It's a significant amount of effort to put this kind of an example together.
The good thing for you all is we've already done the hard work for you. So you can just take this and use it as a starting point. But I can also see that, say, in 2023, when that objective function changes and the constraints change and all that, it's just a matter of going and playing around with those things. And then you can get a whole new design by just essentially having code that you've already written.
So it's good. Something that I tell student teams all the time is make sure you're keeping track of what you've done in the past because this thing that someone created, say, five years ago-- if you've got it running with your team, you can keep using it for years to come.
Yeah. Hey, nice job with the software demonstration. I think I've certainly learned a lot of interesting things from you. Let's go back into the slides, and let's wrap this video up.
Yeah. Let's do some of the takeaways. I want to highlight a couple of things that I think are important. The first thing is optimization can really help automate aircraft design.
We saw what the manual process looks like. We saw what the optimization looks like in really just a couple of minutes once the code is already set up for the actual optimization to run. We also saw how MATLAB offers powerful methods for setting up and solving optimization problems. Right?
There's a lot of fancy technology, actually, in the background. We're solving a non-linear optimization problem. Those are not easy to do--
Yep.
--at all, and we did it quickly. We didn't have to worry about those complications.
Yeah.
You don't have to know anything about optimization to actually get the proper results. So that's really great. We saw how the fixed-wing object handles aircraft performance and stability analysis. And, again, this is really helpful.
It has also some fancy methods in the background there that we can get access to without actually having to write those algorithms and write all those codes. The nice thing is, as you're saying, once the problem is set up it's easy to modify and really tailored to your application.
We're focusing here on model aircraft. But if you're making underwater robots, you can also use the same kind of code and the same setup. And so you should be able to get a lot of use out of this.
And as you're saying, the code can be reused year after year for new designs. Yeah, that's it. Thanks a lot for having me, Connell.
Yeah.
Really appreciate it.
Hey. Thank you so much for taking the time out. Before we wrap up, I just to point you guys to some resources that you can use. If you ever have any questions, roboticsarena@mathworks.com is a good email address to reach us. Someone on our team will respond to you.
We also have a Facebook group with a large community of people. So please join that group on Facebook. You can post your questions there, and the community will answer you.
Don't forget about the software offer. We support a number of competitions. If you go to that link on the screen, you can see if we're supporting a competition that you are taking part in. And we can get your software. If not, just reach out to us, and we'll see what we can do.
And then we've also got the student lounge blog, which is a blog about robots, aerospace, and hackathons, and deep learning. And it's a blog written for students, sometimes by students. So please check us out.
I think we're at the end of the video. So, hey. Thank you for taking the time out to come and talk to us, and we hope to see you again on another episode.