You are on page 1of 9

Laboratory 1

Position Control of a DC Motor

Motor position control is an essential component to a very wide range of engineering applications.
In this lab you will predict the response of a motor position control system and compare these
predictions to the implementation of a motor position control system on simulated hardware. You will
practice applying the control theory discussed in class, and experience the influence of the proportional,
integral and derivative control gains on the performance of the system.

When designing a controller, we often begin with a model of our system which is based on the
governing differential equations of the system and the specifications for the the hardware that we intend
to use. In Section A of this report, you will establish the necessary models by first establishing the plant
transfer function for the motor, and then establishing the closed loop transfer function of our system
with a PID controller added to the motor.

Next, we would typically create a preliminary design for our controller. For a PID controller this
would include establishing the proportional, integral and derivative gains. After creating our
preliminary design, we would typically simulate the performance of this design by predicting the
output response of the system to a set of input conditions that we are interested in. This step could be
performed by multiplying the reference input by the closed loop transfer function of our system and
using the inverse Laplace transform to see our output response in the time domain. But rather than
performing this step by hand, we could use tools such as Matlab or Simulink to plot this response. We
will be covering the methods for designing controller gains later in this course, so instead of creating
your own preliminary design you will be given several sets of gain values to consider. You will then
need to predict the output response of this system for the provided gain values using Matlab (in Section
B) and Simulink (in Section C).

Finally, the controller design would be implemented on the physical hardware and final
adjustments might be made to the controller design based on the true performance of the system. In
some cases, the final controller design is implemented as a block diagram on the physical hardware of
the system. In Section D of this lab, you will implement the controller design on simulated hardware
using the Quanser QLabs system. Although the QLabs motor is still a simulation, it has been developed
based on the performance data from actual physical hardware and can provide us with a reasonably
accurate representation of how the motor would respond. In Section D of this lab you will implement
the design on the QLabs motor, compare the final results to the Simulink predictions and consider the
effects of changes to the controller gains on the QLabs motor.
Lab Report Requirements:

Your lab report should begin with a very brief introduction, to introduce the DC motor system and
provide a brief summary of the report. Following the introduction, the report should include Sections A,
B, C and D. The focus for each of these sections is discussed within this lab manual. At the end of each
section in this lab manual, you will find a Report Requirements heading where the specific
requirements of each section of the report will be discussed. Finally, your report should include a very
brief conclusion which summarizes the report.

Report Rubric:

Report Section Marks (/36)


Introduction and Conclusion /4
Section A /6
Section B /8
Section C /6
Section D /12
Total /36

Additional information regarding the marks for each aspect of the report are indicated within each of
the sections (A-D) of this lab manual. Each mark category is marked on a 4 point scale which is
defined as follows:

4: Strong work is demonstrated through an exceptionally high quality of work that is well
articulated and demonstrates a deep level of understanding.
3: The work is good and demonstrates a good level of understanding, which meets the
expectations of a competent and skilled engineering student.
2: The work is at the developing level and includes an error or is lacking in depth.
1: The element of the report is needing further work and contains multiple errors, a
fundamental error, or insufficiently addresses the requirements.
0: The element of the report is absent or misaligned with the report requirements.
Section A: Establishing the Transfer Functions

In order to develop a controller for a direct current (DC) motor, we must first establish a transfer
function for the motor. To establish a transfer function for a DC motor, both the electrical and
mechanical aspects of the system must be considered (Figure 1).

Figure 1: DC Motor Representation

The torque developed by a direct current electric motor is dependent on current (i), if it is assumed that
the strength of the magnetic field is constant (Kt).

T =Kt⋅i (Equation 1)

The back-electromotive force (back-emf) is proportional to the angular velocity and the constant Kb.
The motor torque constant (Kt) and the back-emf constant (Kb) have an equal magnitude when using SI
units and will each be referred to as K. Using Kirchhoff’s voltage law and Newton’s 2nd law we can
establish the following governing differential equations:
d2 θ dθ (Equation 2)
J +b =K i
dt 2 dt
di dθ
L +Ri=V −K (Equation 3)
dt dt

where J represents the moment of inertia of the rotor, b represents the motor viscous friction constant,
θ represents the rotor’s angular position, L represents the motor’s inductance, and R represents the
electric resistance.

By applying the Laplace transform to the differential equations we can obtain the following equations
in the Laplace domain:

(J s2+b s )θ (s )=K I (Equation 4)


(s )

(Ls+ R) I (s) =V (s )− K sθ (s )
(Equation 5)
Using these two equations we can establish:
(J s 2 +b s )θ
I(s)=
(s) (Equation 6)
K
V (s)−K sθ(s)
I(s) = (Equation 7)
(Ls +R)

