Академический Документы
Профессиональный Документы
Культура Документы
Student Manual
All of Quanser's systems have an inherent open architecture design. It
should be noted that the following experimental setup, accompanying
files, and configuration are merely one of the many possible uses of
this product.
Table of Contents
1. INTRODUCTION..........................................................................................................................................2
2. PREREQUISITES.........................................................................................................................................3
3. OVERVIEW OF FILES..................................................................................................................................3
4. PRE-LAB ASSIGNMENTS.............................................................................................................................5
4.1. Open Loop Transfer Function ..........................................................................................................5
4.2. Proportional Controller.....................................................................................................................7
4.2.1. Routh-Hurwitz Criterion........................................................................................................................8
5. IN-LAB PROCEDURES...............................................................................................................................20
5.1. Proportional Controller in SISO-tool..............................................................................................20
5.2. Proportional-Integral Controller in SISO-tool................................................................................23
5.3. LEAD Controller in SISO-tool.......................................................................................................25
5.4. Simulating LEAD Controller on Linearized Model.......................................................................28
5.5. Simulating LEAD Controller on Non-Linear Model......................................................................33
5.5.1. Non-Minimum Phase Zeros..................................................................................................................37
1. Introduction
The objective of this experiment is to design a position controller for the gyroscope system depicted in
Figure 1. Gyroscopes have become of great practical interest as they are used in control and guidance
systems for air, sea, and space vehicles. The Quanser 3 DOF Gyroscope system can be actuated about
all of its frames using the mounted motors while encoders measure the angle about each axis. In
addition the rotor itself is actuated and measured in the same manner.
The outer rectangular frame, outer red gimbal and the inner blue gimbal are designed such that they can
be individually fixed in place upon desire. This allows the users to perform a variety of different
experiments using the device. Throughout this experiment, the outer rectangular frame will be fixed
while all other frames are free to rotate. For instructions on how to fix each frame please refer to [1].
In this laboratory, the gyroscopic effect will be employed to control the angle of the red gimbal , by
Document Number 807 Revision 1.0 Page 2
applying the control command about the blue gimbal only. In order to do this, the rotor has to have
acquired enough angular momentum (RPM) for the gyroscopic effect to take place. Therefore a
controller is required to control the angular speed of the disk while another is required to control the red
gimbal angle . You will design both these controllers during this experiment while the following
topics are covered:
Obtaining the system transfer function from a set of provided equations of motion.
System stability analysis using the Routh-Hurwitz method.
System stability analysis using the Root Locus method and the MATLAB 'sisotool'.
Effects of non-minimum phase zeros on the system response.
State-feedback control design using LQR.
Friction estimation.
As mentioned earlier all rotating frames of the Quanser 3 DOF Gyroscope plant can be fixed upon
desire giving the user the flexibility to perform various experiments with different setups. For example
the entire material covered in this experiment can be used to perform the same set of tasks with the red
gimbal fixed and the rectangular frame being controlled. As another setup the blue gimbal can be fixed,
while the red gimbal is actuated to control the angle of the rectangular frame.
Please keep in mind that as the purpose of this experiment is to emphasize on design, simulation and
implementation of a control system for the gyro, minimal focus is put on the modeling procedure
involved to obtain equations of motion for this system. However the equations are used throughout the
laboratory to design and implement a complete control system. If you are interested in detailed
information on obtaining equations of motion for the gyro, please refer to [2].
2. Prerequisites
In order to successfully carry out this laboratory, the user should be familiar with the following:
Data acquisition card (e.g. Q8), the power amplifier (e.g. AMPAQ), and the main components
of the Gyroscope (e.g. actuator, sensors), as described in References [3], [4], and [1]
respectively.
Wiring and operating procedure of the Gyroscope plant with the AMPAQ and DAC device, as
discussed in Reference [1].
Transfer function fundamentals, e.g. obtaining a transfer function from a differential equation.
3. Overview of Files
Table 1 below lists and describes the various files supplied with the Gyroscope Position Control
laboratory.
Document Number 807 Revision 1.0 Page 3
File Name
Description
Gyro_model_params.m
s_gyro_position_control_linear.mdl
q_gyro_calibrate.mdl
q_gyro_position_control.mdl
d_gui_lqr_tuning.m
d_gui_lqr_tuning.fig
4. Pre-Lab Assignments
4.1. Open Loop Transfer Function
The following pair of equations describe the motion of the Gyroscope plant and were obtained by
consulting [2].
J y h
=M y
[1]
h J
z =0
[2]
Figure 2 shows the reference co-ordinate frame that results when the configuration mentioned in
section 1 is adopted with the Quanser 3 DOF Gyroscope system.
In equations [1] and [2] Jy is the moment of inertia around the y-axis, is the angle about the y-axis, h
is a constant calculated based on the moment of inertia of the gyroscope rotor about its own axis as well
as its RPM. The variable is the angle about the z-axis and is the variable we are interested in
controlling. As mentioned earlier the only actuated axis in this SISO system is the y-axis and the
control input is the torque applied in this direction denoted by My. Finally Jz is the moment of inertia
about the z-axis.
The block diagram shown in Figure 3 is a simplified general feedback system with a compensator
block, C(s), denoting the controller and a G(s) block denoting the Gyroscope plant. The measured
output, Y(s) which in our case is , is supposed to track the reference signal R(s).
In order to design the controller block C(s) that can stabilize the gyroscope plant, we will apply various
control schemes starting with a basic proportional controller and inspect the stability of the system. But
before applying the proportional control, we need to come up with the open loop plant transfer function
G(s).
1. Using equations [1] and [2] derive the open loop transfer function G(s) for the gyroscope plant
from input My to output .
0 1 2
2. The following table contains numerical values for the parameters appearing in the system
Document Number 807 Revision 1.0 Page 6
equations of motion. Use these values to obtain the numerical open-loop transfer function G(s).
Parameter
Numerical
Value
1.0891
Unit
kg m
s
Jy
0.0026
Jz
0.0342
kg m
kg m
2
2
0 1 2
[3]
This controller is simply a gain that is multiplied by the error signal and fed into the plant. In this
section we will obtain the closed loop transfer function from the reference input to the system output.
This transfer function now includes the effect of the controller and can be used to determine whether a
proportional controller can stabilize the gyroscope plant or not.
1. With C(s) = kp, obtain the complete closed-loop transfer function from the reference input R(s)
to output Y(s). Provide both parametric and numerical transfer functions.
0 1 2
A system is deemed to be stable if the poles of its closed loop transfer function lie strictly in the left
half of the complex plane. In other words in order for a system to be stable the real part of all the poles
of its closed loop transfer function must be negative. There are various methods available to check for
stability of a linear system. The Routh-Hurwitz stability criterion is a necessary (and frequently
sufficient) method to establish the stability of a SISO system. This method works directly with the
characteristic polynomial associated with the closed loop transfer function to determine if there are any
poles with positive real part that will give rise to system instability. The next section gives a brief
discussion on the Routh-Hurwitz procedure and then applies it to the above controller. For more details
on this method and its special cases you are encouraged to refer to your course text book where this
material is covered.
n1
P s=a n s a n1 s
[4]
...a 1 sa 0
The Routh-Hurwitz method consists of forming a table that has n rows and the following general
structure:
an
an-2
an-4
...
an-1
an-3
an-5
...
b1
b2
b3
...
c1
c2
c3
...
...
...
...
...
ci =
an 1 an 2 i an an 2 i 1
an 1
b1 an 2 i 1 bi + 1 an 1
b1
[5]
[6]
The number of sign changes in the first column of the Routh-Hurwitz table indicates the number of
unstable poles for the closed loop system. Therefore if the entries in the first column of the RouthHurwitz array are all positive or all negative the closed loop system can be deemed as being stable. As
mentioned above you are encouraged to refer to your course textbook or the web for more details on the
Routh-Hurwitz method and its special cases.
1. Using the Routh-Hurwitz method check for the stability of the closed loop system obtained by
applying a proportional controller to the Gyro plant.
0 1 2
In the later in-lab sections you will be asked to use the MATLAB siso-tool to check whether a
proportional controller is sufficient for stabilizing the gyroscope plant.
k p ( TI s + 1 )
TI s
[7]
This is a feedback controller that drives the gyroscope plant with a weighted sum of the error
(difference between the output and the desired set-point) and the integral of that value. In equation [7]
kp is the proportional gain and TI is chosen to place a zero on a desired location on the real axis. In this
section we will obtain the closed loop transfer function from the reference input to the system output.
This transfer function now includes the effect of the controller and can be used to determine whether a
PI controller can stabilize the gyroscope plant or not.
1. With C(s) as defined in [7], obtain the complete closed-loop transfer function from the reference
input R(s) to output Y(s). Provide both parametric and numerical transfer functions.
0 1 2
2. Using the transfer function you obtained in the previous question, form the Routh-Hurwitz table
for the gyroscope plant driven by a PI controller.
0 1 2
3. Analyze the Routh-Hurwitz table you obtained in the previous question to conclude whether the
gyroscope plant can be stabilized when driven by a PI controller.
0 1 2
C( s ) =
k (s + )
s+
[8]
This controller introduces a pole-zero pair into the open loop transfer function. In this section we will
use the Routh-Hurwitz method to determine if there are any possible combinations of and that will
cause the above controller to stabilize the closed loop gyroscope system. You will also check for the
stability of the above system during the lab session and using the MATLAB 'sisotool' utility.
1. With C(s) as defined in [8], obtain the complete closed-loop transfer function from the reference
input R(s) to output Y(s). Provide both parametric and numerical transfer functions.
0 1 2
2. Using the transfer function you obtained in the previous question, form the Routh-Hurwitz table
for the gyroscope plant driven by a LEAD controller.
0 1 2
3. Analyze the Routh-Hurwitz table you obtained in the previous question to conclude whether the
gyroscope plant can be stabilized when driven by a LEAD controller.
0 1 2
[9]
1. Using equations [1] and [2] and the state vector given below, obtain the complete state-space
representation for the gyroscope plant. Provide both parametric and numerical values for A and
B matrices.
x=
[10]
0 1 2
4.5.1. LQR
A system is deemed as being controllable if its poles can be placed at any desired location via statefeedback. One method of determining if a system is controllable is called the rank test. In performing
the rank test a matrix called the controllability matrix is first obtained which has the following form:
2
n1
C A , B =[ B , AB , A B , ... , A
B]
[11]
where A is an n x n matrix. If the controllability matrix has full rank (ie. rank (CA,B) = n) the system is
controllable meaning that its closed loop poles can be placed at any desired location using statefeedback.
Once a system has proven to be controllable the LQR method can be used to design a controller of the
following form:
u= Kx
[12]
where K is the control gain obtained by using the LQR method and x is the state-vector which in the
case of our gyroscope plant was defined in equation [10]. In general the LQR method finds the signal
u(t) as defined above that minimizes the cost function:
Document Number 807 Revision 1.0 Page 17
J =
T
T
x( t ) Q x( t ) + u( t ) R u( t ) dt
[13]
.
where Q and R are user-defined weighting matrices that can be tuned in the design process to obtain
desired performance. For any chosen Q and R the LQR method finds the state-feedback gain that will
result in minimizing the cost function defined in [13].
1. Use the rank test to show that the gyroscope plant is controllable.
0 1 2
One of the problems with the LQR method is that there are little guidelines for choosing the Q and R
weighting matrices. Typically they are initially set to their corresponding identity matrices, the
optimization algorithm is ran and the system is simulated using the generated gain to observe the
closed-loop response. The weighting matrices are then adjusted until the desired performance is
obtained. For the gyroscope plant the weighting matrices will be of the following form:
q1 0 0
Q= 0 q 2 0
0 0 q3
and
R=1
[14]
It is useful to gain some insight on how the weighting parameters affect the gain being generated when
using LQR:
1. Expand the expression under the integral of the cost function given in [13] such that it is written
in terms of the weighting parameters qi , the system states and the generated state-feedback gain
vector.
Document Number 807 Revision 1.0 Page 18
0 1 2
2. Based on the result you obtained in the previous question determine which gains are primarily
affected by which weighting parameter. Give the correlations between the qi and the elements of
K.
0 1 2
5. In-Lab Procedures
During the In-Lab procedure you will first use the MATLAB siso-tool utility to verify your findings in
the pre-laboratory section on different control actions on the gyroscope plant. Next a controller that
shows to be able to stabilize the plant will be simulated on the linearized gyroscope model that you
obtained earlier. This controller will also be applied to a non-linear model of the gyroscope (which is
the actual case) and its performance will be compared to that of the controller acting on the linearized
model. Finally this controller will be implemented on the actual gyroscope plant. A state-feedback
controller designed using LQR is also provided to be implemented on the gyro plant. You will tune this
controller to improve its performance using the intuition you have developed during the pre-laboratory
exercises in section 4.5.1.
[15]
Follow the steps below to design an apply a proportional controller to the gyro plant using the
MATLAB siso-tool environment:
1. Load the MATLAB software.
2. Browse through the Current Directory tab in MATLAB and find the folder that contains the
experiment files supplied.
3. Open the script named Gyro_model_params.m. Make sure that the parameter CONTROL_TYPE
has been set to 'MANUAL' and run the file by clicking on the Run button found in the toolbar or
pressing F5 while the above script is the active window. This sets the necessary values for gyro
parameters such as the ones found in Table 2 and also the open-loop gyro transfer function, G,
into the MATLAB workspace.
4. Close the setup script and type sisotool(G) in the MALTAB command prompt and hit the
enter key. This will open the Control and Estimation Tools Manager and the SISO Design Task
windows. The SISO Design Task window shows a plot of the open-loop system poles in the
polar co-ordinate system as well as an open-loop Bode diagram as depicted in Figure 4. The
Control and Estimation Tools Manager window provides various tools to design and tune
compensator blocks, plot responses to various inputs and also lets you to export and import data
Document Number 807 Revision 1.0 Page 20
The purple squares shown in Figure 4 denote the closed loop system poles. You can add poles and
zeros to the closed loop system by right clicking on the root locus plot and selecting Add Pole/Zero
from the drop down menu. This will provide you with another menu from which you can choose what
type of pole or zero (real or complex) you want to add. Once you have selected this clicking any
location on the plot will place your choice of pole/zero on that location and the updated root locus
diagram will be shown. You can also enter the exact location of where you would like your zero/pole to
be placed. To do this bring up the Control and Estimation Tools Manager window and click on the
Compensator Editor tab. The Compensator pane shows the current transfer function of the controller
C(s). To add poles/zeros you can right-click on the Dynamics pane found under the Pole/Zero tab. This
provides you with a drop down menu from which you can choose the type of zero/pole being added.
Once this is selected the corresponding pole or zero is shown in the Dynamics pane. You can edit the
location of an added pole or zero by selecting it from the Dynamics pane and editing its corresponding
value in the Location text box found under the Edit Selected Dynamics tab. Now continuing with our
proportional controller:
5. Looking at [15] we see that the proportional controller is simply a gain and hence does not add
any poles or zeros to the controller transfer function. The value of kp only changes the location
of the poles already present in the system. Try different values for kp by entering them into the
text-box found in front of the drop down menu under the Compensator pane. Examine the
Document Number 807 Revision 1.0 Page 21
resulting changes in the root locus diagram. You can also move backwards meaning you can
manually change the location of the closed-loop system poles by selecting them with your
mouse cursor and moving them around the plot. You can then go to the Control and Estimation
Tools Manager and look at the value of kp that would be required to have the closed-loop poles
in the locations you have chosen. Try placing all three closed-loop poles in the left half plane to
stabilize the system and answer the following question.
1. Can the closed-loop system be stabilized using a proportional controller? If yes, provide the
value of kp that results in a stable system. If no, comment on why this is not possible. Does this
result validate your answer to question 1 in section 4.2.1?
0 1 2
Exit the siso-tool by closing the Control and Estimation Tools Manager window.
k p ( TI s + 1 )
TI s
[16]
Similar to section 5.1 we will use the MATLAB siso-tool to study the effects of applying a PI controller
to the gyro plant. By looking at [15] we see that the PI controller has a pole at the origin and a zero at
-1/TI . Follow the steps below to design an apply a PI controller to the gyro plant using the siso-tool:
1. Type sisotool(G) in the MATLAB command prompt and hit the enter key. This will open the
same two windows (Control and Estimation Tools Manager and SISO Design Task) as
mentioned earlier.
2. In the Control and Estimation Tools Manager window click on the Compensator Editor tab.
3. Right-click in the Dynamics pane found under the Pole/Zero tab and select Add Pole/Zero and
then Real Pole from the menu.
4. The added pole will be shown under the Dynamics pane with a default location of -1. Since our
controller has a pole at zero, select the newly added pole under the Dynamics pane and change
its value to zero in the text-box found in front of Location under the Edit Selected Dynamics
pane.
5. Right-click in the Dynamics pane again and select Add Pole/Zero and then Real Zero from the
menu.
6. The added zero will be shown under the Dynamics pane with a default location of -1. You can
choose a starting value for TI that will result in a corresponding zero location and enter this as
the location of the newly added zero using the same procedure as explained in step 4 above.
7. You can now look at the resulting root locus diagram by opening up the SISO Design Task
window. Notice that there are now 4 purple squares corresponding to the four closed-loop
system poles. The red circle denotes the zero you have added while the red cross at the origin
corresponds the pole you placed at zero. The three original open-loop system poles are also
denoted by blue crosses seen on the imaginary axis and the origin although the open-loop pole
at the origin now lies under the new pole we have added there. You can select any of the closed
loop poles (purple squares) and move them around. This will change the value of kp appearing in
[16].
8. Vary the location of your added zero as well as the proportional gain kp to try to stabilize the
system by placing all four closed loop poles in the left half plane and answer the following
question.
1. Can the closed loop system be stabilized using a PI controller? If yes provide the controller
transfer function. If no comment on why this is not possible. Does this result validate your
answer to question 3 in section 4.3?
0 1 2
Exit the siso-tool by closing the Control and Estimation Tools Manager window.
C( s ) =
k (s + )
s+
[17]
Similar to the last two sections the siso-tool will be used to introduce a pole-zero pair into the closedloop transfer function and tune the pole locations by varying k trying to place all poles in the left half
plane and hence stabilizing the system. Follow the steps below to design the LEAD controller defined
in [17]:
1. Type sisotool(G) in the MATLAB command prompt and hit the enter key. This will open the
same Control and Estimation Tools Manager and SISO Design Task windows as in the last two
sections.
2. In the Control and Estimation Tools Manager window click on the Compensator Editor tab.
3. Right-click in the Dynamics pane found under the Pole/Zero tab and select Add Pole/Zero and
then Real Pole from the menu.
4. The added pole will be shown under the Dynamics pane with a default location of -1. Select a
location for this pole keeping in mind that poles in the right hand plane give rise to system
instability and enter it as the pole location.
5. Right-click in the Dynamics pane again and select Add Pole/Zero and then Real Zero from the
menu.
6. The added zero will be shown under the Dynamics pane with a default location of -1. Choose a
value for the zero location () and enter it.
7. You can now look at the resulting root locus diagram. Notice that regardless of the shape of the
root locus plot there are now 4 closed-loop poles as indicated by the 4 purple squares. The three
original open-loop poles are also denoted by blue crosses two of which lie on the imaginary
axis and the third located at the origin.
8. Vary the location of the compensator pole/zero pair that you have added and tune the k
parameter in [17] by moving the closed-loop poles (the purple squares) around and try to place
all 4 closed-loop poles in the left half plane. You can use the zoom button found in the toolbar
above the plot to change the zoom level as sometimes selecting between adjacent poles/zeros
becomes difficult depending on your design values. Answer the following question once you are
done tuning your controller:
1. Can the closed loop system be stabilized using a LEAD controller? If yes provide the controller
transfer function. If no comment on why this is not possible.
2. How does your answer to the above question compare to what you obtained in question 3 of
section 4.4?
0 1 2
Exit the siso-tool by closing the Control and Estimation Tools Manager window.
23.81s
s29.41
[18]
Follow the steps below to import this controller into the siso-tool environment so that you can begin
tuning it for specifications:
1. Save the above controller transfer function in the MATLAB workspace under the variable
named C by typing the following in the MATLAB command prompt and hitting the enter key.
(If you have closed MATLAB or cleared the workspace from the beginning of this lab re-run the
Gyro_model_params.m script so that the gyro open-loop transfer function, G, is loaded into
the workspace)
C = 17.35*(23.81-s)/(s+29.41);
2. Type sisotool(G) in the MATLAB command prompt and hit the enter key.
3. In the SISO Design for SISO Design Task window click on file and select Import.
Document Number 807 Revision 1.0 Page 28
4. In the System Data window that pops up, double-click in the cell corresponding to C (third row,
second column) and change its value from 1 to C. Click on OK when you're done.
5. Looking at the resulting root locus diagram it is clear that the system is stable.
6. Click on the Analysis tab in the SISO Design for SISO Design Task window and select
Response to Step Command. This will open the LTI Viewer for SISO Design Task window in
which the closed loop step response of the system is plotted in blue. The green plot shows the
output of the controller in response to the step command. As mentioned earlier one of the design
specifications is to keep this value below a threshold of three which is clearly not met under the
current controller.
7. Right-click on the step response plot and select Characteristics and then Rise Time from the
menu. This causes the rise times of both responses to be shown so that you can see the value of
this design requirement while tuning.
8. Without closing the Control and Estimation Tools Manager and SISO Design Task windows,
use the MATLAB current directory window to open the Simulink model named
s_gyro_position_control_linear.mdl. This model is shown below. The Input block sets the
reference signal to a square wave with an amplitude of 1 and frequency of 0.1 Hertz. The system
output is the gyro angle about the z-axis, . The Compensator block holds the C(s) controller
that you entered above, and the Plant block holds the linearized gyro model, G, that was
obtained in the pre-laboratory section.
9. Run the simulation by clicking on the Start simulation button found in the toolbar. Examine the
Torque and Psi () scopes. Figures 6 and 7 below depict plots of these parameters under the
controller defined in [18]. Keep in mind that as mentioned in section 1 we are controlling the
gyro angle about the z-axis by actuating the plant only and only about the y-axis. This is a direct
result of the Gyroscopic Effect. Stop the simulation by clicking on the Stop simulation button
found in the Simulink toolbar.
As you have already noticed, there is a fairly large amount of overshoot on the gyro angle . One way
to measure this overshoot is to type max(Psi) in the MATLAB command prompt and hitting enter.
The scope showing this variable in the Simulink model is also saving it to the workspace. Therefore
running the above command returns a two element vector. The first element is the simulation time at
which the maximum amplitude has been recorded and the second element is this value. Of course there
are many other ways to measure this overshoot such as plotting against time in a MATLAB figure
and using a data cursor to measure the overshoot.
1. Using the above procedure to measure the overshoot or any other preferred method, calculate
the percentage overshoot of the closed-loop system output when running under controller [18].
0 1 2
Go back to the SISO Design for SISO Design Task window. Also have the LTI Viewer for SISO Design
Task window which is showing the system step response open. Begin tuning the controller by moving
the compensator pole and zero around. You can also modify the proportional gain k, by moving the
closed-loop poles (purple squares) around. Notice that the step responses change in real-time while you
tune the controller. Tune the controller until the controller step response amplitude is below 5.
Remember the other two specifications as well. As mentioned earlier you can right-click on the plot on
LTI Viewer for SISO Design Task window and select Characteristics / Rise Time from the menu to see
a real-time updated value of both response rise times on the graph. Tune the controller until all three
specifications are met.
2. Once all three specifications are satisfied, print the LTI Viewer for SISO Design Task window
that is showing your closed-loop and controller step responses as well as the rise time and attach
it to this report. Also provide the transfer function of your controller. In the SISO Design for
SISO Design Task window click on the Designs tab and select Edit Compensator. The controller
transfer function is shown in the Control and Estimation Tools Manager window under the
Compensator pane.
0 1 2
You can now simulate your designed controller on the linearized model and make sure that the design
specifications are satisfied. Follow the steps below:
1. If the s_gyro_position_control_linear.mdl model is still open close it.
2. In the MATLAB command prompt type clear C and hit the enter key.
3. Enter the transfer function of the controller you have designed in the MATLAB command
prompt under the variable C, as was done before for the initial controller.
4. Using the MATLAB current directory, open the Simulink model named
s_gyro_position_control_linear.mdl.
5. Run the simulation and examine the scopes plotting the torque commanded by the controller
and the gyro angle .
6. Once you are done stop the model. Using any preferred method calculate the new percentage
overshoot.
0 1 2
included here to compare the controller performance when acting on the linear and non-linear model.
Finally the Psi scope block plots the reference signal versus the gyroscope angle on both the linear
and non-linear models. The Torque scope block plots the control command when acting on both the
linear and non-linear models.
The VRML block contains the virtual reality simulation that was mentioned earlier. This sub-system
contains a block named VR Sink. You can double-click on this block to see a real-time updated
animation of the gyroscope when being driven by your controller. This lets you monitor gyro's stability
as well as its movements when the model is running.
Document Number 807 Revision 1.0 Page 34
Follow the steps below to apply your earlier designed controller to the non-linear gyroscope plant:
1. If you have closed MATLAB or cleared the workspace since finishing the previous section rerun the setup script named gyro_model_params.m. In the above case your controller transfer
function C(s) is deleted. Therefore enter it again using the MATLAB command prompt under
the variable C as was done in step 1 of section 5.4. When running the above setup script make
sure that the parameter CONTROL_TYPE is set to 'MANUAL'.
2. Using the MATLAB current directory open the Simulink model named
s_gyro_position_control_nonlinear.mdl.
3. Make sure the Ref_Command block has been set to produce a square wave with amplitude
20(deg) and frequency 0.1 Hz.
4. Click on the Incremental build button found in the Simulink toolbar. This can alternatively be
done by selection QUARC and then Build from the menu or pressing ctrl + b while the Simulink
model is the active window.
5. Once the code is successfully built, click on the Connect To Target button found in the
Simulink toolbar and then on the Start real-time code button. Note that selecting QUARC then
Start from the Simulink menu bar also performs the same action.
6. The simulation should now start. Remember that no output should be produced for the first 10
seconds as the gyro disk gets to its set-point RPM. After the first 10 seconds have passed the
reference is applied to the controller. You can open the Psi scope block to see a simultaneous
plot of the reference signal (in blue), response under the controller and linearized plant (in
purple) and response under the controller and non-linear plant (in yellow). Notice that
although the reference signal is set to a square wave, the scopes show a saw-tooth shaped
signal for the reference. This is due to the use of the Continuous Sigmoid block that sets a
maximum speed and acceleration that the reference signal is allowed to acquire.
The response under the linearized plant should be stable as you have already tuned this controller in
the previous section. However as mentioned at the beginning of this section satisfying a set of
specifications on a linearized model does not guarantee that all those specifications will be met on the
non-linear model under the same controller. Therefore you might notice that your controller does not
satisfy the requirements outlined in section 5.4 or is not even stable. If this is the case you should
further tune your controller using the same procedure as followed in the previous section and then try it
on the non-linear plant as instructed above. To do this, first stop the model by clicking on the Stop realtime code button. Now run the siso-tool and import the variable C from the workspace into the SISO
Design Task environment. Open the real-time updated step response window by clicking on Analysis in
the SISO Design Task window and selecting Response to Step Command. Now you can tune your
controller to further satisfy specifications and when you are ready you can enter its new transfer
function in MATLAB as before. You can then re-run the s-gyro_position_control_nonlinear.mdl
model to see the effects of your new controller on the nonlinear model. Each time that you apply your
controller to the non-linear model open the Torque scope block and make sure that the value of the
control command applied to the non-linear plant (yellow plot) stays below the saturation value of 1.5 as
set by the Saturation1 block at the output of the Controller block. If this signal saturates you should try
to decrease the amplitude of the controller step response (green plot) in the LTI Viewer for SISO Design
Task window when tuning your controller. Once you have a stable controller you can open the VRML
sub-system and double-click on the VR Sink block to see the simulated gyroscope virtual environment.
Document Number 807 Revision 1.0 Page 35
1. If your previous controller did not require any further tuning provide its transfer function below.
Also use the Time Figure and Time Figure1 blocks found in the Simulink model to print plots
of reference versus and the control command and attach them to your report. Do the above
with your new controller if your old one required tuning. Show that the control command is
below the saturation value of 1.5. You can use the data cursor by clicking on the Data Cursor
button found above each time figure plot.
0 1 2
C( s ) =
1.41 ( 1 0.38 s )
[19]
1 + 0.04 s
Applying this controller to the open loop plant G that was obtained in question 2 of section 4.1 leaves
us with the following open-loop and closed-loop transfer functions:
G( s ) =
ol
G( s ) =
cl
1.5355 ( 1 0.38 s )
0.3556 10
-5 4
3
2
s + 0.00008892 s + 0.474 s + 1.1861 s
[20]
1.5355 ( 1 0.38 s )
0.3556 10
[21]
-5 4
3
2
s + 0.00008892 s + 0.0474 s + 0.6026 s + 1.5355
Plotting the step response of this closed-loop system using the siso-tool's Response to Step Command
we obtain what is depicted in Figure 9. The blue plot shows the closed-loop system step response from
the reference input to system output which is the gyroscope angle in our case. The green plot shows
the controller step response from its input (error signal) to its output (control command applied to gyro
plant).
Look more closely to the closed-loop step response in the time interval between zero and about 0.4
seconds. As shown above, the response takes on negative values for a short time interval before
becoming positive again and finally settling at about 1.2 seconds. This is a property of a class of
systems called Non-Minimum Phase systems. In general when the open-loop system has a right-half
plane zero as in [20], the step response takes on negative values for some time before becoming
positive. This is known as a Non-Minimum Phase response or an Inverse Response. Since zeros of the
open-loop forwards transfer function G(s)ol appear as closed-loop zeros as in [21], it is concluded that
whenever G(s)cl has right half plane zeros, the system's step response will exhibit undershoot, taking on
negative values. If there are two or more right half plane zeros the form of the Non-Minimum Phase
response becomes more complex.
Figure 10 below shows a plot of the reference signal versus gyro angle when the controller in [19] is
applied to the non-linear gyro model in the Simulink model s_gyro_position_control_nonlinear.mdl.
The reference signal was set to a square wave with an amplitude of 20 degrees and frequency of 0.1 Hz.
The blue plot shows the reference command while the green plot shows the gyro angle .
As expected and seen above the non-minimum phase effect is present in the system. In this section you
will try to eliminate or minimize this effect by tuning the controller in [19]. Follow the steps below:
1. If you have closed MATLAB or cleared the workspace since finishing the previous exercise, run
the setup script gyro_model_ params.m.
2. Enter the controller defined in [19] into the MATLAB workspace under the variable C in the
Document Number 807 Revision 1.0 Page 38
0 1 2
0 1 2
Figure 11: Simulink Model Used to Simulate LQR Controller on Non-Linear Gyro Plant
x=
[22]
This is why in addition to the reference command, the states defined in [22] are also fed into the
controller under signal names dTheta, Psi and dPsi respectively.
As mentioned in section 4.5.1, in the LQR design process the Q and R weighting parameters are first set
to their corresponding identity matrices and are then tuned to meet some specifications. This is the
same procedure that will be followed in this section starting with the following Q and R factors:
1 0 0
Q= 0 1 0
0 0 1
and R = 1
[23]
Follow the steps outlined below to design and simulate the initial LQR controller on the non-linear
Gyro plant:
1. If you have closed MATLAB or cleared the workspace since finishing the last exercise, open
the MATLAB software, set the current directory to the folder where experiment files are saved,
and run the setup script named Gyro_model_params.m. When running this file make sure that
the parameter CONTROL_TYPE is set to 'MANUAL'. Otherwise skip to step 2.
2. Open the Simulink model named s_gyro_position_control_lqr.mdl. This is the model
depicted in Figure 11.
3. Double-click on the LQR Controller block. This should open the sub-system depicted in Figure
12.
As dictated by our state vector x defined in [10], the state feed-back gain K, is a three element
vector [K1, K2, K3], with K1 being the gain on , K2 being the gain on , and K3 acting on
. You can verify this by double-clicking on each of the Gain blocks and checking the gain
values set.
4. Without modifying any of the gain parameters set in the above sub-system, go to the MATLAB
command prompt and enter the A and B model matrices that you calculated in question 1 of
section 4.5 into the MATLAB workspace using the following format and variable names:
A=[a 11 a 12 a13 ; a 21 a22 a 23 ; a 31 a 32 a33 ] ; and
B=[b1 ; b2 ; b 3];
where aii and bii entries correspond to the entry values you have calculated.
5. Our system output is the gyro angle which is the second entry in our state vector defined in
[10]. Therefore enter the C and D matrices into the MATLAB workspace as follows:
C=[0 1 0]; and
D=0 ;
6. With the Simulink model named s_gyro_position_control_lqr.mdl still open type the
following command in the MATLAB command prompt and hit the enter key:
d_gui_lqr_tuning('A', A, 'B', B, 'C', C, 'D', D);
This should open a window similar to the one depicted in Figure 13.
This is a graphical tool that you will use to perform on-line tuning on the LQR controller that is
applied to the non-linear gyro plant in s_gyro_position_control_lqr.mdl. As seen in Figure 13,
you can vary the diagonal entries in the Q weighting matrix as well as R. Every time that you
make a change, clicking on the Apply button will cause a new gain K to be calculated and
applied to the model automatically. This calculated K is the three element vector that was
mentioned earlier and is obtained using the MATLAB 'lqr' function and the Q and R weighting
parameters that you choose. As seen in Figure 13 and equations in [23] the controller you will
begin with has the identity matrices as its Q and R weighting parameters.
7. Click on Apply. The calculated state-feedback gain K will be calculated and is shown below:
K = [1.03 1.00 0.41]
8. Without closing the LQR Tuning GUI, go back the Simulink model
s_gyro_position_control_lqr.mdl. Make sure that the Ref_Command block is set to output a
square wave with amplitude 20 (deg) and frequency 0.1 Hz. Click on the Incremental build
button found in the Simulink toolbar. This can be alternatively done by selecting QUARC and
clicking on Build or holding ctrl + B while the Simulink model is the active window.
9. Once the model real-time code is built, click on the Connect To Target button and then on the
Start real-time code button to start the simulation. This can be alternatively done by selecting
QUARC and clicking on Start or holding ctrl + J while the Simulink model is the active
window.
10. Once the first 10 seconds have passed (during which the gyroscope disk is being brought up to
desired RPM), the reference is applied and you can monitor the system response by looking at
the Ref vs. Psi and Torque scopes. Figures 14 and 15 show these two plots.
You can open the VRML sub-system and double-click on the VR Sink block, to see a real-time
virtual environment simulation of the gyroscope and its movement in response to the reference
input. Again notice that we are controlling the gyro angle about the z-axis, by only
Document Number 807 Revision 1.0 Page 45
commanding the y-axis which is a direct result of the gyroscopic effect. As seen in Figure 14,
the system response is fairly poor and the steady-state error is clearly much greater than zero.
11. Keep the Simulink model running. Go back to the LQR Tuning GUI. You can now begin tuning
the weighting parameters using the text boxes corresponding to each entry. Once you click on
Apply, the new gain will be calculated and applied to the controller in real-time so you can see
the effect of your tuning immediately on the scopes. Tune the controller until you get zero
steady state error. Also make sure that the torque generated by your controller is not saturated at
the threshold level of 1.5 as set by the Saturation block in the Simulink model.
12. Once you obtain a response in gyro angle that has zero steady-state error stop the model by
clicking on the Stop real-time code button in the Simulink toolbar or clicking on QUARC and
selecting Stop. Provide your tuned Q and R weighting parameters and the resulting statefeedback gain vector K. How does changing each parameter in the Q weighting matrix affect the
resulting K? Does this agree with your answer to question 2 in section 4.5.1?
0 1 2
13. Using the Time Figure blocks in the Simulink model s_gyro_position_control_lqr.mdl print
plots of the Reference versus gyro angle and the torque commanded by the controller when
the non-linear plant is driven by your tuned LQR controller and the Ref_Command block is set
to output a square wave with amplitude 20 (deg) and frequency 0.1 Hz. Attach these prints to
your report.
0 1 2
Figure 16: Simulink Model Used to Implement LEAD and LQR Controllers on Actual Gyro Plant
The HIL Interfacing block, implements an interface between the Simulink model and the data
acquisition device and eventually the actual gyro hardware. Reading of encoder counts and applying the
control command to gyroscope motors takes place in this block. Included in the HIL Interfacing subsystem, are two position-velocity controllers labeled Wheel Controller and Theta Controller. The
Wheel Controller block sets a reference RPM for the gyroscope disk and applies the required torque to
the disk such that the desired RPM is reached. As explained earlier the reference on the gyro angle is
set to be zero while the disk is acquiring the desired RPM to avoid instability. This is implemented in
the HIL Interfacing sub-system where there is a switch implemented on the Psi torque input to the
DAQ. The wait time before applying references on is set by the parameter DISK_RPM_DELAY in the
setup script Gyro_model_params.m which is set to 10 seconds by default. The reason for having the
Theta Controller block will become clear as you implement you controllers on the actual plant.
The Psi LEAD Controller block contains the same sub-system as the one found in the Controller block
of the Simulink model s_gyro_position_control_nonlinear.mdl that you used earlier to simulate a
LEAD controller on the non-linear gyro plant. It takes the reference signal and the current value for the
gyro angle as inputs. The output of this block is the control command calculated by the LEAD
controller defined in the Compensator block. Later in this section you will be prompted to enter the
transfer function of the LEAD controller you have designed in section 5.5.1 to the MATLAB work
space to be used as this compensator.
The Psi LQR Controller block contains the same sub-system as the one found in the LQR Controller
block of the Simulink model s_gyro_position_control_lqr.mdl that you used earlier to simulate an
LQR controller on the non-linear gyro plant. It takes the reference signal, and current values for ,
and as inputs. The output of this block is the control command calculated by the LQR controller.
This controller has a three-element gain K. Later in this section you will be prompted to enter the LQR
gain K, you have designed in part 12 of section 5.6 to the MATLAB work space to be used as this
controller.
The Simulation block contains a sub-system with the same structure as the Simulink models
s_gyro_position_control_nonlinear.mdl and s_gyro_position_control_lqr.mdl that you have used
earlier. Parallel to the actual control implementation running in the above blocks, the Simulation block
simulates the same controllers on the non-linear modeled plant for comparison purposes. The same
reference signal is passed through the same Sigmoid block in both the simulation and actual
implementations. The outputs of this block consist of the simulated gyro angle , LEAD controller and
LQR controller commands. These signals, as well as their actual implementation values are passed to
the Plotting & Scopes sub-system where you can monitor actual versus simulated values for these
parameters. Notice the switch labeled LEAD/LQR found in the top model as well as the Simulation subsystem. This switch select between the two controllers and you need to make sure that both switches are
set to the same controller whenever you are looking at a plot to compare simulation and actual
implementation values.
Finally the Continuous Sigmoid blocks found in both the top model and Simulation sub-system are set
to a maximum velocity and acceleration dictated by the variables SIGMOID_VEL_MAX and
SIGMOID_ACCEL_MAX respectively. These variables are defined in the setup script
Gyro_model_params.m.
Follow the steps below to implement the LEAD and LQR controllers you designed in the previous
sections on the actual gyro plant. Please note that it is assumed that the gyro device is wired to the
AMPAQ unit and the data acquisition card as described in [4].
1. If you have closed the MATLAB software since finishing the last exercise, re-load it.
2. Using the MATLAB current directory browse to the folder where the experiment files are saved
and open the setup script Gyro_model_params.m. Make sure the variable CONTROL_TYPE
is set to 'MANUAL' and run the script.
3. Enter the A and B matrices that you calculated in question 1 of section 4.5 into the MATLAB
work space under the variables A and B.
4. Enter the C and D matrices given in step 5 of section 5.6 into the MATLAB work space under
the variables C and D.
Document Number 807 Revision 1.0 Page 50
5. Enter the transfer function of the LEAD controller you designed in section 5.5.1 into the
MATLAB workspace under the variable name C_s. Use the same syntax as the one given in
step 1 of section 5.4.
6. Using the MATLAB current directory Open the Simulink model named
q_gyro_position_control.mdl which is depicted in Figure 16.
7. Configure DAQ: Open the HIL Interfacing sub-system and double-click on the HIL Initialize
block. Ensure that this block is configured for the DAQ device that is installed in your system.
By default it is setup for the Quanser Q8 Hardware-in-the-Loop board. See [5] for more
information on configuring the HIL Initialize block.
8. Now type the following command in the MATLAB command prompt and hit the enter key:
d_gui_lqr_tuning('A', A, 'B', B, 'C', C, 'D', D);
9. The LQR Tuning GUI shown in Figure 13 comes up. Enter the diagonal entries of the Q
weighting matrix you obtained in step 12 of section 5.6 in the appropriate boxes. Also enter the
value of weighting parameter R you obtained in the same question as above.
10. Click on the Apply button. The LQR gain will be calculated and displayed on the MATLAB
command prompt.
11. Using the MATLAB current directory open the Simulink model named q_gyro_calibrate.mdl.
This model simply consists of a HIL Initialize block that is configured to reset the encoders on
the gyro device. Make sure simulation mode is set to External in the Simulink toolbar and build
the real-time code by clicking on the Incremental build button or selecting QUARC/Start from
the Simulink menu.
12. Once the code is successfully built make sure that the gyro device is in an alignment similar to
the one shown in Figure 17. With the gyro aligned as described above, select QUARC/Start
from the Simulink menu. The code will run for 2 seconds and stop automatically. You can now
close the simulink model q_gyro_calibrate.mdl.
13. Go back to the Simulink model q_gyro_position_control.mdl and make sure that the
Reference block in the top model and the Ref_Command block in the Simulation sub-system are
both set to output a square wave with amplitude 20 (deg) and frequency 0.1 Hz.
14. Make sure that both LEAD/LQR blocks in the top model and the Simulation sub-system are
switched to the LEAD controller.
15. Make sure the simulation mode is set to External in the Simulink toolbar and build the real-time
code by clicking on the Incremental build button or selecting QUARC/Build from the Simulink
menu.
16. Once the code is successfully built, click on the Connect To Target button and then the Start
real-time code button. This can be alternatively done by selecting QUARC/Start from the
Simulink menu. Make sure to hold the gyroscope in the configuration shown in Figure 17
when starting the code and release it 3-4 seconds after the gyroscope disk has started
rotating. Avoid touching the wheel with your fingers and hold blue and red frames only.
17. The real-time code will now begin running and the gyroscope disk will start rotating and
speeding up to desired RPM. After the first 10 seconds have passed the references set earlier are
applied and the your controller kicks in.
If at any point during the time that the real-time code is running the system
becomes unstable, stop the model immediately by clicking on the Stop real-time
code button and consult a teaching assistant.
Document Number 807 Revision 1.0 Page 52
18. The gyro angle should be now tracking a reference square wave of amplitude 20 (deg) and
frequency 0.1 Hz. Open the Plotting & Scopes sub-system and double-click on the Reference vs.
Simulated vs. Actual Psi scope. The red plot is showing the reference input, the blue plot is
showing the simulated gyro angle and the purple plot is showing the actual gyro angle .
Notice that although the reference is set to a square wave the reference plot does not have the
shape of a square wave. This is because the reference is passed through the Continuous Sigmod
block which sets a limit on the maximum velocity and acceleration that this signal can acquire.
6. Obtaining Support
Note that a support contract may be required to obtain technical support. To obtain support from
Quanser, go to http://www.quanser.com and click on the Tech Support link. Fill in the form with all
requested software version and hardware information and a description of the problem encountered.
Submit the form. Be sure to include your email address and a telephone number where you can be
reached. A qualified technical support person will contact you.
For more information please contact:
Quanser Consulting Inc.
119 Spy Court
Markham, Ontario, L3R 5H6
Canada
Tel: (905) 940-3575
Fax: (905) 940-3576
e-mail: sales@quanser.com
http://www.quanser.com
7. References
[1]
[2]
[3]
[4]
[5]