You are on page 1of 33

LAB 1 MATLAB Tutorial

Goal
This lab provides the basic information so that all the students will have at least a minimal MATLAB background.

Equipment List

Table 1.1: Equipment

Item Qty Description

1 1 Any PC or UNIX computer with MATLAB

Introduction
MATLAB will be used throughout this course in both lecture and laboratory work. The information and exercised in
this lab are intended to get everyone the basic MATLAB exposure. If you have not used MATLAB much, or feel that
your skills are low, then you should rework these exercises outside of lab, and perhaps, expand on them.

General Concepts
MATLAB, as installed on most computers, consists of the core MATLAB code, and several “MATLAB Toolboxes”
that together allow the user to perform a variety of analyses. The Controls Toolbox is only one of dozens toolboxes
available, so, don’t think of MATLAB as simply a control systems analysis code, it can do much more.
When you start MATLAB you are presented with a window from which you can enter commands interactively. Alter-
natively, you can put your commands in a file and execute it at the MATLAB prompt. In practice, you will probably
do a little of both. One good approach is to incrementally create your file of commands by first executing them
directly in the MATLAB window.
These “files of commands” must be given the file extension .m, and are referred to as m-files. However, m-files are
not limited to being a series of commands that you don’t want to type at the MATLAB window, they can also be used
to create user-defined functions. It turns out that a MATLAB toolbox is usually nothing more than a grouping of m-
files that someone created to perform a specific type of analysis, like control system design. Any of the MATLAB
commands (e.g. sqrt) is really an m-file. For the hackers in the crowd, you can always find the m-files buried in the
MATLAB directory, look at them, or use them as the basis for your own m-files.

MEEM4700 Laboratory Manual - Version 1.0 1


MATLAB Workspace - Lab 1

MATLAB has a built in text editor that is invoked by typing


edit
at the MATLAB prompt. It’s ok, but if you prefer the DOS “edit” editor, or “vi”, those work equally well.
One of the more generally useful MATLAB toolboxes is Simulink -- a drag-and-drop dynamic system simulation
environment. This will be used extensively in lab forming the heart of the Computer Aided Control System Design
(CACSD) methodology that is used.
Finally, the most important MATLAB features is its help. At the MATLAB prompt simply typing
helpdesk
gives you access to searchable help as well as all the MATLAB manuals in .pdf format. Always try help first before
asking a lab or course instructor for help on MATLAB commands. Whenever you ask for help on MATLAB, the first
question you will be asked is: “What did you find out from helpdesk?” The consequences of replying “I didn’t try
that.” are too horrific to imagine. If you know the command name, but just forgot its usage, simply type
help xxxx
where xxxx is the command name and you will get a pretty good description in the MATLAB window.