I = s(J s+b)θ(s ) = V (s )−K sθ (s ) (Equation 8)


(s)
K (Ls+ R)

s (J s+b)(Ls+ R)+K 2 s
(Equation 9)
θ(s)=V(s )
K

Therefore, the transfer function relating our output (the angular position of the motor in radians) to our
input (applied voltage) is:
θ(s) K
= (Equation 10)
V (s) 2
s ((J s+b )(Ls +R)+ K )

The parameters for the specific motor that we will be using in this lab are shown below. Please also
note that the maximum voltage (Vmax) that can be applied to this motor is ±10 V.

Kt 0.042 N.m/A
Km 0.042 V/(rad/s)
J 2.52x10-5 kg.m2
b 4.0x10-4 V/(rad/s)
L 1.16x10-3 H
R 8.4 Ω
Vmax ±10 V

Since the motor inductance (L) is much less than the motor resistance (R), we will neglect this term in
order to simplify our analysis. Similarly the friction (b) of the motor is small compared to the back-
emf, so we will also neglect this term. Following these simplifications, our transfer function for the
motor becomes:
θ(s) K
= (Equation 11)
V (s) 2
s (J Rs +K )

By substituting in our values we obtain:


θ(s) 0.042 4.2⋅10−2 23.81 (Equation 12)
V (s) = = or s (0.12 s +1)
s ((2.52⋅10−5 )(8.4)s +0.0422 ) s(2.12⋅10−4 s +1.76⋅10−3 )
Section A: Report Requirements

Within Section A of your report, restate the transfer function found above and explain whether this
plant could be controlled as an open loop system. For example, could a step input of a correct
magnitude be applied to the plant in order to result in a motor position output of 0.5 radians? Explain
why or why not. (2 marks)

Add a Proportional Integral Derivative (PID) controller to the plant and write the closed loop
transfer function for the system. Represent the plant using the plant variables K, J, and R as shown in
Equation 11, and represent the proportional, integral and derivative gains as KP, KI and KD,
respectively. Simplify the closed loop transfer function as much as possible. (4 marks)
Section B: Matlab

Create a Matlab script to predict the output response of the system for a reference input
commanded position of 0.5 radians, when a PID controller is used to control the motor. Implement your
script to plot the output response for the KP, KI and KD values shown below. Please include three
figures in your report, one figure for each of the 3 numbered trials below. Therefore, the first plot
should include the responses for both trials 1a and 1b, the second figure should include the responses
for trials 2a-2c and the third figure should show the responses for trials 3a and 3b. For a review of how
to plot and label the responses within each figure, please refer to Appendix A of this lab manual.

Trial # KP KI KD
1a 1 0 0
1b 5 0 0
2a 1 0 0
2b 1 2 0
2c 1 0 0.05
3a 5 0 0
3b 5 0 0.1

Section B: Report Requirements

Following a brief introduction to Section B, copy and paste your Matlab code into your report.
Include the three figures in your report that were requested above (4 marks). Briefly explain how an
increase in each gain value (KP, KI, KD) effects the speed of the response, the overshoot and the steady
state error for this system (4 marks).
Section C: Simulink

Represent the same system in Simulink, that you had previously represented in Matlab in Section
B. Implement the same controller gains as Trial 3a from Section B (KP=5, KI=0, KD=0). Compare the
output responses generated by Matlab and Simulink for this case. Please note that the PID block in
Simulink has a filter built in for the derivative path. Please leave this filter in place, we will be
discussing filtering feedback later in this course, but it should be noted that the presence of the filter
will result in differences between the Matlab and Simulink predictions for cases where the derivative
gain is not equal to zero.

In addition to the 0.5 radian step input that we have used so far, we will also want our DC motor to
be able to follow a square wave form with an amplitude of 0.5 radians. Replace the Step Input block in
Simulink with a signal generator by double clicking in the Simulink workspace and typing: Signal
Generator. Double click on the Signal Generator block to edit it’s properties and set the wave form to
square, the amplitude to 0.5, and the frequency to 0.4 Hertz. Connect the Signal Generator block to the
system input instead of the Step Input block. Finally, right click on the Simulink workspace and select:
Model Configuration Parameters from the list of options. In the Configuration Parameters dialog
change the stop time to 10 seconds, use the Fixed-step solver type and the ode1 (Euler) solver. Expand
the Solver details menu and set the Fixed-step size (fundamental sample time) to 0.002. Click OK to
approve the changes. Now run the simulation and view the results using the scope. Repeat the
simulation that you had just run for the gain values of Trial 3.a, but this time with the gain values of
Trial 3.b (KP=5, KI=0, KD=0.1).

