AE4610
  • Welcome
  • Experiments
  • Lab 0: MATLAB & SIMULINK
  • Lab 1: Rotary Servo Base
    • A. Integration (Week 1)
    • B. Modeling (Week 1)
    • C. Control Design (Week 2)
    • D. Controller Implementation & Evaluation (Week 3)
  • Lab 2: 3 DOF Gyroscope
    • A & B. Modeling and Control Design (Week 1)
    • C. Controller Implementation (Week 2)
  • Lab 3: Rotary Flexible Link
    • A. System Identification (Week 1)
    • B & C. Control Design and Controller Implementation (Week 2)
  • Lab 4: Rotary Inverted Pendulum
    • A & B. Modeling and Balance Control
    • C. Swing-up Control (Demo)
  • Final Project
  • Archive
    • Old Lab 1 Model Validation
    • Problem Set
    • DC Motor
    • Lab 1: Rotary Servo Base (Older Version)
      • A. Integration (Week 1)
      • B. Modelling (Week 1)
      • C. Position Control (Week 2)
    • Quadcopter
    • Gyroscope
    • Inverted Pendulum
    • 3DOF Helicopter
    • Torsional Pendulum
    • Aero LQR
      • A. System Identification
      • A. System Identification (Week 1) last check
      • B. Control Design & Implementation (Week 2)
    • Rotary Gyro
      • Rotary Gyro
    • 2 DOF AERO
      • A. System Identification
      • B. Control Design
      • C. Controller Implementation
    • Copy of Lab 4: Rotary Inverted Pendulum
      • Week 1
      • Week 2
Powered by GitBook
On this page
  • Introduction
  • Proportional (Derivative) Control Determined through LQR Analysis
  • Linear Quadratic Theory (LQR)
  • Example of a Simple Mass/Spring/Damper System
  • Control of an Inverted Pendulum
  • Objective
  • Equipment Required
  • Introduction
  • Mathematical Model of the Inverted Pendulum Mechanism
  • Linear Quadratic Regulator (LQR) Design
  • Controller Design Procedure
  • Controller Implementation and Evaluation
  • Analysis

Was this helpful?

Export as PDF
  1. Archive

Inverted Pendulum

This manual documents the modelling of an inverted pendulum, developing a full state feedback control using LQR to balance the unstable equilibrium and evaluatin the LQR on the hardware setup.

PreviousGyroscopeNext3DOF Helicopter

Last updated 3 years ago

Was this helpful?

Introduction

Proportional (Derivative) Control Determined through LQR Analysis

This experiment will demonstrate the control of a system using full state feedback, where the control system is designed using the principles of Linear Quadratic Regulator (LQR) theory. This is an analysis technique that would be seen in more detail during advanced studies. You are not required to completely understand the derivation of the method itself. However, you should understand how to formulate the required matrices (Q and R) and why the overall goal (to minimize the cost, J) leads to the requirements on those matrices, as well as the reasoning behind the formulation of the cost equation, which serves as the purpose behind the method’s derivation.

Linear Quadratic Theory (LQR)

Consider the system

such that the closed-loop system

Example of a Simple Mass/Spring/Damper System

We will demonstrate the previous LQR design using a simple mass-spring-damper system as shown in Fig. 7.2. The equation of motion is

or in state-space form

Choose the weighting matrices as

The Riccati equation gives

Expanding, we obtain

Solving these equations, we get

or that

The optimal gain matrix is given by

The closed-loop system matrix is

The closed-loop system is stable.

Control of an Inverted Pendulum

Objective

The purpose of this experiment is to design a balance control using the principles of linear quadratic regulator (LQR) theory for an inverted pendulum mechanism.

Equipment Required

Introduction

In this lab, we demonstrate a control design using modern “state-space” methods. The plant consists of an inverted pendulum on a cart. The plant has two distinct equilibrium points of which one is stable and the other is unstable. In this experiment, we will show how the plant in its unstable configuration can be controlled using a suitable controller. The methodology used to design the control law is based on the linear quadratic regulator (LQR) theory. The inverted pendulum mechanism to be used in this lab is shown in Fig. 7.3.

