HW 2
HW 2
— Fall 2011 1
This assignment includes all problems in Wk.5.5.x in the online tutor. For any of the sections
of the assignment that require you to write code, please do your work in the file hw2Work.py.
You can discuss this problem, at a high level, with other students, but everything you turn in must
be your own work.
Introduction
In this problem, we use techniques and methods you practiced in Design
Labs 4 and 5 to construct and analyze a model of a system which we will
see again in Design Labs 7 through 9, which controls a motor to turn a
robot “head” (pictured at right) to face a light. The system consists of
three components:
• a light sensor, from which we can determine the position of the light
relative to the head
• a motor, which we can use to turn the head toward the light
• a control circuit, which controls the motor (and which you will build
in later labs)
solute angular position, which we’ll call θh . The goal is to make the head turn to face the light;
that is, we want a system that makes θh become equal to θl . The relation between θh and θl is
pictured below:
1 Preliminary Information
Note that in this course, we use capital letters to denote signals, and lowercase letters to denote
Constants may be either capital letters or lowercase letters, depending on the convention for
The motor in this system produces a torque that accelerates the motor. The angular acceleration
rad
αh (in sec 2 ) of the motor is:
αh [n] = km im [n]
where im is the current flowing through the motor (in Amps), and km is a constant specific to the
motor used.
All motors are generators. If you were to mechanically drive a DC motor (i.e., turn the shaft by
hand), you could measure a voltage drop across the motor’s contacts. In fact, even when we drive
the motor using a battery, this voltage drop (known as back-electromotive force, or back-EMF) is
still produced. This back-EMF vb , measured in Volts, is proportional to the angular velocity of the
motor:
vb [n] = kb ωh [n]
rad
where ωh is the angular velocity of the motor (in sec ), and kb is a constant specific to the motor
used.
Once we know the applied voltage, the back-EMF, and the resistance of the motor, we can find the
current through the motor using Ohm’s law. The current is equal to the total voltage drop across
the motor, divided by the resistance of the motor:
(vc [n] − vb [n])
im [n] =
rm
where vc is the voltage applied to drive the motor, and rm is the resistance of the motor (rm is
constant for a given motor, and is measured in ohms).
We model the light direction sensor as producing a voltage vs that is proportional to the angle
between the light’s angular position and that of the head. We call this difference the error e.
where ks is also a constant. Finally, we use a simple proportional controller (with gain kc ) to
generate the voltage vc , which drives the motor:
vc [n] = kc vs [n]
Notice that kc is the only gain we can control; all of the others are predetermined by the parts we
are using.
Step 1. Find the system function for this control/sensor system, and draw the associated block diagram.
Do these in whatever order you prefer, but make sure your system function matches your diagram.
Step 2. Using the primitives and combinators provided in the lib601.sf module, define a method
controllerAndSensorModel, which takes as input a gain kc , and outputs an instance of
sf.SystemFunction which represents the controller/sensor system with this gain. You may use
within your definition any of the variables defined in hw2Work.py.
Do NOT construct this instance diretcly using the numerator and denominator Polynomials.
Wk.5.5.1 Enter your system function and your code into this tutor problem, and up
load a PDF of your block diagrams. Detailed instructions for entering your
system function into the tutor are available on the tutor page for this prob
lem. For information regarding creating PDF files on various platforms,
consult Appendix 2 of this handout.
As in design lab 5, we separate the plant into two smaller systems: the motor, and an integrator.
2.2.1 Integrator
We start by making an integrator which takes as its input the motor’s angular velocity Ωh , and
outputs the motor’s angular position Θh . Recall that all of the signals are sampled every T seconds.
Step 3. Find the system function for the integrator, and draw the associated block diagram.
Step 4. Using the primitives and combinators provided in the lib601.sf module, define a method in
tegrator, which takes as input a timestep T (the length of time between samples) and returns an
instance of sf.SystemFunction which represents an integrator with the appropriate timestep.
1
The “plant” is the system we are trying to control. It is called the “plant” (as in factory, not as in leafy green thing)
because a common early application of control theory was controlling manufacturing plants.
6.01 HW2: Heads Up! — Fall 2011 4
Note the difference between an integrator and an accumulator; an integrator, for example, trans
forms velocities to positions, in a manner such that the position at a given time step is determined
by the previous position and the previous velocity, as was done in Design Lab 4
Step 5. Using the equations given on the previous page, find the system function for the motor, and draw
the associated block diagram. Label Ah on your diagram. 2
Step 6. Using the primitives and combinators provided in the lib601.sf module, as well as any relevant
methods you have already created, define a method motorModel, which takes the same input as
integrator, but returns an instance of sf.SystemFunction which represents the motor. You
can assume that kb , km , and ks are already defined for you.
Step 8. Using the pieces you’ve constructed above, as well as any relevant primitives and combinators
provided in the lib601.sf module, define a method plantModel, which takes the same input as
integrator and motorModel, and returns an instance of sf.SystemFunction which represents
the entire plant.
Wk.5.5.2 Enter your system functions for both the motor model and the combined
plant model, as well as your code for this section, into this tutor problem,
and upload a PDF of your block diagram for the combined plant. Be sure to
label which part of your block diagram represents the motor, and which
represents the integrator.
Step 9. Find the system function for this composite system, and draw the associated block diagram. Label
the following signals on your diagram: Θl , Θh , E, Vs , Im , Ωh , Ah , Vc , Vb .
Again, do these in whatever order feels more natural to you, but make sure that your system
function matches your diagram.
Step 10. What are the poles of this system? Express your answer as an algebraic expression involving kc
and any necessary constants.
Step 11. Using the pieces you’ve constructed above, as well as any relevant primitives and combinators
provided in the lib601.sf module, define a method lightTrackerModel, which takes as input
2
A is a capital "α," not a capital "a."
6.01 HW2: Heads Up! — Fall 2011 5
the gain to use for the controller (k_c) and the length of a timestep (T), and returns an instance of
sf.SystemFunction which represents the entire light-tracking system with the specified gains
and timesteps.
Wk.5.5.3 Enter your system function for the entire light tracker model, as well as
your code for this section, into this tutor problem, and upload a PDF of
your block diagram for the entire system. Be sure to label the signals Θl ,
Θh , E, Vs , Im , Ωh , Ah , Vc , and Vb in your diagram.
sec2
• km = 1000 Amp
• kb = 0.5 volts
rad
sec
• ks = 5 volts
rad
• rm = 20 ohms
Step 12. Given these values for the constants in the equation, find the value of kc that makes the head
react most quickly to changes in the light’s position, while causing the head to converge to the
desired angular position without oscillation. What are the poles for the best gain? For this step,
use T = 0.005 seconds. (Suggestion: see Appendix 1 on Optimal Solutions).
Explain how you arrived at this answer, and plot the response of the light tracker with your chosen
gain to a unit step input. This will model the behavior of the system when the head starts facing the
light, but at time t = 0 the light is instantly moved to θl = 1 radian, where it remains indefinitely.
Here is a handy procedure that takes a system function as input and generates a plot of the behavior
resulting from the system starting at rest 3 with a unit step signal as input. This function is defined
in hw2Work.py for your convenience.
def plotOutput(sfModel):
smModel = sfModel.differenceEquation().stateMachine()
outSig.plot()
3
When a system “starts from rest,” this means that all inputs to and outputs from the system for time t < 0 have value 0.
6.01 HW2: Heads Up! — Fall 2011 6
Step 13. When T = 0.005 seconds, for what range of kc is the system monotonically convergent? oscillatory
and convergent? divergent? Plot the response of the light tracker to a unit step input for one gain
in each of the ranges you found above.
Step 14. Fix kc at the best value you found in Step 12. Now, try increasing T . Also try decreasing it. Exper
iment with different values of kc and T ; what can you say about how the length of the timestep T
affects the behavior of the system?
Wk.5.5.4 Answer the questions in this problem and upload a PDF with your clearly
labeled plots.
4 Variable Reference
For your reference, here is a summary of the symbols used in this assignment:
• Θl : the absolute angular position of the light, a signal whose samples are θl [n].
• Θh : the absolute angular position of the head, a signal whose samples are θh [n].
• E : the error signal (Θl − Θh ).
• Vs : the voltage produced by the light direction sensor, a signal whose samples are vs [n].
• Im : the current flowing through the motor, a signal whose samples are im [n].
• Ωh : the motor’s angular velocity, a signal whose samples are ωh [n].
• Ah : the angular acceleration of the motor, a signal whose samples are αh [n].
• Vc : motor control voltage, a signal whose samples are vc [n].
• Vb : the back-EMF of the motor, a signal whose samples are vb [n].
6.01 HW2: Heads Up! — Fall 2011 7
is called as follows:
• objective: a procedure that takes a single numeric argument (x in our example) and returns
a numeric value (f(x) in our example),
• xmin, xmax: a range of values for the argument,
• numXsteps: how many points to test within the range,
• compare: an optional comparison function that defaults to be operator.lt, which is the less
than, < , operator in Python. This means that if you don’t specify the compare argument, the
procedure will return the value that minimizes the objective.
This procedure returns a tuple (bestObjValue, bestX) consisting of the best value of the ob
jective (f(x∗ ) in our example) and the x value that corresponds to it (x∗ in our example).
Check Yourself 2. Here are graphs of two functions. Use optimize.optOverLine to find the
minimum of one of them. The function f has a minimum at x = 0.5 of value
−0.25; the function h has a minimum at x = 1.66 with value −0.88.
2.0
30
25
1.5
20
1.0
15
0.5 10
Note: regardless of what method you use to create your PDF files, always double-check to
make sure that they are valid and complete before you submit them; do this by opening them
in a PDF reader and making sure they open correctly and contain everything you think they
should contain.
Print-to-PDF
On Athena (or vanilla Ubuntu): Open the file you want to convert in an appropriate program.
Choose File → Print. Select the “Print to File” option. Make sure “PDF” is selected under
“Output Format.” Choose where to save the resulting PDF file, and click “Print.”
On Windows: Install a PDF printer (such as doPDF). Open the file you want to convert in an
appropriate program. Choose File → Print. Choose to print to your recently-installed PDF
printer; you will then be presented with options about where to save the resulting PDF file.
On Mac OSX: Open the file you want to convert in an appropriate program. Choose File →
Print. Click on the PDF button in the lower left-hand corner of the “print” dialog. Select the
option “Save as PDF...”, choose the location where you want to save the resulting PDF file, and
click “Save.”
LibreOffice / OpenOffice.org
LibreOffice and OpenOffice.org allow exporting files directly to PDF.
Create a file which includes all graphics and text you want to include in your PDF. Choose File
→
Export as PDF.... Make sure the box next to “PDF/A-1a” is checked. For submitting graphs
or scans, you probably want to choose the “Lossless compression” option under “Images.” Click
“Export,” choose where to save the resulting PDF, and click “Save.”
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.