Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Department of Electrical Engineering

EE361L: Control Systems Lab

Course Instructor: Abdullah Mughees Date:

Lab Engineer: Muhammad Kashif Semester: Spring 2024

Batch: BSEE 21

Lab 12: Control of a Rotary Inverted Pendulum

Name Roll No. Lab Marks

Maryam Tanveer Bsee21076

Graded on: _______________________________

Instructor’s Signature: _______________________________


Learning Outcomes
After completing the lab with the aid of LabVIEW and MATLAB, students should be able to

● Design a proportional controller in state-space using full-state feedback to balance a


rotary inverted pendulum.
● Implement the designed controller to stabilize QNET 2.0 Rotary Inverted Pendulum.

● Modify the stabilizing controller to balance at different rotary positions of the inverted
pendulum.
12.1 Quanser Rotary Inverted Pendulum Board
The Quanser QNET 2.0 Rotary Inverted Pendulum Board for NI ELVIS II, pictured in Figure
1.1, is a versatile servo system designed to teach and demonstrate a variety of inverted
pendulum based experiments. The system is driven using a direct-drive 18 V brushed DC
motor housed in a solid aluminum frame (labeled 1). Single-ended rotary encoders are used
to measure the angular positon of the DC motor and the pendulum. The following diagram
illustrates various components in the board. The encoder for the pendulum is labeled 12 in the
figure and the pendulum rod is labeled 2. There are status LEDs for power at different
voltages and communication with the host computer, labeled 3 and 4 respectively. The 24 V
supply for the motor drive is provided at an external connector labeled 5 and an LED labeled
7 shows its status.

Figure 12-1: Quanser Rotary Pendulum Board

2
No. Description No. Description
1 Motor chamber 9 Motor power connector
2 Pendulum link 10 Encoder connector
3 +5 ,−5 ,+ 15V indicators 11 Encoder connector
4 User and status indicators 12 High resolution encoder
5 24 V power jack 13 Pendulum pivot
6 Fuse 14 DC motor
7 External power indicator 15 Encoder
Table 12-1: Components in the QNET Rotary Inverted Pendulum Board

12.1.1 State Space Model of the Rotary Pendulum System


The inverted pendulum in the Quanser board can be modelled by the following pair of
differential equations, where α is the angle of the pendulum rod, θ is the angular position of
the pendulum’s arm and v is the motor’s voltage, as shown in Figure 12-2.
4 2
−mL cos cos ( α ) θ̈+ m L α̈ −mgL sin sin ( α )=0
3

( J eq +m r 2 ) θ̈+mLr sin sin ( α ) α̇2 −mLr cos cos ( α ) α̈ =T out −Beq θ̇


These are second-order nonlinear differential equations. After linearization around the point
where the pendulum rod is pointed upwards¿), the equations are simplified to
a θ̈−b α̈ +e θ̇=fv
−b θ̈+ c α̈ −dα=0
Here, a , b , c , d ,e , f have the following values.
2 4 2
a=J eq + mr + J m , b=mLr , c= m L , d=mgL
3
Km ηm K t
e=Beq + ,f=
Rm Rm
To build a state space model, we rearrange these equations in matrix notation and substitute
the values of the motor and pendulum’s physical parameters. The chosen state variables
vector and the resulting state space model is presented below.
x=[ θ α θ̇ α̇ ] , ẋ= [ 0 0 0 0 0 0−149 2621 0−0.0170 0.0103 0 10 0 ] x + [ 0 0 49.84−49.84 ] v
The pendulum’s angle and other parameters are illustrated in the following diagram.

3
θ

Figure 12-2: Description of the parameters of the pendulum

Symbol Description Value


DC Motor
V nom Nominal input voltage 18.0 V
τ nom Nominal torque 22.0 mNm
ω nom Nominal speed 3050 RPM
I nom Nominal current 0.540 A
Rm Terminal resistance 8.4 Ω
kt Torque constant 0.042 Nm/A
km Motor back-EMF constant 0.042 V/(rad/s)
Jm Rotor inertia 4.0×10-6 kgm2
Lm Rotor inductance 1.16 mH
mh Module attachment hub mass 0.016 kg
rh Module attachment hub radius 0.0111 m
Jh Module attachment hub moment of inertia 0.6×10-6 kgm2
Rotary Pendulum Module
mr Rotary arm mass 0.095 kg
Lr Rotary arm length (pivot to end of metal rod) 0.085 m
mp Pendulum link mass 0.024 kg
Lp Pendulum link length 0.129 m