Mathematical Model of the Inverted Pendulum Mechanism

The equations of motion for the system can be easily derived using the free-body diagrams shown in Fig. 7.6 as follows (here we assume that the track on which the cart moves without sliding):

First, we write the motor equation as

or

where

The torque generated at the output of the motor is given by

Thus, the force transmitted to the cart via the pinion is

and on substituting the values of

we get

Substitution of the above expression for F in the linearized equations results in

Linear Quadratic Regulator (LQR) Design

The LQR formulation provides a linear control law

which minimizes the quadratic cost given by

Assuming the time-domain design specifications are:

one can choose

The block diagram of the experimental setup in the lab is shown in Fig. 7.7.

Controller Design Procedure

  1. Assume that:

  2. Using the lqr command in MATLAB, calculate the optimal feedback gain vector K. The lqr command basically solves the Algebraic Ricatti Equation that you met earlier. >> [k,s,e] = lqr(A,B,Q,R);

  3. Compute the open-loop and closed-loop eigenvalues of the system and comment on the stability of the open and closed-loop systems.

  4. Compute the natural frequencies and damping ratios of the closed-loop system.

Controller Implementation and Evaluation

CAUTION: Always be ready to stop the experiment if the cart goes unstable. This can be done either by pressing the stop button in the Simulink or turning the power off.

  1. Turn the power on.

  2. Open the MATLAB and locate the file InvPendulum_LQR.mdl under the path C:\AE4610_Controls_Lab\Inverted_Pendulum and open it. This is the block diagram for this part of the experiment.

  3. Switch the Command Signal block to 0.

  4. Enter the gains you obtained in the corresponding gain blocks.

  5. Put the cart right in the middle of the track and hold up the pendulum fixed and straight. Do not release it until the controller is on.

  6. Double click on the scopes and open then.

  7. Gently disturb the pendulum to see the effect of the controller and then stop the simulation.

  8. Switch the command signal to step input. It should make the cart to move 20 cm to the right after 10 seconds.

  9. Save the data with a descriptive name. DO NOT SAVE THE MODEL.

  10. Turn the POWER OFF

Analysis

  • Individual: Include the results from the controller design procedure Steps 1-5.

  • Group: Build a SIMULINK block diagram using Fig. 7.7 and obtain the simulated response to the same command input used in the experiment. Compare the simulated response with the experimental response and explain any differences between them.

Average the first 5 seconds of the experimental data to obtain initial conditions for your state-space block in SIMULINK

X˙=AX+BU(7.1)\dot{X}=AX+BU \tag{7.1}X˙=AX+BU(7.1)

where XXX is a state vector and UUU is a m×1m \times1m×1 control input vector. Therefore, AAA and BBB are matrices of dimensions n×nn\times nn×n and n×mn\times mn×m , respectively. Let us suppose that we wish to design a state-feedback controller

U=−KX(7.2)U=-KX \tag{7.2}U=−KX(7.2)
X˙=(A−BK)X(7.3)\dot{X}=(A-BK)X \tag{7.3}X˙=(A−BK)X(7.3)

is stable. Here KKK is a matrix of gains of dimensions m×nm\times nm×n . In achieving closed-loop stability, we wish to use as little control effort as possible. We also wish to avoid large overshoot of the trajectories during the transients. One way to achieve both of these objectives is to find a control law which minimizes the following quadratic cost

J=∫0∞(XTQX+UTRU)dt(7.4)J=\int_{0}^\infty(X^TQX+U^TRU) dt \tag{7.4}J=∫0∞​(XTQX+UTRU)dt(7.4)

where QQQ and RRR are weighing matrices of appropriate dimensions. In order for the previous problem to make sense we must ensure that the two terms in the integral are positive. The requirement that

XTQX≥0(7.5)X^TQX\geq0 \tag{7.5}XTQX≥0(7.5)

for all vectors XXX is satisfied if the matrix QQQ is positive semi-definite (all its eigenvalues are greater than or equal to zero). The requirement that

UTRU>0(7.6)U^TRU>0 \tag{7.6}UTRU>0(7.6)

