getting started with simulink for controls video -凯发k8网页登录
get started with simulink® by walking through an example. this video shows you the basics of what it's like to use simulink.
you will learn how to model, simulate, and test a controller for a solar panel as it tracks the movement of the sun throughout the day. you’ll see how to model a physical system, design a basic pi controller for that system, and then run simulations to ensure that the model is working correctly.
after going through the example, you’ll learn how simulink is just one part of model-based design for modeling, simulating, testing, and implementing real-world systems.
simulink is a graphical environment for modeling dynamic systems---that is, systems that change over time. simulink takes care of the simulation so that you can focus on the engineering. you can use it to model simple things---like a home thermostat; or complex systems---like a fully autonomous vehicle or a surgical robot.
this video will show you the basics of simulink and give you an idea of what working in simulink looks like. stay tuned to the end to find out where to go to learn more about how to use simulink. let’s get started!
at the mathworks headquarters in natick, massachusetts, there’s a number of solar panels to generate electricity.
these panels face south and are fixed in place. that means they produce more electricity when the sun is shining directly on them in the middle of the day, and less power when the sun is to the east or west, early and late in the day.
what if you had solar panels that rotated to track the sun so that you could produce as much electricity as possible?
in this video, we’ll use simulink to design a tracking system to keep a solar panel aligned with the sun. if you want to follow along as we build the model, you can download it using the link below.
the physical system consists of a panel and a motor. we’ll model those first and then we’ll add a controller to track the sun’s position.
once we’re happy with the design, we’ll test it to see how well it does tracking actual sun data.
the physical system has two main components. with some basic physics, we can write out the equations of motion for each. let’s model the panel first.
you start simulink by clicking the simulink button in the matlab toolstrip. this opens the start page, where you can create new models, find examples, and even find basic training.
we’re starting our model from scratch, so we’ll choose blank model.
simulink models are built up from blocks and signals. open the library browser to see all of the blocks available. to model the equation for the panel, we’ll start with the integrator block.
let’s click and drag an integrator from the library to our model.
so why an integrator block? well, the integrator block takes an input and integrates it over time. if we integrate acceleration, we get velocity. if we integrate velocity, we get position. this is the basis for modeling differential equations in simulink.
our equation has acceleration and velocity terms, so we need at least one integrator. let’s add another one to also get the position.
we connect blocks together with signals by clicking and dragging between blocks. don’t worry about these red lines, we’ll connect them up in a second.
it’s a good idea to label signals to keep things organized, so we’ll double-click the signals and type in a name. let’s name this one theta_dot_dot for acceleration, then theta_dot for velocity, and theta for the position of the panel.
next, let’s model the right-hand side of this equation. first, the torque term.
let’s use a constant block. we’ll replace this with the motor later.
you can double-click a block to change its parameters---let’s change the value to 10.
we need to perform a subtraction, so let’s also grab a subtract block.
the damping term depends on the panel’s velocity---the theta_dot signal. we can branch this signal by right-clicking and dragging to connect it to the subtract block.
and don’t forget we still need to multiply that by kd. let’s use a gain block for that.
rather than hard-coding the gain value, we can also use a variable, or even matlab code. so let’s just say the gain is kd. that red box is telling us that kd hasn’t been defined yet. so click the three dots and select create. we’ll give it a value of 5 and store it in matlab’s base workspace. let’s check matlab, and yep, the variable kd has been created.
to finish up the equation, we need to divide by the inertia, j. we’ll do that with another gain block.
but now that we know the name of the block, we can just double-click in the model and start typing the block name. then, use the drop down to find the right block and hit enter.
we’ll set the gain to 1/j and, again, let’s define the variable j in the base workspace with a value of 8.6.
let’s add an annotation to show the equation being modeled---so when we come back to it later, we’ll easily know what the equation is.
that should be all we need to model the panel. but to check if everything is working correctly, we’ll want to visualize some signals. simulink has a bunch of visualization tools. for a quick check of a signal, the easy option is to use a scope block ... and connect it to the signal we want to view.
let’s add a second scope to see the velocity signal.
ok now we’re ready to simulate the model. we can set the simulation stop time in the simulation tab----but, we’ll leave it as 10 for now.
to run the simulation, just click the run button. the simulation finished but what you didn’t see was that simulink numerically solved the differential equation through time.
double-click on a scope to check out what happened.
in the position scope, we see the panel’s angular position increasing.
in the velocity scope, the velocity starts from zero and levels off.
so with a constant torque, the panel starts turning and then settles to rotating at a fixed rate. well that makes sense.
let’s do a quick sanity check and see what happens if we switch the sign of the torque. we can edit the constant value directly on the block!
rerun… and… that looks good---we see the panel now spins in the opposite direction.
now that we have the panel model working, let’s group those blocks together to keep things organized. just select the blocks you want to include---we’ll leave the constant block and the scopes out for now---and then click create subsystem in the modeling tab.
now all of those blocks are contained within this subsystem. let’s name it panel.
you can double-click to see the subsystem contents. these oval-shaped blocks are inports and outports---that’s the data going in and out of the subsystem. let’s adjust the port names.
go back up to the top level... and there are the port names we just entered.
ok, we still need a motor. remember that motor equation? well, we can follow the exact same process to model it.
and.. we’ve got our motor!
we’ll supply a voltage to the motor to generate a torque and move the panel. let’s check what happens. we can see that the panel spins when a voltage is applied to the motor---so everything looks good so far!
ok we’ve modeled the panel and the motor. now we need a controller to set the correct voltage so that the panel tracks the sun.
from our model, we know where the panel is pointing. and, let’s say the sun is over here.
we want the panel pointing at the sun, so the difference between these two angles is the error. we’ll add a controller that applies a voltage to the motor to make that error as small as possible.
and if the sun moves, the controller will react accordingly to keep the panel pointing at the sun.
ok, back to our simulink model!
we have the position of the panel here. to get the error, we need the position of the sun. while we’re designing the controller, we’ll use a unit step input---that’s pretty common in control design. we’ll test it with some actual sun position data later.
now to calculate the error. we’ll use a sum block---it’s already got this nice circular shape common in control schematics. we just need to change the second port to be minus instead of plus.
next we need a controller. there are a lot of options, but a common approach is some form of pid control---which stands for proportional/integral/derivative, because the control output is some function of the error, the integrated error, and the derivative of the error. but we don’t need to build all that ourselves, we’ll just add a pid controller block.
we connect the input to the error signal and the output will drive the motor.
you can see there are a lot of ways to customize the controller. we’ll switch to a pi controller---the d term helps respond to quick changes, which we don’t need because the sun moves steadily across the sky.
there are two gains to adjust: one for the proportional term and one for the integral term. these affect the controller’s response. we’ll set the proportional gain to 240 and the integral gain to 180.
to see how well the controller performs, let’s use the same scope to show both the sun position and the panel position. notice that a new port is automatically added.
let’s run the model… and add a legend to the scope so we can tell the signals apart. let’s also make the position line dashed.
we can see that the controller overshoots a little and then settles to the reference value of 1. that’s good enough for our application.
ok, we designed our controller. but, can it actually track the movement of the sun? well let’s see how it performs when we provide it with some real data.
let’s load some sun position data into the matlab base workspace. this file has two variables: a vector for time spanning 15 hours, and a vector of the sun’s position at each point in time.
let’s plot it.
you can see that the sun rises in the northeast at about 60 degrees from due north and sets in the northwest at about 300 degrees.
we can bring the sun position data into the model by replacing the step block with an inport.
we need to select which data to use. click model settings in the modeling tab. then navigate to the data import/export pane.
there are a lot of settings in here---if you’re ever unsure about anything, just right click and select “what’s this”. this input option is what we need.
when specifying input data, the first column should always be time. after that, you can add a column vector for each inport in your model.
since we now have 15 hours of data, we’ll change the simulation stop time.
let’s run the model and we can see its tracking the sun’s position quite well.
so… we modeled our solar panel system, developed a controller, and tested the system to ensure it will track the motion of the sun. and, it looks like our design works!
but that’s just the beginning. if we want to make these panels a reality, we can incorporate proper design specs into our model.
we can bring in other tools like simscape to model the mechanical and electrical systems, without needing to derive any equations! and with stateflow, we can add logic to make the panels smart, so they spin back to the east at the end of the day, and they know what to do if conditions change.
then when we’re ready, we can automatically generate code from the model and deploy it directly to hardware.
at each step of the way, we can continuously test the design to ensure it’s error-free and meeting specifications.
with the model at the center of our design process, we can tackle all kinds of design questions. and so can you.
now that you have a feel for what working in simulink is like, it’s time to learn it. the best way to learn simulink is to work with it. so, start up simulink onramp, which will teach you the basics of simulink interactively. it’s free and takes just a couple of hours.
welcome to simulink.
download code and files
related products
learn more
download model
featured product
simulink
up next:
related videos:
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 mathworks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- (español)
- (english)
- (english)
欧洲
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
亚太
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)