Practical Controller Design For Dummies
Practical Controller Design For Dummies
For Dummies
By Chris McClellan
1.0 Introduction
Welcome to the Practical Controller Design for Dummies. This manual presents the field of Classical
Control Theory as taught in SYDE 352. This manual is intended as a basic framework for designing a
controller; with more experience and knowledge you can fill out this framework with more complex
techniques. It is broken in to 3 sections: System Identification, Controller Design and Controller
Validation. A simple brushed DC motor system is used as an example to illustrate the framework.
I would like to thank Dr. Eric The Tool Man Kubica for freeing me from the deep, murky, nebulous hole
that is MME. I would also like to thank him for the opportunity to create this manual and for his
guidance and expertise on this project. I would also like to thank Professor Dan Davison, Professor
Glenn Heppler and Professor Nasser Lashgarian Azad for their support in making this manual possible.
I would also like to thank the good people at For Dummies for the use of their logo.
R(s)
I(s)
E(s)
U(s)
P(s)
C(s)
Y(s)
H(s)
Figure 2.0 Typical Feedback System
The goal of System Identification is to derive a mathematical model for each of the following elements:
Reference Input Signal R(s) The Reference Input Signal is the desired set-point(s) as requested by the
operator of the system. This input can take many forms, including impulse signals, step signals, ramp
signals, acceleration signals, sinusoidal signals etc [1]. Your goal is to identify the typical Reference Input
Signal(s) for your system and design a controller to adequately respond to these desired inputs.
Input Filter Transfer Function I(s) The role of the Input Filter is to convert the Input Signal into a form
that is usable by the Controller Transfer Function. In most cases the Input Filter Transfer Function is a
gain but can sometimes take the form of a transfer function that filters the input in ways that improve
the system response.
Error Signal E(s) The Error Signal is calculated by subtracting the output of the Feedback Transfer
Function from the output of the Input Filter Transfer Function. Though you dont need to derive a
model for this part of the system, its important to know the units of this signal.
Controller Transfer Function C(s) The Controller Transfer Function is the brains of your system and the
goal of Controller Design in Section 3.0. It takes the Error Signal and computes the Controller Output
Signal. The Controller can take many forms, but for this course well focus on Proportional (P)
Controllers, Proportional plus Integral (PI) Controllers, Proportional plus Derivative (PD) Controllers,
Proportional plus Integral plus Derivative (PID) Controllers, Phase Lead Controllers, Phase Lag Controllers
and Feedforward Controllers.
Controller Output Signal U(s) The Controller Output Signal is the signal that the Controller calculates
and applies to the Plant. Though you dont need to derive a model for this part of the system, its
important to know the units of this signal. It also should be noted that sometimes when running
experiments on the model of your system, a limit function may be added here to replicate the real world
limits of your system. See Section 3.2.6 for more information.
Plant Transfer Function P(s) The Plant Transfer Function generally consists of an actuator and the
process being controlled. Generally the most difficult task in designing a Controller is to come up with
an accurate model of the Plant. For our purposes, there are 2 main methods for developing a model of
the Plant. The first approach is to Apply First Principles Techniques. For a mechanical system, this will
start with drawing a Free-Body Diagram where we can apply Newtons Second Law of Motion for linear
motion where:
=
Where:
is the net force acting on an object,
is the mass of the object and
is the acceleration of the object.
Or for rotational motion where:
=
Where:
is the net torque applied to an object about an axis of rotation,
is the inertia of the object about the same axis of rotation and
is the angular acceleration of the object about the same axis of rotation.
If you have an electrical system, Kirchhoffs voltage law (KVL) may be applied where:
= 0
=1
Where:
is the voltage across element k of n total elements.
Of course there are many other equations that could be used to predict the response of your Plant. This
technique can be used for any order of Plant but it does require complete knowledge of the Plant.
The second approach, Transient and Steady-State Response Analysis, is great for Plants where little is
known about the Plant. However, this technique is limited to first and second order Plants. The
technique is to apply a known input to your Plant and analyze the transient and steady-state response.
Section 2.2.7 goes into more detail on this approach.
The third approach, Data Driven Modeling, sometimes called gray box modeling, is a very effective tool
when attempting to model a Plant when very little is known, much like training a fuzzy-neural network,
but is beyond the scope of this course.
Feedback Transfer Function H(s) The Feedback Transfer Function generally is a model of the sensor
used to measure the output of your Plant. In most cases this transfer function is modeled as a gain.
Output Signal Y(s) The Output Signal is the physical variable being controlled. Though you dont need
to derive a model for this part of the system, its important to know the units of this signal.
Techniques
Test Model
Is Plant Model
Accurate Enough?
No
Yes
Yes
No
Motor
Optical Encoder
A coeficient that converts the desired angle of rotation in radians to encoder counts.
E(s)
C(s)
A Controller implemented on an Arduino Mega in series with a Dual MC33926 Motor Driver.
U(s)
P(s)
A brushed DC motor (Maxon 2332.968-51.236.200), as shown in Figure 2.3, with a steel arm
attached. Also, the slotted disk (See Figure 2.4) of the optical encoder is attached to the same motor
shaft.
H(s)
An optical encoder (HEDS-5540 A11), as shown in Figures 2.2 and 2.4, and an encoder
counter (HCTL-2022) that converts the angular position of the motors shaft in radians to encoder
counts.
Y(s)
2.2.3 Step 3 Create Model of each Element Except for Controller and Plant
Feedback Transfer Function H(s) -Encoder
From the data sheet for the HEDS-5540 A11 optical encoder, it has a resolution of 500 CPR (Counts Per
Revolution) [2]. In order to free the Arduino Mega from the intensive task of counting the pulses
generated by the optical encoder, an encoder counter is used to count and store the current angular
position. From the data sheet for the HCTL-2022 encoder counter, it states that it has quadrature
decoding capabilities, meaning it can read the two out-of-phase pulse trains and increase the resolution
by a factor of 4 [3]. Therefore:
() = 500
= 318.3
= 318.3
Aside Because the encoder/encoder counter combination cant read fractional counts, a Floor
Rounding Function, that rounds down to the lowest integer value, will be added after the H(s) and I(s)
transfer functions to emulate this characteristic.
La
Ra
m
T
ia
+
Va
e=Kem
M
-
Jm
bm
(b)
(a)
Figure 2.5 DC Motor: (a) Electric circuit of armature; (b) Free-body diagram of rotor [4]
Applying Kirchhoffs voltage law (KVL) to the motors armature circuit results in:
+ = 0
(2.0)
Where:
Ra
ia
La
Ke
Va
10
Using Newtons second law of motion on the motors rotor results in:
=
(2.1)
Where:
Kt
Jm
Combining Equations 2.0 and 2.1 and applying Laplace transforms with initial conditions of zero results
in the motors transfer function:
()
=
3
() + ( + ) 2 + ( + )
(2.2)
Applying Simplification #1 in which the rotational inertia of the arm and encoder disk is added to the
rotors rotational inertia results in:
= + +
(2.3)
Where:
JT
Ja
Je
By combining Equations 2.2 and 2.3 our Plant Transfer Function is:
() =
( + + ) 3 + (( + + ) + ) 2 + ( + )
(2.4)
11
(2.5)
(0.0393)(0.0309)
=
= 1.38106
880.7
12
Estimating Approach #1 Assume the effect of the encoder disk is negligible and model the arm as a
point mass located at half the arms length.
By finding the mass of the arm and its length, the following equation can be used:
2
1 = 2 = ( )
2
(2.6)
Where:
= 0.049
= 0.123
By substituting these values into Equation 2.6, we get the following:
0.123 2
1 = (0.049) (
) = 1.85104 2
2
Therefore, using Equation 2.3:
= + + = 2.78106 + 1.85104 + 0 = 1.8778104 2
Estimating Approach #2 Find the inertias of the both the encoder wheel and arm empirically.
By rearranging Equation 2.1 for JT, we get:
= + + =
(2.7)
Therefore, if we collect the motors angular position and current and differentiate the angular position
twice to get and respectively, we can calculate the combined inertia at each time step. Since the
motor specifications are averages over its operating speeds anyways, we should be able to apply a ramp
function to the motor to get a range of results to average.
13
To do this, first, well open the ControlsLabBaseCode.ino1 file and program the Arduino Mega 2560 for
Open Loop Ramp mode where:
Mode = 1, Ramp_Final = 200, I_Gain = 318.3, Time = 5 and Period = 10.
This puts the Mega into Mode 1 for Open-Loop Ramp Input operation that will output a linearly varying
voltage ramp to the motor for a Time of 5.0s with a Period of 10 ms. This ramp will start at the default
value of 0% duty cycle or 0 V and end at the Ramp_Final value of 200, which is the raw analogWrite
value that represents a duty cycle of (200/255)100% = 78.4% or a voltage of (200/255)12V or 9.4V. The
I_Gain value is the Input Filter Gain that converts radians to encoder counts. By uploading this file, the
Mega is ready to go and a test can be initiated by pressing the Start button. Remember, to keep your
hand close to the Stop but in case your test gets out of hand. To collect data, the collect.m Matlab script
should be used. It returns the following vectors:
R(t)
is the Reference Input Signal vector. In Open Loop mode it represents a voltage and is the
raw analogWrite value. It ranges from 0 255 and its the duty cycle of the Pulse Width Modulated
(PWM) signal where 0 represents a 0% duty cycle (always off), 127 represents a 50% duty cycle (on half
the time) and 255 represents a 100% duty cycle (always on). In Closed Loop mode it represents the
desired angle in radians.
Y(t)
is the Output Signal vector, which in this case is the angular position of the motor in radians.
I(t)
is the current vector in amps flowing through the motors armature. It is important to note
that this value is always positive, regardless of the direction of the flow of current.
Aside the collect.m script will prompt you for which communication port that the Arduino Mega is
currently connected to. To determine which port is being used, open the Device Manager and look
under Ports (COM & LPT), as shown in Figure 2.6.
This Arduino file, as well all the other Arduino and Matlab files used in this manual can be found on the C: drive of
your lab computer under SYDE 352/SYDE Code.
14
By running collect.m, 4 different plots are created, only 3 of which are important to us at this point.
Shown in Figure 2.7 is the plot of the Reference Input vs. Time. As expected, the analogWrite signal that
represents the duty cycle of the PWM signal sent to the motor varies linearly from 0 to 200 over the 5
second duration. The Angular Position of the motor shown in Figure 2.8 exhibits a non-linear output for
the entire test, the worst section being the first 3.5 seconds of the test. Even though weve assumed
our system to be linear, and the input to the systems is a linear ramp, this clearly is not the case. A red
line has been added to the plot to mark the region well consider as linear for our calculation of the
combined inertias. The plot of the motor current shown in Figure 2.9 is very noisy. It should be noted
that an averaging filter has been added to the ControlsLabBaseCode.ino file to help with the noise issue
from the current feedback and this plot is a vast improvement over what is was.
To calculate the angular velocity and acceleration of the motor, the angular position needs to be
differentiated. To help with this, a Matlab function called differ was created that employs the following
simple two-point estimation:
() =
( + ) ()
Where:
= =
16
time_vector_dot
is the returned time vector used for plotting data_vector_dot vs. Time.
data_vector
time_vector
Shown in Figure 2.10 is the plot of the Angular Velocity vs Time. The signal exhibits a small amount of
noise but overall it is fairly smooth and should produce a decent result when using Equation 2.7.
However, this small amount of noise is greatly amplified in the signal of the Angular Acceleration, as
shown in Figure 2.11. This signal is basically a blur and will not produce an acceptable result when using
Equation 2.7.
17
Out of curiosity, I created another Matlab script called J_calculation.m based on Equation 2.7 and
applied our vectors. Shown below in Figure 2.12 is the result.
Even when we zoom-in on the region after 3.5s, the result is way off, as shown below in Figure 2.13.
Not surprising, the average combined inertias over this time period using this script results is an infinite
value.
Figure 2.13 Plot of the Combined Inertias vs. Time from 3.5s to 5.0s
19
By applying the aforementioned data_filter function to the angular velocity with arbitrarily determined
normalized cutoff frequencies of 0.2, 0.1 and 0.02, the following plot was created (Figure 2.14). With a
sampling period of 10ms, our sampling frequency is 100Hz and our Nyquist rate is 50 Hz. Therefore the
cutoff frequencies trialed correspond to 10Hz, 5Hz and 1Hz respectively.
Figure 2.14 Data_filter Function Output of Angular Velocity with Cutoff Frequencies of 10Hz, 5Hz and
1Hz
Though its slightly difficult to see from the plot shown in Figure 2.14, all 3 cutoff frequencies do a nice
job of smoothing out the noise in the Ydot vector. However, the third cutoff frequency of 1Hz adds a
very noticeable shift to the data due to the aggressive 2nd order Butterworth filter being too close to the
cutoff frequency of the system which is not desired. To minimize this effect, the vector filtered at the
second cutoff frequency of 5Hz will be used. Applying the differ function on this new vector results in
plot shown below in Figure 2.15.
Clearly the result shown in Figure 2.15 when compared to the plot in Figure 2.11 is much better, but still
exhibits a fair amount of noise. Using the data_filter function with the same cutoff frequencies
produced the plot shown in Figure 2.16.
20
Figure 2.16 - Data_filter Function Output of Angular Acceleration with cutoff frequencies of 10Hz, 5Hz
and 1Hz
This time the cutoff frequencies of 10Hz and 5Hz did not do an adequate job where the cutoff frequency
of 1Hz did a nice job in smoothing the data but once again added a significant shift. A second trial with
normalized cutoff frequencies of 0.08, 0.04 and 0.02 were used to produce the plot shown in Figure
2.17.
21
Figure 2.17 - Data_filter Function Output of Angular Acceleration with Cutoff Frequencies of 4Hz, 2Hz
and 1Hz
The second cutoff frequency of 2Hz appears to do the best job of filtering the Angular Acceleration
because it produces the smoothest signal without adding a delay to the data and will be used to
calculate the combine inertias. Using the J_calculation script resulted in the following plot (Figure 2.18).
The average combined inertias over the time period of 3.5s to 5.0s was calculated to be:
= + + = 2.4104 2
It was expected that the result of the first approach would yield a conservative estimate because it did
not consider the exact geometry of the arm or the inertia of the encoder wheel. Comparing the
combined inertias value just calculated with the value found using the first approach and we have a
value 28% greater. Im very comfortable with the estimate of the second approach because I expected
it to be larger, but not drastically larger and I will continue with it.
Substituting all our Plant values into Equation 2.4, we now have a complete model of our Plant.
() =
0.0393
3.594107 3 + 0.002389 2 + 0.001558
Or in normalized form:
() =
109348.9
+ 6647.1 2 + 4335
23
Shown in Figure 2.20 is the Angular Position vs Time plot generated by the Scope function block in
base_open_loop_model. It compares the results of our Plant model with the actual Plant when
subjected to a ramp input. The results are very encouraging.
Figure 2.20 Comparison Plot of Plant Model and Actual Plant when Subjected to a Ramp Input
Lets compare step input results. To do so well open the ControlsLabBaseCode.ino file and program the
Arduino Mega for Open Loop Step mode where:
Mode = 0, Step_Input = 100, I_Gain = 318.3, Time = 5 and Period 10.
24
This will output a step voltage of (100/255)12V or 4.7V for the entire test duration. Using the collect.m
Matlab script to collect the test data, transposing vectors T, R and Y, and running it through our
base_open_loop_model yielded the plot shown in Figure 2.21. Again, the results are very encouraging.
Figure 2.21 - Comparison Plot of Plant Model and Actual Plant when Subjected to a Step Input
One more test; lets try a chirp input. A chirp is a signal in which the frequency increases (up-chirp) or
decreases (down-chirp) with time. The term chirp is used interchangeably with sweep signal [5]. Open
the ControlsLabBaseCode.ino file and program the Arduino Mega for Open Loop Chirp mode where:
Mode = 2, Freq_Final = 2, PWM_Amp = 50, I_Gain = 318.3, Time = 10 and Period = 10.
This will output a sinusoidal signal that will range between +/- (50/255)12V or +/- 2.35V with the
frequency linearly increasing from 0 to 2Hz. Using the collect.m Matlab script to collect the test data,
transposing vectors T, R and Y, and running it through our base_open_loop_model yielded the plot
shown in Figure 2.22.
25
Figure 2.22 - Comparison Plot of Plant Model and Actual Plant when Subjected to a Chirp Input
Again, the results are very similar but its obvious the motor is struggling with oscillating the systems
inertia at this frequency by the drift in the position and the reduction in magnitudes of the oscillations as
the frequency increases. Out of curiosity, Ill perform the same test without the arm attached. By
changing the J value for our Plant model, the two results can be compared. As shown in Figure 2.23, the
motor does a lot better job in keeping up with the commanded chirp signal and the Plant model
accurately predicts this result.
There is no standard way of concluding whether a model is accurate enough. However, upon visual
inspection, the results are very similar and Im comfortable with concluding that this model is
sufficiently accurate to proceed. However, can it be simplified?
Figure 2.23 - Comparison Plot of Unloaded Plant Model and Actual Unloaded Plant when Subjected to
a Chirp Input
26
0.0393
0.002389 2 + 0.001558
Or in normalized form:
1 () =
16.45
+ 0.652
(2.8)
Interestingly, the denominator of the old Plant model and new Plant model, before converting to
normalized form, are the same except for the missing 3 term. By using Matlabs bode function to
create a Bode Diagram of both Plant models, as shown in Figure 2.24, we can see that theyre almost
identical, except for a slight difference in phase at higher frequencies.
Based on the Bode Diagram, Im very comfortable with this simplification and require no further testing
to verify its validity.
27
Figure 2.24 Bode Diagram Comparing the Original Plant Model with the New Plant Model
( + 2 )( + 1 )( + 0 )
( + 3 )( + 2 )( + 1 )( + 0 )
(0 + 2 )(0 + 1 )(0 + 0 )
2 1 0
=
(0 + 3 )(0 + 2 )(0 + 1 )(0 + 0 ) 3 2 1 0
When s = 0. And you recognize that 2 is greater than 3, 1 and 0 by a factor of 10 or greater, you can
replace ( + 2 ) with 2 . Thereby simplifying our example transfer function to:
() =
( + 2 )( + 1 )( + 0 )
( + 3 ) 2 ( + 1 )( + 0 )
28
Which has the same value as the original transfer function when s = 0 and at low frequencies. Of course,
at high frequencies there will be slight differences, but it will be negligible because the lower frequency
poles will dominate the response of the transfer function.
This method is effective for systems with a low bandwidth. However, if youre looking to create a
system with a high bandwidth, those high frequency poles and zeros may be very important. Another
approach is to look at the Plants poles and zeros to see if there are any poles and zeros that can cancel
each other.
Using Matlabs pole function, the Plants poles were found at:
P1 @ 0, P2 @ -0.652 and P3 @ -6646
Since there are no s terms in the Plant numerator, there are no zeros.
Shown in Figure 2.25 is a plot of the Plant models poles and zeros using Matlabs pzmap function.
Fortunately none of the poles lie in the unstable Right Half Plane (RHP), however, it does have a pole
directly on the Imaginary axis. Furthermore, none of the poles have any imaginary components,
meaning the system is critically damped or over-damped. Since none of the poles are at the same
location, the system is considered overdamped. Interestingly, there is a very high frequency pole at
-6646 which should have very little effect on how the model performs. By removing this pole and
replacing it with a DC gain, our new Plant model is the following:
2 () =
109348.9
( + 0.6523)(6646)
Or:
2 () =
16.45
( + 0.652)
(2.9)
This new Plant model is identical to the result obtained from the Approach #1. Lets try the transient
and steady-state response analysis technique to verify this result.
29
30
There are 2 things to note from this open-loop step response. First, the slope at t = 0 is zero, which
indicates that the system must be second order system or higher. Oscillations in the output would have
also indicated a second order system or higher. Second, the output position does not reach a steady
state. Instead a steady velocity is reached. This indicates that our system may look like a first order
system with an integrator term after, as shown in Figure 2.27:
+ 1
Note
31
If we differentiate the position output to get velocity, we get the following plot shown in Figure 2.28:
As you can tell in Figure 2.28, the output does have a slope greater than zero at t = 0, there are no
oscillations and the output reaches a steady state, indicating a first order system. Based on the
knowledge that a first order system reaches 63.2% of its final value after 1 time constant T [6], we can
find our time constant T when the response has reached 63.2% of its final value of 100rad/s or
63.2rad/s. As shown on the same plot, red lines have been added to indicate this intersection which is
when T = 1.07s. Also, since our gain K is the steady state result divided by the gain of the open-loop step
input, our gain K is 100/4.7 or 21.3. Therefore our Plant model is:
() =
21.3
(1.07 + 1)
Rearranging the result in Modeling Approach #1 into the same form as just derived results in:
() =
25.27
(1.53 + 1)
Creating Bode Diagrams to compare both Plant models results in the plots shown in Figure 2.29. As you
can see, they are very close. There is a slight difference in the Phase plot but the Magnitude plot is
almost identical.
32
Using the data collected earlier to run through our Simulink base_open_loop_model resulted in the
following plots:
Figure 2.30 - Comparison Plot of Plant Model and Actual Plant when Subjected to a Step Input
33
Figure 2.31 - Comparison Plot of Plant Model and Actual Plant when Subjected to a Ramp Input
Figure 2.32 - Comparison Plot of Plant Model and Actual Plant when Subjected to a Chirp Input
34
2.2.7.1 Conclusion
Both approaches yield acceptable models. However, with Approach #2, Transient and Steady-State
Response Analysis, was much easier and far quicker. Comparing Figures 2.20-22 and Figure 2.30-32, the
results are very similar, with neither being perfect. Since our intended purpose for this system is for
position control, well proceed with the Plant model derived by Approach #2 because its step input
result is better. This concludes the System Identification portion and well proceed to Controller Design.
Aside If our Plant was a typical second order system such as:
() =
2
2 + 2 + 2
(2.10)
And was underdamped, the damping ratio could be calculated from the percent overshoot (%OS) from a
step input by using [7]:
%
(
)
100
=
2 + 2 (%)
100
Furthermore, the damped natural frequency can be measured off the plot of the step response using
the equation shown below, where is the time interval between two consecutive peaks [7]:
=
2
t
1 2
A similar approach can be taken using a chirp input to create a Bode Plot. See Extras: System
Identification for more information [7].
35
R(s)
I(s)
E(s)
U(s)
P(s)
KP
Y(s)
H(s)
Yes
Yes
No
nd
2 Order System?
No
Order of System > 2
Test
37
(3.0)
()
()
= ()
()
1 + () ()
R(s)
()
()
1 + () ()
Y(s)
( + )
()
()
1
() =
= ()
=
()
1 + ( + ) () + 1 + ()
1
Or in standard form:
() =
()
=
() +
Where:
= 1 + ()
(3.1)
And:
= ()
(3.2)
Using either the Transient Response Equation for 1% settling time to a step input [9]:
=
4.6
(3.3)
38
Or the Transient Response Equation for rise time for a step input [9]:
=
2.2
(3.4)
We can back calculate for and then back calculate for using Equation 3.1.
If your Plant has a zero in the numerator, temporarily ignore it and apply the above equations as a
starting point. Afterwards, iteratively tune your Controller by trial and error with the zero included.
Aside - For a first order system, no overshoot is possible, therefore = 0. This is because the one
pole for a 1st order system must lie on the real axis. To have any kind of overshoot, a system must have
poles that have an imaginary component. However, since complex poles, which have an imaginary
component, only come in pairs, its impossible for a 1st order system to have a lone complex pole to
produce overshoot.
(
)
()
()
( + 1 )( + 2 )
() =
= ()
= 2
()
1 + (
) () + (1 + 2 ) + (1 2 + ())
( + 1 )( + 2 )
Or in standard form:
() =
()
2
= 2
() + 2 + 2
Where:
2 = 1 2 + ()
(3.5)
2 = 1 + 2
(3.6)
2 = ()
(3.7)
And:
And:
39
Depending on which specifications are given, use the following Transient Response Equations for a step
input [11]. For the rise time:
=
1.8
(3.8)
= 1 , 0 < 1
(3.9)
(3.10)
Where:
= 1 2
(3.11)
(3.12)
(3.13)
=
Where:
Im(s)
Im(s)
Im(s)
= 1
Re(s)
Re(s)
Re(s)
Figure 3.3 Graphs of Regions in the S-Plane for Rise Time, Overshoot and 1% Settling Time
Respectively for a Step Input [11]
40
Shown in Figure 3.3 are the graphs of regions in the s-plane that are produced by the aforementioned
Transient Response Equations for rise time, overshoot and 1% settling time for a step input.
For an undamped and underdamped 2nd order system, the resulting poles will be at:
1,2 =
0 < 1
For a critically damped 2nd order system, both poles will be at:
1,2 =
= 1
For an overdamped 2nd order system, both poles will be unique but lie on the Real axis.
If your Plant has one or more zeros in the numerator, temporarily ignore it/them and apply the above
equations as a starting point. Afterwards, iteratively tune your Controller by trial and error with the
zero(s) included. Know that a zero in the Left Half Plane (LHP) of the s-plane will increase the overshoot
to a step response if the zero is within a factor of 4 of the real part of the complex poles, and a zero in
the RHP will suppress the overshoot but may cause the step response to start out in the wrong direction
[12].
Note 1 For the derivations in Sections 3.1.1 and 3.1.2, it was assumed that I(s) and H(s) were strictly
gains.
Note 2 - It should be noted that these equations are qualitative guides and not precise design formulas.
They are meant as a starting point for design iteration [10]. For tuning the Controller for a 2nd Order
System, if the system is responding too slow, increase the natural frequency . If there is too much
overshoot, increase the damping coefficient . If the transients persist too long, move the pole left in
the s-plane. [9].
Note 3 If you are given 1 specification to a step input, using the Transient Response Equations for a
second order system will result in one unique value for . If you have been given 2 specifications to a
step input, each will produce a value for and it most cases, each value will be unique and produce
transient responses that do not satisfy both specifications. If you were to combine specifications and
combine the regions shown in Figure 3.3, you will get a unique set of poles to meet the specifications.
However, there is a good chance that a Proportional Controller will not be able to produce that desired
result. This can be verified by plotting the systems Root Locus.
41
R(s)
I(s)
E(s)
P(s)
KP
Y(s)
H(s)
(3.14)
And if you vary from zero to infinity, you will create the systems Root Locus.
Breaking Equation 3.14 into its complex components you have the equation for the magnitude:
| () ()| = 1
(3.15)
< () () = 180(2 + 1)
(3.16)
42
Or:
(3.17)
Where:
k = # of poles # of zeros 1
(3.18)
And for a pole or zero with the form = + , the angle is computed using the following:
< = tan1 ( )
(3.19)
When using the Root Locus method for a multi-order system, this technique will only help you to
visualize the system and how it changes with different values of . This will allow you to see which
values of produce a stable system whereby the systems poles exist in the LHP but it will not allow
you to estimate its performance characteristics such as rise time, overshoot and settling time. These
features can only be determined by simulation in Simulink or testing on the physical system.
Aside - When using the Root Locus function rlocus(sys) in Matlab, keep in mind that:
= () ()
43
3.1.5 Test
If the Proportional Controller meets the specifications given you can skip to the Section 5.0, Controller
Validation. Following Figure 3.8, if the Proportional Controller produces too much overshoot, proceed
to Proportional plus Derivative Control. If your Controller produces too much steady state error, skip to
Proportional plus Integral Control. If instead your Controller produces too much overshoot and steady
state error, skip to PID Control.
( + 1 )( + 2 )
19.9
( + 0)( + 0.935)
1 + 2
2
(3.20)
44
By substituting our values for 1 , 2 and into Equation 3.20 results in:
=
0 + 0.935
= 0.67 /
2(0.7)
2 1 2
()
(3.21)
By substituting our values for , 1 , 2 , and () into Equation 3.21 results in:
=
(0.67)2 (0)(0.935)
= 7.04105
19.9(318.3)
In order to test this result, Ive created a Simulink model called base_closed_loop_model and added the
model elements particular to this example. I then setup a unit step input to inject into our model to see
the result. Shown in Figure 3.5 is a very smooth but slow response to a step input. Though it meets our
overshoot specification of 5%, it in no way comes close to our target rise time of 0.1s. Lets apply the 2 nd
Order Transient Response Equations for rise time and compare.
45
1.8
(3.22)
And substituting our value for into Equation 3.22 results in:
=
1.8
= 18 /
0.1
And substituting our values for , 1 , 2 , and () into Equation 3.21 results in:
=
(18)2 (0)(0.935)
= 0.051
19.9(318.3)
Substituting this new value for into our Simulink model resulted in the unit step response shown in
Figure 3.6. Yikes!
46
3.1.6.4 Conclusion
We can only meet 2 of the 3 Design Specifications. As expected, the overshoot and rise time
specification conflict with each other. Out of interest I plotted the Root Locus using Matlab to see what
is really going on. As you can see from Figure 3.7, as you increase the value for greater than 0.4675,
the value for decreases, so when we tried to decrease our rise time by increasing , the value for
decreased creating a no-win situation.
To further understand why the Proportional Controller failed, lets use the damping ratio of 0.7 that
results from the overshoot specification and the natural frequency of 18 rad/s that results from the rise
time specification to calculate the desired closed-loop poles where:
1,2 = = 1 2
(3.23)
47
Since we met our steady-state specification, well try a Proportional plus Derivative Controller.
No
Too much Overshoot?
Yes
No
Yes
Apply PID Control
nd
Yes
Order = 2?
2 Specifications
Given and No Zero in
Plant?
No
Yes
No
Apply Root Contour
Iteration
Apply Coefficient
Mapping
Test
(3.24)
49
()
= 2
() + 1 + 0
(3.25)
(3.26)
(3.27)
And rearranging Equations 3.26 and 3.27 will give us our gains for our PD Controller.
50
2 1 2(12.6) 0.935
=
= 3.83103
1
318.3(19.9)
=
=
= 0.051
1
318.3(19.9)
Which gives us the following PD Controller:
() = + = 0.051 + 3.83103
51
()
=0
()
We get:
1 + 6336.3
=0
+ 0.935 + 6336.3
()
= 2
() + 0.935 + 6336.3
Doing so we get the Root Locus plot shown in Figure 3.10 where Ive found the closest points of
intersection. Note the desired closed-loop poles in red.
Note that both the positive and negative real components of our desired closed loop poles result in
approximately the same gain value of:
= 24.4
And this produces a Derivative gain value of:
=
24.4
= 3.85103
6336.3
2nd Iteration - Now lets set to 3.85x10-3 and vary . . This results in the following characteristic
equation:
2 + (0.935 + (318.3)(3.85103 )(19.9)) + (0 + (318.3) (19.9)) = 2 + 25.2 + 6336.3
Or:
1 + 6336.3
1
=0
+ 25.2
1
2 + 25.2
We get the Root Locus plot shown in Figure 3.11. As you can see, this Root Locus plot goes through our
desired closed-loop poles, which are estimated by Matlab to produce 4.57% of overshoot with a
damping ratio of approximately 0.7 and natural frequency of 18rad/s. Our gain for these points is found
to be:
= 323
Which results in the Proportional gain of:
=
323
= 0.051
6336.3
53
3.2.5 Conclusion
As expected, both methods produced almost identical gains for our PD Controller. Now lets test our
Controller. By modifying the Simulink model called base_closed_loop_model created earlier I got the
results shown in Figure 3.12. I also added the 2nd order approximation as a means of comparison.
Figure 3.12 - Unit Step Response for PD Controlled System and 2nd Order Approximation
54
With respect to our PD Controller, the result shown in yellow in Figure 3.12 shows 20% overshoot but a
rise time of 0.05s. This leads us to ask why our rise time is easily met but our overshoot is off when we
designed our PD Controller to match the characteristics of our desired closed-loop poles. The short
answer is that we didnt factor in the result of our added zero by the addition of the Derivative term.
Looking at the poles and zeros of our closed-loop system we get:
P1 and P2 @ -12.6 j12.82 and Z1 @ -13.32
As youll notice, the real portion of the poles and the zero are very close which would account for
greater overshoot. As mentioned previously in Section 3.1.2, any additional zero within a factor of 4 of
the real component of the nearest pole will have a noticeable effect. Comparing the rise times between
the PD controlled system with the result of the 2nd order approximation, the PD controlled system is
much quicker, which is a nice bonus of the additional zero.
With respect to the 2nd order approximation results, youll notice that the overshoot specification is met
but the rise time is not. As mentioned previously, the 2nd Order Transient Response equations are an
approximation and were noticing this inaccuracy. Youll also notice that we now have a steady state
error which was not there previously. Why is that? Its because our 2nd order approximation, with its
two complex poles has lost its zero in the denominator, reducing it to a Type 0 system.
However, before I get into the problem, let me first explain the system model shown in Figure 3.13. Ive
created 3 separate models that get routed through a multiplexer to be plotted on the same graph. One
of the quirks I found in Matlab is that a function block has to be proper. That means that the order of
the denominator must be equal or greater than the order of the numerator. This means that you cant
implement a PD or PID Controller using a function block. To work around this, in the top model I
switched the numerator of the Plant with the numerator of the Controller. A little confusing but it
works. However, it creates another problem in that I cant monitor the Controller Output Signal U(s).
To work around this I created a second model using Matlabs PD Controller transfer function. Now Im
sure youre going to ask Why didnt I use it in the first place dummy?. I would have liked to but Matlab
implements their PD Controller using the following equation:
= +
1+
Searching the documentation they call their Derivative implementation a Filtered Derivative where N
determines the pole location. This high-pass filter is used to get around the original quirk I found where
the transfer function has to be proper. (This kind of Filtered Derivative is also called a Phase Lead
Controller. See Section 4.3 for more information.) I was able to achieve matching results between the
top two models when I set N to 1000, which puts the pole at 1000rad/s and well outside the systems
bandwidth. (For more information in system bandwidth see Section 5.1.1) Now that the second model
works I was able to add a scope after the PD Controller function block and found the following:
Figure 3.14 Controller Output Signal Response from Unit Step Input
56
It may be a little hard to tell by Figure 3.14 but the Controller Output Signal initially jumps to 1400V then
settles out to something a little more reasonable. Realistically though, we dont have a power supply
that could source the lethal voltage of 1400V. Furthermore, even if we could find that kind of power, it
would surely fry the motor controller and the motor itself. For our tests weve been running the motor
off a 12V power supply so to model this physical limitation, as shown in Figure 3.15, Ill add a saturation
block after the Controller.
As shown in the plot from the scope placed after the saturation block in Figure 3.16, the voltage
supplied to the Plant is now limited to 12V.
Figure 3.16 - Controller Output Signal Response After Saturation Block from Unit Step Input
However, as shown in Figure 3.17, the addition of the saturation block has a drastic effect on our
systems performance (shown in purple). Our system response to a step input with the addition of the
saturation block now resembles the 2nd order approximation in that the overshoot is close to our
specification but the rise time is quite sluggish. What do we do next?
57
Figure 3.17 Unit Step Response of PD Controlled System Without Saturation Block, With Saturation
Block and 2nd Order Approximation Without Saturation Block
Using Equation 3.26 and rearranging for the Derivative gain we get:
=
2 1 2(17.5) 0.935
=
= 5.4103
1
318.3(19.9)
And using Equation 3.27 and rearranging for the Proportional gain we get:
=
2 + 2 0 (17.5) + (17.8)2 0
=
= 0.1
1
318.3(19.9)
As shown in Figure 3.18, our new PD Controller, shown in purple, meets all our specifications with an
overshoot of 3.7% and a rise time of 0.9s. Youll also notice that it has zero steady-state error for a step
input. The next step is to validate our Controller by implementing it on our physical system and then to
look into its stability. However, before we do that lets talk about PI and PID control and then look into
Phase Lead/Lag Controller Design and Feedforward Design.
Figure 3.18 Unit Step Response of PD Controlled System Without Saturation Block, With Saturation
Block and 2nd Order Approximation
59
nd
Yes
Order = 1?
2 Specifications
Given and No Zero in
Plant?
No
Yes
No
Apply Root Contour
Iteration
Apply Coefficient
Mapping
Test
60
Aside - For another technique on tuning a PID Controller, try the Zeigler-Nichols Method.
nd
Test
61
= lim ()() [1
0
= lim ()() [
0
() ()()
]
1 + ()()()
1
]
1 + ()()()
Fortunately, this type of calculation is quite common and a table based on system Type for common
inputs is available. As shown in Table 3.0 we have the Steady State Errors for Step inputs, Ramp Inputs
and Parabola inputs based on the system Type. The system Type is based on the total number of poles
at the origin or integrator terms in the Controller C(s), the Plant P(s) and the Feedback Transfer Function
H(s).
System Type
Step Input
Ramp Input
(0)
1 + (0)(0)(0)
Type 0
Type 1
Type 2
Parabola Input
(0)
(0)(0)(0)
(0)
(0)(0)(0)
62
+
+
If we arbitrarily set z equal to 1 and p equal to 10 and compare it to a PD Controller with unity gains we
get the following Bode Diagram:
PD Controller
Phase Lead Controller
When comparing the Bode Diagrams in Figure 4.0 youll notice that both Magnitude plots start to ramp
at 20dB per decade at 1rad/s or the location of the zero. However, because of the pole in the
denominator of the Phase Lead Controller, its Magnitude plot levels off at 10rad/s where the Magnitude
plot for the PD Controller continues to ramp indefinitely. Youll also notice one of the drawbacks of the
Phase Lead Controller in the reduction in magnitude at low frequencies. Furthermore, the Phase Lead
Controller produces a hump in its Phase plot centered in between its zero and pole locations, starting at
0 degrees and ending at 0 degrees where the Phase plot for the PD Controller starts at 0 degrees and
ramps up to 90 degrees where it levels off. The length, height and centre point of this hump is the focus
of Phase Lead Controller design in the effort to increase Phase Margin.
Conversely, a Phase Lag Controller produces a valley centered about its zero and pole locations (Figure
4.1). This is the consequence of having z greater than p. This valley is actually the main drawback of
Phase Lag Controller design. Instead, the focus of Phase Lag Controller design is to balance the sideeffects of the phase lag distortion by appropriately designing the size and location of this valley in order
to boost the gain of the system at low frequencies, thereby improving steady-state tracking
performance and disturbance rejection. As shown in Figure 4.1, both Controllers boost low frequency
gain.
PI Controller
Phase Lag Controller
64
R(s)
1.5
1
+1
2
+ 2 + 1
Y(s)
1.5
1
2
2
+ 1 + 2 + 1
We get the Bode Diagram shown in Figure 4.3. Matlab tells us that the Gain Margin is 8.52dB at the
Phase Crossover Frequency of 1.73rad/s and Ive added an arrow to indicate this. The Gain Margin
is calculated using the following equation:
= 0
Where Gain is the distance between the curve and 0dB at the Phase Crossover Frequency . Notice
that if the Gain Margin is below 0dB at the Phase Crossover Frequency the Gain is negative resulting in a
positive Gain Margin and if its above 0dB the Gain is positive, resulting in a Gain Margin thats negative.
If the Phase plot never dips below -180, the Gain Margin is considered to be infinite.
Matlab has also calculated our Phase Margin to be 41.7 at the Gain Crossover Frequency
of 1.04 rad/s and Ive added an arrow to indicate this. The Phase Margin is calculated using the
following equation:
= 180 +
Where Phase is the value of the curve at the Gain Crossover Frequency . Notice that if the Phase
Margin is above -180 the Phase Margin is positive and if the Phase Margin is below -180 the Phase
Margin is negative. If the Magnitude plot never dips below 0dB, the Phase Margin is considered to be
infinite.
65
Phase Margin
Gain Margin
When designing a Controller, the conservative rule of thumb for stability margins are:
10 and
60
However, some texts promote typical stability margins as low as:
6 and
30
The idea behind the Gain and Phase Margins are that they provide a factor of safety. If you were
walking along the a cliff, would you feel comfortable with walking right along the edge, or would say 10
feet from the edge make you feel more comfortable? With experience youll know when you can get
away with less conservative stability margins but for now it would probably be wise to stick with the
conservative approach.
66
No
Apply Phase Lag Control
Yes
No
Yes
Apply Phase Lead and
Lag Control
Following the procedure laid out by Prof. Dan Davison in his SYDE 352 Course Notes [13], our objective is
to satisfy the specifications using:
() = () =
1 1 +
1 +
(4.0)
Where:
K = Controller gain
a = ratio of pole position to zero positon (a > 1)
T = pole time constant (T > 0)
67
2010
-2010
Step 1: Sketch the Bode plot of the open-loop system. As shown in Figure 2.0, our open-loop system
will consist of:
= () () ()
Where:
() = 1
Step 2: If a desired Gain Crossover Frequency is known, adjust the gain K so that the Gain Crossover
Frequency of KP(s) is equal to the desired Gain Crossover frequency. Accomplish this by trial and error
with Matlabs margin function or by inspection of the Bode Diagram and convert the value in dB using
the following equation:
= 10
)
20
68
Set:
=
OrUsing the Final Value Theorem, calculate the gain K to meet the steady-state error specification and add
a buffer of 10dB in anticipation of the decrease in gain that will result from the Lead Controller.
Set:
=
OrIf no specifications are given that the gain can influence, set:
= 1 =
Step 3: Determine the Phase Margin of the augmented open-loop system where:
= () ()
Step 4: Determine the additional phase lead required to meet the Phase Margin required. If no
Phase Margin has been specified, use the following approximation to determine the desired Phase
Margin for a Second Order System:
100,
0 0.7
1 +
1
(4.1)
(4.2)
69
Clearly our Phase Margin needs some adjustment. Since a Gain Crossover Frequency has not been given
and our steady-state error for a step input has been satisfied by our Type 1 system, well set:
= 1 and
= = 79.2/
Since we have a K value of 1, the augmented Phase Margin is the same as our original Phase Margin of:
= 0.676
70
Since our Plant is second order, we can use the damping ratio based on the percentage of overshoot to
calculate our desired Phase Margin of:
100 = 100(0.7) = 70
Therefore our additional phase lead required is:
= = 70 0.676 = 69.324
However, this additional phase lead is greater than 60, so well have to design for two Controllers, each
contributing half the additional phase lead of:
=
69.324
= 34.662
2
1 + 1 + sin(34.662)
=
= 3.64
1 1 (34.662)
1
79.23.64
= 6.62103
Using the parameters just calculated, we get the following Phase Lead Controller:
() =
1 1 +
1 1 + 3.64(6.62103 )
1 + 0.024
= (1)
= 0.52
3
1 + 6.6210
1 + 6.62103
1 +
3.64
However, since we had to create two equal Controllers to get the additional phase lead required well
put them in series like this:
() = 0.52
1 + 0.024
1 + 0.024
0.52
3
1 + 6.6210
1 + 6.62103
Or:
() = 0.25
1 + 0.024
1 + 0.024
3
1 + 6.6210 1 + 6.62103
By modifying the Simulink model called base_closed_loop_model created earlier, I tested our Phase
Lead Controller versus the PD Controller designed earlier. As shown in Figure 4.7, the overshoot is
approximately 3.6% and the rise time is 0.077s, both below the specifications and better than the PD
Controller. Youll also notice that both Controllers produce zero steady-state error for a step input.
71
Out of interest I rechecked the Gain and Phase Margins for our new Phase Lead Controller. As shown in
Figure 4.8, our Gain Margin has stayed at infinity and our Phase Margin has increased to 69.6. Youll
also notice that the Magnitude Plot of the open-loop system with the Controller has been shifted down
before the Gain Crossover Frequency and shifted up after. This was one of the expected side effects of
the Phase Lead Controller. However, the Phase Plot shows a pronounced hump at the Gain Crossover
Frequency which created the boost in Phase Gain we were looking for.
Figure 4.8 Bode Diagram of Open-Loop System With and Without Phase Lead Controller
72
We now have 2 Controllers we will need to validate, but before we do, lets look at two more
Controllers.
2010
0
0
0
Step 1: Sketch the Bode plot of the open-loop system. As shown in Figure 2.0, our open-loop system
will consist of:
= () () ()
Where:
() = 1
Step 2: If a desired Gain Crossover Frequency is known, adjust the gain K so that the Gain Crossover
Frequency of KP(s) is equal to the desired Gain Crossover frequency. Accomplish this by trial and error
with Matlabs margin function or by inspection of the Bode Diagram and convert the value in dB using
the following equation:
= 10
)
20
Set:
=
OrIf the desired Phase Margin is known, adjust the gain K so that Phase Margin of KP(s) is the desired
value plus an extra 5 in anticipation of the loss of Phase Margin that will occur when we include the lag
compensation. Set:
=
If no Phase Margin has been specified, use the following approximation to determine the desired Phase
Margin for a Second Order System:
100,
0 0.7
74
Step 4: Use the Gain Crossover Frequency of KP(s) to calculate the zero time constant by:
10
(4.4)
=
(4.5)
Where:
K = Controller gain
a = ratio of pole position to zero positon (a > 1)
T = pole time constant (T > 0)
a = ratio of zero position to pole positon (a > 1)
T = zero time constant (T > 0)
Step 1: Sketch the Bode plot of the open-loop system. As shown in Figure 2.0, our open-loop system
will consist of:
= () () ()
Where:
() = 1
Step 2: If a desired Gain Crossover Frequency is known, adjust the gain K so that the Gain Crossover
Frequency of KP(s) is equal to the desired Gain Crossover frequency. Accomplish this by trial and error
with Matlabs margin function or by inspection of the Bode Diagram and convert the value in dB using
75
)
20
Set:
=
OrUsing the Final Value Theorem, calculate the gain K to meet the steady-state error specification and add
a buffer of 10dB in anticipation of the decrease in gain that will result from the Lead Controller.
Set:
=
OrIf no specifications are given that the gain can influence, set:
= 1 =
Step 3: Determine the Phase Margin of the augmented open-loop system where:
= () ()
Step 4: Determine the additional phase lead required to meet the Phase Margin required. Be sure
to add an extra 5 to offset the effects of the Phase Lag Controller. If no Phase Margin has been
specified, use the following approximation to determine the desired Phase Margin for a Second Order
System:
100,
0 0.7
76
Step 8: Use the Gain Crossover Frequency of to calculate the zero time constant by:
=
10
(4.6)
F(s)
R(s)
I(s)
E(s)
C(s)
+
P(s)
Y(s)
U(s)
H(s)
With this topology, a transfer function connects the Reference Input Signal R(s) with the Controller
Output Signal U(s). By adding the Feedforward transfer function in parallel with the Controller, a second
degree of freedom is added to the system, meaning that the Controller and the Feedforward transfer
functions can be designed separately. In comparison, the topology previously discussed in Figure 2.0 is
considered a one degree of freedom system. By adding the second degree of freedom, the Controller
can be designed so that the error transfer function has certain desirable characteristics where the
Feedforward transfer function can be selected to help satisfy the performance requirements with
reference to the input/output relationship. Other benefits to this design are that it unburdens the
Controller feedback loop because, under ideal circumstances, the Feedforward path generates most of
the signal, thereby allowing the Controller to provide only corrections and to respond to disturbances or
77
modelling inaccuracies. Problems with the Feedforward topology include requiring accurate knowledge
of the system to be controlled and extra computation requirements.
By looking at the closed-loop transfer function shown below:
() =
()
(() + ()) ()
= ()
()
1 + () () ()
(4.7)
Youll notice that the Characteristic Equation is the same as the one degree of system we looked at
earlier. Therefore, our Controller can be designed using the methods outlined earlier. This also means
that our Feedforward transfer function can be non-linear and not affect how we design our Controller.
But how do we design the transfer function for the Feedforward term? Well, thats only possible for a
process that is well understood. Usually its the inverse of the Plant or a portion of the Plant. Lets
revisit our brushed DC motor system example to see how this works.
(4.8)
Now, this is where the art of Feedforward Design begins. We know from Section 2.2.1 where we
identified the system elements that the Controller Output Signal U(s) will be in volts, so lets rearrange
Equation 4.8 to be in terms of volts.
=
+
2 +
(4.9)
In general, each of the two terms on the right side of Equation 4.9 could be used independently or
together for our Feedforward transfer function. However, since were looking to develop a Controller
for a step input, the first term will attempt to differentiate a step input twice. The first differentiation
will produce an impulse and the second differentiation will result in a doublet, which in this case is
effectively zero, making this option useless. The second term will produce an impulse, giving the system
a boost as the step input is applied but after that it will go back to zero. Since the addition of the
Feedforward term doesnt affect our Controller design, Ill reuse the PD Controller designed earlier in
Section 3.2.6. As shown in Figure 4.11, we have the original one degree of freedom design with a PD
Controller and our only viable Feedforward design with the same PD Controller.
As mentioned in
Section 3.2.6, Matlab wont implement a pure derivative term because its an improper transfer
function. To get around this quirk I applied the solution they used for their PID Controller function block
by implementing a normalized high pass filter with a pole at 1000rad/s.
78
Figure 4.11 Matlab Models of Original One Degree of Freedom Design Compared to Feedforward
Design
Interestingly, both models produce the same result. Why is that? Since our model is in continuous time,
there is no noticeable delay between the application of the step input and an error being produced for
the Controller to react to. And since the Controller has its largest output, basically at the same time as
impulse from the Feedforward term, and both outputs are greater than our physical saturation limit of
12V, there is no difference in input to the Plant and its output.
Obviously this wasnt the best example to apply Feedforward design to. My hope was that it would
show you how to apply the technique. Though Feedforward design is not that common, there are a
bunch of examples where it can come in handy. A useful instance is when you have a gravity term
affecting position control. You will be looking at this more in-depth with the inverted pendulum lab.
79
To do so well open the ControlsLabBaseCode.ino file and program the Arduino Mega for PID Closed
Loop Control for a Step Input mode where:
Mode = 3, Kp = 0.1, Ki = 0, Kd = 0.0054, Reference_Input = 1, I_Gain = 318.3, V_In = 12, Time = 5 and
Period 2.
Based on the discussion in Section 5.1.1 about Choosing the Proper Control Loop Frequency, I chose a
Control Loop Frequency of 500Hz. As shown in Figure 5.0, the bandwidth of the closed-loop system with
the PD Controller designed in Section 3.2.7 is 50.95Hz. (This same value can be verified using Matlabs
bandwidth(sys) function.) Based on the prescribed rule of thumb of a factor of 10, we get a Control
Loop Frequency of 508Hz which well approximate as 500Hz.
-3db
50.95Hz
Using the collect.m function created in Matlab, I was able to record and plot the response for a unit step
input of our system with the PD Controller devised earlier. As shown in Figure 5.1, the unit step
response looks good. It has a 2.7% overshoot, a rise time of 0.092s and zero steady-state error.
81
Figure 5.1 Step Response for Example Closed-Loop System using PD Controller
Since weve met our Design Specifications, no more tests need to run. However, there is one last thing I
would like to do. Id like to compare the response of our physical system with our modeled response.
Using the Simulink model I created called base_closed_loop_model_test, I was able to compare both
results. This program is very similar to the program created in Section 2.2.5 to compare open loop
results. As shown in Figure 5.2 our modeled response shown in yellow is very close to the actual
response shown in purple. Im very confident our model is accurate enough to predict the systems
stability in the Section 5.2.
1 + 0.024
1 + 0.024
3
1 + 6.6210 1 + 6.62103
82
Figure 5.2 Comparison Plot of Unit Step Response of Modeled System vs. Actual System using a PD
Controller
However, to write the code for this Controller requires the Controller Transfer Function to be first
converted from the Laplace domain to the discrete domain and then into a difference equation. To
convert from the Laplace domain to the z-domain, I used the following equation to convert its zeros and
poles:
=
(5.0)
83
-3db
111.1Hz
Stupid Matlab
Figure 5.3 Bode Diagram of Example Closed-Loop System using Phase Lead Controller
Rearranging our Phase Lead Controller Transfer Function in terms of zeros and poles, we get the
following:
() =
Using Equation 5.0, we can covert our Laplace domain zeros to z-domain zeros as follows:
= = 41.6667(0.001) = 0.9592
Using Equation 5.0, we can covert our Laplace domain poles to z-domain poles as follows:
= = 151.0574(0.001) = 0.8598
This leaves us with the following transfer function:
() =
( 0.9592) ( 0.9592)
( 0.8598)( 0.8598)
84
To calculate the value of k, the usual method is to equate the DC gain when s = 0 and z = 1. This results
in:
3.29(0 + 41.6667)(0 + 41.6667) (1 0.9592) (1 0.9592)
=
(0 + 151.0574)(0 + 151.0574)
(1 0.8598)(1 0.8598)
Which gives us:
= 2.96
And the following discrete Controller:
() =
Or in normalized form:
() =
Now that our Controller is in the z-domain, our next step is to convert it into a difference equation.
Following the procedure laid out by Silvano Balemi [14], where he converts the general discrete
Controller:
() + 1 1 + 2 2 + 1 + 0
() =
=
()
+ 1 1 + 2 2 + 1 + 0
Into the following form:
= 1 1 0 + + + 1 +1 + 0
Where in this case k represents the discrete time step, we get the following Phase Lead Controller in
difference equation:
= 1.721 0.73932 + 2.96 5.6781 + 2.7232
Coding and uploading this equation into the Arduino Mega and using the collect.m function in Matlab to
record and plot the response for a unit step input of our system results in the plot shown in Figure 5.4.
The unit step response looks good as well, with a 3.36% overshoot, a rise time of 0.095s and zero
steady-state error. Interestingly, the Phase Lead Controller did not perform as well on the physical
system as the PD Controller, which does not match our simulation results. Why is that? Its most likely
because we were not able to implement our Phase Lead Controller at the required Control Loop
Frequency of 1111Hz.
85
Figure 5.4 Step Response for Example Closed-Loop System using Phase Lead Controller
Since weve met our Design Specifications, no more tests need to run. However, again, Id like to
compare the response of our physical system with our modeled response. As shown in Figure 5.5, the
actual response shown in purple seems to lag noticeably to the modeled response shown in yellow.
Fortunately, this deviation is most likely a result of the Control Loop Frequency implemented on the
Arduino Mega being lower then desired. Im still very confident our model is accurate enough to predict
the systems stability.
Unfortunately, stupid reality gets in the way. The main culprits are model inaccuracies, aging, noise and
disturbances. Remember, the poles represent physical properties, and as a system ages, the properties
change and so do the locations of the poles. Likewise, noise and disturbances can push a stable pole to
the right of the Imaginary Axis and cause the system to go unstable. As a result, the best way to protect
your system from going unstable is to insure it has a sufficiently large stability margin.
Figure 5.5 Comparison Plot of Unit Step Response of Modeled System vs. Actual System using a
Phase Lead Controller
87
5.2.1.1 Example Continued - Stability Analysis using Bode Diagrams for System with PD Controller
Using Matlabs margin function for an open-loop system with the PD Controller, the following Bode
Diagram was plotted:
Using this function, Matlab calculates a Gain Margin of infinity and a Phase Margin of 65.5 at 38rad/s.
Both values exceed our conservative rule of thumb for Gain and Phase Margins so Im confident our PD
Controller will remain stable regardless of aging, noise and/or disturbances.
5.2.1.2 Example Continued Stability Analysis using Bode Diagrams for System with Phase Lead
Controller
Using Matlabs margin function for an open-loop system with the PD Controller, the Bode Diagram in
Figure 5.7 was plotted.
88
Figure 5.7 Bode Diagram of Example System with a Phase Lead Controller
Using this function, Matlab calculates a Gain Margin of infinity and a Phase Margin of 69.9 at 71.4rad/s.
Both values exceed our conservative rule of thumb for Gain and Phase Margins so Im confident our
Phase Lead Controller will remain stable regardless of aging, noise and/or disturbances.
1
) = 2010 ( )
(5.1)
89
If the Nyquist Plot intersects the real axis at the origin or on the positive real axis, the Gain Margin is
considered infinite.
Similarly, the Phase Margin is defined as the angle that the Nyquist Plot would have to change to move
to intersect the (-1, 0) point. On a Nyquist Plot, the angle is measured from the negative real axis about
the origin towards the intersection between the Nyquist Plot and the unit circle. If the angle is counterclockwise direction, it is considered positive. If the Nyquist Plot never intersects the unit circle, the
Phase Margin is considered infinite.
As shown below in Figure 5.8, the Sample Nyquist Plot has a Phase Margin of 112. It also has a Distance
of 0.2, and using Equation 5.1, the Gain Margin is:
() = 2010 (
1
) = 2010 (5) = 15
0.2
Unit Circle
Distance = 0.2
Well use the same conservative rule of thumb for Gain and Phase margins that we used stability
analysis using Bode Diagrams.
90
6.0 References
[1] Ogata, Katsuhiko, Modern Control Engineering, page 159, Prentice Hall, New Jersey, 5th Edition,
2010.
[2] Avago Download Page, Accessed June 1st, 2015, http://www.avagotech.com/docs/AV02-1046EN.
[3] Avago Download Page, Accessed June 1st 2015, http://www.avagotech.com/docs/AV02-0096EN.
[4] Franklin, Gene and Powell, J. David and Emami-Naeini, Abbas,Feedback Control of Dynamic
Systems, page 48, Prentice Hall, New Jersey, 6th Edition, 2010.
[5] Chirp, Wikipedia: The Free Encyclopedia, Wikimedia Foundation Inc., May 5, 2015, Accessed June
12th, 2015, http://en.wikipedia.org/wiki/Chirp.
[6] Ogata, Katsuhiko, Modern Control Engineering, page 161, Prentice Hall, New Jersey, 5 th Edition,
2010.
[7]
Extras:
System
Identification,
Accessed
http://ctms.engin.umich.edu/CTMS/index.php?aux=Extras_Identification.
13th,
June
[8] Root Locus, Wikipedia: The Free Encyclopedia, Wikimedia Foundation Inc., January 24, 2015,
Accessed June 20th, 2015, http://en.wikipedia.org/wiki/Root_locus.
[9] Franklin, Gene and Powell, J. David and Emami-Naeini, Abbas, Feedback Control of Dynamic
Systems, page 120, Prentice Hall, New Jersey, 6th Edition, 2010.
[10] Franklin, Gene and Powell, J. David and Emami-Naeini, Abbas, Feedback Control of Dynamic
Systems, page 119, Prentice Hall, New Jersey, 6th Edition, 2010.
[11] Franklin, Gene and Powell, J. David and Emami-Naeini, Abbas, Feedback Control of Dynamic
Systems, pages 116-119, Prentice Hall, New Jersey, 6th Edition, 2010.
[12] Franklin, Gene and Powell, J. David and Emami-Naeini, Abbas, Feedback Control of Dynamic
Systems, page 129, Prentice Hall, New Jersey, 6th Edition, 2010.
[13] SYDE 352, Introduction to Control Systems, Course Notes, Package 2 of 2, Winter 2006, Prof. Dan
Davison, Dept. of Electrical and Computer Engineering, University of Waterloo.
[14] Balemi, Silvano, Advanced Control, June
http://www.dti.supsi.ch/~smt/courses/DigImpl.pdf.
3,
2011,
Accessed
August
13,
2015,
91