4
Motor and Pendulum Encoders
Encoder line count 512 lines/rev
Encoder line count in quadrature 2048 lines/rev
Encoder resolution in quadrature 0.176 deg/count
Amplifier
Amplifier type PWM
Peak current 2.5 A
Continuous current 0.5 A
Output voltage ±10 V
Table 12-2: Physical parameters of the pendulum system

12.2 Using the Quanser Rotary Inverted Pendulum Board with LabVIEW
12.2.1 Initialization
The initialization blocks provide the necessary functionality to start up and initialize the
motor driver and the rotary encoders. These are placed in the accompanying VI and the user
does not need to change them in any way.

Figure 12-3: Initialization blocks

12.2.2 Reading the Pendulum and Arm Angles


The pendulum and arm angles are available from two blocks shown in Figure 12-4. These
two blocks give the serial data from the two rotary encoders connected to the pendulum and
the arm.

Figure 12-4: Encoder read blocks

5
12.2.3 Calculating the Angular Velocities of Pendulum and Arm
The angular velocities of the arm and the pendulum can be found by differentiating the
corresponding angular positions available from the blocks shown in Figure 12-4. The
differentiator block is available in the menu Control and Simulation -> Continuous Linear
Systems.
12.2.4 Applying Voltage to the Motor
The blocks shown in Figure 12-5 are used to apply voltage to the motor. Note that it is
important to limit the voltage being sent to the analog write block to within ± 10V to avoid an
error from DAQmx Write block.

Figure 12-5: Applying voltage to the motor

12.2.5 Implementing Feedback Control in State Space


The implementation of the state feedback controller is equivalent to calculating the dot
product of state vector and the gain vector. This can be implemented in LabVIEW by
multiplying individual pairs of elements from both vectors and performing the sum of all the
products. However, a simpler way is to use element-wise vector multiplication and vector-
sum as shown in Figure 12-6.

Figure 12-6: Implementing the state feedback controller

12.2.6 Correcting the Pendulum Angle


The incremental encoder used to measure the angular position of the pendulum considers the
angle to be zero at its position where the VI is started. To have a consistent zero position for
every run of the VI, we start the VI with the pendulum at rest in the downright position.

6
However, the state space model and the controller need the pendulum angle to be zero at the
upright position. Thus we need the calculation shown in Figure 12-7 for the angle correction.

Figure 12-7: Correcting the pendulum angle

12.2.7 Limiting the Working Angle


There is only a limited range of the pendulum angle α for which the state space model we are
using, is valid. Outside this region, not only the pendulum’s behavior deviates from our
model but also the controller we are using will not control the pendulum as we have designed
it. So we need the controller to operate only when the pendulum angle α is within our desired
range around the equilibrium position, α =0 . Outside this range, we simply let it fall down.
The operations shown in Figure 12-8 provide the calculated voltage from the controller to the
motor only if the pendulum angle α is within ± 0.3 rad range, otherwise a zero voltage is
applied to the motor. A Boolean indicator also lights up in the front panel when the pendulum
angle is within range.

Figure 12-8: Limiting the working angle

12.3 Full State Feedback and Design via Pole Placement


In this lab, we use the state-space model of the inverted pendulum (somewhat similar to the
one used in section 4.6) to design and implement its controller. The controller is essentially
an LTI system that takes the state vector x as the input and delivers the input of the
pendulum, u as the output. We can design this controller using the following approach so that
it provides the pendulum with suitable input to make it balance upright.
To understand how we can design such a controller, consider an LTI system represented as
the following state space model.
ẋ= Ax+ Bu
y=Cx

7
Figure 12-9 shows the signal flow diagram of the state-space model.

Figure 12-9: An LTI system represented as a state space model

In a typical feedback control system, the output, y , is fed back to the summing junction. It is
now that the topology of the design changes. Instead of feeding back y , what if we feed back
all of the state variables? If each state variable is fed back to the control, u, through a gain,
there would be n such gains k i. These gains can be adjusted to yield the required closed-loop
pole values. The negative feedback through the gains, k i, is represented in Figure 12-10 by
the feedback vector −K .

Figure 12-10: A state space model with full state feedback