for all vectors UUU is satisfied if the matrix RRR is positive definite (all its eigenvalues are greater than zero). This optimization problem has a closed-form solution. The optimal gain matrix KKK is given by

K=R−1BTP(7.7)K=R^{-1}B^TP \tag{7.7}K=R−1BTP(7.7)

where the n×nn\times nn×n matrix PPP is the positive definite solution of the following Algebraic Riccati Equation (ARE):

0=ATP+PA−PBR−1BTP+Q(7.8)0=A^TP+PA-PBR^{-1}B^TP+Q \tag{7.8}0=ATP+PA−PBR−1BTP+Q(7.8)
mx¨+cx˙+kx=Fm\ddot{x}+c\dot{x}+kx=Fmx¨+cx˙+kx=F
[x˙1x˙2]=[01−km−cm][x1x2]+[01m]F\begin{bmatrix} \dot{x}_1 \\[1ex] \dot{x}_2 \end{bmatrix} = \begin{bmatrix} 0 & 1 \\[1ex] -\frac{k}{m} & -\frac{c}{m} \end{bmatrix} \begin{bmatrix} x_1 \\[1ex] x_2 \end{bmatrix} + \begin{bmatrix} 0 \\[1ex] \frac{1}{m} \end{bmatrix}F[x˙1​x˙2​​]=[0−mk​​1−mc​​][x1​x2​​]+[0m1​​]F

where x1=xx_1=xx1​=x and x2=x˙x_2=\dot{x}x2​=x˙ . Let m=1, k=2m=1,\space k=2m=1, k=2 and c=1c=1c=1 . The system matrices are

A=[01−2−1],B=[01]A = \begin{bmatrix} 0 & 1 \\[1ex] -2 & -1 \end{bmatrix}, \qquad B = \begin{bmatrix} 0 \\[1ex] 1 \end{bmatrix}A=[0−2​1−1​],B=[01​]
Q=[12004],R=1Q = \begin{bmatrix} 12 & 0 \\[1ex] 0 & 4 \end{bmatrix}, \qquad R = 1Q=[120​04​],R=1
[0 ⁣ ⁣00 ⁣ ⁣0] ⁣= ⁣[0 ⁣ ⁣−21 ⁣ ⁣−1] ⁣[p11 ⁣ ⁣p12p21 ⁣ ⁣p22] ⁣+ ⁣[p11 ⁣ ⁣p12p21 ⁣ ⁣p22] ⁣[0 ⁣ ⁣1−2 ⁣ ⁣−1] ⁣− ⁣[p11 ⁣ ⁣p12p21 ⁣ ⁣p22] ⁣[ ⁣01] ⁣[0 ⁣ ⁣1] ⁣[p11 ⁣ ⁣p12p21 ⁣ ⁣p22] ⁣+ ⁣[12 ⁣ ⁣00 ⁣ ⁣4]\begin{bmatrix} 0 \! & \! 0 \\[0.5ex] 0 \! & \! 0 \end{bmatrix} \! = \! \begin{bmatrix} 0 \! & \! -2 \\[0.5ex] 1 \! & \! -1 \end{bmatrix} \! \begin{bmatrix} p_{11} \! & \! p_{12} \\[0.5ex] p_{21} \! & \! p_{22} \end{bmatrix} \! + \! \begin{bmatrix} p_{11} \! & \! p_{12} \\[0.5ex] p_{21} \! & \! p_{22} \end{bmatrix} \! \begin{bmatrix} 0 \! & \! 1 \\[0.5ex] -2 \! & \! -1 \end{bmatrix} \! - \! \begin{bmatrix} p_{11} \! & \! p_{12} \\[0.5ex] p_{21} \! & \! p_{22} \end{bmatrix} \! \begin{bmatrix} \! 0 \\[0.5ex] 1 \end{bmatrix} \! \begin{bmatrix} 0 \! & \! 1 \end{bmatrix} \! \begin{bmatrix} p_{11} \! & \! p_{12} \\[0.5ex] p_{21} \! & \! p_{22} \end{bmatrix} \! + \!\begin{bmatrix} 12 \! & \! 0 \\[0.5ex] 0 \! & \! 4 \end{bmatrix}[00​00​]=[01​−2−1​][p11​p21​​p12​p22​​]+[p11​p21​​p12​p22​​][0−2​1−1​]−[p11​p21​​p12​p22​​][01​][0​1​][p11​p21​​p12​p22​​]+[120​04​]
p122+4p12−12=0p11−2p22−p12−p12p22=0p222−2p12+2p22−4=0p_{12}^2+4p_{12}-12=0\\[5pt] p_{11}-2p_{22}-p_{12}-p_{12}p_{22}=0\\[5pt] p_{22}^2-2p_{12}+2p_{22}-4=0p122​+4p12​−12=0p11​−2p22​−p12​−p12​p22​=0p222​−2p12​+2p22​−4=0
p11=10,p12=2,p22=2p_{11}=10, \quad p_{12}=2, \quad p_{22}=2p11​=10,p12​=2,p22​=2
P=[10222]P=\begin{bmatrix} 10 & 2\\ 2 & 2 \end{bmatrix}P=[102​22​]