MATLAB Workspace
The workspace is the window where you execute MATLAB commands, and all the data that you have put in it. The
best way to probe the workspace is to type
whos
This command shows you all the variables that are currently in the workspace. You can save the workspace by typing
save
which creates the file matlab.mat in your current directory. You can find out what your current directory is by typing
pwd
You should always change you working directory to an appropriate location under your user name. Changing direc-
tory is accomplished by typing
cd xxxx
where xxxx is the path name of your destination (you can move backwards in the directory tree by typing “cd ..”.
If you ended your MATLAB session by typing
quit
then restarted MATLAB and typed
load
your workspace would be completely restored from the matlab.mat file. Another useful workspace-like command is
clear all
it eliminates all the variables in your workspace. For example start MATLAB, and execute the following sequence of
commands
a=2;
b=5;
whos
clear all
whos
The first two commands added the two variables, a and b to the workspace and assigned values of 2 and 5 respec-
tively. The clear all command effect was obvious.
The arrow keys are real handy in MATLAB when typing in long expressions at the command line. The up arrow
scrolls through previous commands, and the down arrow advances the other direction. Instead of retyping a previ-
ously entered command, just hit the up arrow until you find it. If you need to change it slightly the other arrows let
you position the cursor anywhere in the command.

MEEM4700 Laboratory Manual - Version 1.0 2


MATLAB Data Types - Lab 1

Finally, any DOS command can be entered in MATLAB as long as it is preceded by an exclamation mark (!).

MATLAB Data Types


The most distinguishing aspect of MATLAB is that it allows the user to manipulate vectors, and matrices with the
same ease as manipulating scalars. Before diving into the actual commands, we must spend a few moments reviewing
the main MATLAB data types. The three most common data types you may see are arrays, strings, and structures. In
this course, we will only use arrays. As far as MATLAB is concerned a scalar is 1 by 1 array. For example clear your
workspace and execute the commands
a=4.2;
A=[1 4;6 3];
whos
Two things should be evident. First, MATLAB distinguishes the case of a variable name, and that both a and A are
considered arrays. Now let’s look at the contents of a and A, type
a
A
Again two things are important from this example. First, you can examine the contents of any variable simply by typ-
ing its name at the MATLAB prompt. Second, when typing in a matrix, spaces between elements separate columns,
whereas semicolons separate rows. For practice, create the matrix

3 0 –1
B = 44 2 1.1
7 2 11

in your workspace by typing it in at the MATLAB prompt.


You’ve probably noticed that when you display a variable’s contents in the workspace it has only 5 significant digits.
The precision of the actual variable is much higher (about 16 significant digits). To change the way you see the con-
tents, use the format command. For example, setting
format long e
changes the workspace viewing format to double precision, with scientific notation. There’s all kinds of other fun for-
mat options you can explore by looking at
help format
It is also possible to construct arrays automatically. For example, let’s say you want to create a time vector, where the
time points start at 0 seconds and go up to 5 seconds, by increments of 0.001. The MATLAB command is simply
my_time = 0:0.001:5;
Other examples of automatic construction include arrays of all ones
my_one = ones(3,2)
or all zeros
my_zero = zeros(4,5)
or any size identity matrix
my_I = eye(5)
Note: Any MATLAB command can be terminated by a semicolon, which suppresses any echo information to the
scree.

Scalar versus Array Math Operations


Since MATLAB treats everything as an array, you can add matrices as easily as scalars. For example
clear all
a=4;

MEEM4700 Laboratory Manual - Version 1.0 3


Conditional Statements - Lab 1

A=7;
alpha=a+A
b=[1 2;3 4];
B=[6 5;3 1];
beta=b+B
Of course, you cannot violate the rules of matrix algebra. For example try
clear all
b=[1 2;3 4];
B=[6 7];
beta=b*B
In contrast to matrix algebra rules, the need may arise to divide, multiply, or raise to a power one vector by another,
element-by element. The typical scalar commands are used for this (/,*,^) except, you put a . in front of the scalar
command. That is, if you need to multiply the elements of [1 2 3 4] by [6 7 8 9], just type
[1 2 3 4].*[6 7 8 9]
Getting help on the low-level math operations (e.g. +, .*, etc.) is obtained by typing
help xxxx
where xxxx is any of the low-level math symbols. Try it.

Conditional Statements
MATLAB, like most programming languages, supports a variety of conditional statements (e.g. if-then-elseif) and
looping statements (e.g. for, while, etc.). To explore these, simply type
help if
or
help for

Plotting
MATLAB’s potential in visualizing data is pretty amazing. One of the nice features is that with the simplest of com-
mands you can have quite a bit of capability. For more sophisticated applications, it get’s a bit tricky. Your graphs can
also be saved with several different file formats (e.g. jpeg, postscript, etc.) for embedding in other documents.
Let’s start by
clear all
t=0:.1:10;
y=sin(2*pi*.5*t);
Note: MATLAB has some built-in constants that are handy, e.g. pi.
To see a plot of y versus t simply type
plot(t,y)
To add labels, legend, grid and title, use
xlabel(‘Time (sec)’);
ylabel(‘Output (volts)’);
title(‘D/A Output’);
legend(‘signal 1’);
To save this plot as a postscript file for use in a report type
print -depsc -tiff -r600 plot1.eps
The commands above provide the most basic plotting capability and represent several shortcuts to the low-level
approach to generating MATLAB plots. Specifically, the use of handle graphics. The helpdesk provides access to a
.pdf manual on handle graphics for those really interested in it. We will cover a few aspects of it here as it will be use-
ful later in the course.

MEEM4700 Laboratory Manual - Version 1.0 4


Plotting - Lab 1

Handle Graphics
A MATLAB plot is really a hierarchy of objects, “figure” -> “axes” -> “line” and “text”, where “figure” is the highest
level object (there are really more object types, but we’ll only consider these). Each object is automatically assigned a
numerical “handle” that is used to reference it. MATLAB uses a “parent” and “child” syntax to keep track of the heri-
archy. That is, “axes” is the child of “figure” and also the parent of “line” and the parent of “text”. Each handle has
many properties that can be manipulated using the “set” command. Memorizing all the handle’s properties is unreal-
istic. However, they are easily found in the helpdesk (Handle Graphics section), or in the MATLAB window by typ-
ing
set(handle_name)
where handle_name is any of the valid handle names (e.g. figure, axes, line, text, etc.).
Having access to a plot’s handles is the best way to manipulate the finer details of the plot. There are many methods
for getting a plot’s handles, the most direct approach being to explicitly assign your variables to the handles as you
create the plot.
Repeating the previous example, we could have started by first creating a blank figure window, and creating a variable
to store its handle
clear all
t=0:.1:10;
y=sin(2*pi*.5*t);
h1 = figure;
Next, we’ll make the plot, and use the variable h3 to hold the handle of the “line”
h3 = plot(t,y);
We can extract the value of the “axes” handle by extracting the parent from h3
h2 = get(h3,’Parent’);
Note: the “get” command is the opposite of the “set” command, in that it allows you to query the setting of any of a
handle’s property.
As an example of manipulating “line” properties, we’ll add diamonds at each of the points (called “markers”. These
diamonds will have red edges (“MarkerEdgeColor”) and green insides (“MarkerFaceColor”). For good measure,
we’ll change the width of the line (default is 0.5) to 0.8 points.
set(h3,’Marker’,’d’);
set(h3,’MarkerEdgeColor’,’r’);
set(h3,’MarkerFaceColor’,’g’);
set(h3,’LineWidth’,0.8);
As an example of manipulating the “axes” properties, we’ll change the axis labels fonts (FontName) from the default
of Helvetica to Times, and change their size (FontSize) from 10 points to 8 points. In addition, we’ll change the x-axis
limits (XLim) to -2 to 4, with spacing of 0.5 seconds.
set(h2,’FontName’,’Times’);
set(h2,’FontSize’,8);
set(h2,’XLim’,[-2 4]);
set(h2,’XTick’,[-2,-1.5,-1,-.5,0,.5,1,1.5,2,2.5,3,3.5,4]);
We can also add labels, each a “text” object with its own handle.
h4=xlabel(‘Time (sec)’);
and make it big and bold
set(h4,’FontSize’,15);
set(h4,’FontWeight’,’bold’);
Next, we’ll see one of the more powerful plotting capabilities in MATLAB. Specifically, placing several plots in a
single figure window using the “subplot” command. First we’ll make some data sets
clear all
t = 0:0.1:10;
y1=sin(2*pi*.5*t);
y2=cos(2*pi*0.5*t);
Now we’ll create a single figure with three plots in it -- sin, cos, and both.

MEEM4700 Laboratory Manual - Version 1.0 5


Functions - Lab 1

h1=figure;
h2=subplot(3,1,1);plot(t,y1);
h3=subplot(3,1,2);plot(t,y2);
h4=subplot(3,1,3);plot(t,y1,t,y2);
The syntax of “subplot” is rather strange. The first two arguments (3,1 in this example) specify the number of rows
and columns of plots within the figure window. So, 3,1 breaks the figure window into 3 rows, and 1 column. You can
also have more plots in a figure (e.g. subplot(3,3) creates 9 plots, etc.). The third argument indicates which of the
plots you want to be “active.” That is, which one do you want to work with. Knowing the hierarchy structure you can
easily get the axes of these handles for finer manipulation of the plot’s look.
There’s a variety of additional plot commands available. Some that we will use later in the course are “errorbar” and
“semilogx.” You may want to do a help on these and experiment with them.

Functions
As mentioned earlier, a .m file can be used to store a sequence of commands, or a user-defined function. A function is
a generalized input/output device. That is, you give it some input (i.e. an argument) and provides some output. In
MATLAB the inputs and outputs can be very general (scalars, matrices, etc.). MATLAB functions allow you much
capability to expand MATLAB’s usefulness. We will just touch on functions here, as you may find them beneficial
later in the course.
We’ll start by looking at the help file on functions
help function
The example shown is a little more complicated than it should be as introduction. That is, it has the “subfunction”
concept in it too. Let’s not consider the subfunction yet, and just focus on plain old functions. As an example, we’ll
create our own function that given an input matrix returns a vector containing the sums of each of the matrices rows.
So, given

in = 3 2 9 1.2
–1 0 4

as input, the output would be

out = 14 1.3
3

We’ll name the function “myfun.” It should be noted that “myfun” must be stored in a file named “myfun.m.” Using
an editor of you choosing, type the following commands and save them as “myfun.m.” At the MATLAB prompt test
it out using the example above, or any others you’d like. In addition, try the MATLAB help on “myfun” by typing
help myfun
Here’s the function.
function zout = myfun(zin)
% This function computes the sum of the elements of the rows of the input
matrix. The usage
% is
%
% y = myfun(x)

% extract the number of rows and columns of the input


[nrow,ncol]=size(zin)
% allocate a vector of the proper size to store the result
zout = zeros(nrow,1);
% loop through the nrow rows and sum all the elements, storing them in the
output vector
for i = 1:nrow
zout(i) = sum(zin(i,:));
end

MEEM4700 Laboratory Manual - Version 1.0 6


Simulink - Lab 1

Note: It’s wise to comment your functions using the “%” symbol.
Finally, clear you workspace, then try some example using “myfun.” Afterwards, take a look at the variables in the
workspace. Notice that the variables internal to the function (e.g. “i”, “zout”, etc.) are not in the workspace. They
were created and later destroyed all during the execution of the function.

Simulink
There is no way that we can do Simulink justice in the time we have in this lab. The basics will be presented, and you
will be expected to explore on your own.
Typing
simulink
at the MATLAB prompt starts Simulink and brings up the “Simulink Library Browser.” Each of the items listed are
the top level of a hierarchy of palettes of elements that you can add to a Simulink model of your own creation. At this
time, expand the “Simulink” palette, as this contains the majority of the elements you’ll use in this course. The “mod-
els” you create are really simulations, usually of dynamic systems. Simulink has built into it a variety of integration
algorithms for integrating the dynamic equations.
You can place the dynamic equations of your system into Simulink in four ways -- (1) using integrators (bad idea), (2)
using transfer functions (you’ll see this later), (3) using state-space equations (you’ll see this real soon), (4) using S-
Functions (the most versatile approach, but beyond this course). Once you have the dynamics in place you can apply
inputs from the “Sources” palette, and look at the results in the “Sinks” palette.
A brief introduction to digital simulation follows along with a simple of example of entering a dynamic system into a
Simulink model.
Introduction to Digital Simulation
When designing a controller for a dynamic system it is often useful to have a digital (computer) simulation of the sys-
tem. This allows the designer to (1) obtain a better understanding of the plant by running many different input and
configuration scenarios, (2) develop a comprehensive set of experiments for testing the controller in hardware, (3)
“test” the control system (including sensors and actuators) prior to implementing it in hardware. In most situations
this is much more cost effective than examining the performance using only hardware.
One of the first steps in controller design is to develop a mathematical model of your system, usually given by differ-
ential equations. A simple example is shown in EQ 1.4.
ẋ ( t ) + 2x ( t ) = u ( t ) x(0) = 5 1.4
If the input can be described by a mathematical function
u ( t ) = 3 sin ( t ) 1.5
then we can get a closed form solution to this system by solving the differential equation. However, if u ( t ) is not a
mathematical function (perhaps it is an operator’s input), or the plant model is nonlinear, then a digital simulation is a
convenient solution method.
To simulate this system means that we will use a digital computer, and numerical integration algorithms, to generate
the output ( x ( t ) ) for some prescribed input ( u ( t ) ) at specified points in time.
As an example let’s consider the plant of EQ 1.4, where the input is zero for all time. The closed form solution is
x ( t ) = 5e –2t 1.6
So, we can insert any value for time ( t ) and compute the corresponding output x ( t ) . This system can also be simu-
lated, however, the output will now only be an approximation to the closed form solution. The accuracy of the output
depends on several factors some of which are beyond the scope of this course. However, one of the most important
factors effecting accuracy is the sample period between computing successive outputs. We will denote this as h .
The first step in constructing a simulation is to convert the differential equation to a difference equation using a care-
fully chosen integration method. Using Euler integration, our differential equation becomes

MEEM4700 Laboratory Manual - Version 1.0 7


Simulink - Lab 1

x n + 1 = ( 1 – 2h )x n + x 0 h 1.7

When using SIMULINK to simulate a dynamic system, this step is done for you automatically, and behind the scenes.
The subscript notation of EQ 1.7 indicates the sample number of the output. That is, x o is the initial value of x ( t ) , x 1
is really an approximation of x ( h ) , x 2 is an approximation of x ( 2h ) , and so on. So, it should be clear from EQ 1.7
that if we know x 0 , and we choose a sample period h , then we can compute an approximation for x for all time,
specifically
x ( h ) ≈ x 1 = ( 1 – 2h )x 0 + hx 0

x ( 2h ) ≈ x 2 = ( 1 – 2h )x 1 + hx 0
1.8
The accuracy of the approximation is proportional to the sample period. So, you want to select a small enough h to
get acceptable accuracy, but not too small that it makes the simulation run excessively slow. Figure 1 shows a plot of
this system simulated using SIMULINK for h = 0.1, 0.2, 0.4 seconds compared to the closed form solution. Data
points are shown individually to illustrate that the output is only available at the sample period increments.
In the space below, compute the exact solution, and the approximate solution for t = 0.4 with h = 0.1 , h = 0.2 ,
h = 0.3 , and h = 0.4 . Compare your results to the table below.

Exact
h = 0.1
4
h = 0.2
h = 0.4

3
x

0
0 1 2 3 4
Time (sec)
Figure 1.1. Response of “x” as a function of integration sample period.

Table 1.1 shows the actual data used for the plots. You can obtain exactly the same data by computing the first few
points by hand, or by using SIMULINK.

Table 1.1: Sample Period Effect on Output

t x ( t ) , exact x ( t ) ( h =.1) x ( t ) ( h =.2) x ( t ) ( h =.4)

0 5.0000000e+000 5.0000000e+000 5.0000000e+000 5.0000000e+000

.1 4.0936538e+000 4.0000000e+000

.2 3.3516002e+000 3.2000000e+000 3.0000000e+000

.3 2.7440582e+000 2.5600000e+000

.4 2.2466448e+000 2.0480000e+000 1.8000000e+000 1.0000000e+000

.5 1.8393972e+000 1.6384000e+000

.6 1.5059711e+000 1.3107200e+000 1.0800000e+000

MEEM4700 Laboratory Manual - Version 1.0 8


Simulink - Lab 1

Table 1.1: Sample Period Effect on Output

t x ( t ) , exact x ( t ) ( h =.1) x ( t ) ( h =.2) x ( t ) ( h =.4)

.7 1.2329848e+000 1.0485760e+000

.8 1.0094826e+000 8.3886080e-001 6.4800000e-001 2.0000000e-001

.9 8.2649444e-001 6.7108864e-001

1.0 6.7667642e-001 5.3687091e-001 3.8880000e-001

1.1 5.5401579e-001 4.2949673e-001

1.2 4.5358977e-001 3.4359738e-001 2.3328000e-001 4.0000000e-002

1.3 3.7136789e-001 2.7487791e-001

1.4 3.0405031e-001 2.1990233e-001 1.3996800e-001

1.5 2.4893534e-001 1.7592186e-001

1.6 2.0381102e-001 1.4073749e-001 8.3980800e-002 8.0000000e-003

1.7 1.6686635e-001 1.1258999e-001

1.8 1.3661861e-001 9.0071993e-002 5.0388480e-002

1.9 1.1185386e-001 7.2057594e-002

2.0 9.1578194e-002 5.7646075e-002 3.0233088e-002 1.6000000e-003

2.1 7.4977884e-002 4.6116860e-002

2.2 6.1386700e-002 3.6893488e-002 1.8139853e-002

2.3 5.0259179e-002 2.9514791e-002

2.4 4.1148735e-002 2.3611832e-002 1.0883912e-002 3.2000000e-004

2.5 3.3689735e-002 1.8889466e-002

2.6 2.7582822e-002 1.5111573e-002 6.5303470e-003

2.7 2.2582905e-002 1.2089258e-002

2.8 1.8489319e-002 9.6714066e-003 3.9182082e-003 6.4000000e-005

2.9 1.5137774e-002 7.7371252e-003

3.0 1.2393761e-002 6.1897002e-003 2.3509249e-003

3.1 1.0147153e-002 4.9517602e-003

3.2 8.3077864e-003 3.9614081e-003 1.4105550e-003 1.2800000e-005

3.3 6.8018402e-003 3.1691265e-003

3.4 5.5688757e-003 2.5353012e-003 8.4633297e-004

3.5 4.5594098e-003 2.0282410e-003

3.6 3.7329290e-003 1.6225928e-003 5.0779978e-004 2.5600000e-006

3.7 3.0562638e-003 1.2980742e-003

MEEM4700 Laboratory Manual - Version 1.0 9


Simulink - Lab 1

Table 1.1: Sample Period Effect on Output

t x ( t ) , exact x ( t ) ( h =.1) x ( t ) ( h =.2) x ( t ) ( h =.4)

3.8 2.5022572e-003 1.0384594e-003 3.0467987e-004

3.9 2.0486749e-003 8.3076750e-004

4.0 1.6773131e-003 6.6461400e-004 1.8280792e-004 5.1200000e-007

It turns out that the controllers you design will often be, in themselves, dynamic systems. That is they will be
described by differential equations, representable in state-space form. When you implement the controller in hard-
ware, you are really generating a simulation of the system that runs in real-time. How well your controller works in
practice will be governed by well you “simulate” it in hardware.
Using SIMULINK for Dynamic System Simulation
In this section we will use the plant of EQ 1.4 as an example of how to use SIMULINK to simulate a dynamic system.
Duplicate this example using SIMULINK as you follow along.
MATLAB’s SIMULINK toolbox allows you to easily simulate both linear and nonlinear dynamic systems. A block
diagram of our example system is shown below

Figure 1.2. Sample SIMULINK block diagram

The blocks (Constant, State-Space, To Workspace) can be found in the SIMULINK palette.
The time domain equations should be converted to state space form
ẋ = Ax + Bu
y = C x + Du
1.1
The coefficients of the A, B, C and D matrices and the state’s initial conditions can then be entered into the “Block
Parameters: State Space” block in SIMULINK as shown in Figure 1.3 (they can also be set as variables in the work-
space and the variable names used in the State-Space block).

MEEM4700 Laboratory Manual - Version 1.0 10


Simulink - Lab 1

Figure 1.3. Simulink State-Space Block Parameters.

To set the sample period and the integration method used, use the Parameters pull-down menu and set it up as shown
in Figure 1.4. Be sure to note the “Fixed step size” which we have been calling the sample period and the “Solver
Options.”

Figure 1.4. Simulink Simulation Parameters.

Running this simulation will produce equally spaced (0.1 seconds) approximations to the output x .
Your lab assignments will often require you to first simulate a dynamic system, design a controller, test the controller
in simulation, then implement the controller in hardware. Fortunately, the SIMULINK simulation used during the
analysis phase is also used to implement the controller. Specifically, the plant is replaced by I/O interface blocks.
At this point you should be very curious about how to select the sample time period h . This will be discussed a little
later after we investigate transfer functions.
The output of the simulation is placed in the MATLAB workspace since the “To Workspace” block was placed at the
end of the simulation output. You can now manipulate the output of the simulation (e.g. plot it, save it, etc.) just like

MEEM4700 Laboratory Manual - Version 1.0 11


Simulink - Lab 1

an other data set in the workspace. Double clicking on the “To Workspace” box lets you set the name of the variable
of the workspace data. Set the name to “mydata” (also make sure that you specify that the output is a “matrix” and not
a “structure”) and run the simulation. Plot the data and compare to the plot above. Also look at the first 10 data points
and compare them to the table.

MEEM4700 Laboratory Manual - Version 1.0 12


LAB 2 Introduction to Diagnostic
Instrumentation

Goals
The two primary goals of this lab are
1. Practice using the oscilloscope, multimeter, and function generator
2. Investigate how signals are passed through the real-time control hardware/software system using Digital-to-Ana-
log converters and Analog-to-Digital converters.

Equipment List

Table 2.1: Equipment

Item Qty Description

1 1 Agilent 34401A Multimeter and Users Guide

2 1 Agilent 33120A Function Generator and Users


Guide

3 1 Agilent 54621A Oscilloscope and Users Guide

4 1 4ft black bananna jack to bananna jack cable

5 1 4ft red bananna jack to bananna jack cable

6 1 Quanser UPM-2405 power supply

7 1 Dell PC with MultiQ board and connector panel

8 1 T connector (BNC)

9 3 4 ft BNC cables

10 2 BNC to phono adapters

11 1 floppy disk

12 1 lab2.wcp

MEEM4700 Laboratory Manual - Version 1.0 13


Introduction - Lab 2

Introduction
The control software and hardware used in the remaining labs allow you to read a variety of sensors and display them
graphically on the computer. During normal control design experiments, this will be sufficient for you to complete
your designs. However, there will be times when you will want to use external measurement devices to debug prob-
lems. Three instruments (oscilloscope, multimeter, and function generator) are supplied for that purpose.
During a typical debugging exercise you may attach the oscilloscope to a signal source knowing what you expect to
see. When you see something different it could mean one of two things: (1) something is wired incorrectly in the sys-
tem, (2) the measurement equipment is causing an unexpected change in the signal.
In this lab you will be introduced to the debugging instruments you have access to. In addition, you will explore the
effects of the D/A and A/D that are built into the MultiQ I/O board, through which all your control signals pass.
Analog-to-Digital Converters
Before the advent of inexpensive microprocessors, control systems were implemented using analog circuits consist-
ing of op-amps, capacitors and inductors. Today, microprocessor based control implementation is the norm. A typical
system will have one or more sensors generating analog signals that must be represented as numbers inside the micro-
processor. The microprocessor combines these quantities in a prescribed way to generate one or more output signals
to send to the system’s actuators.
For example, let’s say you have a speed control system which tries to maintain the speed of a motor at the user speci-
fied value. The sensor may be a tachometer connected to the motor’s output shaft generating a voltage proportional to
the shaft rate (1 volt per 1000 rpm is typical). Setting a variable inside the microprocessor to the tachometer voltage
value requires the voltage to be converted to a digital representation of a number -- that is, the signal must be dis-
cretized. Now that the approximate value of shaft speed is safely in the microprocessor, the controller can be imple-
mented to produce the desired motor voltage value. One approach would be to simply multiply the error between the
desired and actual motor speed by a constant. The result would be the new motor voltage command. Of course, it is
still just a number inside the microprocessor. This “number” must be converted to an actual voltage, again, by means
of discretization process. In summary, discretization results in both getting analog voltages into the computer, and in
converting the microprocessor generated number back into an analog voltage.
A specialized integrated circuit (or “chip”) called an Analog-to-Digital (A/D) converter is used to convert analog
input signals into binary numbers. One of the key specifications of an A/D is its resolution in bits (8,12 and 16 bit A/
D’s are quite common). The discretization level is the A/D’s input range divided by 2^resolution. The input range is
usually one of the following (1) 0 to 5 volts, (2) -5 to 5 volts, (3) -10 to 10 volts. For example, a 12 bit A/D with an
input range of -10 to 10 volts has a discretization level of 20/4096. If the true input voltage was 1.5 volts, the com-
puter would get 1.49902343. An eight bit A/D with the same 1.5 volt input would register 1.4843750. These errors
are important considerations in sizing components for the control system, since higher resolution components are
more expensive.
Digital-to-Analog Conversion
As mentioned in the previous section, discretization also occurs when the microprocessor generate “command” is
converted into an analog output suitable for use by the system’s actuators (e.g. DC motors). Again, a specialized inte-
grated circuit called a Digital-to-Analog (D/A) converter is used. The key specifications of a D/A are also its resolu-
tion in bits (8, 12, and 16 are common) and its output range. The discretization level is the D/A’s output range divided
by 2^resolution. For example if the computer generates a motor command of 2.4 volts and sends this value to a 16 bit
D/A with output range of -5 to 5 volts, the actual voltage sent to the motor would be 2.39990234
Control System Update Rate
Another large factor in a microprocessor based control system is the rate at which its outputs are updated. During one
controller cycle three things must happen before the next cycle can begin (1) sensors are read (A/D inputs), (2) the
microprocessor computes the actuator commands, (3) the actuator commands are output (D/A outputs). Between
cycles, the command outputs are held constant. So, if the controller is updated every 0.5 seconds, the output of the
controller would look like a staircase, changing every 0.5 seconds. As you might expect, the faster the dynamics are
of the system you are trying to control, the faster you must update the controller. Again, these are important consider-
ations in specifying a control system since high speed systems can become very expensive.

MEEM4700 Laboratory Manual - Version 1.0 14


Introduction - Lab 2

MultiQ Connector Panel


The MultiQ connector panel (Figure 2.1) is the interface between the MultiQ board inside the computer, and all of the
I/O needed for implementing a control system. The connector I/O has the following I/O capability.
• 8 Output Channels (D/A, outputs)
• 8 Input Channels (A/D, inputs)
• 8 Encoder Channels (inputs) Note: encoders will be the focus of Lab #2.

Figure 2.1. MultiQ connector panel.

MEEM4700 Laboratory Manual - Version 1.0 15


Pre-Lab - Lab 2

Pre-Lab
1. (15 pts) A 12 bit A/D with input range of -10 to 10 volts has an input applied to it of -6.3 volts. What is the value
of the discretized signal (use 10 significant digits)? _________________________________________
2. (15 pts) The same A/D as in (1) has an input applied to it of 13.1 volts. what is the value of the discretized signal
(use 2 significant digits)? _____________________________________________________________
3. (20 pts) A microprocessor based control system outputs a sine wave (amplitude of 2.0 volts and frequency of 10
Hz) with an update rate of 0.01 seconds (100 Hz). In the space below sketch both the idealized sine output, and
the output of the controller over two cycles labeling the axes._________________________________

In-Lab Tasks
1. Measure the voltage of the UPM between +Vs and GND, and then between -Vs and GND using banana jack
cables, using 4, 5 and 6 digits and enter the results in the table below.

Table 2.1: Multimeter Readings Using Different Digit Settings

Digits +Vs and GND -Vs and GND

5
6

2. In this exercise you will explore both the oscilloscope and function generator, in addition to A/D and D/A con-
version and update rate. Specifically, you will use the function generator to create a 10 Hz sine wave as input to
an A/D. After passing through the computer the signal is output to a D/A, and read by the oscilloscope. Both the
true input (from the function generator) and the discretized, sampled output (from the D/A) will be displayed on
the scope in real-time. The scope will then be used to save the data for plotting and further analysis in MATLAB.
a. Set the function generator to the high impedance mode (see page 40 of the 33120A User’s Guide)
b. Configure the function generator so that it is generating a sine wave of 10 Hz with 2 volts peak-to-peak.
c. Attach a T connector to the 33120A function generator output BNC plug with a 3 foot BNC cable going to
Channel 0 of the Analog Inputs section of the MultiQ connector panel (you will also need a BNC to phono
adapter).
d. From the Windows 98 main screen, start the W95Server application located under Programs - WinCon3.
e. From the WinCon Server application that just appeared, open the file called Lab2.wcp. The plot window that
appeared will display the signal as read by the A/D, resident in the computer (prior to being sent to the D/A
output). Start the application by clicking on the green START button and verify the signal displayed on the PC
is correct.

MEEM4700 Laboratory Manual - Version 1.0 16


In-Lab Tasks - Lab 2

f. Turn on the oscilloscope and reset it by the sequence


• Save/Recall
• Default Set-Up (softkey)
• Autoscale
g. Attach a 3ft BNC cable (with BNC to phono adapter) from Channel 0 of the Analog Outputs section of the
MultiQ connector panel to channel 1 of the oscilloscope and press Autoscale again.
h. Set the horizontal to 10 mSec/div and the vertical to 500 mV/div. Set the center adjust to 0 mV.
i. Attach a 3ft BNC cable from the other end of the T connector to Channel 2 of the oscilloscope, and activate
channel 2 on the scope. Set the vertical of channel 2 to 500 mV/div and set the center adjust to 0 mV.
j. Press ‘Single’ on the oscilloscope to capture a single trace of data.
k. Have your lab instructor inspect your output ____________________________________________
l. Insert a disk in the oscilloscopes disk drive and press the ‘Quick Print’ button. Stop the WinCon application.
m. Move the disk to the PC and save the print_00.csv file to your hard drive calling it print_00.dat. In addition,
modify the data by replacing the commas with spaces. One way to do this is to use the DOS ‘edit’ editor. Also
delete the first two rows of the print_00.dat file (Note: the first column is time, the second column is the output
from the MultiQ board, and the third column is the output of the function generator).
n. Start MATLAB, change directory to your working directory, and load the data by typing
load print_00.dat
o. Plot the data in MATLAB using the command
plot(print_00(:,1),print_00(:,2:3))
p. Have your lab instructor inspect your plot ______________________________________________
q. Based on your data, what do you believe the update rate of the D/A is (seconds)? _______________

MEEM4700 Laboratory Manual - Version 1.0 17


LAB 3 Hardware/Software Introduction

Goals
The three primary goals of this lab are
1. Develop proficiency in basic I/O connections
• Cart
• Universal Power Module (UPM)
• MultiQ Connector Panel
2. Write a Wincon application to read the encoder
3. Develop and implement encoder calibration strategy

Equipment List

Table 3.1: Equipment

Item Qty Description

1 1 Quanser UPM-2405 power supply

2 1 Motor/cart system (no heavy base)

3 1 Metal ruler

4 1 Dell PC with MultiQ and connector panel

5 1 Encoder cable

MEEM4700 Laboratory Manual - Version 1.0 18


Introduction - Lab 3

Introduction
In the sections below the primary components are described. After reading them, you will then be asked to attach the
motor cart system to the computer and power supply. This will enable you to take readings from the motor’s position
encoder to compute the cart’s location on the track.
Electrical Connections
The cart has three electrical connectors: (1) motor power (input), (2) beam balance encoder (output), and (3) cart
position encoder (output) shown in Figure 3.1.
Motor power (input)
x
Beam balance encoder (output)
motor gear

Cart position
encoder gear
Cart position encoder
(output)

Figure 3.1. Motor/cart system

Sensors and Actuators


The cart has two sensors (encoders) and one actuator (DC motor).
• Cart position encoder: The cart position encoder gear rides on the toothed track, and measures the cart’s position
along the track ( x ). When connected through the MultiQ connector panel, the encoder driver software outputs
“counts” proportional to the rotation of the gear. Each cart position encoder gear revolution generates 4096
counts. So, if the gear rotates three times, the output of the Wincon driver will be 3*4096=12288 counts. Cart
position along the track can be computed if the cart position encoder gear radius is known.
• Beam balance encoder: The encoder on top of the cart measures the angle of the shaft used to connect a balanc-
ing rod (this will be used in some later experiments).
• DC Motor: The cart’s actuator is an armature controlled DC motor. It takes a voltage input and generates an
angular rate of the motor gear. This allows the motor’s output torque to be converted into a force to drive the lin-
ear motion of the cart. The motor has an internal gear reduction set which has the effect of increasing the motor
torque constant (and the back emf constant). For all of your experiments, the command voltage to the DC motor
will be generated by the computer. The digital output signal is fed through a digital to analog converter (D/A) on
the MultiQ connector panel. The analog signal is then passed through the UPM such that high currents are avail-
able to the motor.
MultiQ Connector Panel
See the description in Lab 2.
Universal Power Module (UPM)
A brief overview of the UPM (shown in Figure 3.2) is given here only as it relates to the labs for this course. It has
other capabilities that will not be used immediately.

MEEM4700 Laboratory Manual - Version 1.0 19


Introduction - Lab 3

The UPM amplifies the control signals coming out of the MultiQ connector panel, permitting sufficient current to drive
the D.C. motor. Therefore, outputs from the MultiQ connector panel always are connected to the UPM. The outputs
from the UPM then are connected to the cart’s motor.

control signals
from the MultiQ output from here
connector panel is used to power
go here the motor

Figure 3.2. Universal Power Module

MEEM4700 Laboratory Manual - Version 1.0 20


Pre-Lab - Lab 3

Pre-Lab
You must derive an equation for computing the scale factor (S f ) that relates encoder counts, ( E c ) to cart position
along the track ( x ), assuming you know the radius of the encoder gear ( r e = 1.50cm ± 0.05cm ), and the resolu-
tion of the encoder ( E r = 4096counts ⁄ rev ).

1. (15 pts) Derive an expression for S f in terms of the quantities described above where
x = (S f )(Ec) 3.1

Do not “plug-in” any numbers.

Sf =

2. (10 pts) Using your expression in (1) compute the numerical value of S f using 7 significant digits

Sf =

3. (10 pts) If the encoder gear radius, r e , is off by 10%, what is the percent error in S f ? ______________
4. (15 pts) Explore MATLAB’s polyfit and polyval command for curve fitting experimental data. Write the MAT-
LAB command for fitting a line to two vectors of data. The vector of independent variable values (x) is called
“counts” and the vector of dependent variable values (y) is called “position”. ____________________

In-Lab Tasks
Hardware Connections
1. Connect the cart encoder to the MultiQ connector panel as shown in Figure 3.3.

“New Model”
icon MultiQ
Connector
Panel

Figure 3.3. Hardware connections.

MEEM4700 Laboratory Manual - Version 1.0 21


In-Lab Tasks - Lab 3

Create a WinCon Application to Read the Encoder


1. Start MATLAB and Simulink
a. Make sure that the cart, UPM, and MultiQ connector panel are connected as described above.
b. Start MATLAB

“New Model”
icon

Figure 3.4. Simulink library browser.

c. In the MATLAB window, change the current directory to


cd c:\usr\stationx\L0x\lab2
d. Start Simulink from the MATLAB window creating the Simulink Library Browser in Figure 3.4.
2. Create a WinCon application for reading the encoder
a. Left-click on “New Model” icon in the Simulink Library Browser
b. Expand the Quanser Library in the Simulink Library Browser
c. Expand Quanser Consulting MQ3 Series
d. Left-Click/Hold Encoder Input and drag to the new model

Figure 3.5. Encoder block parameters.


e. Double left-click the Encoder Input block that is now in your model, make sure that it looks like Figure 3.5.
This block is the software driver interface that allows the encoder output to be brought into the PC in real-time.
f. Expand Simulink in the Simulink Library Browser
g. Expand Sinks
h. Add a scope to your model and attach it to the output of the encoder block. Change its name from “Scope” to
“counts.” Having a scope in your model allows you to see the data streaming in from the encoder in real-time.
i. Save your model as “lab3.mdl”, it should look like Figure 3.6.

MEEM4700 Laboratory Manual - Version 1.0 22


In-Lab Tasks - Lab 3

Figure 3.6. Simulink block diagram.

3. Set the parameters necessary for real-time data acquisition and control
a. In the MATLAB window, type the command
wc_setoptions(‘lab3’)
b. In your “lab3” simulink model window, use the pull down menus to access Simulation-Parameters. Modify its
contents so it looks like Figure 3.7.

Figure 3.7. Simulink parameters for simulation


update rate.

c. Use the tab in the Simulation Parameters pull down menu to access the Real-Time Workshop menu, and make
sure it looks like Figure 3.8.

MEEM4700 Laboratory Manual - Version 1.0 23


In-Lab Tasks - Lab 3

Figure 3.8. Simulink parameters for code gener-


ation.

4. Build the real-time WinCon application


a. In your lab3 Simulink model, use the WinCon pull-down menu and select Build.
b. Several things should happen on the screen. In the MATLAB window, a lot of messages will scroll by. When
the process is complete you will have the following message in your MATLAB window:
### Successful completion of Real-Time Workshop build procedure for model: lab3
c. A new window (WinCon Server) will also be available on your screen, as shown in Figure 3.9.

Figure 3.9. WinCon tool for starting and stopping


the application.

d.
The build process caused the lab3 Simulink model to be written into C-code, compiled, linked with the librar-
ies needed for real-time execution, and “attached” to the WinCon Server.
e. Save this as “lab3.wcp” using the File-Save As pull down menu. Make sure you save it in your lab directory.
5. Create a GUI to examine the encoder output in real-time, and to save the data.

Figure 3.10.WinCon dialog box for assign-


ing a Simulink model variable to a scope for
viewing the output in real-time.

MEEM4700 Laboratory Manual - Version 1.0 24


In-Lab Tasks - Lab 3

a. In the WinCon Server window, use the pull down menus, Plot => New => Scope, to bring up a scope.
b. This automatically brings up the “Select Variables to Display” window shown in Figure 3.10. Check the
“counts”, and close the window.
c. In the WinCon Server window, use the pull down menus to bring up a Digital Meter (Figure Figure 3.11) using
the same method you used to bring up the scope. Note, in the “Select Variables to Display” window, you will
again check “counts”, since that is what the name of the scope is in the lab3 Simulink model.

Figure 3.11.Digital meter display.

6. Starting and Stopping the application


a.
Put the cart approximately in the center of the track.
b.
Click the green START button in the WinCon Server window. Note the following:
• When you click the green start button it changes to a red stop button
• The output of the encoder is 0
• The scope is (by default) in autoscale mode
c. Move the cart 3 cm to the right and note the output of the encoder ___________________________
d. Move the cart 3 cm to the left and note the output of the encoder ____________________________
e. Click the red STOP sign in the WinCon Server to shut off the application
f. Turn the application back on and note the encoder output __________________________________
7. Saving data
a. With the application off, change your plot so that it has
• fixed scale with limits of -10000 and 10000
• Update - Buffer to 5 seconds (this is the duration of the data capture)
• Enable Update - Freeze Polt (this will capture only the 1st 5 seconds of data, instead of continously captur-
ing data every 5 seconds).
b. Start the application, then move the cart back and forth so you have some “action” on the plot. Using the pull
down menus of the plot window, select Update - Freeze Plot. Again, using the pull down menus of the plot
window, select File - Save - Save to Workspace.
c. Now bring up the MATLAB window and type
whos
You should see two new variables in the workspace called “plot_time” and “lab3_counts”. This is the data that
you captured using the freeze plot command. In MATLAB, type
plot(plot_time,lab3_counts);grid;
to bring up another plot of the same data.
d. To save this data to disk we’ll first create a temporary array containing both the time vector (plot_time) and the
data (lab3_counts). Use the command
temp=[plot_time labv1_Scope];
e. To see what you have, take a look at the first ten elements of this matrix by typing
temp(1:10,:)
f. Save this matrix of ascii text values to your local hard drive in a file named “run1.dat” by typing
save -ascii run1.dat temp
In this format, you can import the data into other data analysis software tools (e.g. excel, applix, etc.), or bring
it back into MATLAB at a later date. To examine this last capability, first clear the MATLAB workspace by
typing
clear all
To check if everything is “cleared”, use the command
whos

MEEM4700 Laboratory Manual - Version 1.0 25


In-Lab Tasks - Lab 3

You should have no variables in the workspace. Now load back in your data by typing
load run1.dat
Now execute
whos
You should have the single matrix named “run1”. To plot the data type
plot(run1(:,1),run1(:,2));grid;
g. (15 pts) Ask the lab instructor to check your work to this point. You will also be asked to demonstrate some of
the activities above (e.g. acquiring, plotting, saving, loading data, etc.) _______________________
Encoder Calibration
1. Devise, implement, and verify an encoder calibration strategy. This will give you a single gain that when multi-
plied by the “raw” output of the encoder gives you the cart position in centimeters.
a. (10 pts) Move the cart to the left side of the track (about two centimeters from the left track gap). If your Win-
Con application for reading the encoder counts was on, then stop it and restart it. If it was off when you moved
the cart, then start it. Using the application developed above record 13 pairs of cart position (measured by
ruler), encoder measurements.

Table 3.1: Encoder Calibration Data

Encoder
Cart Position
Reading
(cm)
(counts)

12

15

18

21

24

27

30

33

36

b. The encoder measurements in the second column are accurate to within 0.5 counts, that is, ± 0.5 counts. Based
on your ruler gradations, and your capabilities, how accurate are the measurements in the first column above
(plus/minus)______________________________________________________________________

MEEM4700 Laboratory Manual - Version 1.0 26


In-Lab Tasks - Lab 3

c. (9 pts) List three possible error sources that could effect either the accuracy, or the repeatability of the data
you’ve acquired (and approximate their magnitudes)
i ____________________________________________________________________________
ii ____________________________________________________________________________
iii ____________________________________________________________________________
d. Enter your data from Table 1 into MATLAB. Create the cart position vector using the command
position = 0:3:36;
position = position’;
Enter the encoder data as
counts = [12;3422;6778;...];
e. Plot position versus counts using error bars by typing
errorbar(counts,position,pos_err);grid;
where
pos_err = ones(size(position))*xxx
where xxx is your accuracy estimate from part (1b) above.
f. Use MATLAB’s polyfit command to generate the polynomial coefficients of the best-fit line to your data. Enter
the polynomial coefficients that correspond to the scale factor ( S f ) and the bias below where
position = S f ⋅ counts + Bias
Sf =
Bias = 3.1
g. (5 pts) In Table 3.2 enter the values of the scale factor and bias you found in step (f), and in the pre-lab. In addi-
tion, compute the percent error. Are the errors you encountered justified based on your answers in (c) and in
the pre-lab? Explain. _______________________________________________________________

Table 3.2: Scale factor error analysis results.

Pre-Lab In-Lab Absolute Percent


(Analytical) (Empirical) Error Error

Scale Factor

Bias

h. Use MATLAB’s polyval command to create a new vector of positions using your measured counts, and the
line fit coefficients, that is,
position_fit = polyval(polyfit(counts,position,1),counts);
i. Use MATLAB to generate analytical positions using your scale factor computed in the pre-lab
analytical_fit = Sf*counts;
where S f is the scale factor you computed in the pre-lab.

MEEM4700 Laboratory Manual - Version 1.0 27


In-Lab Tasks - Lab 3

j. (6 pt) Use MATLAB to create a plot that overlays all three sets of data (raw data with error bars, curve fit based
on the raw data, analytical), save it as a postscript file, and print it out.
errorbar(counts,position,pos_err,’r’);
ylabel(‘Position’);
xlabel(‘Counts’);
title(‘Calibration Results’);
hold on
plot(counts,position_fit,’b’);
plot(counts,analytical_fit,’g’);
print -depsc -tiff -r600 plot1.eps
k. Which scale factor do you recommend using, and why? ___________________________________
Saving the Real-Time Application
The real-time application, including all plot windows, etc. can be saved for re-execution as a .wcp file. You created a
.wcp file for your application earlier. Here you will see how you can re-execute the application witout starting MAT-
LAB.
1. Save your application using the WinCon server File-Save pull down menu.
2. Exit the WinCon server, and exit MATLAB
3. From the Windows 98 Start - Programs - WinCon3 menu execute W95Server. The WinCon server screen will
appear.
4. Open the .wcp file you just created (Lab3.wcp). The Start button will now become activated. You can start and
stop the application, and record data just as you did before.

MEEM4700 Laboratory Manual - Version 1.0 28


LAB 4 Motor Cart Control -- Freestyle

Goals
Explore closed-loop control phenomenon by designing a position controller for the motor/cart system such that the
cart can be accurately positioned to any point on the track, specifically
• The cart should be fast (go from the 0 position to 10 cm in under 0.5 seconds)
• The cart should be accurate (position error less than 2 mm, and overshoot less than 4 mm)

Equipment List

Item Qty
DRAFT Table 4.1: Equipment

Description

1 1 Quanser UPM-2405 power supply

2 1 Motor/cart system (no heavy base)

3 1 Metal ruler

4 1 Dell PC with MultiQ and connector panel

5 1 Encoder cable

Introduction
During the rest of this course you will learn systematic methods for designing closed-loop control systems. Hope-
fully, this lab, where you try to design a controller in an ad-hoc manner, will provide motivation for that process. As
you test your control designs strange and disturbing things may happen. Make sure you document all your
approaches, and the results as described below.

Pre-Lab
(50 pts) Develop two different control strategies to accomplish the goal above. Describe your approaches using both a
block diagram and a written description. Develop your ideas on scratch paper first, then document them neatly in the

MEEM4700 Laboratory Manual - Version 1.0 29


Pre-Lab - Lab 4

space provided. Your description must contain elements such as (1) the control strategy, (2) how sensors will be used
for cart position feedback, and (3) how the motor command will be generated. The primary element of the system is
the motor/cart “plant” shown in Figure 1, and should form the heart of block diagram descriptions

motor cart
input Motor/Cart position
(volts) Plant (cm)

Figure 4.1. Motor/Cart plant

MEEM4700 Laboratory Manual - Version 1.0 30


Pre-Lab - Lab 4

Control Strategy #1
Block Diagram

Written Description

MEEM4700 Laboratory Manual - Version 1.0 31


Pre-Lab - Lab 4

Control Strategy #2
Block Diagram

Written Description

MEEM4700 Laboratory Manual - Version 1.0 32


In-Lab Tasks - Lab 4

In-Lab Tasks
1. Have your lab instructor check your two strategies and help you to choose the most promising approach for
implementation. Circle your choice below.

1 2
2. Implement your control strategy using the necessary Simulink blocks. With the UPM amplifier powered off,
build your application as you did in Lab #2. If there are errors, then go back to your Simulink block diagram and
correct them. After getting a successful “build”, develop a Wincon application with the following features
• A horizontal sliding control allowing the user to specify the commanded position of the cart in centimeters
• A plot window displaying the cart’s voltage input
• A plot window displaying the cart’s position in centimeters
Save your Wincon application as Lab3.wcp.
3. Have your lab instructor inspect your control strategy implementation, and your Wincon application. With your
lab instructor watching, power on the UPM and run the application by commanding the cart to go from 0 to 10
cm. If it works, then proceed to answering the questions below, if it does not work, then discuss with your
instructor possible modifications to your strategy. Make the necessary fixes, and rerun your application. You may
need to iterate several times before obtaining satisfactory positioning performance. When you are done iterating,
have your lab instructor inspect your final implementation and proceed to the questions below.
4. (16 pts) Using your Wincon application command the cart to go from 0 to 10 cm, acquire both the position and
voltage data and answer the following questions.
a. Does the voltage saturate, and if so, at what voltage?______________________________________
b. How long does it take the position response to go from 0 cm to 9.5 cm?_______________________
c. What is the maximum excursion of the position response above 10 cm?_______________________
d. After the cart stops, what is the error between what you commanded (10 cm) and the actual cart position (use
both the encoder measurement, and a visual inspection of the ruler)? _________________________
5. (16 pts) Using your Wincon application command the cart to go from 0 to 20 cm, acquire both the position and
voltage data and answer the following questions.
a. Does the voltage saturate, and if so, at what voltage?______________________________________
b. How long does it take the position response to go from 0 cm to 9.5 cm?_______________________
c. What is the maximum excursion of the position response above 10 cm?_______________________
d. After the cart stops, what is the error between what you commanded (10 cm) and the actual cart position (use
both the encoder measurement, and a visual inspection of the ruler)? _________________________
6. (8 pts) Is there a relationship between your answers in 4 (b)-(d) and 5 (b)-(d) (e.g. is one twice as much as
another, etc.) _______________________________________________________________________
7. (10 pts) With the controller on, and the cart in the zero position, displace the cart 5 cm positive, hold it a couple
of seconds, then let it go.
a. After the cart stops, what is the error between what you commanded (0 cm) and the actual cart position (use
both the encoder measurement, and a visual inspection of the ruler)? _________________________
b. When you displaced the cart and held it by hand, what common device did it feel like? __________
8. Saving the Wincon application (the .wcp file) is very useful if you want to run the application at a later date with-
out going through the build process again. To examine this capability, power OFF the UPM, and re-save your
Wincon application as Lab2.wcp, and exit Wincon. In addition, exit from Simulink. Using the Windows Start
menu (at the bottom left corner of the screen) start the WinCon server application. The start/stop bar should
appear. From it, open your .wcp application, power ON the UPM and start your application. Since you built your
application previously, you do not need MATLAB or Simulink.

MEEM4700 Laboratory Manual - Version 1.0 33