MAE 211—Mechatronics Lab #1: Gears, Bearings and Power

advertisement
MAE 211—Mechatronics
Lab #1: Gears, Bearings and Power Transmission
Objectives:
• Familiarization with “Lego” building blocks, which will be used throughout the
rest of the laboratory experiments.
• Introduction to different types of bearings, including thrust bearings and roller
bearings.
• Introduction to basic concepts of bearing placement for proper shaft constraint
and alignment.
• Demonstration of gear ratios and their affect on torque and power transmission.
• Introduction to lead screws and their uses.
Introduction:
Much of mechanical engineering involves making things move, a process that
involves applying forces or torques to objects or fluids to cause motion. This is called
power transmission. During the course of this lab students will study some basic elements
of power transmission: gears, shafts, and bearings.
Part 1: Bearings
Bearings are simply places where two objects in motion relative to each
other come together. They can accommodate either rolling or sliding motions, or
even a combination of the two. The purpose of a bearing is to limit motion in one
direction, while allowing motion in another. Bearings come in a variety of shape
and sizes, but in general, their purposes are as follows: to allow one object to
move relative to another while limiting motion in a least one axis, to reduce
friction and wear as much as possible on moving parts, to reduce bending stresses
on shafts, and to provide a replaceable, “sacrificial” part in a large or expensive
mechanism.
Fig.1-1—Lego bearings
In this lab students will work with plain bearings, which use a simple
sliding contact between two objects, as opposed to a rolling element bearing such
as a ball bearing. Plain bearings may rely either on slippery materials or a type or
lubrication to reduce friction between two objects.
Whether plain or rolling element, bearings come in three basic
configurations. Radial bearings allow a shaft to rotate but prevent it from
translating along the axis perpendicular to the shaft. This type of bearing is
usually attached to a base or mounting system.
A thrust bearing allows rotation of the shaft, but will not allow translation
along the axis of the shaft. Consider the hinge pin in a door. It allows the door to
swing open and closed, but does not allow the door to fall and drag along the
floor. Such bearing are found in almost every mechanical system.
Linear bearings constrain motion along the axis of the shaft, to a guide
way, but do not allow motion perpendicular to the shaft. These may or may not
allow rotation about the shaft, depending on the type of application.
Part 2: Gears
A second aspect of power transmission is gearing. As students will
discover as they complete the lab, gears come in all shapes and sizes. In order for
gears to fit together, they must have the same gear pitch. To find the gear pitch,
the following equation is used:
N +2
P=
(1)
OD
where P is the pitch, N is the number of teeth, and OD is the outside diameter of
the gear. Knowing the gear pitch is useful for everyday application, however, all
Lego gears are made to fit together, therefore, it will not be necessary to take this
into account in this laboratory.
Another important gear aspect is the gear ratio. This is the concept that
will be most important in this class. To calculate gear ratios, use the following
calculation:
N ω
D
r
GR = 1 = 2 = 1 = 1
(2)
N 2 ω1 D2 r2
Where GR means gear ratio, N1 is the number of teeth of the first gear, ω1 is the
angular velocity of the first gear, D1 is the diameter of the first gear, r1 is the
radius of the first gear, N2 is the number of teeth in the second gear, and ω2 is the
angular velocity of the second gear D2 is the diameter of the second gear, r2 is the
radius of the second gear. Generally, the input gear is gear 1 and the output gear is
gear 2. The gear ratio is important because it allows for the calculation of relative
velocities among the gear train gears. These become important because as speed
increase, torque decreases, and vice versa. Therefore, it is important to balance
these two qualities in designing any gear train for a particular apparatus.
Bevel gears, worm gears, and rack and pinions are three different types of
gears that will prove very useful in mechanism design. Bevel gears are a special
type of gears that work just like spur gears, except that they can transfer power at
a 90º angle. Worm gears and racks both have special functions that will be shown
later in the lab activities, however it is important to note that each of these gear is
calculated as having a single tooth.
Experiments:
Experiment 1: Simple gear trains
• Mesh an 8-tooth gear with a 40-tooth gear.
• Mesh a 24-tooth gear with a 16 tooth gear.
Pay attention to these tooth numbers. Be sure to experiment with using
each gear as the input gear, and how this changes the speed. Use a
ruler to measure the outside diameter of each of these gears. You will
need these numbers to answer the results questions.
Fig. 1-2—8-tooth gear meshed with 40tooth gear
Fig. 1-3—24-tooth gear meshed with 16tooth gear
Experiment 2: Compound gear trains
• Mesh an 8-tooth gear with a 40-tooth gear combined with an 8-tooth
gear on the same shaft. Mesh this 8-tooth gear with another 40-tooth
gear.
Fig. 1-4—Compound 8-tooth and 40-tooth gear train
Experiment 3: Bevel gears
• Assemble a gear train including two bevel gears (one large and one
small), to turn the train at a 90º angle.
Fig. 1-5—Bevel gear train
Fig. 1-6—Bevel gear meshed with 40tooth gear
Experiment 4: Differentials
• Construct a differential gear including a differential case and three
small bevel gears. Turn one axle, then hold one axle fixed and turn the
other.
Fig. 1-7—Differential with bevel gear
Fig. 1-8—Differential assembly
Experiment 5: Worm gears
• Assemble a gear train with a worm gear and a 24-tooth gear. Turn the
worm gear forward and notice what happens. Then, turn the worm
gear in reverse by turning the spur gear and notice what happens.
Fig. 1-9—Worm gear meshed with 24-tooth gear
Experiment 6: Rack and pinion
• Assemble a rack and pinion gear train including two racks, laid end to
end, and an 8-tooth gear. Perform this set up twice; once with the rack
held fixed, then with the 8-tooth gear held fixed. Note: The gear not
held fixed may slide along a smooth Lego block.
• Combine the rack and worm gear.
Fig. 1-10—Rack and 8-tooth gear with
rack held fixed
Fig. 1-11—Rack and 8-tooth gear with 8tooth held fixed
Experiment 7: Lead screw
• Assemble the lead screw assembly shown, using the threaded rod
along with a coupler. You do not need to use the motor. These items
will be provided to you by the TA when you reach this experiment.
You will also need the smooth Lego pieces that are included in the lab
tool kit.
Fig. 1-12—Lead screw assembly
Project:
•
Using the knowledge gained from this lab experiment, devise a gear
train in which 100 turns of the input shaft will generate approximately
3 inches of displacement in the lead screw.
Questions:
1. (Experiment 1) (3 pts each) Find the gear ratio for each of the two meshes and
calculate the gear pitch.
2. (Experiment 2) (6 pts) Assuming an input velocity of 5 rad/s. Find the output
velocity of the second 40-tooth gear.
3. (Experiment 3) (4 pts) Calculate the gear ratio of the bevel gear setup.
4. (Experiment 4) (4 pts) What happens to the other axle when one is held fixed
and the other is turned?
5. (Experiment 5)
a. (3 pts) How many teeth forward does the 40-tooth gear move with each
rotation of the worm gear?
b. (3 pts) What happens when the spur gear is turned backward against the
worm gear?
c. (4 pts) Calculate the gear ratio for the rack and worm gear.
6. (Experiment 6)
a. (2 pts) Calculate the gear ratio of the rack and 40-tooth gear.
b. (2 pts) What happens to the speed of the two gears relative to each
other when the gear is reduced to a 24-tooth gear?
7. (Experiment 7)
a. (2pts) Count the number of turns of the threaded rod needed to move
the nut one inch.
b. (2 pts) How far will the nut move in ¼ turn?
8. (Project) (10 pts) Describe the gear train used for this problem (including a
picture may help to clarify). Calculate the displacement of the lead screw with
relation to the input shaft using any necessary concepts described in this lab, and
show your work.
MAE 211—Mechatronics
Lab #2: Introduction to Electrical Circuitry
Objectives:
• Introduction to the 4-band color code for resistors
• Familiarization with basic measurements of resistance, voltage, and current.
• Introduction to the rules for resistance in series and parallel.
• Introduction to the rules for voltage in series and parallel.
• Introduction to the rules for current in series and parallel.
Introduction:
Mechanical engineering often involves controlling a mechanical system using
electricity to drive the system. In order to provide electrical power to a system, a basic
knowledge of electrical circuits is needed. In this lab students will study resistance,
voltage, and current in different configurations, including series, parallel, and
combination circuits.
Simple circuits can be solved using Ohm’s Law. This law states that the voltage
across a resistor in volts (V) is equal to the current passing through that resistor in
amperes (A) multiplied by the resistance of the resistor in ohms (Ω). Or, to state this law
as an equation:
V = IR
(1)
where V is voltage in volts, I is current in amps, and R is resistance in ohms. This
equation can also be applied to an entire circuit, rather than just a single element, by
calculating equivalent resistances.
Part 1: Resistance
Resistors are the most common element in an electrical circuit. All
electrical components have a resistance, including metal objects like wires. Even
motors have a resistance, though it is usually referred to as impedance, and is
slightly different. The focus in this experiment and in this course will be on
simple ideal resistors. In order to calculate equivalent resistances to use Ohm’s
Law, apply the equations described below depending on the configuration.
When resistors are placed in series, as shown in the figure, the resistances
simply add. See the equation below:
Req = R1 + R2 + R3 ...
(2)
where Req is the equivalent resistance, and R1, R2, and R3 are the resistances of the
separate resistors.
Fig. 2-1—Resistors in series
When resistors are placed in parallel, as shown in the figure, the
resistances add inversely. See the equation below:
1
1
1
1
(3)
= +
+ ...
Req R1 R2 R3
where Req is the equivalent resistance, and R1, R2, and R3 are the resistances of the
separate resistors.
Fig. 2-2—Resistors in parallel
Part 2: Voltage
Voltage across an element is a measurement of the amount of voltage
dissipated across the element. For instance, in a circuit containing a voltage
source and a resistor the source voltage can be measured across the resistor where
it is dissipated.
Regardless of the source and the variety and number of resistors in a
circuit, the total voltage supplied by the source will be dissipated in the circuit
across the resistors. For resistors in series, voltage division can be used to
determine the voltage drop across each circuit element. The equation for this is as
follows:
⎛ R2 + R3 + R4 ... ⎞
(4)
V1 = ⎜
⎟ *VS
⎝ R1 + R2 + R3 + R4 ... ⎠
where V1 is the voltage drop across the desired resistor, R1 is the desired resistor,
R2, R3, and R4 are the rest of the resistors in the series circuit, and Vs is the source
voltage. In order to use this rule in a circuit which contains resistors in parallel,
use the rules for equivalent resistors in parallel to find the equivalent resistance
for these resistors, and treat the equivalent resistance as a resistor in series with
the other resistors in series. It is important to note that the voltage drop across
each branch of a parallel circuit is the same. This means that once the voltage
drop across the equivalent resistance is found, the voltage drop across the actual
resistors is also known.
Part 3: Current
Current is a measure of the amount of charge traveling through a circuit.
Current, like water, always takes the path of least resistance. For this reason,
current acts in a way that is opposite of voltage. For instance, whereas voltage
drop is different across components in series and the same in parallel, current
stays the same in series and changes in parallel. Due to this, current division
equations can be used. Just like water, the amount of current flowing into a
junction must be the same as the current flowing out. A junction is any place
where two or more circuit elements join. To describe this as an equation:
I in + I out = 0
(5)
where Iin is the current entering a junction and Iout is the current leaving a
junction. See the diagram to clarify.
Fig. 2-3—Current flow at a junction
Kirchoff’s Current Law can be used in conjunction with the above
equation and Ohm’s Law to solve simultaneous equations to find the magnitude
of different currents in a circuit. This will be covered more in-depth during the
course, but this topic will prove to be very useful in the future.
Experiments:
Experiment 1: Reading and measuring resistance
• Choose three different resistors from the lab kit. For each, record the
color code of the resistor. Work out the resistance using this code and
the color code listed on the card provided in the lab kit. Then set the
digital multi-meter (DMM) to ohms. Place the leads of the DMM on
each side of the resistor, and record the value displayed. You may need
to vary the magnitude setting on the DMM to get a more accurate
reading. Also, do not attempt to read a resistor’s value with current
flowing through it as you will get erroneous results. Keep the values
you have recorded, as you will need them to answer your results
questions.
Fig. 2-4—Reading a resistor
Fig. 2-5—Resistor Color Code
Experiment 2: Potentiometer
• Using the DMM still set to ohms measure the total resistance of the
potentiometer by placing one lead on the left-most terminal and one on
the right-most terminal. It may be useful to record this value, though
you will not need it for the results questions.
• Now turn the wiper all the way one direction. Measure the resistance
from the left-most terminal to the center terminal and from the center
terminal to the right-most terminal.
• Turn the wiper to some place in between the two extreme positions.
Repeat as above, taking measurements of each side. Notice how these
measurements compare. You may want to repeat this a few times with
the wiper in different positions for clarification.
Right-most
terminal
Left–most
terminal
Middle terminal
Fig. 2-5--Potentiometer
Experiment 3: Photoresistor
• Measure the resistance of the photoresistor uncovered, partially
covered, and fully covered. Make note of the difference.
Fig. 2-6--Photoresistors
Experiment 4: Voltage Measurement in Series
• Attach one side of a 100Ω resistor to the 5V power supply using the
breadboard, and attach the other side to the ground terminal. Measure
the voltage across the resistor using the DMM.
• Attach one side of a 1000Ω resistor as done above, instead of the 100Ω
resistor. Again, measure the voltage using the DMM.
• Now place two 1000Ω resistors in series with each other and measure
the voltage across each.
• Replace one of the 1000Ω resistors with a 330Ω resistor and measure
the voltage drop across each.
Fig. 2-7—Measuring voltage
Fig. 2-8—Resistors in series
Experiment 5: Voltage Measurement in Parallel
• Attach 2 1000Ω resistors in parallel with the 5V source. To do this,
place one end of each resistor in line with the power, and the other end
of each resistor in line with the ground. Measure the voltage drop
across each of these.
• Now place a 330Ω resistor in parallel with the 1000Ω resistors.
Measure the voltage drop across each of the resistors.
• Make a combination circuit using a 330Ω resistor in series with the set
of 2 1000Ω resistors and the 330Ω resistor in parallel. Measure the
voltage drop across each of the resistors.
Fig. 2-9—Resistors in parallel
Fig. 2-10—Combination circuit
Experiment 6: Measuring Current in Series and Parallel Circuits
• Using the previous circuit, measure the current of each circuit. Be
CAREFUL! Current is NOT measured in the same way as resistance
or voltage. Whereas these are measured with the DMM in parallel with
the circuit, for current, the DMM must be in series with the circuit. To
do this, break apart the circuit in the branch you wish to measure
current in and use the meter to complete the circuit. See the figure
below.
Fig. 2-11—Measuring current
Project:
•
Place a potentiometer in series with an LED, so that the resistance seen
by the circuit can be changed. Reverse the direction of the LED and
notice what happens. Measure the voltage drop across each at various
resistances and measure the current through the circuit at each
measurement.
Fig. 2-12—LED with potentiometer
Questions:
1. (Experiment 1)
a. (3 pts) For each of the three resistors tested, list the color of the 4
colored bands, show the explanation of the value with code means, and give the
actual reading of the resistance as measured by the DMM.
b. (2 pts) Why is the measured resistance not exactly the same as the
resistance given by the color code?
2. (Experiment 2)
a. (2 pts) What happens when the wiper is turned all the way to one side?
b. (5 pts) How do the measurement between the left-most terminal and
center and right-most terminal and center compare to the total measurement from
the left-most to right-most terminals?
3. (Experiment 3) (3 pts) What happens to the resistance of the photoresistor as it
receives less and less light?
4. (Experiment 4)
a. (4 pts) What conclusions can you draw from this part of the
experiment?
b. (8 pts) If a series circuit is made using a 330Ω, a 1000Ω, and a 100Ω
resistor, and the voltage source is 12V, calculate the voltage drop across each
resistor in the circuit.
5. (Experiment 5)
a. (3 pts) What do you notice about each of the measurements across the
parallel branches?
b. (5 pts) Calculate what the voltage drop across each of the resistors
using Ohm’s Law. Compare this to the values measured in lab.
6. (Experiment 6) (5 pts) Calculate the appropriate current in each portion of the
circuit and compare the values calculated with those measured.
7. (Project) (8 pts) What conclusions about LEDs can you draw from the voltage
and current measurements?
MAE 211—Mechatronics
Lab #3: Introduction to Using the Data
Acquisition Board
Objectives:
• Introduction to basic programming logic
• Familiarization with basic flowchart logic
• Familiarization with basic output and functions
• Use of if, for, while, switch, case, tone, pause, and display functions
Introduction:
Mechanical engineers often find themselves with a need to gather data using a
computer. Data acquisition is likely the most important aspect of an experiment. After all,
quantitative results tend to be more useful than the qualitative results that can be observed
with one’s naked eye. In this course, the data acquisition board (DAQ board) will be used
to output signals to motors or relays and to collect data from various types of sensors, as
could be done in a real world setting. In order to do so, some knowledge about using the
DAQ board must be obtained.
Fig. 3-1—DAQ Board
Part 1: MATLAB
MATLAB is used in this course as an interface between the DAQ board
and the user. MATLAB is a user-friendly, programmable application, with a wide
variety of uses beyond what will be experienced during the course of this lab.
Many of these functions are contained in the many toolboxes incorporated in
MATLAB. For the purposes of this course, MATLAB is a programming language
with which to instruct the DAQ board. As such, some simple programming skills
will be necessary. Keep in mind that for any function, you may access the help
file by typing “Help” and the function in the command line.
Part 2: Programming logic
In order to tell the DAQ board what you want it to do, you must give it a
program with a specific set of instructions for it to execute. Obviously, a
computer does not understand a command like a person does. A computer needs a
step by step account of exactly the tasks you want it to execute and when.
Computers “think” in a logical order. As such the commands you give will be
followed in order from start to finish.
In order to organize your program into a logical order, it is often useful,
and depending on the depth of the program, necessary, to make a flowchart. A
flowchart is a logical order of processes the computer should execute during a
program. This should be as detailed as necessary to explain the details of the
program to someone else. See Fig. 3-2 below for an example of a flowchart.
Fig. 3-1—Flowchart Shapes
Fig. 3-1—Flowchart for the for-loop program in this lab
Part 3: DAQ Board
The DAQ board is the unit the computer uses to “talk” to sensors, gather
data from them or send messages to them. The basic functionalities of the DAQ
board are digital input/digital output (DIO), analog input (AI), and analog output
(AO). Each of these important functions will be explained in-depth in future labs.
This lab is intended only to familiarize students with accessing the DAQ board to
send messages to or receive messages from it.
Experiments:
Experiment 1: Initializing
Open MATLAB by clicking on the desktop shortcut or finding it under the
Start menu. When MATLAB is ready, type “initialize” in the command
window, just as it appears in the quotation marks. If this is correct,
MATLAB should initialize the mechlab toolbox (the functions you will
use in this lab), and then “DAQ Initialized” will appear on the screen. You
will need to do this each time you open MATLAB, unless “DAQ
Initialized” already appears on the screen.
Experiment 2: Outputting to the screen
• Open a new file by clicking on the File Menu under MATLAB, select
New, then select M-File. Aside from giving MATLAB instructions one at
a time in the command window as with the initialize function, we may
also write an M-File and call it from the directory to send a whole program
at once. For multiple instructions, this is the better and more efficient way
to send code.
• In this M-File, type “clear” on the first line. MATLAB maintains all
variables and information in its memory until cleared by the user. This can
be a double-edged sword when writing complex programs so always be
sure to clear the memory using the “clear” command at the beginning of
your programs. It may also be useful in this lab to use the “initialize”
function at the beginning of each program to make sure the DAQ board is
reset each time you run the program. Obviously, you will not need to do
this outside of lab.
• Once the memory is cleared, it is time to begin programming. MATLAB
will execute commands in the order given, logically. Type the following
code into your M-File:
%Simple output function
disp(‘Hello world!’);
rand(3)
tone(1000.0, 1.0);
Save this file as myfile1.m under the desktop folder “Student Documents.”
Change the directory at the top of the MATLAB window to this folder by
clicking on the button “…” and selecting the “Student Documents” folder.
You may now use any M-File saved in this folder simply by typing its
name in the command window. Do this by typing “myfile1” in the
command line.
Notice the way that MATLAB displays the data. If in a program a line of
data should be displayed to the screen, do not place a semi-colon after it. If
you do not wish to see an output displayed, place a semi-colon after it.
This is called suppressing an output.
The “tone” function introduced above plays a sound. The user can define
this sound by first giving the frequency, then the duration in seconds
inside the parenthesis.
Experiment 3: Deciding statements and loops
• There are several different common statements used in programming.
The common ones are “if”, “for”, “while”, and “switch”/“case”. These
will be explored now.
• Type the following code:
clear
initialize
y=1;
if y<10
disp(‘y<10’);
end
You see that this executes the if-statement when run. Try changing the
value of y to something above 10. You should see that the if statement
is not executed. There are also if/else statements. Try changing your
code to the following:
clear
initialize
y=1;
if y<10
disp(‘y<10’);
else
•
disp(‘y>10’);
end
You should see that now, no matter the value of y, the statement is
executed one way or the other.
Type the next code:
clear
initialize
n=1;
for n=1:10
tone(1000.0, 0.5);
%plays a note for 0.5 seconds
pause(1.0);
%pauses the program for 1.0 seconds
end
Notice that the program beeps 10 times. This is because you defined
the for-loop to continue from n=1 to n=10 at intervals of 1 unit.
Pay attention to the use of the pause function. The tone function will
play a note for the specified time, but unlike many languages,
MATLAB will not wait for this command to be completed before
continuing with the rest of the program. Therefore, to hear each note, a
•
•
pause at least as long as the note must be included after the tone
command.
Enter this code:
clear
initialize
n=1;
while n<=10
n
n=n+1;
tone(1000.0, 0.5);
pause(1.0);
clc
end
The “clc” function is useful for keeping the workspace neat. It clears
all the type from the command window. This function does not clear
any variables stored in memory however. Notice that the above
program has virtually the same effect as the for-loop program, but
written in a different way. Depending one the way one needs to define
a loop will determine whether to use a for- or while-loop. Generally, a
for loop is used when there is a specified number of iterations, and a
while loop is used when the number of iterations is not precisely
known, but a desired result is.
Switch statements are a bit more complicated than those above. Enter
this code:
clear
initialize;
clc;
n=3;
switch n
case 1
tone(1000,1);
pause(1);
case 2
tone(1000,0.5);
pause (1);
tone(1000,0.5);
pause (1);
case 3
tone(1000,0.25);
pause(1);
tone(1000,0.25);
pause(1);
tone(1000,0.25);
pause(1);
end
Notice that when executing this statement it only runs once. Try
changing the initial value of n. A switch/case statement is like a
choice, depending on the case. It is equivalent to writing a series of
if/if else statements, though tends to be considerably easier and faster
once the user is proficient at using the switch/case.
Project:
•
Using the above concepts, write a program that will play a four note
scale (see below for frequency breakdown) first in whole notes, then in
half notes, then in quarter notes, and finally in eighth notes.
Notes
A
A#
B
C
C#
D
D#
E
F
F#
G
Ad
4th
octave
440.00
466.16
493.92
523.28
554.40
587.36
622.24
659.28
698.48
740.00
784.00
830.64
Frequency by octave (Hz)
5th
6th
7th
octave
octave
octave
880.00 1760.00
3520
932.32 1864.66 3729.31
987.84 1975.53 3951.07
1046.56 2093.00 4186.01
1108.80 2217.46 4434.92
1174.72 2349.32 4698.64
1244.48 2489.02 4978.03
1318.56 2637.02 5274.04
1396.96 2793.83 5587.65
1480.00 2959.96 5919.91
1568.00 3135.96 6271.93
1661.28 3322.44 6644.88
8th
octave
7040
7458.62
7902.13
8372.02
8869.84
9397.27
9956.06
10548.08
11175.30
11839.82
12543.85
13289.75
Questions:
1. (Experiment 1) What should happen if the DAQ board is not initialized and
commands from the mechlab toolbox are used?
2. (Experiment 2) How do you display the value of a variable to the screen in
Matlab?
3. (Experiment 3) Note: Do not use the examples given in this lab for your
answers. Make up your own!
a. Define the difference between using an if-statement and a switch case
statement, and give an example of a situation in which you would use
each.
b. Define the difference between a for-loop and a while-loop and give an
example for the use of each.
4. (Project) Include you code for this program (for proper formatting, see the lab
formatting guide or ask one of the TAs). For this program, also make a
flowchart. Explain why you chose to use the type of statement(s) or
loop(s) you did for this program. If applicable, tell why the other options
would not be satisfactory.
MAE 211—Mechatronics
Lab #4: Digital Output
Objectives:
• Introduction to digital output function and uses
• Familiarization with relays and Lego motors
• Familiarization with solenoids
• Familiarization with stepper motors
Introduction:
Mechanical engineers often need to be able to turn on and off a motor or other
device from a remote location, or at a very specific time when certain conditions are met.
It is not feasible to do this manually, as will be explored in this and future labs. For this
purpose digital output is an extremely useful concept that may be used for a wide variety
of applications.
Part 1: Digital Output
Digital output is the simplest output concept. Essentially it is the same as
flipping a light switch or opening a door. It is a simple on or off command, given
as a binary 0 or 1. The good and bad part of digital out is that it is not a variable
signal. For instance, in the mechatronics lab you may turn on a motor using the
12V power supply by connecting it to a digital output and turning on the relay.
However, if you need the motor to use only 8V, you will have to find some other
way of achieving this. The digital output will only return 12V or 0V.
Fig. 4-1—Digital outputs on the DAQ board
Part 2: Relays
Relays are a common component in mechanical devices. They come in
many shapes and sizes, and are specified for different purposes. This lab will
focus on solid state relays and double pole double throw relays. Relays are
effectively an electrically controlled switch. Rather than having to physically
press a button, either by hand or using a mechanism, a simpler way is to use a
relay. To throw a relay, it must be supplied with at least the proper throw voltage.
Supplying this voltage is equivalent to pressing a switch, or changing a
connecting in the circuit.
Double pole double throw relays (DPDT) and single pole single throw
relays (SPST) are electromechanical relays. They work using internal
electromagnets to change their position. DPDT relays contain two sets of
contacts, open and closed. If the supply voltage is present, it will activate the
electromagnets within the relay, forcing the contacts to the open position.
Otherwise, the relay remains closed. In such a way we can change and direct the
flow of current. Keep in mind that the current used to throw the relay does not
necessarily need to be the same as the current passed by the relay. In this way, a
small voltage could be used to pass a much larger voltage, if need be.
Unlike electromechanical relays, solid state relays (SSR) contain no
moving parts. SSR generally contain a light-emitting diode (LED) which, when
given current, shines on a photo-sensitive diode, causing the diode to activate a
metal-oxide semiconductor field-effect transistor (MOSFET). The MOSFET can
then switch the load.
Fig. 4-3—Solid State Relay
Fig. 4-2—Double Pole Double Throw
Relay
Part 3: Solenoids
Like a relay, a solenoid is an electromechanical switch, used to direct the
flow of a fluid. Using this fluid, we can convert electromechanical energy into
linear motion. Again, as in a relay, when the proper switching voltage is applied,
the solenoid will switch, as will the directed flow of the fluid in the cylinder. In
this lab, we have pneumatic cylinders, but solenoids are also capable of
controlling hydraulic cylinders.
Fig. 4-4--Solenoid
Part 4: Stepper Motors
Stepper motors are a type of digital motor. These motors contain multiple
coils, usually and in this case, four coils. These motors work by turning on and off
each coil in succession and in the appropriate order. The motors get their name
from the coils. Each time a coil is activated, the motor will move a small amount,
called a step. The step size is determined by the motor. To turn the motor
continuously, the coils must be continually activated and deactivated in the
correct sequence.
Fig. 4-5—Stepper Motor
Experiments:
Experiment 1: Using digital out
• Connect your motor to one of the digital outs on the board, either using
the bread board, or by directly attaching the motor leads to each of the
terminals of the digital out.
• After connecting the motor, turn the digital out on by typing
•
digital_out(1,1)
in the command window. This is the syntax for the digital output. The
numbers in the parentheses are channel (1 through 8) followed by on
or off (1 or 0). If you need further help, type help digital_out in the
command window to access the help file for digital out.
Experiment with turning the motor on and off using the digital out.
Experiment 2: Connecting the DPDT relay
• Using the diagram below, connect the DPDT relay to the DAQ board
and the motor. The relays should be attached to the project board in the
correct orientation, with the button or diagram facing right.
• After connecting the relay, experiment with turning the motor on and
changing the direction of it, by changing the digital outputs as in the
previous activity. Pay attention to the way in which the motor moves
with which digital inputs on or off.
• Once fluent in turning on and reversing the motor, write a code the
will turn the motor on for 2 seconds, off for .5 second, reverse for 2
seconds, and off for .5 second, and repeat this 3 times. Save this code
for later.
Fig. 4-6—Schematic of Relay Setup
Experiment 3: Connecting the solenoid
• To power the solenoid, connect each of the prongs on it to one of the
digital outs. Use the digital out to turn it on and off. See figures below
for a description of a solenoid.
Fig. 4-7—Interior of a Solenoid
Experiment 4: Stepper motor
• Connect the black wire of the stepper motor to the DAQ board as a
ground (one of the terminals without a red wire leading to it). Then
choose four digital outputs and connect the motor’s other leads in the
order green-red-white-brown. You should now have four digital outs
capable of controlling the stepper motor. These digital outs must be
turned on and off in the correct order in order to make the motor
continue to spin forward. Turn on the digital outs in the order given
above, so that the motor will spin forward. Do not move on until you
have successfully done this.
• Once you have made your stepper motor spin forward, you can make it
spin in reverse by reversing the order of the steps. Activate the coils in
the order brown-white-red-green, so that the motor will spin in reverse.
• You can slow down the stepper motor by placing a pause between
turning the coil on and turning it off again. Do this and watch how the
motor runs at a slower speed. Save this code for later.
Fig. 4-8—Stepper motor setup
Project:
•
Write a program to run the stepper motor forward. At each full rotation
of the stepper motor, open and close the solenoid. Save this code for
later.
Questions:
1. (Experiment 1) (3 pts) From the information given in this lab, describe how
the digital output works? (Describe any important components in the process.)
2. (Experiment 2)
a. (5 pts) How does the direction of the motor change? Explain in detail
which relays change what, and why this is so.
b. (10 pts) Include your code for this program. See formatting guide for
proper inclusion.
3. (Experiment 3) (3 pts) From the block diagram above, label which of the
lettered ports performs what function for the solenoid in each position.
4. (Experiment 4)
a. (10 pts) Include your code for the stepper motor program.
b. (3 pts) Discuss why a designer might choose to use a stepper motor over
another type of motor.
5. (Project) (14 pts) Include your code for the final project. Describe why you
chose this approach for the program.
MAE 211—Mechatronics
Lab #5: Digital and Analog Input
Objectives:
• Introduction to basic programming logic
• Familiarization with basic output and functions
Introduction:
When choosing sensors, mechanical engineers are presented with two very useful,
yet very different types of sensors, those that read digitally and those that are analog.
While different, each has it advantage over the other for certain applications. An engineer
must be aware of the difference, and be able to choose the appropriate sensor for the
given application.
Part 1: Digital Input
Digital input, like digital output, consists of two states, on or off, 0 or 1.
However, instead of telling an apparatus which state to take, a digital input reads
which state the apparatus is in. For instance, a digital output could tell you
whether a switch was pressed or not, or whether a door was open or closed.
Fig. 5-1—Digital inputs
Part 2: Analog Input
Analog input also reads the state of an apparatus. Unlike digital input,
however, analog input can give us more specific information. An analog input
returns the voltage passing between its positive and negative terminals. This
voltage may then be scaled to return to information needed from the sensor. As
such, the analog input has a theoretically infinite number of values it may return.
Of course the actual accuracy is dependent of the resolution of the sensor and
equipment, but this must only be taken into account when choosing these things,
and will not be needed for this lab.
Fig. 5-2—Analog inputs
Experiments:
Experiment 1: Basic digital sensors
• Attach the mechanical switch to the digital input. Read the digital
input by typing the syntax digital_in(ch), replacing the channel with
the number of the channel you are using. Read this sensor both pressed
and not pressed.
Fig. 5-3—Mechanical switch
•
Attach the optical proximity sensor to the digital input. Read this
sensor both covered and uncovered.
Fig. 5-4—Optical proximity sensor
•
Attach the inductive proximity sensor to the digital input. Read this
sensor both in the presence of metal and not in the presence of metal.
Fig. 5-5—Inductive proximity sensor
Experiment 2: Encoder
• Attach the encoder wheel to the motor and position the encoder sensor
so that the encoder wheel falls comfortably in the slot. Attach the
sensor to the digital in using the color code.
• Read the sensor using the digital in command both with the clear
section in the slot and with the black section in the slot.
Fig. 5-6--Encoder
Experiment 3: Basic analog sensors
• Attach the potentiometer to the analog in using the figure below. The
left terminal should be attached to a 100Ω resistor and then to the 5V
power line. The middle terminal should be attached to the positive
terminal of the analog input. The right terminal should be attached
both to the power supply ground and to the negative terminal of the
analog input. Read the sensor using the syntax analog_in(ch),
replacing the channel with the number of the channel the
potentiometer is connected to. Continue to read the value of the
potentiometer in various positions and note how the voltage changes.
Fig. 5-7—Potentiometer setup
•
Attach the photo resistor to the analog input as shown in the diagram.
The photoresistor should be placed in series with a 100Ω resistor.
Read the sensor with varying amounts of light reaching it and note
how the voltage changes.
Fig. 5-8—Photoresistor setup
Project: Lunar Lander
• Write a program to simulate a lunar landing. The program should turn
the motor on, display “Thrusters on!”, wait for a change in the
photoresistor’s reading, display “Approaching!”, wait for the inductive
sensor, display “10m away”, wait for the mechanical switch, turn off
the motor, and display “Safe landing!”. Keep in mind that the program
may not skip any steps if they are performed out of order. For instance,
if the switch is pressed first, the program should not respond to it. It
may be useful to use “empty” while loops to make the program wait.
Questions:
1. (Experiment 1)
a. (2 pts) Given what you know about digital readings, is the mechanical
switch normally open or normally closed?
b. (4 pts) Given that the optical proximity sensor detects light, do you think
that this sensor can only be used as a digital, or could it also be an analog?
Why do you think this is?
c. (4 pts) Does the type of metal make any difference as to whether the
sensor can detect it or how far away it can detect?
2. (Experiment 2) (10 pts) What is the best way to get the encoder sensor to
count correctly?
3. (Experiment 3) (10 pts) What could be some uses for the potentiometer in this
configuration?
4. (Project) (18 pts)
a. Include your code for this program.
b. Create a flowchart for this program.
MAE 211—Mechatronics
Lab #6: Analog Output and Closed Loop
Programming
Objectives:
• Introduction to analog output
• Familiarization with basic output and functions
• Familiarization with scaling
• Introduction to closed loop control with analog sensors
Introduction:
During the course of mechanical engineering, an engineer may have a need to be
able to turn a motor or other apparatus at a variable speed by feeding it specific voltages.
An engineer may also have a need for a program the runs continuously to monitor or
record an input, or continuously change an output with respect to this input. These
common tasks are known as analog output and closed loop control, respectively.
Part 1: Explanation of analog output
Analog output is similar to the digital output that has already been
covered, however, instead of just being on or off, you may output a variable
voltage. The DAQ Board is capable of outputting a voltage between positive 10V
and negative 10V; however this experiment will only use ±5V. If this output is
hooked to a motor, as it is here, it means that the speed of the motor can be
controlled by changing the output voltage.
The chip attached to the DAQ Board’s analog output pins and shown in
the figure serves an important purpose. Although the DAQ board can output a
variable voltage, it is only capable of supplying 5mA of current. Such a small
current is insufficient to turn a motor or other device. For this reason, the motor
control chip is present. Using an operational amplifier, it is possible to magnify
the current using an external source, while keeping the voltage output by the DAQ
board the same. This allows the user to run a small motor at variable speeds
directly from the DAQ.
Fig. 6-1—Motor control chip
Part 2: Using the DAQ board’s analog output function
The analog_out function in the mechlab toolbox requires two parameters,
channel and voltage. The DAQ board has two analog output channels, and can
accept voltages ranging from -10V to +10V, and is accurate to approximately
0.001V. This give much flexibility to specify exactly what the user needs.
Aside from the analog_out function, a secondary function called
motor_out has been written. The purpose of this function is to easily scale -5V to
+5V to -100% to +100%. The reason for this is that this is a simpler way to
command the motor when using an encoder, as Matlab’s reaction time is too slow
to accurately read the encoder if it is running much faster than 5V. It is important
to understand that these commands are essentially the same, however, it is
encouraged that you make use of the motor_out command as often as possible for
simplicity and avoidance of erroneous encoder readings. The motor_out
command, like the analog_out, requires two parameter, channel (1 or 2) and speed
(-100 to +100).
Part 3: Scaling
Many sensors do not begin reading at 0 units of what they are measuring.
For instance, the temperature sensors you will use in this lab will output a voltage
of 0.01V/°F. However, the sensor has a base temperature reading of 70°F,
meaning if you would get a reading of 0.01°F, the temperature is 71°F rather than
1°F. For this reason, the sensor reading must be scaled using the line equation
from basic Algebra:
y=mx+b
(1)
Using this equation, the programmer can write a function to directly
display the meaning of the output, rather than a voltage that still needs to be
interpreted.
Part 4: Closed loop programming
A closed loop program is one that executes indefinitely until manually
stopped. In this lab, you will build a thermostat and a variable speed motor. Using
the thermostat as an example, think of how a heating system works. A desired
temperature is given, which is compared to the room temperature. If the room
temperature is lower than the desired temperature, the heat turns on, but if it is
higher, the heat stays off. A person would not want to manually turn the heat on
or off constantly to keep the room at the desired temperature, nor would the
person want to have to continuously tell the thermostat to check the temperature.
In essence, this is closed loop control. An infinite loop is created, so that the
program will run on its own, over and over, without any external intervention,
aside from changing the desired setpoint. “Set it and forget it,” as they say.
Experiments:
Experiment 1: Using analog speed
• Connect the motor to one of the motor outputs and turn it on using the
syntax motor_out(ch,speed). Change the speed several times and
notice how the motor speed changes.
Fig. 6-2—Motor connected to analog output
Experiment 2: Potentiometer
• Hook the potentiometer to an analog input using the schematic below.
The left terminal should be attached to the 5V power supply with a
100Ω resistor in series, the right terminal should be grounded both to
the power supply and to the ground terminal on the analog input and to
the ground terminal on the power supply. The center terminal should
be connected to the positive terminal on the analog input.
• Turn the power supply on and use an infinite loop to read the
potentiometer’s voltage continuously. Make sure that the values
changes continuously from approximately zero to 5V. Make note of
the min and max values observed here.
Fig. 6-3—Potentiometer diagram
Experiment 3: Variable speed
• Using the potentiometer as a setpoint, write a program to continuously
vary the speed of the motor with respect to the position of the
potentiometer. The motor should spin in reverse from -100 to 0 while
the potentiometer is between 0 and 2V. The motor should remain off
while the potentiometer reads between 2V and 3V. The motor should
spin forward from 0 to +100 while the potentiometer reads between
3V and 5V. You will need to using scaling for this part.
Experiment 4: Reading RPM
• Place an encoder and encoder wheel on your motor. Use this to read
the speed of you motor, and convert it to display the RPM of your
motor every second, as the speed of the motor is varied.
Fig. 6-4—Motor with encoder wheel
Project: Thermostat
• Attach the temperature sensor to the analog input. Scale its output to
print the temperature in degrees. (See previous information on how
this sensor reads.)
• Scale your potentiometer’s reading of 0 to 5V to be 70°F to 140°F
• Connect a 100Ω resistor directly to the digital output, so that when
turned on it will heat up. CAUTION: THIS GETS HOT! Do not leave
this on long or the resistor will burn.
• Using the temperature sensor to detect the temperature of the resistor,
write a program so that the potentiometer can be used to give a
setpoint, this setpoint will be compared to the temperature of the
resistor, and the resistor will turned on or off according to the
temperature of the resistor compared to the setpoint temperature.
Demonstrate this program to a TA.
Fig. 6-5—Thermostat
Questions:
1. (Experiment 1) (5 pts) Describe how the analog_out and the motor_out are
related, and explain how the motor_out works, in relation to the analog_out
command.
2. (Experiment 2) (5 pts) Why is the 100Ω resistor needed in the power line of
this circuit?
3. (Experiment 3)
a. (5 pts) Show the calculations needed to scale the motor input versus the
potentiometer output.
b. (5 pts) Tell why the input is not simply scaled, but a “space” called a
deadband is left in the center of the potentiometer input.
4. (Experiment 4) (10 pts) Include your code for this program.
5. (Project)
a. (12 pts) Include the code for this project.
b. (6 pts) Show the calculations for scaling the temperature input.
MAE 211—Mechatronics
Lab #7: Position Control
Objectives:
• Familiarization with more advanced programming logic
• Creation of a system to allow position control
• Inference of the speed/accuracy balance principle
Introduction:
As the final experiment in this course, this is the most complicated experiment
students will face prior to the final project. Students should note that if a true
understanding of this experiment is obtained, the final project should present little
challenge. This experiment incorporates all of the ideas encompassed within this course.
Students should be able to select sensors and be able to program a function to control the
system.
Experiments:
Experiment 1: Setting up to lead screw
• Set up the lead screw as shown below. Choose a gear train to balance
speed and accuracy of this mechanism. You will be asked to explain
your choice later. It may be helpful to try a few before deciding.
Fig. 7-1—Lead screw and carriage assembly
Experiment 2: Counting pulses
• Use an encoder to measure the number of pulses recorded as the load
travels from one side of the assembly to the other. Repeat this several
times and average the results.
Experiment 3: Defined position control
• Write a program in which the load travels to 20%, then 90%, then 50%
of the length of the lead screw. Save this code.
Fig. 7-2—Load at 90%
Project: Undefined position control
• Set up a potentiometer and scale its reading to percentage. Use this
reading to control the position of the load on the lead screw. For
instance, if the potentiometer is turned to 50%, the load will travel to
50% of the lead screw. This should be done without “homing” the load
first. Save this code, and demonstrate this to a TA before leaving.
Questions:
1. (Experiment 1) (4 pts) Why was this specific gear train chosen?
2. (Experiment 2) (4 pts) Why is it important to take several counts and average
the results?
3. (Experiment 3) (10 pts) Include your code.
4. (Project)
a. (15 pts) Explain how you wrote this code. You may include flowcharts
to help explain. Be sure to include any ideas that may or may not have
worked, which were discarded, and why they were less effective than the
method you chose.
b. (15 pts) Include your code.
Download