This closed-loop system can itself be represented as a state space model as follows.
ẋ=( A−BK ) x +Br
Y =Cx
Recall that the eigenvalues of the system matrix are the poles of the transfer function. Now
the poles of this system are represented by the eigenvalues of the new system matrix, A−BK .
Therefore, we can use the elements k i of the gain vector K to design the poles of the closed-
loop system with full-state feedback. There are several ways to do this, and the most
straightforward one is using the Ackerman’s formula.
12.3.1 Using the Ackerman’s Formula in MATLAB
The Ackerman’s formula calculates the gain vector K to place the closed loop poles of a
system represented as a state space model, at the locations specified in the row vector P. It is
available in MATLAB with the function acker() in the following format. A and B are the
state and input matrices respectively.

8
K = acker(A, B, P);

12.4 Task 1: Setting Up the Environment for Inverted Pendulum Board


Objectives: On LabVIEW, process the encoder readings from the inverted pendulum to get
the angle in a format useful for our linear controller. Add a condition to apply voltage to the
motor only when the pendulum is near the upright position.
The accompanying VI with the inverted pendulum board contains the blocks to read the arm
and pendulum angles and to write the voltage to the arm motor. The sensors being used to
measure the angles are incremental optical encoders. These sensors do not give the absolute
value of the angle, rather, they just give the offset from the position when the controller has
started up. Thus it is important to always start the pendulum from downright, steady position.
1. Perform the following function on the pendulum angle and connect it to a chart to display
the resulting angle. If you implement this block correctly, then the pendulum angle, α
would be π when is suspended downwards and 0 when it is pointed right upward. Also, if
you rotate the pendulum completely, its angle would remain within π to – π . [2
points]

Figure 12-11: Correction of the pendulum angle for controller

2. The controller must be active for a small limited range of pendulum angle to make sure it
does not make the pendulum move violently when the angle is out of this range.
Implement the logic shown in Figure 12-12 to set the motor voltage to zero if the
pendulum angle is outside the range± 0.3 rad . Place a Boolean indicator on the front panel
to indicate when the pendulum is within this range. If you implement this correctly, the
Boolean indicator would light up only when the pendulum is within ± 0.3 rad of the
upright position. Show the implemented logic to the lab instructor and get it graded.
[3 points]

9
Figure 12-12: Placing a limit on the pendulum working angle

12.5 Task 2: Inverted Pendulum Stabilization with Full State Feedback Control
Objective: Design and implement a controller to stabilize the position of arm and angle of
the pendulum.
The inverted pendulum on the rotary platform can be modeled by the state space
representation mentioned earlier in section 12.1.1.
You are required to design and implement a feedback controller that stabilizes the closed loop
system with the following transient response parameters.
T s=1.4 ,T P =1.2

1. Pre Lab Find the σ and ω d for a second order system with the above transient response
characteristics. [2 points]
σ =2.85
Wd=2.618
Wn=3.889

2. Pre Lab The closed-loop inverted pendulum is a 4th order system. So in order to achieve a
response like a 2nd order system, the remaining two poles must be at a position such that
they have no significant effect on the response of this system. Find the transfer function of
a 4th order system with two poles defined by the σ and ω d, as calculated in the previous
part, and the remaining two poles at suitable insignificant location. Write the characteristic
equation with these poles. [4 points]

= [s + 2.857 + 2.619i] [s + 2.857 – 2.619i] [s + 28] [s + 29]


= 𝒔𝟒 + 62.714𝒔𝟑 + 1152.719𝒔𝟐 + 5495.999s + 12197.54732

