Professional Documents
Culture Documents
04 Golnaraghi App D D-1-D-64
04 Golnaraghi App D D-1-D-64
04 Golnaraghi App D D-1-D-64
Control Lab
Most undergraduate control courses have labs dealing with time response and control of
dc motors—namely, speed response, speed control, position response, and position con-
trol. In many cases, because of the high cost of control lab equipment, student exposure
to test equipment is limited, and as a result, many students do not gain a practical insight
into the subject. In this appendix, recognizing these limitations, we introduce the con-
cept of Control Lab, which includes two classes of experiments: SIMLab (model-based
simulation) and LEGOLab (physical experiments). These experiments are intended to
supplement, or replace, the experimental exposure of the students in a traditional under-
graduate control course.
In this appendix, we have created a
series of inexpensive control experiments
Learning Outcomes for the LEGO® MINDSTORMS® NXT dc
After successful completion of this appendix, you will be able to motor that will allow students to do their
1. Simulate speed and position time response of dc motors and simple work within the MATLAB® and Simulink®
control systems using MATLAB and Simulink. environment—even at home. This cost-
2. Learn how to identify the parameters of a system—based on system effective approach may allow educational
time response. institutions to equip their labs with a num-
3. Gain a practical sense of real-life control problems, through the use of ber of LEGO test beds and maximize stu-
LEGO MINDSTORMS, MATLAB, and Simulink tools.
dent access to the equipment at a fraction
of the cost of currently available control-
systems experiments. Alternatively, as a supplemental learning tool, students can take the
equipment home after leaving a security deposit and learn at their own pace. This con-
cept has proven to be extremely successful at Simon Fraser University—Farid Golnaraghi’s
home university in Vancouver, Canada.
The labs include experiments on speed and position control of dc motors, followed
by a controller design project involving control of a simple robotic system conducting a
pick-and-place operation and position control of an elevator system. Two other projects
also appear in Chaps. 1 and 9. The specific goals in this appendix are
• To provide an in-depth, practical discussion of the dc motor speed response, speed
control, and position control concepts.
• To provide examples on how to identify the parameters of a physical system,
experimentally.
• To give a better feel for controller design through realistic examples.
Before starting the labs, you must have completed the relevant background preparation
in Chaps. 6 and 7.
D-1
USB Interface
NXT Brick
NXT Cables
NXT Motors
Host Computer
Output Shaft
Gear-train
DC Motor
In order to develop position and speed control in the system shown above, it is neces-
sary to first characterize and model the motor.1
1
It is important to note that the measured values provided here will vary from motor to motor; and for better accu-
racy, you are advised to conduct your own experiments to determine your system’s parameter values.
D-1-2 Interfacing
Interfacing between the NXT motor and the host computer is of importance because
the user should be able to both control the motor as well as sample positional data from
the motor encoder or any other sensors connected to the NXT brick. Interfacing will be
performed using MATLAB and Simulink via a Bluetooth and USB connection. A Bluetooth
connection is required to sample data from the NXT motor in real time, whereas a USB
connection is required to upload Simulink models onto the NXT Brick.
Introduction to Simulink2
Simulink is an environment used for multidomain simulation where the user is able to
create models for dynamic and embedded systems. It includes a customizable set of graphi-
cal block libraries, which the user can drag and drop to design and simulate a variety of
time-varying systems. In this appendix, we are particularly interested in utilizing Simulink
to simulate the model of the NXT motor and implementing speed and position control
systems. We also use Simulink to run the NXT motor experiments.
To start the Simulink software, enter “simulink” in the MATLAB command window
or alternatively, click on the Simulink icon on the MATLAB toolbar. This will take you
to the Simulink Library Browser menu. This menu displays all of the block libraries that
are installed on your computer, similar to what is shown in Fig. D-3. These blocks can be
dragged and dropped into a Simulink model to design your very own system. To create an
2
or a more in-depth introduction to Simulink, please refer to www.mathworks.com; for example, http://www
F
.mathworks.com/videos/simulink/getting-started-with-simulink.html, http://www.mathworks.com/help/simulink/
examples/index.html.
empty model, select File → New → Model from the Library Browser menu. An example of
an empty Simulink model is shown in Fig. D-4.
To add blocks to the model, return to the Library Browser and drag and drop them into
the model window. Some of the commonly used blocks along with their func-
tions are shown in Table D-2. Utilizing the blocks shown in Table D-2, one is
The Simulink model is essentially able to create a Simulink model for a dc motor—a position control example is
the same as a block diagram of a illustrated in Fig. D-5 (more examples appear later in the section). This model
control system. Note: The motor
can be used to simulate the behavior of a specific motor for known motor
model includes, implicitly, the
parameters. Every block can be customized by double clicking on them and setting
gear-train model as well.
1 1 1
1 1 +– K– ++ 1
L.s+R J.s+b s
In Out
Input Amplifier Electrical Current Motor Gain Mechanical Integrator
Voltage Gain Saturation
Saturation Disturbance
2
Kb
Motor feedback
the desired parameters. Note that the two saturation blocks were purposely added to simu-
late real-life scenarios. You may elect not to include them in your simulations.
In addition to creating simulations, Simulink is also able to interface with hard-
ware in real time. In particular, it is able to interface with the NXT brick via the LEGO
MINDSTORMS NXT Simulink library.
LEGO NXT Simulink Library
The LEGO NXT Simulink library has been specifically developed to interface with the NXT
brick through MATLAB and Simulink. Again, you will require MATLAB and Simulink
2012 or newer to install the library. Information can be found online that will help
Instructional video available. you with the interfacing details.3
To begin installation, enter “targetinstaller” into the MATLAB command win-
dow, and select to install from the internet when prompted. Select the LEGO NXT
library for installation and follow further on-screen instructions to finish installing the
add-on. After the library has been successfully installed, the new library will appear in
the Simulink Library Browser menu. The library blocks are shown in Fig. D-6. In par-
ticular, we are most interested in the motor and encoder blocks shown in Table D-3.
LEGO X
Acceleration LEGO LEGO
Y Battery Button
Port 1 Z Sensor
LEGO
Data Receive via Blu- LEGO
Send via Bluet- LEGO
Sound Sensor
Mailbox 1
Size etooth(R) Con... Mailbox 1 ooth(R) Conne.. Port 1
Vol
Speaker Timer Touch Sensor
Port 1
LEGO
Ultrasonic
Port 1 Sensor
3
See introductory video, Interfacing with LEGO MINDSTORMS NXT Using MATLAB and Simulink, Part 1,
at http://www.youtube.com/watch?v=jdjeubqgmjo&feature=youtu.be; also see http://www.mathworks.com/prod-
ucts/simulink/simulink-targets/videos/introduction-to-simulink-support-for-target-hardware.html.
Port A
Encoder
LEGO Controls the speed of the motor based on the value (−100 − 100)
of the block input port.
Port A
Motor
The Simulink library in Fig. D-6 will be used throughout this section to determine the
mechanical and electrical characteristics of the NXT motor.
4
It is important to note that the measured values provided here may vary from motor to motor, and you are best to
conduct your own experiments to determine your system’s parameter values.
Ground
Ω Motor Power 2
V A
Motor Power 1
V A
OFF
LEGO
10
Port A
Constant Figure D-9 Open-loop motor
Motor input Simulink model.
To power the motor, connect one end of the cable to the NXT brick and the other end
to the motor and apply a small voltage to the motor using Simulink. The Simulink model
shown in Fig. D-9 will power the motor connected to Port A to 10 percent; however, you
may edit the constant block to supply the power of your choice. Upload the model to the
NXT brick and execute the program.5 Also, ensure there is no external load connected to
the motor during the test.
While the motor is running, stall the motor by completely stopping rotation with either
your hand or with a LEGO piece. You will notice the current will drastically increase when
the motor is stalled. Record the stall current, Istall, that is reported by the multimeter and
repeat for various trials. Avoid stalling the motor for more than a few seconds, otherwise
the motor coils will burn out.
After measuring the stall current, the armature voltage must also be measured. Con-
nect the multimeter in parallel with the white wire as shown in Fig. D-10. Again, apply a
small voltage to the motor using Simulink and stall the motor. Record the supplied voltage
in the white wire reported by the multimeter and repeat for various trials.
Next, we must measure the voltage supplied in the black wire (motor power 2). This
time, connect the multimeter in parallel with the black wire as illustrated in Fig. D-11.
Again, apply a small voltage to the motor using Simulink and stall the motor. Record the
supplied voltage in the white wire reported by the multimeter and repeat for various trials.
5
See LEGO MINDSTORMS NXT library documentation for program-uploading instructions. Or see the intro-
ductory video at www.mhprofessional.com/golnaraghi; also see
http://www.mathworks.com/products/simulink/simulink-targets/videos/introduction-to-simulink-support-for-
target-hardware.html.
Motor Power 2
Ground
Ω
V A
Motor Power 1
V A
OFF
Motor Power 1
Ground
Ω
V A
Motor Power 2
V A
OFF
Note that direct measurements of voltage differences between motor power 1 and motor
power 2 may also be performed.
After recording the required voltages and currents calculate the armature voltage using
Armature Inductance
There are a number of ways to measure the motor inductance. One way commonly prac-
ticed in most undergraduate control labs is to connect a known resistor R (select a value
close to Ra) in series with the motor, stall the motor as in the previous section, provide the
system a constant input voltage, turn off the input and measure the electric time constant
La /(R + Ra). Knowing the time constant and resistance values, you can calculate La. We took
the easy way out by using a multimeter that is able to measure inductance. Simply connect
the multimeter to the motor terminals, and set the multimeter to measure inductance, as
shown in Fig. D-12. The experimentally measured armature inductance was found to be
La = 4.7 mH.
Tm = K iia (D-3)
where Tm is the motor torque and ia is the armature current. Determining the torque
constant experimentally requires you to measure both the current supplied to the motor
and the torque that it provides.
Start by attaching a shaft and spool to the end of the motor as illustrated in Fig. D-13.
Next, wrap some thread or fishing line around the spool so that it acts as a pulley. Finally,
attach a weight with known mass to the end of the thread; this will act as the external torque
that the motor has to overcome in order to rotate. The torque can be calculated using
6
It is important to note that the measured values provided here may vary from motor to motor, and you are best to
conduct your own experiments to determine your system’s parameter values.
NXT motor
Spool
Variable mass
Figure D-13 Torque constant test setup.
where rspool is the radius of the spool and W is the weight corresponding to mass M. The
motor will stall when T = 0. The corresponding Tm and ia are motor stall torque and current,
respectively.
In this experiment, the motor rotation results in the mass M to move up or down. You
will be required to measure the current supplied to the motor for a variable mass—recall the
earlier instructions on how to measure the motor current form Sec. D-1-3. Start by apply-
ing an input the motor using Simulink and let the mass rise to the top. While the motor is
pulling the mass upwards, measure the current supplied to the motor using a multimeter.
Repeat this process for various masses and plot the experimental torque Tm from Eq. (D-3)
against the measured current. It should be noted that Ki is independent of the input voltage
value. Table D-5 shows some of the measurements for our experiment. Note that for TW = 0
Nm, ia = 0.041 A, which is the current in the motor to overcome the internal motor fric-
tion. This value can later be used to calculate the motor damping parameter. Also note that
for mass M = 0.874 kg the motor stalls and the corresponding stall torque is Tstall = TW =
0.116 Nm. The experimental motor torque curve for our NXT motor is shown in Fig. D-14,
where the experimental motor torque curve is extrapolated from the data points using the
linear regression tool in MATLAB. The NXT experimentally measured motor constant is
the inverse of the slope (3.95A/N·m) or Ki = 0.252 N·m/A.
Back-emf Constant
From Chap. 6, the back-emf constant is obtained from
eb = K bω m (D-5)
where eb is the back-emf or motor voltage and wm is the motor angular speed. To measure the
motor back-emf constant, you will be required to test the motor’s open-loop speed response
using Simulink as well as measuring the supplied voltage using a multimeter. Begin by creat-
ing the Simulink model shown in Fig. D-15 to apply an open-loop step input to the motor.
0.7
0.6
0.5
0.2
0.1
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Torque (Nm)
Figure D-14 Experiment motor torque Tw versus current curve for NXT motor to calculate Ki.
This program will serve as the basis for measuring the open-loop step response of the motor.
In this model, the “Transport Delay” block, delays the step input by a specified time. The step
input must be delayed because Simulink cannot sample encoder data from time t = 0 s,
but rather starts sampling between 0 to 1 s. To overcome this problem, the step input is
delayed by 1 s. Make sure to set the “Time Delay” parameter to 1 in the Transport Delay
block parameters as illustrated in Fig. D-16. Keep in mind that doing this will require you to
take all measurements starting from time t = 1 second rather than time t = 0 s. Additionally,
the “Motor” block is used to apply a voltage to the motor, whereas the “Encoder” block is
used to sample positional encoder data from the motor encoder. Also, set the “Save format”
in the “To Workspace” block to “Structure With Time” as illustrated in Fig. D-17. By doing
this, all sampled encoder data will be accompanied with a timestamp. Finally, the step input
to the motor can be edited by changing the “Final Value” parameter in the step input block
as shown in Fig. D-18. In this example, the motor is powered to 50 percent.
Before executing the model, ensure there is no external load connected to the NXT
motor. Also, prepare the multimeter to measure voltage as described in the head “Armature
Resistance” measurement in Sec. D-1-3. Change the simulation time to the desired runtime
and run the model.
LEGO
Port A
Step Transport
Delay Motor
LEGO
Output
Port A
To Workspace
Encoder Figure D-15 Open-loop step input.
While the motor is running you will be required to measure the supplied armature
voltage for various step inputs. After execution is completed, positional encoder data will be
stored into the “output” variable. To differentiate the positional data and plot the open-loop
speed response, execute the following code in MATLAB:
A sample open-loop step response for a 2.0-V step input is shown in Fig. D-19. You
will observe that there is noise visible in the output. The noise is a result of differentiation of
the low resolution position signal from the encoder to find speed, and it may also be attrib-
uted to the gear backlash. As a result, you need to record the average steady-state speed for
various step inputs and record the steady-state speed and armature voltage for each trial.
Finally, plot the experimental armature voltage against the measured steady-state average
speeds. A sample plot is shown in Fig. D-20 where the experimental data points are shown
as well as an extrapolated trend line found using the linear regression tool in MATLAB. The
slope of this line is the back-emf constant of the motor. The back-emf constant of the NXT
motor was experimentally measured to be Kb = 0.249 V/ rad/s.
It should be noted that, in an ideal case, the back-emf constant and motor torque constant
are numerically equal in the SI units. However, because these values have been experimentally
measured, their corresponding experimentally measured values are close, but not equal. To
equate the two constants, we can find the average value that exists between them so that
both Kb and Ki are numerically equal. The average value between Kb = 0.249 V/rad/s and
Ki = 0.252 N·m/A is 0.25; therefore this average value will be used for both Kb and Ki.
Viscous-Friction Coefficient
The viscous-friction coefficient describes the amount of friction that exists in the system. In
reality, the friction may not be viscous. However, as discussed in Chaps. 2 and 6, this is an
assumption that we make to arrive at an approximate linear model for the
Note: All parameters obtained motor-gear-train combination—again any reference to motor implicitly refers
will be for the motor-gear-train to the motor-gear-train combination. Important note: Because of various non-
combination. linear affects such as friction and gear backlash, it is not expected that this
parameter can be estimated accurately.
Using small inductance assumption, i.e. La ≈ 0, we can arrive at the effective damping
due the electrical and mechanical components. From Sec. 6-3-6, the speed response of the
motor in Fig. D-13 (assuming negligible spool inertia) is
dω (t ) KK e (t )K i
Jm + Bm + i b ω (t ) = a − Tw (D-6)
dt Ra Ra
7
Average steady-state speed = 7.636 rad/sec
5
Speed (rad/sec)
63.2% of steady-state speed = 4.826 rad/sec
4
0
0 1 2 3 4 5 6 7 8 9 10
Time (sec)
Figure D-19 Open-loop speed response for 2.0 V input (50 percent power).
4
Voltage (V)
2
Slope = 0.249 V/rad/sec
0
0 2 4 6 8 10 12 14 16 18 20
Steady-State Speed (rad/sec)
2Ki
ω fv = limω (t ) =
t →∞ K i K b + Ra Bm (D-7)
As a result, we can calculate Bm experimentally, at steady state, using
2K 1
Bm = i − K i K b
ω fv Ra (D-8)
2(0.25) 1
= − (0.25)2 =1.31 × 10−3 N ⋅ m/s
7.636 2.27
To measure the viscous-friction coefficient, apply a step input—in this case 2 volts—to
the motor, using the procedure outlined earlier in back-emf constant measurement section,
and observe the open-loop speed response, as shown in Fig. D-19. Record the steady-state
speed—in this case 7.636 rad/s—and substitute the values in Eq. (D-8), as shown.
Alternatively, using the mechanical equation of the motor, and replacing the motor
torque with armature current using Eq. (D-3), we have
dω (t )
Jm + Bmω (t ) = K iia − TW (D-9)
dt
Hence, the viscous-friction coefficient at steady-state angular speed can also be meas-
ured using
Ki T
Bm = ia − W (D-10)
ω fv ω fv
Using the no load case (TW = 0), from Table D-5 the no load armature current ia = 0.041
A, and we can calculate Bm experimentally to be
Ki (0.41)(.25)
Bm = ia = = 0.001342 N ⋅ m/s (D-11)
ω fv 7.636
The no load value of current is what the motor needs to overcome internal friction.
You can also obtain the viscous-friction coefficient for different load torque values
using Eq. (D-11) and Table D-5, provided that you have the corresponding steady-state
angular speed for each TW. Constructing the motor speed-torque curve, as in Fig. D-21,
will help you with this task. You can experimentally obtain this curve using the same proce-
dure as in Ki calculation that was discussed earlier in this section. In Fig. D-21, the relation
between angular speed and torque is
ω fv = −63.63Tm + ω fv (noload )
= −63.63K iia + 7.636 (D-12)
From Table D-5 and Eqs. (D-10) and (D-12), the average value of viscous-friction
coefficient Bm = 1.36 × 10-3 N ⋅ m/s.
8
No Load Speed
7
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Moto Torque (Nm)
Caution: the value of Bm varies with the power provided to the motor. In our case we
have calculated the viscous damping coefficient at power equal to 50 percent. Upon appli-
cation of different percentage of power to the motor, we can find a relationship between
viscous-friction coefficient and percentage of motor power. As shown in Fig. D-22 the
viscous-friction coefficient value decreases as the motor power increases. In this project,
therefore, the lower value of viscous-friction coefficient of the NXT motor with no load was
adopted—i.e., Bm = 1.31 × 10-3 N ⋅ m/s.
The experiment was repeated with the arm attached to the motor and the equivalent
motor-payload viscous-friction coefficient was experimentally measured using Eqs. (D-8)
and (D-11) to be B = Bm + Barm/payload = 2.7 × 10−3 N ⋅ m/s. The higher value of B in this
case amounts to the higher initial torque required to overcome the higher internal fric-
tion associated with moving the arm/payload system. Please note that this measurement
required the robot arm to rotate with the payload attached for about 10 s. In most practical
0.007
0.006
Viscous Damping Bm (N/s)
0.005
0.004
0.003
0.002
0.001
0
0 0.2 0.4 0.6 0.8 1
Power provided to the motor (1 = 100%)
Figure D-22 Measured damping coefficient as the power supplied to the motor varies from 10 to
100 percent.
applications, this approach, while simple, may not be feasible. The alternative approach may
be to use the position control response to obtain or fine tune the value of B.
In the end, it is recommended that the no load motor is operated at 40 percent or higher
motor powers. For the setup with the robot arm and payload, a minimum of 60 percent
motor power is recommended.
Mechanical Time Constant
As discussed earlier in this appendix, the mechanical time constant tm is defined as the
time required for the motor speed to reach 63 percent (more accurately 63.2 percent)
of its final value for a step input. To measure the time constant, you will be required to
use the open-loop speed response experiment described earlier in back-emf calculations.
First, ensure there is no external load connected to the motor. Next, apply a step input to
the motor using the model shown in Fig. D-19 and plot the resulting response. Find the
average steady-state speed and calculate 63.2 percent of the steady-state speed as shown
in Fig. D-19.
In this trial, the average steady-state speed is measured to be 7.636 rad/s while
63.2 percent of the steady-state speed (to measure the time constant) is calculated to be
4.826 rad/s. The mechanical time constant for the NXT motor with no load was experi-
mentally measured to be τm = 0.081 s. The experiment was repeated with the robotic arm
and the time constant was experimentally measured to be τm = 0.10 s—obviously the slower
response is due to a higher inertia added through the payload.
Moment of Inertia
The combination armature-load moment of inertia Jm can be experimentally calculated
using
KK
J m = τ m Bm + i b (D-13)
Ra
where this equation relates the overall motor-gear-train moment of inertia to the other
parameters found in the previous sections. Applying Eq. (D-13) and substituting the
parameters found in previous sections, the moment of inertia of the motor-gear-train is
experimentally calculated to be Jm = Jmotor + Jgear = 2.33 × 10−3 kg·m2.
As a final check, for the no load motor with speed response shown in Fig. D-19, after
reaching the final speed value, turn off the input and record how the speed decays with time
to reach zero, as shown in Fig. D-23. The system equation with power off is
dω (t )
Jm + Bmω (t ) = Tm (D-14)
dt
where, the time constant of the system in this case is τ = J m Bm. Based on our estimated
values of Jm and Bm the system time constant is τ =1.78 s, which is very close to the measure
value of τ =1.68 s, shown in Fig. D-23.
As a result, we have a very high confidence on the accuracy of our estimated param-
eters of the system.
Similarly, the moment of inertia of the motor with the arm attached and the payload is
experimentally calculated to be Jtotal = Jm + Jgear + Jarm/payload = 3.02 × 10−3 kg·m2. Note the total
inertia was obtained using Eq. (D-13) with τm = 0.10 and B = Bm + Barm/payload = 2.7 × 10−3.
Alternatively, you can calculate the arm/payload inertia by first identifying the com-
bined mass center using techniques such as parallel axis theorem that you have learned in
your second year dynamics course (or through using a CAD software). Then, by measuring
10
Average Max Speed
8
4
Time constant 37% of
2 Average Max = 1.68 seconds
–2
0 5 10 15 20
Time (seconds)
Figure D-23 Time constant measurement with the motor input off after reaching steady-state response.
2
the mass of the arm/payload, you can estimate J arm/payload = M arm/payload rcm . This approach
assumes the arm/payload system as a point mass M at a distance rcm away from the axis of
rotation. You may, however, find this a bit time consuming. It all depends on how much
time you plan to spend on finding an approximate model. In practice, good enough is good
enough!
Input
To Workspace1
1 1
+– Ki +– Output
L.s+R J.s+b
Step Electrical Motor Gain Mechanical To Workspace
Step Disturbance
(N.m) Scope
Kb
Motor Feedback
7
Steady-state speed = 7.639 rad/sec
6
Angular Speed (rad/s)
0
0 1 2 3 4 5
Time (seconds)
Simulink model. After running your Simulink simulation, use the following MATLAB
commands to plot the response:
plot(output.time,output.signals.values)
hold on;
plot(input.time,output.signals.values)
In order to further verify the model with the arm attached, it is recommended that you
look at the position control response, discussed next.
Input
To Workspace1
1 1 1 Output
–K– +– KP +– Ki ++ s –K– Output
L.s+R J.s+B
Step Deg to Rad Gain Electrical Motor Gain Mechanical Integrator Rad to Deg To Workspace
Input
Step Disturbance
(N.m) Scope
Kb
Motor Feedback
Figure D-26 Closed-loop position control Simulink model for a dc motor simulation.
stay within the voltage range (~±4.5 V) of the motor measured in Sec. D-1-3. The current
saturation block role will be to limit the current to stay within the current range of the
motor (~±1 A). See the next section for the corresponding screenshots and block descrip-
tions. All other motor parameters, in the model in Fig. D-26, have been derived in the pre-
vious sections, and are shown in Table D-5. Comparing this model to the standard position
control block diagram of a dc motor, shown in Fig. 7-19, you can see the Simulink model
is very similar. Note, in this case, the sensor gain of Ks = 1, has been used—this implies the
sensor has been calibrated so that 1 rad at the output is 1 V.
In the case of position control, the Gain block “KP” controller values correspond to
proportional controller KP. To select the controller gain, simply double-click the Gain block
“KP” and enter the designated values, or as done here, assign a parameter “KP” to the block
and enter its value in the MATLAB Command Window before running your simulation.
The position control Simulink model used for the actual NXT motor is shown in
Fig. D-27. In this model, the NXT motor takes inputs from −100 to 100 percent, which cor-
respond to the percent of maximum voltage. The “Volt to Volt%” block converts voltage to
voltage% by multiplying the input voltage by a factor of 100%/4.5 V. The “Saturation” block
ensures that the maximum 100 percent power input to the motor is not exceeded. Again, to
be consistent, in your simulation model in Fig. D-26, you could include the input voltage
LEGO
+– –K– –K– PID
Step Input Transport Deg to Rad Volt to PID Saturation Port A
Delay Volt% Controller Motor
Encoder
LEGO
Port A
Output
To Workspace
Figure D-27 Closed-loop position control Simulink model for NXT motor.
200
KP = 2.5
KP = 5
150
Position (deg)
KP = 1.5
100
50
0
0 0.5 1 1.5 2 2.5 3
Time (seconds)
Figure D-28 Simulated no-load closed-loop position response results for multiple KP gains.
and the current saturation blocks, as shown earlier in Fig. D-5. However, our observation
was that without them, the motor current and applied voltage values remains within these
thresholds.
See the next section for the corresponding screenshots and block descriptions. In both
Figs. D-26 and D-27, the parameters of the PID controller can be customized to tune the
position response.
No-Load Position Response
Using the model shown in Fig. D-26, the closed-loop position response of the motor with
no load is simulated for a step input of 160° or 5.585 rads. The results are shown below in
Fig. D-28 for multiple KP gains in the PID block.
Next, the closed-loop position response of the NXT motor is found using the Simulink
model shown in Fig. D-27. The results are shown in Fig. D-29 for multiple KP gains in the
PID block.
Both the model response and actual motor response performance specifications are
measured and tabulated in Table D-7. By analyzing the results in Table D-7, the system
model matches the behavior of the actual motor, and no further fine tuning is necessary.
200
KP = 2.5
KP = 5
150
Position (deg)
KP = 1.5
100
50
0
0 0.5 1 1.5 2 2.5 3
Time (seconds)
Figure D-29 NXT motor no-load closed-loop position response results for multiple KP gains.
200
KP = 3
KP = 5
150
Position (deg)
KP = 2
100
50
0
0 0.5 1 1.5 2 2.5 3
Time (seconds)
Figure D-30 Robotic arm with payload closed-loop position response results for multiple KP gains.
200
Experiment
150
Position (deg)
Simulation
100
50
0
0 0.5 1 1.5 2 2.5 3
Time (seconds)
Figure D-31 Comparison of simulated and experimental robotic arm with payload closed-loop
position response for KP = 3.
constant τ e = La /Ra = 0.002 s is very small. Hence, similar to Example 7-5-1, the simplified
closed-loop transfer function is
K P Ki K s
Θarm/payload (s ) Ra J total ω n2
= = 2 (D-15)
K P K i K s (s + 2ζω n s + ω n )
2
Θin (s ) 2 Ra B + K i K b
s + s+
Ra J total Ra J total
where Ks is the sensor gain, calibrated to Ks = 1. Since Eq. (D-15) is a second-order system,
we have
R B + Ki Kb
2ζω n = a
Ra J total (D-16)
K P Ki
ωn = (D-17)
Ra J total
Ra B + K i K b
ζ= (D-18)
2 K P K i Ra J total
Considering Eqs. (D-17) through (D-19), and using the parameter values in Table D-8 and
KP = 3, we have
Further, upon examining Fig. 7-18, which describes the effects of moving a second-
order system poles (in the s-plane) on its time response performance, moving the two poles
in Eq. (D-23) horizontally to the left should increase z while reducing system overshoot,
rise time and settling time. To do so the first term in Eq. (D-23) should increase while the
second term should be held a constant. Having these two conditions met simultaneously
may be a tedious task. So without bothering with rigorous mathematical expressions, we
resort to trial and error and reduce the value of Jtotal while checking the overall response.
Alternatively, you can vary B or both Jtotal and B, simultaneously. Variation of Jtotal seems to
be the best choice for fine tuning, as our confidence levels for Jtotal was not high, see discus-
sions in Sec. D-1-4.
The best response for KP = 3 may be achieved for Jtotal = 0.00273 kg·m2, as shown in
Fig. D-32. For this parameter choice from Eqs. (D-17) to (D-19), we have
ζ = 0.503 (D-24)
s1,2 = −5.54 ± j 9.03
(D-25)
where the poles in Eq. (D-25), in comparison to Eq. (D-22) have moved to the left while
both z and wn have increased. From Eq. (7-42), the PO is expected to decrease. Also from
200 KP = 3
180 KP = 5
160
140
Position (deg)
120 KP = 2
100
80
60
40
20
0
0 0.5 1 1.5 2 2.5 3
Time (seconds)
Figure D-32 Simulated robotic arm with payload closed-loop position response results for multiple
KP gains.
Eqs. (7-46) and (7-50), the rise time and settling times are also expected to decrease. For the
second-order model using performance specification formulas, we get
1−ζ 2
percent maximum overshoot =100e − πζ / =16 (D-26)
π
t max = = 0.33 s (D-27)
ωn 1−ζ 2
1 − 0.4167ζ + 2.917ζ 2
tr = = 0.14 s (D-28)
ωn
3.2
5 percent settling time: t s ≅ = 0.58 s (D-29)
ζω n
The performance specifications of the system, shown in Table D-9, for KP = 3 are
in line with these expectations. The minor discrepancies between the calculated values,
Eqs. (D-27) and (D-28), and the simulation measurements (using the “Data Cursor” in
MATLAB figure) in Table D-9 are obviously attributed to the differences between the
second- and third-order models—the Simulink simulation results do not omit the electric
time constant. Note also since our system is nonlinear in reality, we should not expect the
simulation response to closely match that of the experiment for other controller gain values.
From Table D-9, we see this is in fact the case.
Do not forget that the PO for the experimental system is measured from the response
final value, using Eq. (7-41). For example for KP = 2, the NXT motor (with arm and payload)
response final and peak values are at 164° and 167°, respectively. So
167 − 164
PO =100 =1.8 (D-30)
164
At this point you may wish to further fine tune system parameters, or decide that the
model is good enough. For all practical purposes, the parameter values shown in Table D-10
appear reasonable, and we should stop the fine tuning process.
In the end, now that we have a good enough model of the system, we can design dif-
ferent type of controllers for this system. In Chap. 8, we will provide labs that allow you to
TABLE D-9 Robotic Arm Closed-Loop Position Response Performance Specification Comparison
Percent
KP Overshoot Settling Time (5%) (s) Rise Time (s)
Simulated position response Gain = 2 8 0.61 0.22
Gain = 3 13 0.55 0.19
Gain = 5 19.4 0.68 0.18
further compare the real-life motor characteristics with simulation using MATLAB and
Simulink software. We also revisit the NXT motor in Chap. 11, where we study more com-
plex controller design techniques.
NXT Motor
Elevator Frame
Thread
Simulink Control Model
Elevator Car
NXT Brick
Up Touch
Sensor
Down Touch
USB Interface Cable Sensor
Host Computer
(a) (b)
(c) (d)
Figure D-34 (a) The top view of the elevator model. (b) The elevator car. (c) The front view of the
elevator model. (d) The side view of the elevator model.
move up by one floor, and to move down, the lower sensor is used. There are seven floors in
the elevator model—floor 0 to 6, each 5 cm high. The elevator car should stop when the yel-
low measuring pole reaches the yellow labels, as shown in Fig. D-34b. A laptop computer is
used to program the system using Simulink. The programs can be uploaded on to the NXT
brick via USB interface—see NXT brick description in the previous section. Figure D-34
provides different views of the system.
A complete set of instructions for this section can be found at www.mhprofessional
.com/golnaraghi.7
Objective. The elevator must move up 5 cm once the upper touch sensor is pushed, and
down by 5 cm once the lower touch sensor is pushed.
7
For an instructional video, also visit http://www.youtube.com/watch?v=7A4CskIYTZg.
Design criteria. The initial elevator car position is zero—the ground floor. The elevator
car is then to move to various floors and come back. The elevator car may not overshoot the
desired position by more than 5 percent. The steady-state error should be less than 1 mm.
The 5 percent settling time should be less than 1 s.
La dT (t ) K K K dθ (t )
+ T (t ) = i ea (t ) − i b
Ra dt Ra Ra dt (D-31)
d 2θ (t ) 1 1 B dθ (t )
= T (t ) − TL (t ) −
dt 2 J total J total J total dt (D-32)
2
J total = Mrspool + J m (D-33)
In the elevator model in Eq. (D-32), gravity applies a constant disturbance torque TL,
which can be calculated using
where, spool radius rspool is 1.375 cm, gravitational acceleration is 9.81 m/s2 and the mass of
the elevator car is 124 g. Note that this model is identical to the far simpler system earlier
shown in Fig. D-33.
Practical Observation
Obviously the elevator system in Fig. D-34 has a greater level of complexity, which our
idealized mathematical model in Eqs. (D-31) and (D-32) do not consider. For example
since the elevator car and the frame are in contact, friction is a parameter that is expected
to play a significant role in the elevator system behavior in comparison to the motor-mass
system in Fig. D-13. But we need to start from somewhere, and keeping our model as sim-
ple as possible is a good starting point.
Using Eq. (D-33) the total inertia of the system can be calculated as
TABLE D-11 The Elevator and NXT Motor System Estimated Parameters
Armature resistance Ra = 2.27 Ω
Armature inductance La = 0.0047 H
Motor torque constant Ki = 0.25 N · m/A
Back-emf constant Kb = 0.25 V/rad/s
Equivalent viscous-friction coefficient B = 0.002 N · m/s
Mechanical time constant τm = 0.08 s
Combined motor and gear-train moment of inertia Jtotal = 0.0024 kg·m2
Torque from gravity of elevator car TW = −0.017 N · m
Finally, using Eq. (D-10), we find B = 0.0018 N·m/s. Obviously the damping in the elevator
system is going to be higher (or much higher!) than the system in Fig. D-13. To account for
this, we arbitrarily increased our estimated value to B = 0.002 N·m/s.
We now use the position response of the system to fine tune this parameter. Table D-11
summarizes the values we will be using in our simulations.
To Workspace1
1 1 1
+ –K– + PID + Ki + –K– Output
– – – L.s+R + J.s+b s
Step Up Hight to Rad PID Controller Input Current Motor Gain Integrator Rad to Height To Workspace
Electrical Mechanical
Voltage Saturation
Saturation
Step
Disturbance DC Motor Position Control
(N.m) Simulink Block Diagram
Step Down
Double-click on the
Kb DC motor block to modify
the motor parameters.
Motor feedback
Scope1
Figure D-35 Closed-loop position control Simulink model for the elevator system.
D-33
07/02/17 5:28 PM
D-34 Appendix D. Control Lab
P
Proportional
I +
1 s + 1
+
In_1 Out_1
Integral Sum
D du/dt
D Derivative
P
Kp out
I 2
Ki out Parameters
D
(a) Kd out (b)
Figure D-36 (a) The PID controller diagram obtained from “Look Under Mask” in the PID block in
Fig. D-35. (b) Parameter values of the PID block in Fig. D-35.
from Table D-11. Be sure to enter the system parameters in the MATLAB Command
Window before running your Simulink simulation. The entered parameters must have
exact names as those used in the Simulink model (i.e., L, R, J, b, Ki, Kb, and KP).
Run the total simulation for 4 s, and plot the results by using the following commands
in the MATLAB Command Window:
plot(output.time,output.signals.values)
hold on
plot(output.time,input.signals.values)
We can now check the validity of these results by comparing the simulated position
response to the position response of the actual motor. The system time response is shown in
Fig. D-40, and the time response performance specifications are documented in Table D-12.
The performance values shown were measured using the “Data Cursor” under the “Tool”
menu in the MATLAB figure environment.
The position control Simulink model used for the actual NXT motor is shown in
Fig. D-41. In this model, the NXT motor takes inputs from −100 to 100 percent, which
6
KP = 5
5
KP = 3
4
KP = 2
Height (cm)
–1
0 0.5 1 1.5 2 2.5 3 3.5 4
Time (seconds)
Figure D-40 Simulated elevator model closed-loop position response results for multiple KP gains.
TABLE D-12 Simulated Elevator Closed-Loop Position Response Performance Specifications for Different KP Values
Elevator Car Position Percent Settling Time Steady-State
Response Overshoot (5%) (s) Rise Time (s) Error (cm)
Move upward KP = 2 5.9 0.37 0.25 0.1
KP = 3 9.5 0.52 0.23 0.07
KP = 5 13.8 0.51 0.22 0.04
LEGO
+– +– –K– –K– PID(s)
Step Up Height to Volt to PID Saturation Port A
Rad Volt% Controller Motor
LEGO
–K–
Step Port A
Deg to Height
Down
Output
To Workspace
Figure D-41 One-step closed-loop position control Simulink model for NXT motor.
correspond to the percent of maximum input voltage. The “Volt to Volt%” block converts
voltage to voltage% by multiplying the input voltage by a factor of 100%/4.5 V, as shown in
Fig. D-42. The “Saturation” block ensures that the maximum 100 percent power input to
the motor is not exceeded.
In Fig. D-41, we apply a step input of 5 cm starting at 2 s and a second step input
of −5 cm starting at 4 s (both inputs have 2 s duration), to arrive at the system time
response. The response of the system was obtained for three proportional gain values of
6
KP = 5
5 KP = 3
4 KP = 2
Height (cm)
3
–1
1 2 3 4 5 6
Time (seconds)
Figure D-43 NXT motor closed-loop position response for different KP.
TABLE D-13 NXT Motor Closed-Loop Position Response Data for Different KP
Elevator Car Position Percent Settling Time Steady-State
Response Overshoot (5%) (s) Rise Time (s) Error (cm)
Move upward KP = 2 0 0.39 0.24 0.15
KP = 3 5.8 0.31 0.22 −0.015
KP = 5 11.7 0.47 0.21 0.08
KP = 2, 3, and 5. The system time response is shown in Fig. D-43, and the time response
performance specifications are documented in Table D-13. The performance values
shown were measured using the “Data Cursor” under the “Tool” menu in the MATLAB
figure environment.
Comparing the values in Tables D-12 and D-13, it is interesting to see that our simu-
lation model parameters are not too far off, and our model does a relatively good job in
predicting the response of the actual system. We will therefore stop the fine tuning process
at this stage. To further increase your model accuracy, you may wish to increase the value
of B to reduce the overshoot values of the simulation system.
6
KP = 2, KI = 0.1
5 KP = 2, KI = 0.2
KP = 2, KI = 0.3
4
Height (cm)
3
1
X: 5.67
0 Y: –0.2399
–1
1 2 3 4 5 6
Time (seconds)
Figure D-44 NXT motor closed-loop position response for KP = 2 with different KI values.
TABLE D-14 NXT Motor Closed-Loop Position Response Performance Specifications for KP = 2 with Different
KI Values
Elevator Car Position Percent Settling Time Rise Steady-State
Response Overshoot (5%) (s) Time (s) Error (cm)
Move upward KI = 0.1 0 0.35 0.25 0.01
KP = 2 KI = 0.2 0 0.36 0.25 0.03
KI = 0.3 0.5 0.37 0.25 0.08
Move downward KI = 0.1 0.47 0.58 0.25 0.24
KP = 2 KI = 0.2 0.46 0.58 0.24 0.24
KI = 0.3 0.46 0.59 0.24 0.24
6
5
4
Height (cm)
3
2
1
0 KP = 5, 40% power
KP = 5, 60% power
–1 KP = 5, 80% power
–2
1 2 3 4 5 6
Time (seconds)
Figure D-45 NXT motor closed-loop position response for KP = 5 with different power.
TABLE D-15 NXT Motor Closed-Loop Position Response Performance Specifications for KP = 5 with Different Power
Elevator Car Position Percentage Percent Settling Time Rise Steady-State
Response Power (%) Overshoot (5%) (s) Time (s) Error (cm)
LEGO LEGO
K Ts
+ + –K– –K– PID(s)
z-1 – –
Port 1 Discrete-Time Height Height Volt to PID Controller Saturation
Port A
Touch Sensor Up Up Integrator Saturation to Red Volt% Motor
Encoder
Deg to Height
LEGO LEGO
K Ts
–K–
z-1
Port 2 Discrete-Time Port A
Touch Sensor Down Down Integrator
Output
To Workspace1
Figure D-46 Touch sensor closed-loop position control Simulink model for NXT motor elevator
system.
in both cases to 0.01 s. As shown in Fig. D-48, we used a height saturation block, set to 0 to
30 cm, for safety reasons.
A discrete time integrator has also been added to both up and down touch sensors—
this is outside the scope of this appendix, but necessary for proper system operation. The
sample time for this block is set to 0.5 s, and the gain value is 10, as shown in Fig. D-49. As
a result, to move up or down you must press the respective buttons for less than 0.5 s. If you
push the up or down touch sensors longer than 0.5 s, the elevator will move 10 cm at a time,
which is two floors.
The other blocks have been discussed earlier in this section.
Finally, Fig. D-50 shows position response of the elevator model, for KP = 5 with 40 percent
power, using touch sensor to move up and down.
8
See instructional video on SIMLab and LEGOLab, Interfacing with LEGO MINDSTORMS NXT Using MATLAB
and Simulink, Part 2, at http://www.youtube.com/watch?v=yiiWGh9XSgY.
35
30
25
20
Height (cm)
15
10
–5
0 5 10 15 20 25 30 35
Time (seconds)
Figure D-50 NXT motor elevator system closed-loop position response for KP = 5 with 40 percent
power.
To launch the ACSYS9 applet, navigate to the appropriate directory in the MATLAB
command window, and type Acsys at the command prompt. The SIMLab or LEGOLab
experiment windows can be called from the ACSYS applet by clicking on the appropriate
button.
When SIMLab or LEGOLab is opened, the experiment control window will be
displayed. The Experiment menu can be used to switch between different control experi-
ments, as in Fig. D-52. The grey control panel on the left contains the control buttons for
the experiment. Every experiment has a button to enter model parameters, a field to enter
simulation time, and additional experiment-specific plot controls.
Once the model parameters have been entered and the simulation executed, the
plots or animations that the experiment supports appear in the display panel on the right.
Figure D-53 shows a typical experiment control window in SIMLab.
SIMLab allows you to display the motor transfer functions in various formats and
to access other custom tools from the SIMLab Tools dropdown menu. For step-by-step
instructions on using the experiment window, click on the Help Me button in the menu
bar. The standard Microsoft Windows calculator and a unit conversion tool can be accessed
from the top menu.
The model parameters must be set first in any experiment. By selecting the Enter Model
Parameters button, a Simulink (.mdl) window containing the model for the experiment will
be launched. The model, shown in Fig. D-54, contains a simple closed-loop system using
PID speed control, with a reference step input and multiple outputs.
All the simulation parameters for the Simulink model are pre-set. Selecting Simulation
from the Simulink menu and next choosing Configuration Parameters allows access to
these settings, shown in Fig. D-55. The Start Time and Stop Time settings in the Solver
options are most important as far as SIMLab and LEGOLab examples are concerned,
and they can be manipulated in Configuration Parameters, or on the left panel in the
SIMLab/LEGOLab interface. They allow you to modify the simulation running time.
Other options in Configuration Parameters should not be modified, as they may cause
errors in the SIMLab and LEGOLab software.
When the Simulink model is opened, double-click on the appropriate model block
to modify model parameters such as the PID values. For SIMLab, double-clicking on the
motor block brings up a window containing a list of adjustable motor parameters (see
Fig. D-56). All motor parameters, such as the resistance, back-emf constant, load inertia,
and damping coefficient, may be modified. By default, the parameters are set to the NXT
dc motor parameters, but may be changed to model a different motor. Right-clicking on a
SIMLab motor block and selecting Look under Mask makes the dc motor model available.
However, the LEGOLab motor blocks are completely opaque to the user since they use
an actual dc motors. One other feature that SIMLab has, which LEGOLab does not, is a
torque-disturbance input into the motor. This can be used to investigate the stall torque
and the effect of an integral controller on disturbance or steady-state error elimination (see
Sec. 7-7, Fig. D-2, or Chap. 11 for more details).
To run the simulation in SIMLab, close the Simulink model and click the button labeled
Run Simulation. The Print to Figure button allows the current response plot to be sent to a
separate MATLAB figure. To read values from the figure, click on the Data Cursor button
above the MATLAB figure, and then on the appropriate curve. For a finer reading, you can
right-click on the figure and change the Selection Style to “Mouse Position.” This figure can
also be saved as a .fig or image file for future reference and analysis. Again, in the LEGOLab,
you cannot change the system parameters, but PID controller box values are available for
modification. To run the simulation in LEGOLab, follow the instructions shown in the
Simulink model file.
Some of the experiments have additional features, such as animation and calculation
tools. These are discussed in the following sections. Selecting Close Experiment in the con-
trol window exits the current experiment.
AK i − t /τ
ω m (t ) =
10
(1 − e m ) (7-15)
K i K b + Ra Bm
motor may also be saturated. To create these effects in software, right-click the dc motor
block and select Look under Mask to obtain the motor model shown in Fig. D-58. Double-
click both the voltage and current blocks and adjust their values (default values of ±4.5 V
and ±1 A have already been set). If you do not wish to include saturation, you can set the
limits very large (or delete these blocks altogether). Run the above experiments again and
compare the results.
Assuming a small electric-time constant, we may model the dc motor as a first-order
system. As a result, the motor inertia and the viscous-damping friction could be calculated
with measurements of the mechanical-time constant using different input magnitudes. For
a 3-V step input, the open-loop speed response is shown in Fig. D-59. After measuring the
mechanical-time constant of the system τm, you can find the inertia Jm, assuming all other
parameters are known. Recall that for a first-order system, the time constant is the time to
reach 63.2 percent of the final value for a step input—verify using Eq. (7-15).11 In Fig. D-59,
the steady-state velocity and the time constant τm can be found from the time-response plot
by using the cursor.
AK i − t /τ
11
ω m (t ) = (1 − e m ) (7-15)
K i K b + Ra Bm
1 1
1 1 +– K– ++ 1
J.s+R J.s+b
In Out
Input Amplifier Electrical Current Motor Gain Mechanical
Voltage Gain Saturation
Saturation 2
Disturbance
Kb
Motor feedback
Figure D-59 Speed response of the open-loop system (SIMLab) for input voltage of 3 V.
In SIMLab, the disturbance torque default value is set to zero. To change an input value,
simply change its final value.
Now that you have gained insight into the motor speed response, it is time to apply your
knowledge to test the LEGO experiment. Here you have no access to the system parameter
values. Use the LEGOLab to test the following:
7. Apply step inputs of +1 V, +3 V, and −2 V. How different are the results from Step 1?
8. From the transient and steady-state responses, identify the system model as closely
as possible.
In this experiment, we use the open-loop model represented in LEGOLab Experiment
3: Open-Loop Speed. The Simulink system model is shown in Fig. D-60, representing a
simple open-loop model with a motor speed output.
Recall that the motor and amplifier have built-in nonlinear effects due to noise, friction,
and saturation. So in Step 8, your model may vary for different input values. You will also
notice the step input begins at 1 s rather than 0 s. This is due to data sampling limitations
on the NXT motor, therefore take all measurements from time = 1 s rather than time = 0 s.
In addition, distorted values may be obtained if the input to the motor is excessive and
saturates. Caution must be taken to ensure that the motor input is low enough such that this
does not happen. Use the mechanical time constant and final value of the response in this
case to confirm the system parameters defined in Table D-5. These parameters are needed
to conduct the speed- and position-control tasks.
Figure D-61 shows the LEGOLab motor speed response to a 3-V step input. The friction
effect is observed when the motor starts. Noise at steady state may also be observed, which
is due to a low sampling rate and encoder measurement limitations. When measuring the
steady-state speed, take the average speed observed in noisy areas. Note that for higher
input magnitudes, the response will saturate at the motor’s maximum speed.
12
You can use this tool to conduct an experimental frequency response study of the system—this concept is dis-
cussed in Chap. 10.
The frequency of the sine wave will dictate the gain and phase of the response curve.
There is a Gain and Phase Calculator in the Experiment 4 control window. To measure the
magnitude and phase of the steady-state response, enter a frequency of 1 rad/s in the edit
block. Entering the input frequency and clicking on Calculate displays the gain and phase of
the system. Using the Gain and Phase Calculator, you can record the gain and phase of the
response. Repeat with other input frequencies, and discuss any trends.
Figure D-64 SIMLab time response and gain and phase calculation for input = 2 sin(t).
Figure D-65 LEGOLab time response and gain and phase calculation for input = 2 sin(t).
Figure D-66 SIMLab time response and gain and phase calculation for input = 10 sin(t).
Figure D-67 LEGOLab time response and gain and phase calculation for input = 10 sin(t).
Figure D-69 SIMLab speed-control response for −10 rad/s input and proportional gain = 0.5.
For a given input to change the proportional gain values, enter the following sets of PID
values and print all three plots.
P = 0.1 I = 0 D = 0
P = 0.5 I = 0 D = 0
P = 1 I = 0 D = 0
Figure D-71 LEGOLab speed-control response for −10 rad/s input and proportional gain = 0.5.
21. Design a PI controller that will give a 30 percent overshoot and a rise time of
0.1 s. What is the maximum step input amplitude that will meet these calculated
requirements (i.e., not cause the amplifier to saturate), given the default current
and voltage saturation limits of ±1 A and ±4.5 V, respectively.
22. In all previous cases, comment on the validity of Eq. (7-53).13
Open Experiment 2: Position Control from the SIMLab Experiment menu. A screen
similar to Fig. D-52 will be displayed. Next, select Enter Model Parameters to get the system
Simulink model, as shown in Fig. D-72. This model represents a simple PID position-
control system. Double-clicking on the PID block allows you to edit the PID gain values.
The values of the step-input and the disturbance-torque blocks are also adjustable. The
disturbance-torque default value is set to zero. To change an input value, double-click on
the relevant block and change the number in the final value field. Figure D-73 the SIMLab
position response for a 160° and proportional gain of 1.5.
The position time response is also animated when the simulation is run. This is a useful
tool that gives the user a physical sense of how a real motor turns. The time, input-angle,
and output-angle values are displayed on the animation field, as shown in Fig. D-73.
The nonlinearities due to voltage and current limits cause the time response to saturate
at a high enough proportional gain. The maximum speed and acceleration of the dc motor
are dictated by the voltage and current saturation limits.
23. For proportional gains of 1.5, 2, and 5 (requires modification of PID block
parameters), repeat Step 16 using LEGOLab.
KK i K s
13 Θm ( s ) Ra J ω n2
(7-53)
= = 2
Θin (s ) R B + Ki Kb KK i K s ( s + 2ζω ns + ω n )
2
s2 + a m s +
RJ a RJa
Figure D-73 SIMLab position response for 160° and proportional gain of 1.5.
Figure D-75 LEGOLab position response for 160° and proportional gain of 1.5.
Design criteria. The arm is required to move in only one direction from the initial
position. The hole location may be anywhere within an angular range of −90° to +90° from
the initial position. The arm may not overshoot the desired position by more than 5°. A
tolerance of ±3 percent is acceptable (settling time). These criteria may easily be altered to
create a new scenario.
The objective may be met by looking at the settling time as a key design criterion.
However, you may make the design challenge more interesting by introducing other design
constraints such as the percent overshoot and rise time. In SIMLab, you can also introduce
a disturbance torque to alter the final value properties of the system. The LEGOLab system
contains nonlinear effects that make the controller design more challenging. You may try
to confirm the system model parameters first, from earlier experiments. It is highly recom-
mended that you do the design project only after fully appreciating the earlier experiments
in this appendix and after understanding Chap. 7. Have fun!
This experiment is similar to the position-control experiment in some respects. The idea
of this experiment is to get an object held by a robotic arm by an electromagnet from posi-
tion 0° to a specified angular position with a specified overshoot and minimum overall time.
Select Experiment 5: Control System Design from the SIMLab Experiment menu. A
screen similar to Fig. D-52 will be displayed. Next, select Enter Model Parameters to get
the system Simulink model, as shown in Fig. D-76. As in Sec. D-5-1, this figure represents
a simple PID position-control model with the same functionalities. Double click on the
DC Motor block to edit the model parameters. By default, they are set to the robotic arm
parameters as shown in Fig. D-76.
The added feature in this model is the gripper control. By double-clicking the
Gripper Control block, a parameter window pops up, as in Fig. D-77, which allows the
user to adjust the drop-off payload location and the time delay (in seconds) to detach
after reaching the target. This feature is particularly useful if the response overshoots and
passes through the target more than once. So, in Fig. D-78, the “Drop position angle” is the
angle where the gripper detaches dropping the payload. “Start to wait for drop position at
time” refers to the time where the position trigger starts to wait for the position specified
by “Drop position angle.”
An important note to remember is that in the LEGOLab the gripper will never drop
the object exactly where it is specified due to error in the motor encoder. A SIMLab time
response of the system for proportional gain of 3 is shown in Fig. D-79.
The model response is also animated. This feature makes the simulation more realistic.
In SIMLab, it is possible to change the dimensions of the experiment setup. Choose Modify
Load Drop Setup from the SIMLab Tools menu to adjust the height of the drop and the
length of the arm, and change your controller design accordingly.
Create the test bed shown in Fig. D-1 and try the experiment in LEGOLab and com-
pare the results with SIMLab. Upon opening the experiment in LEGOLab, the Simulink
model in Fig. D-80 will appear. Just like with SIMLab, the drop angle and drop position
time can be edited by double clicking on the Arm/Gripper Control block. A LEGOLab time
response of the system for proportional gain of 3 is shown in Fig. D-81.
D-6 SUMMARY
In this appendix, we described the SIMLab and LEGOLab tools to improve your
understanding of control and to provide a better practical appreciation of the subject. We
discussed that, in a realistic system including an actuator (e.g., a dc motor) and mechanical
(gears) and electrical components (amplifiers), issues such as saturation of the amplifier,
friction in the motor, or backlash in gears will seriously affect the controller design. This
appendix focused on problems involving dc motors including modeling, system identifica-
tion, and controller design. We presented experiments on speed and position control of dc
motors, followed by a controller design projects. In these design projects, aside from the
speed and position control topics, other controllers such as PID may also be utilized. You
may wish to visit Chap. 11 to become more acquainted with these topics.
REFERENCE
Golnaraghi, F., “MSE 312 Mechatronics Design II—Course Project,” Simon Fraser University, School of
Mechatronic Systems Engineering, British Columbia, Canada, Lab Manual, 2012.
PROBLEMS
D-1. Create a model of the motor shown in Fig. D-25. Use the following parameter values:
Jm = 0.0004 kg·m2; B = 0.001 N · m/rad/s, Ra = 2 Ω, La = 0.008 H, Km = 0.1 N·m/A, and Kb = 0.1 V/rad/s.
Assume that the load torque TL is zero. Apply a 5-V step input to the motor, and record the motor
speed and the current drawn by the motor (requires modification of SIMLab blocks by making
current the output) for 10 s following the step input.
(a) What is the steady-state speed?
(b) How long does it take the motor to reach 63 percent of its steady-state speed?
(c) How long does it take the motor to reach 75 percent of its steady-state speed?
(d) What is the maximum current drawn by the motor?
D-2. Set the viscous friction B to zero in Prob. D-1. Apply a 5-V step input to the motor, and record
the motor speed and current for 10 s following the step input. What is the steady-state speed?
(a) How long does it take the motor to reach 63 percent of its steady-state speed?
(b) How long does it take the motor to reach 75 percent of its steady-state speed?
(c) What is the maximum current drawn by the motor?
(d) What is the steady-state speed when the applied voltage is 10 V?
D-3. Set the armature inductance La to zero in Prob. D-2. Apply a 5-V step input to the motor, and
record the motor speed and current drawn by the motor for 10 s following the step input.
(a) What is the steady-state speed?
(b) How long does it take the motor to reach 63 percent of its steady-state speed?
(c) How long does it take the motor to reach 75 percent of its steady-state speed?
(d) What is the maximum current drawn by the motor?
(e) If Jm is increased by a factor of 2, how long does it take the motor to reach 63 percent of its steady-
state speed following a 5-V step voltage input?
(f) If Jm is increased by a factor of 2, how long does it take the motor to reach 75 percent of its steady-
state speed following a 5-V step voltage input?
D-4. Repeat Probs. D-1 through D-3, and assume the load torque TL = −0.1 N·m (don’t forget the
minus sign) starting after 0.5 s (requires change of the disturbance block parameters in SIMLab).
(a) How does the steady-state speed change once TL is added?
(b) How long does it take the motor to reach 63 percent of its new steady-state speed?
(c) How long does it take the motor to reach 75 percent of its new steady-state speed?
(d) What is the maximum current drawn by the motor?
(e) Increase TL and further discuss its effect on the speed response.
D-5. Repeat Probs. D-1 through D-3, and assume the load torque TL = −0.2 N·m (don’t forget the
minus sign) starting after 1 s (requires change of the disturbance block parameters in SIMLab).
(a) How does the steady-state speed change once TL is added?
(b) How long does it take the motor to reach 63 percent of its new steady-state speed?
(c) How long does it take the motor to reach 75 percent of its new steady-state speed?
(d) What is the maximum current drawn by the motor?
(e) Increase TL and further discuss its effect on the speed response.
D-6. For the system in Fig. D-1, use the parameters for Prob. D-1 (but set La = 0) and an amplifier
gain of 2 to drive the motor (ignore the amplifier voltage and current limitations for the time being).
What is the steady-state speed when the amplifier input voltage is 5 V?
D-7. Modify the model in Prob. D-6 by adding a proportional controller with a gain of Kp = 0.1, apply
a 10-rad/s step input, and record the motor speed and current for 2 s following the step input.
(a) What is the steady-state speed?
(b) How long does it take the motor to reach 63 percent of its steady-state speed?
(c) How long does it take the motor to reach 75 percent of its steady-state speed?
(d) What is the maximum current drawn by the motor?
D-8. Change Kp to 1.0 in Prob. D-7, apply a 10-rad/s step input, and record the motor speed and cur-
rent for 2 s following the step input.
(a) What is the steady-state speed?
(b) How long does it take for the motor to reach 63 percent of its steady-state speed?
(c) How long does it take for the motor to reach 75 percent of its steady-state speed?
(d) What is the maximum current drawn by the motor?
(e) How does increasing Kp affect the response (with and without saturation effect in the SIMLab model)?
D-9. Repeat Prob. D-7, and assume the load torque TL = −0.1 N·m starting after 0.5 s (requires change
of the disturbance block parameters in SIMLab).
(a) How does the steady-state speed change once TL is added?
(b) How long does it take the motor to reach 63 percent of its new steady-state speed?
(c) How long does it take the motor to reach 75 percent of its new steady-state speed?
D-10. Repeat Prob. D-7, and assume the load torque TL = −0.2 N·m starting after 1 s (requires change
of the disturbance block parameters in SIMLab).
(a) How does the steady-state speed change once TL is added?
(b) How long does it take the motor to reach 63 percent of its new steady-state speed?
(c) How long does it take the motor to reach 75 percent of its new steady-state speed?
D-11. Insert a velocity sensor transfer function Ks in the feedback loop, where Ks = 0.2 V/rad/s (requires
adjustment of the SIMLab model). Apply a 2-rad/s step input, and record the motor speed and current
for 0.5 s following the step input. Find the value of Kp that gives the same result as in Prob. D-7.
D-12. For the system in Fig. D-3, select Kp = 1.0, apply a 1-rad step input, and record the motor
position for 1 s. Use the same motor parameters as in Prob. D-1.
(a) What is the steady-state position?
(b) What is the maximum rotation?
(c) At what time after the step does the maximum occur?
D-13. Change Kp to 2.0 in Prob. D-12, apply a 1-rad step input, and record the motor position for 1 s.
(a) At what time after the step does the maximum occur?
(b) What is the maximum rotation?
D-14. Using the SIMLab, investigate the closed-loop position response using a proportional control-
ler. For a position-control case, use proportional controller gains of 0.1, 0.2, 0.5, 1, and 2; record the
step response for a 1-rad change at the output shaft; and estimate what you consider to be the best
value for the proportional gain. Use the same motor parameters as in Prob. D-1.
D-15. Using the SIMLab, investigate the closed-loop position response using a PD controller. Modify
the controller used in Prob. D-14 by adding derivative action to the proportional controller. Using the
best value you obtained for Kp, try various values for KD, and record the step response in each case.
D-16. Repeat Prob. D-15 and assume a disturbance torque TD = −0.1 N·m in addition to the step
input of 1 rad (requires change of the disturbance block parameters in SIMLab).
D-17. Repeat Prob. D-15 and assume a disturbance torque TD = −0.2 N·m in addition to the step
input of 1 rad (requires change of the disturbance block parameters in SIMLab).
D-18. Use the SIMLab and parameter values of Prob. D-1 to design a PID controller that eliminates
the effect of the disturbance torque, with a percent overshoot of 4.3.
D-19. Use the SIMLab and parameter values of Prob. D-1 to design a PID controller that eliminates
the effect of the disturbance torque, with a percent overshoot of 2.8.