Notice that the solution matrix P is positive definite. Its eigenvalues are λ1,2=10.472, 1.528\lambda_{1,2}=10.472,\space1.528λ1,2​=10.472, 1.528.

K=R−1BTPK=[01][10222]=[22]K=R^{-1}B^TP\\[5pt] K=\begin{bmatrix} 0 & 1 \end{bmatrix} \begin{bmatrix} 10 & 2 \\ 2 & 2 \end{bmatrix} = \begin{bmatrix} 2 & 2 \end{bmatrix}K=R−1BTPK=[0​1​][102​22​]=[2​2​]
A−BK=[01−4−3]A-BK=\begin{bmatrix} 0&1\\ -4 & -3 \end{bmatrix}A−BK=[0−4​1−3​]

and the eigenvalues are λ1,2=−1.5±i1.323.\lambda_{1,2}=-1.5\pm i1.323.λ1,2​=−1.5±i1.323.

Consider an inverted pendulum of mass mpm_pmp​ and length 2lp2l_p2lp​ connected on a sliding cart of mass mcm_cmc​ as shown in Fig. 7.4.

The angle θ\thetaθ is measured from the up-right position. We can apply a force to the cart through the cartwheel motors. We wish to design a controller to balance the pendulum to the upright position θ=0\theta=0θ=0. Note that the problem of balancing a pendulum is akin to the problem of stabilizing a rocket during ascent.

(mp+mc)x¨+mpθ¨lpcos⁡(θ)−mpθ˙2lpsin⁡(θ)=Fmplpcos⁡(θ)x¨+Iθ¨+mpθ¨lp2−mpglpsin⁡(θ)=0\begin{equation} \tag{7.9} \begin{aligned}(m_p+m_c)\ddot{x} + m_p\ddot{\theta}l_p\cos(\theta) -m_p\dot{\theta}^2l_p\sin(\theta) &= F \\[5pt] m_pl_p\cos(\theta)\ddot{x} + I\ddot{\theta} + m_p\ddot{\theta}l_p^2 - m_pgl_p\sin(\theta) &= 0 \end{aligned} \end{equation}(mp​+mc​)x¨+mp​θ¨lp​cos(θ)−mp​θ˙2lp​sin(θ)mp​lp​cos(θ)x¨+Iθ¨+mp​θ¨lp2​−mp​glp​sin(θ)​=F=0​​(7.9)​

where III is the moment of inertia about the pendulum's mass center given by I=mplp23I=\cfrac{m_pl_p^2}{3}I=3mp​lp2​​.

This system has two equilibria (x˙=x¨=θ˙=θ¨=0)(\dot{x}=\ddot{x}=\dot{\theta}=\ddot{\theta}=0)(x˙=x¨=θ˙=θ¨=0) which are (xe1,θe1)=(0,π)(x_{e1},\theta_{e1})=(0,\pi)(xe1​,θe1​)=(0,π) and (xe2,θe2)=(0,0)(x_{e2}, \theta_{e2})=(0,0)(xe2​,θe2​)=(0,0).

