Вы находитесь на странице: 1из 55

Quanser Specialty Plant: 3 DOF Gyroscope

Gyroscope Position Control

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.

Gyroscope Position Control Laboratory Student Manual

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

4.3. Proportional-Integral Controller ....................................................................................................11


4.4. LEAD Controller............................................................................................................................14
4.5. State-Feedback LQR Controller ....................................................................................................16
4.5.1. LQR......................................................................................................................................................17

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

5.6. LQR Simulation on Non-Linear Plant ...........................................................................................42


5.7. LEAD and LQR Controllers Actual Implementation.....................................................................48
6. OBTAINING SUPPORT...............................................................................................................................52
7. REFERENCES...........................................................................................................................................53
Document Number 807 Revision 1.0 Page i

Gyroscope Position Control Laboratory Student Manual

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.

Figure 1: Quanser 3 DOF Gyroscope

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

Gyroscope Position Control Laboratory Student Manual

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

Gyroscope Position Control Laboratory Student Manual

File Name

Description

Gyro Position Control Student


Manual.pdf

This laboratory guide contains pre-lab and in-lab exercises


demonstrating how to design an implement a control system
on the Quanser gyroscope plant using QUARC.

Gyro User Manual.pdf

This user guide contains general information on the


gyroscope hardware, its accompanying devices, and wiring
procedure.

Gyro_model_params.m

The main MATLAB script that sets the necessary


parameters required to perform this laboratory. Run this file
only to setup the experiment!

s_gyro_position_control_linear.mdl

Simulink model that simulates a LEAD controller on the


linearized gyroscope plant.

s_gyro_position_control_nonlinear.mdl Simulink model that simulates a LEAD controller on the


non-linear gyroscope plant.
s_gyro_position_control_lqr.mdl

Simulink model that simulates an LQR controller on the


non-linear gyroscope plant.

q_gyro_calibrate.mdl

Simulink model used to reset the encoder counts on the


actual gyroscope hardware.

q_gyro_position_control.mdl

Simulink model used to implement both LEAD and LQR


controllers on the actual gyroscope hardware.

d_gui_lqr_tuning.m

MATLAB file that creates a user input dialog box for


interactive LQR controller tuning. The dialog box allows
input of the Q and R weighting matrices as well as saving
the parameters, for future reference to the following file:
lqr_tuning_logfile.txt.

d_gui_lqr_tuning.fig

MATLAB GUI file that contains the graphical user interface


used in interactive LQR controller tuning.

Table 1: Files supplied with the Gyroscope Position Control experiment.

Document Number 807 Revision 1.0 Page 4

Gyroscope Position Control Laboratory Student Manual

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.

Figure 2: 3 DOF Gyroscope Co-ordinate Frame

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).

Document Number 807 Revision 1.0 Page 5

Gyroscope Position Control Laboratory Student Manual

Figure 3: Typical Feedback Diagram

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

Gyroscope Position Control Laboratory Student Manual

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

Table 2: Parameter Numerical Values

0 1 2

4.2. Proportional Controller


In this section a simple proportional controller will be studied as the C(s) block in Figure 3. The general
form for a proportional controller is:
C( s ) = k p

