Lab# 2

advertisement
EE311 – Systems
College of Engineering
South Dakota School of Mines & Technology
Spring Semester 2015
Prof. C. R. Tolle
Inst. L. J. Tolle, P.E.
Lab 2
Motor Model Simulations
Week of Feb. 8, 2015
Due Wed., Feb. 18, 2015
Rev. 0
I NTRODUCTION
This lab assignment uses Matlab and Simulink to each create a simple model of a rotating mechanical system (motor) and
generate plots associated with the model. The motor that will be modeled is a Pittman Lo-Cog DC Motor that was donated to
the university. Since this is a simple model, only some of the constants on the attached data sheet will be used. Use whatever
variable names make sense to you.
D ERIVATION OF E QUATIONS
The following equations are from Control Systems Engineering 7th Edition by Norman S. Nise, section 2.8 Electromechanical System Transfer Functions. Please refer to this section to understand how the equations were derived. Notice that the
first two transfer functions are related to voltage, while the torque transfer function is related to θ(s). This means you will
have to do some math to have the correct torque equation comparing it to voltage.
Angular Position:
θm (s)
Ea (s)
=
Angular Velocity:
ω(s)
Ea (s)
=
Kt /(Ra Jm )
Kt Kb
)]
s[s+ J1 (Dm + R
m
a
Kt /(Ra Jm)
s+ J1 (Dm +
m
Torque:
τ (s)
θ(s)
Kt Kb
)
Ra
=
=
K
s(s+α)
K
s+α
= Jm s2 + Dm s = s(Jm s + Dm )
M ATLAB C OMMANDS AND S IMULINK M ODELS U SED
The commands and models used are as follows:
Matlab: close, clear, clc, tf, sim, step, subplot, plot, title
Simulink: step (input), transfer function, mux, to workspace (output)
If you are unfamiliar with any of the Matlab commands, type “help” followed by the command name in the Command
Window. If you are unfamiliar with any of the Simulink commands, go to the Simulink Library Browser, click on Help, then
Help for the Selected Block.
M ATLAB M ODEL
1. m-file Setup
• Open a new m-file. Using the “%” to denote commented lines of code, enter your name, class number, lab
number, and the fact that this is the Matlab portion of the lab at the beginning of the file. Be sure to comment
your code throughout this lab.
• The commands close, clear, and clc will close all of the currently open figures, clear all of the variables, and clear
the command window respectively. Add a line at the beginning of your m-file that says close all; clear all; clc;.
1
2. Enter Given Constants
• From the data sheet, using the English units (oz, inches, etc), enter the constants for rotor inertia (Jm ), viscous
damping (Dm in our equation and D on the data sheet), torque constant (Kt ), back emf constant (Kb in our
equation and Ke on the data sheet), and armature resistance (Ra in our equation and Rt on the data sheet).
• Units are key. At the end of this lab, you will be asked to plot a torque speed curve and compare it to the one at
the bottom of the data sheet. Notice that the units for Jm are oz-in-s2 and that the speed on the plot is in rpm.
This will require us to divide the constant Jm by 602 .
• Also note that Ke and Dm are in V/krpm instead of V/rpm. To address this, divide the constants Ke and Dm by
1000.
• This will make the units work out in the end.
3. Calculate Coefficients for Angular Position
• In order to keep the m-file clean, put the transfer functions into a more standard format. For angular position, the
K
equation is in the form s(s+α)
. To do this, define variables K and α where K = RaK∗Jt m and α = J1m ∗ (Dm +
Kt ∗Kb
Ra ).
These constants are used in all three transfer functions, so this will come in handy.
4. Set Up Coefficient Arrays for Angular Position
• In order to calculate transfer functions, an array will be set up with the coefficients of the polynomial in s terms
from the highest power (in this case s2 ) through the lowest power (s0 ).
• If any of the terms are not present in the equation, 0 must be entered as a place holder. So for the transfer function
to calculate the angular position, the numerator array is [0 0 K] and the denominator array is [1 alpha 0]. Set up
appropriate variable names for these two arrays and enter them into your m-file. Remembering that there will be
3 transfer functions used, let’s call them num position and den position.
5. Perform a Transfer Function Evaluation for Angular Position
• The “tf” Matlab command will be used to calculate the transfer function. For the angular position, assign
sys position = tf(num position, den position).
6. Calculate the Transfer Function for Angular Velocity and Torque
• Using the methods in steps 3-5 above, calculate any new s term coefficients and enter the numerator and denominator coefficients for the angular velocity and torque equations. Perform the transfer function evaluation on each
of these systems.
7. Step Function Input to the 3 Transfer Functions
• Apply the step function to the systems by using the “step” command. Since this motor has a very quick response
time, it will only be evaluated from 0 to 0.0002 in 0.000001 step intervals.
• By looking at the data sheet, you will notice that this motor runs at 12 V, so we will apply the step function to
the transfer functions and store the results in a matrix containing the calculated values and time signals in order
to scale them (which will be done in step 8). To do this for the angular position transfer function, use the code
[values position,time] = step(sys position, 0:0.000001:0.0002).
• Remember to evaluate the angular velocity and torque as well.
8. Plot Results
2
• The amplitudes of the results are too different to be examined all on one plot. In order to see the results in
comparison with each other, use the “subplot” command.
• Multiply the values calculated above by 12 and plot the results vs. time.
• Also label the resulting figures with titles using the “title” command. So for the Angular Position, the code
will be subplot(4,1,1), plot(time,values position*12), title(‘Angular Position’). Plot each of the transfer function
results in a different subplot.
9. Compare Results with Data Sheet
• In order to compare the simple model created in this lab with the information on the data sheet provided by the
manufacturer, add a fourth subplot that plots the angular velocity vs. torque. Don’t forget to multiply by 12 for
each axis.
• Now compare this to the torque speed curve at the bottom of the data sheet. Remember that only 5 of the motor
specifications were used, so the plot will not be exact, but it should be close.
10. Items Due
• Matlab’s “publish” feature will combine the m-file and figures into one document to be turned in. The default
setting generates an .html file. Once the file has been generated, Matlab will return the path so that you know
where the file is saved. Hint: In order to not have your .html file full of lists of numbers, put a “;” at the end of
each line that performs calculations.
• To execute this, go to the Command Window and type publish(’filename.m’).
• Print out the .html file to turn in.
S IMULINK M ODEL
1. Open Simulink by clicking on the Simulink button in the Matlab Command Window. Once Simulink is running, open
a new Simulink model.
2. Place Blocks in Model
• The blocks needed for this simulation are a step input, three transfer functions, a mux, and a to workspace output.
The Step block is located in the Sources library. Click and drag it to the Simulink model window. Drag 3 Transfer
Fcn blocks from the Continuous library, a Mux block from the Signal Routing library and a To Workspace block
from the Sinks library to the model window.
3. Configure Input
• To configure the input, double click on the Step block. To turn on the step function at time 0, change Step Time
to 0. In order to compare the results of this lab to the data sheet for the motor, realize that the motor runs at 12 V.
To make our model run at 12 V, change the Final Value to 12.
4. Configure Transfer Function Blocks
• Now change the numerator and denominator coefficients of the Transfer Fcn blocks by double clicking on the
blocks. The same arrays used in the Matlab portion of the lab will be used here. This means that for the Angular
Position transfer function, the Numerator Coefficients are entered as [0 0 K] and the Denominator Coefficients
are [1 alpha 0]. Then double click on the name of the block and change it to “Angular Position”. Now edit each
of the blocks as needed.
3
5. Configure Mux Block
• The Mux block will put all of the values calculated by the transfer function blocks into one matrix in the return
structure. The Mux will need to have 3 inputs, so double click on the Mux block and change “Number of Inputs”
to 3.
6. Configure Output
• Edit the To Workspace block so that the Save Format is “Structure with Time”. This will result in Simulink
returning a matrix with the results of the 3 transfer functions along with the time samples so that the results can
be plotted vs. time. If desired, change the output variable to something other than “simout”. For the purposes of
consistency in this explanation, “simout” is used.
7. Connect Blocks
• To connect the blocks, put the cursor over the output port of a block and crosshairs will appear. Drag until double
crosshairs appear at the input of the next block and release. A dark arrow should connect the blocks. Attach the
Step block as input to all 3 Transfer Fcn blocks. The output from each of the 3 Transfer Fcn blocks is the input
to one port on the Mux, and the Mux’s output is the input to the To Workspace block.
• If you have trouble connecting the Step input with all 3 Transfer Fcn blocks, start at the Transfer Fcn input and
drag back to a line already coming off of the Step input.
8. Edit Start, Stop and Step Times
• The last thing to do before running the simulation is to edit the start, stop and step times. To do this, in the
Simulink model window, go to Simulation -> Configuration Parameters. Change the Type of Solver to “Fixedstep” and the Solver to “ode1 (Euler)”. Now change the Start, Stop and Fixed-step size to the parameters specified
in the Matlab portion of the lab.
9. Enter Constants
• What’s missing? If you have a different Matlab session running or have cleared the variables between the Matlab
and Simulink portions of this lab, then the constants from the data sheet have not been entered.
• The cleanest way to provide all of the information needed is to open a new m-file. Using comments, enter your
name, class name, lab number, and the fact that this is the Simulink portion of the lab at the beginning of the
m-file. Also enter the close all; clear all; clc; line as before.
• Now enter the constants as well as your calculations for K and α into the m-file.
• Be sure to save this m-file with a different file name than the m-file from the Matlab portion of the lab.
10. Run Model
• To have the m-file call your Simulink model and run it, enter sim(’filename’).
• If you would like to run the Simulink model on it’s own for troubleshooting purposes, be sure that the variables
and calculations for K and α have been done by checking to see if the variables are defined in the Workspace.
Then run the simulation by going to Simulation -> Start.
11. Plot Results
• The results from the model are now stored in matrices where the variable “simout.time” contains the time values,
and “simout.signals.values” contains the values of your transfer functions with each transfer function contained
in a separate column.
4
• Note that the order of the signals coming into the Mux block is the order of the signals being sent to the
workspace. Be sure that you know which signal is in which position.
• Remember that when specifying a matrix position the notation is (row, column). So to obtain all of the values in
a given column in Matlab, use the notation (:,column). To plot all of the values in the first column vs. time, the
code is plot(simout.time,simout.signals.values(:,1)). Again, use the “subplot” command to plot all of the results
in the same figure and the “title” command to label your subplots.
• Add a fourth subplot to the Simulink results that plots the angular velocity vs. torque. Hint: this will be a
comparison of two of the simout.signals.values data items, not a comparison against simout.time.
12. Compare Results with Data Sheet
• Now compare your results with the torque speed curve at the bottom of the data sheet. Remember that only 5 of
the motor specifications were used, so the plot will not be exact, but it should be close.
13. Items Due
• Matlab’s “publish” feature will combine the m-file and figures into one document to be turned in. The default
setting generates an .html file. Once the file has been generated, Matlab will return the path so that you know
where the file is saved. Hint: In order to not have your .html file full of lists of numbers, put a “;” at the end of
each line that performs calculations.
• To execute this, go to the Command Window and type publish(’filename.m’).
• Print out the .html file to turn in.
5
Download