The first equilibrium corresponds to the down position (stable) and the second equilibrium corresponds to the upright position (unstable) of the pendulum. Linearizing the previous equations about the equilibrium of interest (0,0)(0, 0)(0,0) we obtain the following equations:

ddt[xθx˙θ˙]=[001000010−3mpgmp+4mc0003(mp+mc)g(mp+4mc)lp00][xθx˙θ˙]+[004mp+4mc−3(mp+4mc)lp]F(7.10) \frac{d}{dt} \begin{bmatrix} x \\[1ex] \theta \\[1ex] \dot{x} \\[1ex] \dot{\theta} \end{bmatrix} = \begin{bmatrix} 0 & 0 & 1 & 0 \\[1ex] 0 & 0 & 0 & 1 \\[1ex] 0 & -\cfrac{3m_pg}{m_p+4m_c} & 0 & 0 \\[1ex] 0 & \cfrac{3(m_p+m_c)g}{(m_p+4m_c)l_p} & 0 & 0 \end{bmatrix} \begin{bmatrix} x \\[1ex] \theta \\[1ex] \dot{x} \\[1ex] \dot{\theta} \end{bmatrix} + \begin{bmatrix} 0 \\[1ex] 0 \\[1ex] \cfrac{4}{m_p+4m_c} \\[1ex] -\cfrac{3}{(m_p+4m_c)l_p} \end{bmatrix}F \tag{7.10}dtd​​xθx˙θ˙​​=​0000​00−mp​+4mc​3mp​g​(mp​+4mc​)lp​3(mp​+mc​)g​​1000​0100​​​xθx˙θ˙​​+​00mp​+4mc​4​−(mp​+4mc​)lp​3​​​F(7.10)

The input force FFF in the above equations can be written in terms of the input voltage VVV applied to the motor of the cart and the cart velocity x˙\dot{x}x˙ as shown below.

V=ImRm+KmKgωg=ImRm+KmKgx˙rV=I_mR_m+K_mK_g\omega_g=I_mR_m+K_mK_g\frac{\dot{x}}{r}V=Im​Rm​+Km​Kg​ωg​=Im​Rm​+Km​Kg​rx˙​
Im=VRm−KmKgRmx˙r(7.11)I_m=\frac{V}{R_m}-\frac{K_mK_g}{R_m}\frac{\dot{x}}{r} \tag{7.11}Im​=Rm​V​−Rm​Km​Kg​​rx˙​(7.11)

VVV : voltage applied to motor (Volts)

ImI_mIm​ : current in motor (Amp)

KmK_mKm​ : back EMF constant (Volt/(rad/sec))

KgK_gKg​ : gear ratio in motor gearbox

RmR_mRm​ : motor armature resistance (Ohms)

ωg\omega_gωg​ : angular velocity of the wheel (rad/sec)

x˙\dot{x}x˙ : cart velocity (m/sec)

rrr : radius of motor pinion that meshes with the track (m)

Tm=KtKgIm(7.12)T_m=K_tK_gI_m \tag{7.12}Tm​=Kt​Kg​Im​(7.12)

where KmK_mKm​ is the motor torque constant given by

Kt=kKm(7.13)K_t=k K_m \tag{7.13}Kt​=kKm​(7.13)

where kkk is the conversion factor from volt-amp to N-m given by

