3 Ways to Build a Model | Understanding PID Control, Part 5 - MATLAB
Video Player is loading.
Current Time 0:00
Duration 13:44
Loaded: 0.00%
Stream Type LIVE
Remaining Time 13:44
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 13:44

    3 Ways to Build a Model | Understanding PID Control, Part 5

    From the series: Understanding PID Control

    Brian Douglas

    Tuning a PID controller requires that you have a representation of the system you’re trying to control. This could be the physical hardware or a mathematical representation of that hardware.

    If you have physical hardware, you could guess at some PID gains, run a test to see how it performs, and then tweak the gains as necessary. This guess-and-check brute force tuning method might work, but you have other, more precise, options available if you have a mathematical model of the system. Therefore, this video presents three different ways to model your system so that you can take advantage of each of these methods when tuning your controller.

    The first method uses a detailed understanding of the system to develop the model with first principles. The second method uses system identification, the known input, and resulting output signal to fit the data to the model structure of your choice. The third method creates a model by linearizing an existing nonlinear model around a given operating point.  

    With any of these models, you can start the process of developing and tuning a PID controller.

    Published: 1 Aug 2018

    In the last video, we walked through a PID tuning guide, showing several different paths you could take to tune the PID gains for your system. Now, in this video, we're going to demonstrate how you can accomplish some of these paths with a DC motor control example using MATLAB and Simulink. Specifically, this video is going to focus on getting over to this model-based tuning section of the flow chart.

    Now once you have your model and you understand how it was generated and its limitations, you'll be in a much better position to know whether to approach PID tuning using your physical system or with your newly generated model. I'm Brian, and welcome to a MATLAB Tech Talk.

    Here's the setup. You have a DC motor, and you want to develop a PID controller that will control the motor speed. When you apply a voltage to the motor, the motor will accelerate up to some steady-state speed. The higher the voltage, the faster the motor will run.

    Now, the PID controller is in charge of generating the necessary voltage that will cause the motor to run at the commanded speed. If it's designed correctly, then the motor will be able to follow the command quickly with minimum overshoot, and it will be stable. Now we could just use the hardware and guess at some PID gains, run it to see how it does, and then tweak them as necessary.

    That's this left portion of the flowchart. Now, this guess and check method might work. But we have so many other options available to tune the controller if we have a mathematical model of the system. So with that in mind, let's go through a few ways to generate a model of this DC motor. Now quick caveat before we begin. I'm going to walk through the details of each of these methods pretty quickly.

    But the point of this video is to show that there are multiple ways to accomplish the same thing and then give you a general idea of when one method is better suited over another. Now if you want more detailed information on modeling systems, definitely check out the links in the description of this video. All right, the first method we're going to talk about is deriving a model from first principles.

    If your system is simple enough to understand, then you can write out the equations directly that govern its behavior. This is sometimes referred to as the white box method because it's as if you shined a flashlight into the box representing your system and was able to see all the bits and pieces that make it up. And since you know everything about it, you can derive a model using whatever technique you enjoy or are good at. This might be free body diagrams, Lagrangian mechanics, or building a larger model from individual components, for example.

    This is what it means to derive a model from first principles. You're going all the way back to the fundamental physical concepts and assumptions. Now, this type of modeling is usually what you learn first and with good reason. It helps you understand the intricacies of the system you're trying to control and forces you to think about what the important components are and therefore, what needs to be modeled and which components can just be left out.

    For example, for the DC motor, is it important to model static friction? Well, if the motor is always operating at some non-zero speed, then probably not. The model won't benefit from having static friction, and including it just creates a more complicated model and slows the simulation down. Now, a real quick side note, sometimes you know the structure of the system, but you don't know the specific parameter values.

    For example, with our motor, you know that the rotor has inertia but you just don't know what the value is. This is sometimes called the gray box method because you know something about the system, but the specifics elude you. And this is a pretty common situation, and you can handle it by either testing your motor and measuring that value, or you can fit it to an existing model that has the correct structure and then have software find the optimal parameters. I'll touch on this a bit more when we discuss system identification.

    For now, I'll go over to MATLAB and Simulink and open up a nonlinear model of a DC motor and speed sensor that I created using first principles. This model takes motor voltage as an input and outputs motor speed in radians per second. And you can see that it's not a terribly complicated model. It's just a handful of components. But like I said earlier, as long as you have insight into the structure and parameters of your system, you can build a model like this.

    I want to quickly show you another way to develop a model from first principles using Simscape within Simulink. Simscape essentially lets you avoid writing out the ordinary differential equations like we just did and, instead, lets you draw the mechanical and electrical circuits of the system directly. This is a Simscape model of a DC motor just to briefly show you what it looks like. Instead of integrators and gain blocks, this model is built with voltage sources and current sensors. Even the DC motor itself is modeled with resistors, inductors, and mechanical components. So two different ways to create a motor model from first principles.

    Now we can use this model to close the loop with a PID controller and tune the gains to get the behavior that we want. And if this nonlinear model is a pretty good representation of your real physical system, then the gains we get using it can transfer over to the real hardware and work there as well. Now, I know you probably want to get into actually tuning this controller, but we're going to cover that in the next video. For now, I want to move on to a different way to develop a model.

    Let's say that your system is too complicated to derive a model directly, either with differential equations or mechanical and electrical components, and, instead, you'd rather create a model of the hardware using system identification techniques. System identification allows you to generate a model without knowing the details down to the fundamental physical concepts. Instead, you can rely on the relationship between the input signal and the output response to infer a model of the system. This is sometimes referred to as the black box method because you don't have to have insight into the specifics of the system.

    Now, as a rather absurd example, imagine a box with a hole in either side and a conveyor belt that moves through it. You don't know what happens inside the box, but you do have access to items before and after they go through it. You place a loaf of bread at room temperature on the belt and send it through. When it comes out, the bread is 10 degrees warmer.

    Now, at this point, you're pretty confident that whatever is in the box supplies heat, and by understanding the thermal properties of the bread, you can infer how much heat was imparted by the system and create a representative heating model. Now is this heating done with an electric coil or with microwaves? You don't know that at this point, and perhaps you don't care about that detail.

    But this is an important concept with system identification. You get to avoid needing to understand the details of your system since they're lumped into general behavior. However, you still need to understand your system well enough to know whether you generated the right model structure. For example, if you based your model on how bread heats up, and then you send some metal through, you might realize pretty quickly that you do, in fact, need to know whether it's a coil or a microwave. So this isn't a method that you can run with complete ignorance.

    All right, let's use system identification with our DC motor. We can apply a known signal into our motor and measure the response. Now normally, this is done using physical hardware. But since I don't have a real motor for this video, we're going to pretend that the nonlinear model that we have is our physical hardware, and we'll just get our needed information from it instead. All right, with the step input and response output measured, I can use the system identification app to fit a model to this data.

    Now, the details on how to use this app are in the description of this video. But what you should take away from this is that there are existing system identification tools available to you. And these tools don't remove the need to understand how system identification works. They just make the whole process easier and faster.

    From my input and output data, the system identification app came back with a second-order transfer function, about 6.6s plus 2.4 divided by s squared plus 0.9s plus 0.2. And now we can go back to Simulink and put our new identified linear model to the test. I'll add a transfer function block and write out the numerator and denominator explicitly. You could use the LTI block and just assign it to TF1 directly, but I like writing it out explicitly in videos so that you can see the transfer function clearly in the block mask.

    As a reminder, this block represents a linear model of both the DC motor plan and the sensor. And we got this model using only an input and response signal from our system. Now we can run both of them side by side and see that our estimated linear model matches our nonlinear model pretty nicely. But of course, this looks good. This is the data we use to fit the model. The real test is to see how our linear model compares against a wide range of arbitrary inputs. And again, it worked pretty well.

    So you can see how simple it can be to create a model using system identification rather than slugging through a model with first principles. And now that we have this model, we could wrap a PID controller around it and use the linear model to tune the gains. All right, let's set this aside for a moment and talk about a third way to generate a model using linearization techniques.

    We just created a linear model using system identification, and that's a legitimate way to generate a linear model. However, when a nonlinear model is available, linearization, or linerizing that model, can produce more trustable and reliable results than system identification. And it might be easier to troubleshoot. For these reasons, it's a technique worth learning.

    Linear systems are awesome, or more accurately, linear system models are awesome because there is no such thing as a truly linear system. Real systems all have some nonlinear behavior to them. But that doesn't stop us from approximating a real system with a linear model.

    We just did that very thing with system identification, and now we're going to start with an existing nonlinear model and make it linear. The hope is that your real system behaves linearly enough that you're OK with this approximation. And why are we trying to shoehorn all of these systems into linear models? Well, it's because we know how to solve linear models, and we've built up a whole lot of tools that we can use to design and tune control systems with linear plans.

    Do you want to work in the Laplace domain? Do you want to do loop shaping or pole placement or some other classical linear control technique? Then you're going to need a linear model. Well, for our DC motor, the static friction that I mentioned earlier is nonlinear behavior. This is because the motor won't spin until the torque is strong enough to overcome the static friction. So there's this range of very low input voltages that don't actually produce a spinning motor.

    Now, had this been a linear motor, then very low voltages would still cause the motor to spin, even if it's very slowly. So if we want to generate a transfer function for our motor, we need to linearize it around some operating point. And just to show you a quick demonstration of it, we can do that easily in Simulink. The first thing we need to do is set the open loop input and output points by right-clicking on the signal lines and selecting linear analysis points. This tells Simulink where to begin and end the linearization.

    I've set it up so that we linearize the motor plant and sensor together. With these set, we can launch the linear analysis tool. This tool is going to look at our nonlinear model and remove all of the nonlinear components or estimate them as best it can as linear components and then return the linearized model. Again, I'm not going to go into detail on how to use this tool. You can find that information in the links below.

    But just like with system identification, it's important to have an understanding of what it means to linearize as a system and what information you're losing in the process. For us, our linear model won't behave like the real molar at very low RPMs. This is because we're essentially removing the static friction component. And with this information, I know not to trust this linear model in these cases and only rely on it for situations where the motor is spinning.

    OK. So here's our linear model. It's a second-order transfer function that has two poles and no zeros. Let's head back over to Simulink and try out our new linear model. I'll copy the previous transfer function block and then just change the values to these new values and hook it up to our step input and scope output and then run a step response. And there we have it, three different models of the same physical system.

    The first we generated by writing out the equations directly, the second we took input and output data from the model or the physical hardware and used system identification to fit that data to a model of our choice, and the third, we linearised our nonlinear model around an operating point of our choice. These three models all seem pretty different. But you can see that they produce similar results even with an arbitrary input.

    It's now at this point that we can start the process of developing a PID controller for our system. And we have four different systems that we can use. There's the physical system itself and then the three different models we generated of it. Well, in the next video, we're going to dive deeper into these tuning methods using MATLAB and Simulink. So if you don't want to miss the next Tech Talk video, don't forget to subscribe to this channel. Also, if you want to check out my channel, Control System Lectures, I cover more control theory topics there as well. Thanks for watching, and I'll see you next time.

    Up Next:

    View full series (7 Videos)

    View more related videos