[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.

Document Number 807 Revision 1.0 Page 7

Gyroscope Position Control Laboratory Student Manual

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.

4.2.1. Routh-Hurwitz Criterion


Consider a characteristic polynomial of the following form:
Document Number 807 Revision 1.0 Page 8

Gyroscope Position Control Laboratory Student Manual

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

...

...

...

...

...

Table 3: General Form of a Routh-Hurwitz Array

where the elements bi and ci can be computed as follows:


bi =

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.

Document Number 807 Revision 1.0 Page 9

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 10

Gyroscope Position Control Laboratory Student Manual

4.3. Proportional-Integral Controller


In this section a proportional-integral (PI) controller will be studied as the C(s) block in Figure 3. The
general form for a PI controller is:
C( s ) =

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

Document Number 807 Revision 1.0 Page 11

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 12

Gyroscope Position Control Laboratory Student Manual

0 1 2

Document Number 807 Revision 1.0 Page 13

Gyroscope Position Control Laboratory Student Manual

4.4. LEAD Controller


In this section a LEAD controller will be studied as the C(s) block in Figure 3. The parametric transfer
function of the LEAD controller under study in this section is:

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

Document Number 807 Revision 1.0 Page 14

Gyroscope Position Control Laboratory Student Manual

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

Document Number 807 Revision 1.0 Page 15

Gyroscope Position Control Laboratory Student Manual

4.5. State-Feedback LQR Controller


In this section a state-feedback controller will be applied to the gyroscope plant. We will first examine
whether state-feedback can be used to stabilize this system or not. In order to do so we should refer
back to equations [1] and [2] and use them to obtain a state-space representation in the following form:
x = AxBu
y=CxDu

[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]

Document Number 807 Revision 1.0 Page 16

Gyroscope Position Control Laboratory Student Manual

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

Gyroscope Position Control Laboratory Student Manual

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

Gyroscope Position Control Laboratory Student Manual

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

Document Number 807 Revision 1.0 Page 19

Gyroscope Position Control Laboratory Student Manual

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.

5.1. Proportional Controller in SISOtool


The MATLAB siso-tool utility provides a SISO design GUI for interactive compensator design. This
graphical environment allows the user to design single-input/single-output controllers using root locus,
Bode diagrams, Nicholse and Nyquist techniques. The siso-tool can also provide response plots for
various input types such as step and ramp with real-time update as you tune your controller parameters.
You will use the root locus diagrams to design controllers in this laboratory. As mentioned above the
controllers studied in the pre-laboratory section will be examined using the siso-tool and the root locus
diagrams. The first controller studied in section 4.2 was a proportional controller with the following
transfer function:
C( s ) = k p

[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

Gyroscope Position Control Laboratory Student Manual

between the siso-tool and the MATLAB workspace.

Figure 4: SISO Design Task Window

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

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 22

Gyroscope Position Control Laboratory Student Manual

5.2. Proportional-Integral Controller in


SISO-tool
In this section we examine the proportional-integral controller that was studied in section 4.3. This
controller had the following transfer function:
C( s ) =

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.

Document Number 807 Revision 1.0 Page 23

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 24

Gyroscope Position Control Laboratory Student Manual

5.3. LEAD Controller in SISO-tool


In this section the LEAD controller of section 4.4 will be studied using the MATLAB siso-tool. The
controller had the following transfer function:

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:

Document Number 807 Revision 1.0 Page 25

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 26

Gyroscope Position Control Laboratory Student Manual

2. How does your answer to the above question compare to what you obtained in question 3 of
section 4.4?

Document Number 807 Revision 1.0 Page 27

Gyroscope Position Control Laboratory Student Manual

0 1 2

Exit the siso-tool by closing the Control and Estimation Tools Manager window.

5.4. Simulating LEAD Controller on


Linearized Model
In this section you will be given a LEAD controller. You will first simulate this controller on the
linearized model of the gyro that was obtained during the pre-laboratory section. Then you will be
prompted to tune this controller using the siso-tool until it satisfies the two conditions below:

Rise Time < 2 s


% OS < 20
Controller step response peak Amplitude < 5

Use the following LEAD Controller to start:


C s =17.35

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

Gyroscope Position Control Laboratory Student Manual

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.

Figure 5: Gyro Position Control Simulation Model

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.

Document Number 807 Revision 1.0 Page 29

Gyroscope Position Control Laboratory Student Manual

Figure 6: Gyro Angle (rad) Under Controller [18]

Figure 7: Control Signal Under Controller [18]

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

Document Number 807 Revision 1.0 Page 30

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 31

Gyroscope Position Control Laboratory Student Manual

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

Document Number 807 Revision 1.0 Page 32

Gyroscope Position Control Laboratory Student Manual

5.5. Simulating LEAD Controller on


Non-Linear Model
The open loop model, G, that has been used up to this point to apply and analyze different controller
types is the linearized model obtained in questions 1 and 2 of section 4.1. The actual gyroscope plant
however is non-linear and hence we need to verify whether our earlier findings on the linearized plant
are also valid on the actual one. In this section you will simulate the LEAD controller you have
designed in the previous section on the non-linear gyroscope plant. You will be able to monitor the
system output and make sure that the specifications mentioned in the previous section are still met.
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.
In this section you will also use the Virtual Reality toolbox which is a solution for interfacing with
virtual models of dynamic systems over time. You can create virtual worlds or three-dimensional
scenes that allow you too see a real-time animated virtual environment showing the gyroscope and its
movement when being simulated under a user-defined controller.
The
Simulink
model
that
will
be
used
in
this
section
is
named
s_gyro_position_control_nonlinear.mdl and is depicted in Figure 8. The Ref_Command block sets
the desired gyroscope angle to a square wave with amplitude 20 (deg) and frequency 0.1 Hz. The
Continuous Sigmoid block has been used to have control over the maximum velocity and acceleration
that the reference signal can acquire. Notice the Switch block that has been used on the output of the
Continuous Sigmoid block. This switch has been used to ensure that for the first 10 seconds after the
simulation has been started no reference input is applied to the gyro. This is done because the
gyroscope disk requires some time to get to its set-point RPM. If references are applied before this
RPM is reached, the closed-loop system will go unstable since not enough angular momentum has been
acquired for the gyroscopic effect to take place. After the first 10 seconds have passed the reference is
applied to the system and responses can be monitored.
The Gyroscope Non-Linear Plant block implements the non-linear model of the gyroscope to which
you will apply the controller you have designed in the previous section. The input to the plant is a four
element vector. The first two elements of this vector are zero since there is no actuating device present
in the plant that corresponds to these entries. The third element of this vector represents the control
input to the plant which is the torque to be applied about the gyroscope y-axis as explained in section
4.1. The fourth element of this vector is the input to the gyroscope disk motor. This input applies a setpoint RPM of 2000 to the gyroscope disk in order to acquire the required angular momentum for the
gyroscopic effect to take place. The outputs of the Gyroscope Non-Linear Plant block consist of the
gyroscope angles about z and y axes ( and respectively), the current disk position and their
velocities.
The Controller block takes the reference signal and the current value of as inputs. The block
implements the LEAD controller that you have designed in the previous section. The output of this
controller is the motor torque and is hence input to the Gyroscope Non-Linear Plant block. The Linear
Simulation block implements the same simulation as was ran in the previous section and has been
Document Number 807 Revision 1.0 Page 33

Gyroscope Position Control Laboratory Student Manual

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.

Figure 8: Simulink Model of Non-Linear Gyroscope Plant and LEAD Controller

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

Gyroscope Position Control Laboratory Student Manual

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

Gyroscope Position Control Laboratory Student Manual

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

Document Number 807 Revision 1.0 Page 36

Gyroscope Position Control Laboratory Student Manual

5.5.1. Non-Minimum Phase Zeros


Consider the following LEAD controller:

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).

Figure 9: Closed-Loop Step Response Under Controller [19]


Document Number 807 Revision 1.0 Page 37

Gyroscope Position Control Laboratory Student Manual

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 .

Figure 10: Reference vs. Gyro Angle Under Controller [19]

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

Gyroscope Position Control Laboratory Student Manual

same fashion as was done in step 1 of section 5.4.


3. Type sisotool(G) in the MATLAB command prompt and hit the enter key.
4. In the SISO Design for SISO Design Task window click on File and select Import.
5. In the System Data window that pops up change the Data value of the system variable C from 1
to C by double-clicking on the 1 in front of this variable and changing it to C.
6. Click on OK. The SISO Design for SISO Design Task window will show the root locus resulting
by applying this controller to the gyro plant.
7. Click on Analysis and select Response to Step Command in the SISO Design for SISO Design
Task window. This will open the step response plots shown in Figure 9.
8. Begin tuning the controller as before to eliminate the Non-Minimum Phase response. Try to
keep the other specifications outlined in section 5.4 satisfied as well.
9. Once you see a step response that satisfies the specifications without showing a non-Minimum
Phase response click on File in the SISO Design for SISO Design Task window and select
Export.
10. In the SISO Tool Export window that pops up, select the Compensator C component and click
on Export to Workspace. Make sure that the Export As column corresponding the the
compensator has the value C. This will make sure that the compensator is saved in the
workspace under the variable name C that out models are set to use. A Variable Name Conflict
window may open. You can click on Yes.
11. If you have closed the s_gyro_position_control_nonlinear.mdl Simulink model open it using
the MATLAB current directory. If it is still open skip this step.
12. Go to the MATLAB command prompt and type qc_update_model; and hit the enter key. This
will download the new C transfer function to the Simulink model.
13. Set the Ref_Command block to output a square wave with amplitude 20 degrees and frequency
0.1 Hz.
14. Start the simulation by clicking on QUARC in the Simulink model toolbar and selecting Start.
You can now look at various scopes in the model to see the effect of your controller tuning on the nonlinear system response. Remember that as it was mentioned in section 5.5 although a satisfactory
response may be obtained when tuning a controller on the linearized plant, when this controller is
applied to the non-linear model, the closed-loop response will change. If some specifications are not
met or the Non-Minimum Phase response is still present repeat the steps above. Once you come up with
a controller that satisfies the specifications and shows no Non-Minimum Phase response, stop the
model by clicking on the Stop real-time code button.
1. Print a copy of the LTI Viewer for SISO Design Task page showing the closed-loop step
response, rise time and maximum amplitude of your tuned controller and attach it to this report.
Also provide the transfer function of your controller. Show that your controller is satisfying the
specifications of section 5.4 and no non-minimum phase response is present. Is the NonMinimum Phase response removed compared to Figure 9?

Document Number 807 Revision 1.0 Page 39

Gyroscope Position Control Laboratory Student Manual

0 1 2

2. Using the Time Figure and Time Figure1 blocks in s_gyro_position_control_nonlinear.mdl


print plots of the reference versus gyro angle and the torque commanded by the controller
when the reference signal is a square wave with amplitude 20 (deg) and frequency 0.1 Hz.
Attach these plots to your report. Show that the control command is below the saturation
threshold of 1.5. Is the Non-Minimum Phase response removed compared to Figure 10?

Document Number 807 Revision 1.0 Page 40

Gyroscope Position Control Laboratory Student Manual

0 1 2

Document Number 807 Revision 1.0 Page 41

Gyroscope Position Control Laboratory Student Manual

5.6. LQR Simulation on Non-Linear


Plant
Up until this section you have been working with a LEAD controller and have tuned an initial
compensator to satisfy a set of requirements and also to remove the effects of non-minimum phase
response. It was shown in section 4.5.1 that the gyroscope plant is controllable using state-feedback. In
this section you will begin with a state-feedback controller designed using LQR that has nonsatisfactory response. This controller computes a control command of the form u = -Kx, where x is the
state vector as defined in [10] and K is the state-feedback gain, designed using LQR. Using the intuition
you should have developed in section 4.5.1, you are asked to tune the weighting parameters of this LQR
design (Q and R weighting matrices) to improve the controller's performance. The Simulink model that
you will use to perform this section is named s_gyro_position_control_lqr.mdl and shown in Figure
11.

Figure 11: Simulink Model Used to Simulate LQR Controller on Non-Linear Gyro Plant

Document Number 807 Revision 1.0 Page 42

Gyroscope Position Control Laboratory Student Manual

The main structure of this model is similar to that of s_gyro_position_control_nonlinear.mdl. The


only difference is that the Controller block in s_gyro_position_control_nonlinear.mdl held a LEAD
controller for which you would design and enter a transfer function C, in the MATLAB command
prompt. In the model depicted in Figure 11 however, the LQR Controller block implements a statefeedback controller with gain K. Recall that in section 4.5 we defined our state-vector x in the following
form:

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.

Figure 12: LQR Controller Sub-system

Document Number 807 Revision 1.0 Page 43

Gyroscope Position Control Laboratory Student Manual

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.

Figure 13: LQR Tuning GUI

Document Number 807 Revision 1.0 Page 44

Gyroscope Position Control Laboratory Student Manual

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.

Figure 14: Reference vs. Gyro Angle


Response (Initial LQR Controller)

Figure 15: Control Command (Initial LQR


Controller)

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

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 46

Gyroscope Position Control Laboratory Student Manual

0 1 2

Document Number 807 Revision 1.0 Page 47

Gyroscope Position Control Laboratory Student Manual

5.7. LEAD and LQR Controllers Actual


Implementation
During the previous in-lab exercises you have worked with the linearized as well as the non-linear gyro
plant in simulation and have tuned a LEAD controller and an LQR controller to satisfy a set of
specifications. In this section you will implement these controllers on the actual gyroscope hardware.
You can then monitor the response of each controller when acting on the actual plant. If necessary you
can perform more tuning on your controllers to obtain desired results with the actual hardware. The
Simulink model used in this section is named q_gyro_position_control.mdl and is depicted in Figure
16.

Document Number 807 Revision 1.0 Page 48

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 49

Gyroscope Position Control Laboratory Student Manual

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

Gyroscope Position Control Laboratory Student Manual

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.

Document Number 807 Revision 1.0 Page 51

Gyroscope Position Control Laboratory Student Manual

Figure 17: 3 DOF Gyroscope Starting Configuration

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

Gyroscope Position Control Laboratory Student Manual

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

Document Number 807 Revision 1.0 Page 53

Gyroscope Position Control Laboratory Student Manual

7. References
[1]

Gyroscope User Manual

[2]

Cannon, Robert. H, Dynamics of Physical Systems, Chapter 19, Section 5, McGRAW-HILL,


New York.

[3]

Quanser. DAQ User Guide

[4]

Quanser. AMPAQ User Manual

[5]

Quanser. QUARC User Manual (type doc quarc MATLAB to access).

Document Number 807 Revision 1.0 Page 54

Вам также может понравиться