k=1.3558 N−m/s/(volt−amp)k = 1.3558 \mathrm{~N-m/s/(volt-amp)}k=1.3558 N−m/s/(volt−amp)
F=Tmr=KtKgVrRm−KtKgKmKgRmx˙r2=kKmKgVrRm−k(KmKg)2Rmx˙r2(7.14)F=\frac{T_m}{r}=\frac{K_tK_gV}{rR_m}-\frac{K_tK_gK_mK_g}{R_m}\frac{\dot{x}}{r^2}=\frac{kK_mK_gV}{rR_m}-\frac{k(K_mK_g)^2}{R_m}\frac{\dot{x}}{r^2} \tag{7.14}F=rTm​​=rRm​Kt​Kg​V​−Rm​Kt​Kg​Km​Kg​​r2x˙​=rRm​kKm​Kg​V​−Rm​k(Km​Kg​)2​r2x˙​(7.14)
Km=0.00767 volt−amp/rad/s,Kg=3.7k=1.3558 N−m/s/(volt−amp),r=0.00635 m,Rm=2.6 ohmsK_m=0.00767~ \mathrm{volt-amp/rad/s},\quad K_g=3.7 \\ k=1.3558~\mathrm{N-m/s/(volt-amp)},\quad r=0.00635~\mathrm{m},\quad R_m=2.6\space \mathrm{ohms}Km​=0.00767 volt−amp/rad/s,Kg​=3.7k=1.3558 N−m/s/(volt−amp),r=0.00635 m,Rm​=2.6 ohms
F=2.3305V−10.4152x˙(7.15)F=2.3305V-10.4152\dot{x} \tag{7.15}F=2.3305V−10.4152x˙(7.15)

Letting a1=2.3305a_1=2.3305a1​=2.3305 and a2=10.4152a_2=10.4152a2​=10.4152 , the input force F can be written as

F=a1V−a2x˙(7.16)F=a_1V-a_2\dot{x} \tag{7.16}F=a1​V−a2​x˙(7.16)
ddt[xθx˙θ˙]=[001000010−3mpgmp+4mc−4a2mp+4mc003(mp+mc)g(mp+4mc)lp3a2(mp+4mc)lp0][xθx˙θ˙]+[004a1mp+4mc−3a1(mp+4mc)lp]F(7.17)\frac{d}{dt} \begin{bmatrix} x \\[1ex] \theta \\[1ex] \dot{x} \\[1ex] \dot{\theta} \end{bmatrix} = \begin{bmatrix} 0 & 0 & 1 & 0 \\[1ex] 0 & 0 & 0 & 1 \\[1ex] 0 & -\cfrac{3m_pg}{m_p+4m_c} & -\cfrac{4a_2}{m_p+4m_c} & 0 \\[3ex] 0 & \cfrac{3(m_p+m_c)g}{(m_p+4m_c)l_p} & \cfrac{3a_2}{(m_p+4m_c)l_p} & 0 \end{bmatrix} \begin{bmatrix} x \\[1ex] \theta \\[1ex] \dot{x} \\[1ex] \dot{\theta} \end{bmatrix} + \begin{bmatrix} 0 \\[1ex] 0 \\[1ex] \cfrac{4a_1}{m_p+4m_c} \\[3ex] -\cfrac{3a_1}{(m_p+4m_c)l_p} \end{bmatrix}F \quad \tag{7.17}dtd​​xθx˙θ˙​​=​0000​00−mp​+4mc​3mp​g​(mp​+4mc​)lp​3(mp​+mc​)g​​10−mp​+4mc​4a2​​(mp​+4mc​)lp​3a2​​​0100​​​xθx˙θ˙​​+​00mp​+4mc​4a1​​−(mp​+4mc​)lp​3a1​​​​F(7.17)

The above set of linear differential equations is of the form X˙=AX+BV\dot{X}=AX+BVX˙=AX+BV , where X=[x, θ, x˙, θ˙]⊤X=[x,~\theta,~ \dot{x},~\dot{\theta}]^\topX=[x, θ, x˙, θ˙]⊤. We seek a linear control law of the form V=−KXV=-KXV=−KX, where KKK is a 1×41 \times 41×4 vector of gains.

V=−KX(7.18)V=-KX \tag{7.18}V=−KX(7.18)
J=∫0∞(XTQX+VTRV)dt(7.19)J=\int_0^{\infty}(X^T QX+V^T RV) dt \tag{7.19}J=∫0∞​(XTQX+VTRV)dt(7.19)

for some user-defined matrices Q=QTQ=Q^TQ=QT and R=RTR=R^TR=RT . It is assumed that QQQ is positive semi-definite (all the eigenvalues are non-negative) and RRR is positive definite (all the eigenvalues are positive). Here VVV is the input voltage, XXX given by