10
3. Build the inverted pendulum’s state space model in MATLAB and define a row vector P
comprising of the poles of the 4th order system found in part 2. Use the Ackerman’s
formula to find the gain vector K. Write the value of K in the following space. [5
points]
K = [ -2.2853 -31.7708 1.0271 2.3173
4. Find the system matrix of the state space model of the closed loop system ( A−BK ) with
the value of K calculated in the previous part. Use eig() function in MATLAB to find
the eigenvalues of the closed loop system matrix. Write the eigenvalues here. [3 points]
Poles = eig (A – BK) are verified. Poles:
• 30.00 +0.0i
• 28.57 +0.0i
• 2.8570 + 2.6180i
• 2.8570 – 2.6180i

5. Implement your controller in LabVIEW on QNET Rotary Inverted Pendulum. Recall that
v is the voltage applied to the arm motor, θ and α are the angles of arm and pendulum and
K is the gain vector calculated above. If the pendulum is stable in the upright position and
successfully corrects small disturbances, show the implementation to the lab instructor.
Remember to manually hold the pendulum in the position where θ and α are both zero,
every time before starting the VI. [10 points]
v=−Kx , x=[ θ α θ̇ α̇ ]

6. Analysis Disturb the pendulum gently and observe its behavior. Disturb it a bit harder but
not too hard to drop it down from the inverted upright position. Describe how the
pendulum behaves in terms of angles θ and α . [2
points]
If the pendulum is moved in counter clock-wise direction then 𝜶 and 𝜽 goes high and
if the pendulum is moved clock wise direction then 𝜶 will be below zero and for 𝜽 is
above zero for counter clockwise movement.

7. Analysis Touch the arm rod (silver-colored) softly and observe how it behaves. Describe
and explain the difference in the reactions of the pendulum when perturbed on the

11
pendulum rod (red-colored) vs when perturbed on the arm rod (silver-colored). [3
points]
If the red touched with the little force, if forcefully come back to its horizontal angle
which is set to the zero and it re adjusts the rod.

12.6 Task 3: Position Control of Inverted Pendulum


Objective: Implement a full state feedback controller to set the position of the arm according
to an input command.
By modifying the controller implemented in the Task 2, we can make the pendulum’s arm
follow a position command instead of staying at a fixed position. For this operation, the
controller must be as in the following expression. Here, v is the voltage to the arm motor, x is
the state of the system and x r is the required state of the system. This controller tries to bring
x to x r, the reference, or desired, state.
v=K ( x r−x ) , x r=[ θ r α r θ̇r α̇ r ]

It is worth noting that in steady state, the pendulum angle α and its derivative cannot have
any value other than zero. Thus, only θr and θ̇r can have non zero values in x r.
1. Implement the controller given above in LabVIEW with the Quanser Rotary Pendulum
Board. Use α r= α̇ r =θ̇r =0 and connect a square wave signal generator with the following
parameters in the place of θr . If the controller is implemented correctly, the pendulum
would stay upright and the arm would swing left to right at a frequency of 0.1 Hz . Show
the implementation to the lab instructor. [5 points]

Parameter Value
Amplitude 1 rad

Frequency 0.1 Hz

Offset 0 rad

2. Change the settings of the signal generator so that it generates a sine wave signal with the
same amplitude and frequency. Plot θ and θr on a new chart and find the phase difference
between them. [3 points]

Phase difference = 𝟎.𝟒 𝟏𝟎 * 360 = 14.4

12
13
Assessment Rubrics
Method:
Lab report evaluation and instructor observation during lab sessions.
CLO Able to complete the tasks Able to complete the Tasks completion below Marks
Performance
over 80% (4-5) tasks 50 – 80% (2-3) 50% (0-1)
1. Teamwork 1 Actively engages and Cooperates with other Distracts or
cooperates with other group members in a discourages other
group members in an reasonable manner. group members from
effective manner. conducting the
experiment.
2. Laboratory 1 Respectfully and Observes safety rules Disregards safety
safety and carefully observes safety and procedures with rules and procedures.
disciplinary rules and procedures minor deviation.
rules
3. Realization of 3 Selects relevant Needs guidance to Incapable of selecting
experiment equipment to the select relevant relevant equipment to
experiment, develops equipment to the conduct the
setup diagrams of experiment and to experiment.
equipment connections develop equipment
or wiring. connection or wiring
diagrams.
4. Conducting 3 Uses each equipment and Uses the equipment Unable to use
experiment components as intended, and components with appropriate
conducting the minor error. Needs equipment, and
experiment perfectly. help in conducting experiment is
experiment. substantially wrong.

5. Data 3 Plans data collection to Plans data collection Does not know how
collection achieve experimental to achieve to plan data collection
objectives, and conducts experimental to achieve
an orderly and a objectives, and experimental goals;
complete data collection. collects complete data data collected is
with minor error. incomplete and
contain errors.
6. Data analysis 3 Accurately conducts Conducts Unable to conduct
simple computations and computations and simple analysis on
statistical analysis using analysis on collected collected data; no
collected data; correlates data with minor error; attempt to correlate
experimental results to reasonably correlates experimental results
known theoretical values. experimental results with known
to known theoretical theoretical values.
values.
7. Computer use 3 Uses computer to collect Uses computer to Does not know how
and analyze data collect and analyze to use computer to
effectively. data with minor error. collect and analyze
data.

Total (out of 35)

14

You might also like