Section C: Report Requirements

In Section C of your report, introduce your Simulink model and include an image of your Simulink
model. Compare the predicted output responses from both Matlab and Simulink for Trial 3a (KP=5,
KI=0, KD=0) (4 marks). Include the predicted output response from Simulink for the square wave input
for systems with the PID values of Trial 3.a and 3.b and briefly explain whether the responses match
your expectations (2 marks).
Section D: QLabs Implementation

QLabs on Windows 10:


First download the file qLabsL1.slx from the Lab 1 folder on UMLearn and open it in Simulink.
Next open the QLabs application. Once you are logged into the application, you should see a list of
simulated hardware available, select the Cube Servo 2. The qLabsL1.slx file has hardware connection
blocks built into it’s simulation model. A connection should be established between Simulink and
QLabs, as though Simulink is attached to physical hardware. Run the QLabs system through Simulink
for the square wave using the gain values of Trial 3a and 3b. Compare these responses to your
predicted responses using Simulink from Section C. Finally, experiment with adjusting the
proportional, integral and derivative gains.

QLabs on non-Windows 10 Operating Systems:


Open the QLabs application, and after logging in, select the Cube Servo 2 system. Use the sliders
and text boxes to enter the same gain values that were used in Trial 3a and 3b. Compare these responses
to your predicted responses using Simulink from Section C. Finally experiment with adjusting the
proportional, integral and derivative gains.

Section D: Report Requirements


In Section D of your report, compare the responses that were predicted in Section C using Simulink
with the PID gains according to Trial 3.a and 3.b, compared with the corresponding responses from
QLabs obtained in Section D. Discuss the possible reasons for these differences. Keep in mind that the
responses generated in Section D should be representative of the results from physical hardware and
that simplifications to our system representation were made back in Section A which would affect our
Section C predictions (4 marks).

Additionally, discuss how experimenting with different gain values effected the response. Did
changes to each of the proportional, integral and derivative gains cause similar changes to speed of the
response, overshoot, and steady state error as was seen in Sections B and C (2 marks)? Were you able
to see the effects of the motor becoming saturated at high gain values? This would result in a voltage
greater than 10V being applied to the motor (which can be monitored using the scope that is attached
prior to the plant), and yet the motor would not provide an increase in torque beyond the 10V
maximum voltage that is part of the motors specifications (4 marks).

Lab Conclusion
In this lab you have gone through the process of representing the system using transfer functions,
predicted the output response of the system to a wide range of conditions using Matlab and Simulink,
and implemented the controller on a simulated motor. Add a brief conclusion section to your report to
summarize your results.
Appendix A:

The following example Matlab code has been included to demonstrate the process of creating
figures which include multiple data sets using Matlab. For this example a system will be used which
has a PID controller applied to a plant. The plant transfer function is: 1/(s+1), and a step input of 2 is
applied to the system. A plot is created which compares the responses for systems which have two
different PID gain parameters.

clear; % clear the workspace


clc; % clear the command window
s=tf('s'); % define the transfer function model for ‘s’
plantTF=1/(s+1); % define the plant transfer function
stepMag=2; % define the magnitude of the step input
figure(1); % create a new figure
hold on; % retain the plots, so that new plots are added rather than replacing the previous plots
t=0:0.1:20; % analyze the system from when time=0 seconds to time=20 seconds, with a sample time of 0.1 seconds
kp=1; ki=0.5; kd=0; % set the proportional (kp=1), integral (ki=0.5), and derivative (kd=0) gains
clTF=feedback(pid(kp,ki,kd)*plantTF,1);
% define the closed loop transfer function for a PID controller added to our plant with negative unity (,1) feedback
step(stepMag*clTF,t); % plot the response of the closed loop system to a step input of 2, over the defined interval t
step(stepMag*(feedback(pid(1,1,0)*plantTF,1)),t);
% the line above does the same thing as the preceding lines, but now with the controller gains kp=1, ki=1, kd=0
title('Appendix A - Example'); % figure(1) title
ylabel("Displacement (meters)"); % lables the y-axis
axis([0 20 0 2.5]); % sets the axis of the plot: axis([x-min, x-max, y-min, y-max])
legend('Line-1:Kp=1,Ki=0.5,Kd=0','Line-2:Kp=1,Ki=1,Kd=0'); % defines the legend
hold off; % ends the hold operation for the figure(1) plot

You might also like