X=[xθx˙θ˙](7.20)X=\begin{bmatrix} x\\[1ex] \theta \\[1ex] \dot{x} \\[1ex] \dot{\theta} \end{bmatrix} \tag{7.20}X=​xθx˙θ˙​​(7.20)

is the state vector, and KKK given by

K=[k1  k2  k3  k4](7.21)K = [ k_1 ~~ k_2 ~~ k_3 ~~ k_4] \tag{7.21}K=[k1​  k2​  k3​  k4​](7.21)

is the controller gain vector. Note that the input voltage VVV is scalar and therefore, RRR is also scalar. In practice, the weighting matrices QQQ and RRR are chosen to be diagonal. A simple way for choosing QQQ and RRR is the following (Bryson's rule):

∣V∣≤Vˉ,∣Xi∣≤Xiˉ|V|\leq\bar{V}, \quad|X_i|\leq\bar{X_i}∣V∣≤Vˉ,∣Xi​∣≤Xi​ˉ​
R=1Vˉ2,Q=diag(1Xˉi2)(7.22)R=\frac{1}{\bar{V}^2},\quad Q=\mathrm{diag} \left(\frac{1}{\bar{X}_i^2} \right) \tag{7.22}R=Vˉ21​,Q=diag(Xˉi2​1​)(7.22)

Further tuning of RRR and QQQ may be required for improving the controller performance. Note that increasing RRR means increasing the penalty on the control input (using less control effort). Similarly, increasing QQQ means increasing the penalty on the states (states reaching equilibrium position quickly and with less overshoot).

(Note: Conventional error signal shown, but u=−KΔX,ΔX=X−XCu=-K\Delta X, \Delta X=X-X_Cu=−KΔX,ΔX=X−XC​)

where xxx is position of the cart, x˙\dot{x}x˙ is velocity of the cart, θ\thetaθ is angular position of the rod from the vertical, θ˙\dot{\theta}θ˙ is angular velocity of the rod, and KKK is a vector of feedback gains K=[k1 k2 k3 k4]K = [ k_1 ~ k_2 ~ k_3 ~ k_4]K=[k1​ k2​ k3​ k4​].

Obtain the A and B matrices of the system using mp=0.21 kg, mc=0.815 kgm_p=0.21\space kg,\space m_c=0.815\space kgmp​=0.21 kg, mc​=0.815 kg , and lp=0.305 ml_p=0.305\space mlp​=0.305 m .

Choose Q≥0Q\geq0Q≥0 and R>0R>0R>0 based on the following:

0.4m≤∣xmax∣≤0.5m0.4m\leq|x_{max}|\leq0.5m0.4m≤∣xmax​∣≤0.5m

π6rad≤∣θmax∣≤π4rad\frac{\pi}{6}rad\leq|\theta_{max}|\leq\frac{\pi}{4}rad6π​rad≤∣θmax​∣≤4π​rad

6 volts≤∣Vmax∣≤10 volts6\space volts\leq|V_{max}|\leq10\space volts6 volts≤∣Vmax​∣≤10 volts

No constraints on x˙max⁡\dot{x}_{\max}x˙max​ and θ˙max\dot{\theta}_{max}θ˙max​ . (They can go to infinity…)

According to Bryson’s rule, this will result in the following QQQ and RRR matrices:

Q=[400001.62110000000000]Q= \begin{bmatrix} 4 & 0&0&0 \\ 0&1.6211&0&0 \\ 0&0&0&0 \\ 0&0&0&0 \end{bmatrix}Q=​4000​01.621100​0000​0000​​ and R=[0.01]R= [0.01]R=[0.01]

To build the model, click the down arrow on Monitor & Tune under the Hardware tab and then click Build for monitoring . This generates the controller code.

Press Connect button under Monitor & Tune and then press Start .

Figure 7.1: Inverted pendulum mechanism [Image source: https://grabcad.com/library/inverted-pendulum-1]
Figure 7.2: A simple mass / spring / damper system
Figure 7.3: Inverted Pendulum mechanism in the lab
Figure 7.4: Inverted pendulum mechanism
Figure 7.5: Powered rocket during ascent
Figure 7.6: Free Body Diagrams
Fig 7.7: Block diagram of the experimental set-up