integration project

27
SC4050: Integration Project Control of Inverted Pendulum Due on June 12, 2015 Robert Babuska / Gabriel Lopes Shekhar Gupta(4419677) and Shwetha M R(4420578)

Upload: shekhar-gupta

Post on 13-Sep-2015

49 views

Category:

Documents


1 download

DESCRIPTION

Control of a inverted pendulum

TRANSCRIPT

  • SC4050: Integration Project

    Control of Inverted PendulumDue on June 12, 2015

    Robert Babuska / Gabriel Lopes

    Shekhar Gupta(4419677) and Shwetha M R(4420578)

  • Contents

    1 Introduction 2

    2 System Identification 3

    Lab Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Lagrangian Dynamic Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Generalized Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Kinetic and Potential Energy Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Lagrangian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Modelling of DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Algebraic Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Nonlinear Simulation Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Parameter Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    Model Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    3 LQR Control 10

    Linearised Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    Pendulum Up ( = 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    State Space Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    LQG Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    Observer Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    Continious Time Simulation Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    Converting the continuous time model to discrete time . . . . . . . . . . . . . . . . . . . . . . 13

    Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Comparison of LQG controller performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    4 Model Predictive Control 19

    Sample time: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    Prediction Horizon: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    Control horizon: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    Weight tuning: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    5 Conclusion 24

    Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    LQR control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    Model Predictive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    1

  • Chapter 1

    Introduction

    The Cart-Inverted Pendulum System (CIPS) is a classical benchmark control problem. Its dynamics resem-

    bles with that of many real world systems of interest like missile launchers, pendubots, human walking and

    Segway and many more. The control of this system is challenging as it is highly unstable, highly non-linear,

    non-minimum phase system and under actuated. Further, the physical constraints on the track position

    control voltage etc. also pose complexity in its control design.

    For this course our task is to design two controllers that can control the motion of the cart such that the

    pendulum is balanced in its upright position with the following requirements.

    keeping the pendulum inverted and track the reference signal for the cart position.

    The controlled system should have zero steady state error and recover from a small tick against thependulum.

    To obtain these objective we are going to follow systematic procedure that are required to obtain controllers

    which fulfils these objectives. The first step to do this is by modelling the system. It is very important to have

    some information about the plant so that its output can be controlled. Hence most of the control algorithm

    rely on the model of the plants that needs to be controlled. We first create a first principle mathematical

    model of the Pendulum Cart system and the DC motor. Modelling and Dynamics analysis of Cart pendulum

    system is done by writing the Lagrange equations. Then we carry out parametric system identification for

    the inverted pendulum using a nonlinear simulation model as we didnt have exact measurement of the input

    to force gain km and the damping coefficient b (including viscous friction and the back-emf of the motor).

    Once we have the model of the system we are going to design two linear controller for the system. In order

    to do that we need to linearize the model which can be done by linearizing the system equation obtained

    by Langrange equation at the equilibrium position. After we linearize the system we can derive the state

    space model of the system. This continuous time the state space model will be converted into discrete time

    state space model. Once we have the discrete time state space model, we can proceed with the designing of

    the controller. First we will design a Full State Feedback Controller i.e. Linear Quadratic Gaussian (LQG)

    compensator. The compensator aims at providing a proper control input that provides a desired output in

    terms of the Pendulum Angle and Cart Position. Once we design the controller first we want to test the

    controller in a simulation model and tune the weights, then follow the same procedure on the real setup to

    get optimum results.

    We then design Model Predictive Control (MPC) using the MATLAB MPC toolbox and simulate the

    output by tuning the weights of the controller and then implement the controller on the real-time setup and

    further tune the weights.

    2

  • Chapter 2

    System Identification

    There are two basic approaches to modeling : the First principle modeling and the black box modeling.

    Both the approaches have their own advantages and disadvantages. In black box modeling we can use same

    algorithm to identify different plants which are complex in nature and are not easy to identify using first

    principle due to its complicated mathematical equations. But since the black box modeling is done by

    analysing the input and the output data of the plant, the model is generally valid only for the signal it was

    calculated from. For example if a step signal was used to identify the plant, this plant should not be used

    for the analysis of high frequency signals.

    Plants obtained by using first principle are more robust as whole range of input signals can be used to

    analyse it. But the drawback of first principle is that there are lot of unknown constants and relations in

    the model description. Hence these constants need to obtained by performing real-time experiments on the

    plant. In our case we are going to use first principle method to obtain the system model.

    Lab Setup

    Figure 2.1: The lab setup of The Cart-Inverted Pendulum System (CIPS)

    The lab setup is the Linear Servo Base Unit of Quansers consulting. It consists of a cart driven by a DC

    motor, via a rack and pinion mechanism, to ensure consistent and continuous traction. The cart is equipped

    with a rotary metal shaft to which a free turning pendulum is attached. The Linear Servo Base Unit system

    has two encoders: one encoder is used to measure the carts position and the other encoder is used to sense

    the position of the pendulum shaft. The Linear Inverted Pendulum is mounted on the cart and is free to fall

    along the carts axis of motion.

    3

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Description

    Figure 2.2: Inverted Pendulum on a cart structure

    The inverted pendulum setup consists of a cart driven by a DC motor. The motor can steer the cart left and

    right on a track approximately one meter long. On the cart, a pendulum is mounted such that it can freely

    rotate around an axis that is perpendicular to the direction of motion of the cart. The schematic diagram in

    Figure 2.2 shows the construction of the system including all the relevant parameters and variables. Positive

    directions of variables are indicated by arrows. This system has one control input u, which is the voltage

    driving the cart motor. This input is commanded from the computer and is scaled between 1 (correspondsto the maximal input moving the cart to the left) and +1 (corresponds to the maximal input moving the cart

    to the right). There are two measured outputs: x the displacement of the cart from the track center, and

    the angle of the pendulum. These measurements are given in their physical units meters and radians,

    respectively. The physical parameters of the system are listed in Table 2.1. Most of the values can easily be

    determined by measuring the dimensions and masses (such as the pendulum length, mass of the cart, etc.)

    Table 2.1: Physical parameters and their valuesSymbol Parameter Value

    g acceleration due to gravity 9.81 ms2

    l half length of pendulum 0.30 mm mass of pendulum 85 g

    J inertia of pendulum ml2

    3

    M mass of cart 0.49 kg

    Lagrangian Dynamic Analysis

    A complete theoretical model of the pendulum cart system can be done using Lagrangian Dynamics. First

    we choose generalized coordinates, and then derive energy functions, and Lagrangian. Finally, we can use

    Lagranges Equation to derive the equations of motion. A schematic of the system is shown in Figure 2.3.

    This model and coordinate system will be used in the analysis. For completeness, this derivation involves

    inertia about the pendulum center of mass.

    Page 4 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 2.3: Schematic of Pendulum Cart Model includes cart mass M , pendulum of mass m and inertia I

    about its center of mass, which is a distance l from the pendulum pivot.

    Generalized Coordinate System

    The cart pendulum system has two degrees of freedom and can therefore be fully represented using two gen-

    eralized coordinates. For this analysis, the generalized coordinates are chosen as the horizontal displacement

    of the cart, x, and the rotational displacement of the pendulum,

    Kinetic and Potential Energy Functions

    The kinetic co-energy function for the cart mass is:

    T =Mv1

    2

    2(2.1)

    The velocity of the cart is simply

    v1 = x (2.2)

    For the pendulum, the co-energy function can be derived from :

    T =Mv2

    2

    2+I2

    2(2.3)

    The angular velocity of the pendulum is

    = (2.4)

    Kinetic energy in along both x and and kinetic energy due to rotation

    v2 (x) =

    x(x l sin ) = x l cos (2.5)

    v2 (y) =

    x(l cos ) = l sin (2.6)

    v22 = v2

    2 (x) + v22 () = x2 + l22 2xl cos (2.7)

    Page 5 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Substituting Equation 2.7 into Equation 2.3 and upon simplifying equation 2.1 and 2.3. The total kinetic

    co-energy is

    T =(M +m)x2

    2+ml22

    2+I2

    2mxl cos (2.8)

    Since the cart moves only in the horizontal direction, the potential energy of the system is determined entirely

    by the angle of the pendulum, given by

    V = mgl cos (2.9)

    Lagrangian

    From the kinetic co-energy and potential energy functions, the Lagrangian is given by

    L = T V (2.10)

    Using Equations 2.8 and 2.9, the Lagrangian can be written as

    L =(M +m)x2

    2+ml22

    2+I2

    2ml cos (g + x) (2.11)

    Applying Euler Lagrange Equation we get,

    F bx = d(Lx )

    dt Lx

    (2.12)

    d(L

    )

    dt L

    = 0 (2.13)

    Substituting equation 2.11 in equations 2.12 and 2.13 and evaluating the partial derivatives and simplifying

    and rearranging, the system state equations are

    F = (M +m)x+ bx+ml cos ml 2 sin (2.14)

    (I +ml2) +mlx cos +mgl sin = 0 (2.15)

    Modelling of DC Motor

    Figure 2.4: Schematic of a DC motor

    Ldi

    dt+Ri = V Vb (2.16)

    Page 6 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Vb = K = Kd

    dt(2.17)

    Jd2

    dt2 bd

    dt= T (2.18)

    In general, the torque generated by a DC motor is proportional to the armature current and the strength

    of the magnetic field. In this example we will assume that the magnetic field is constant and, therefore,

    that the motor torque is proportional to only the armature current i by a constant factor k as shown in the

    equation below. This is referred to as an armature-controlled motor.

    T = Ki (2.19)

    since torque is force times the radius we have

    T = Fr (2.20)

    where r is the radius of the pinion

    i =V

    R(2.21)

    F =KV

    rR(2.22)

    F = kmu (2.23)

    where km is equal toKrR and V = u

    Algebraic Loops

    When analysing or simulating a system described by a block diagram, it is necessary to form the differential

    equations that describe the complete system. In many cases the equations can be obtained by combining

    the differential equations that describe each subsystem and substituting variables. This simple procedure

    cannot be used when there are closed loops of subsystems that all have a direct connection between inputs

    and outputs, known as an algebraic loop. When algebraic loops are present, it is necessary to solve algebraic

    equations to obtain the differential equations for the complete system.

    Hence for our simulation model well further simplify these equation so that we can incorporate these

    equation in Matlab simulink. Equation 2.14 and 2.15 can be written as

    x =1

    M(kmuN bx)

    =1

    I(Nl cos + Pl sin )

    (2.24)

    where

    P = m(l sin l cos ) + gN = m(x l2 sin + l cos )

    (2.25)

    and F is replaced by kmu as derived in the DC motor modeling.

    Nonlinear Simulation Model

    As described above we used equation 2.24 and 2.25 to create a non linear simulink model. Figure 2.5 shows

    the simulink model.

    Page 7 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 2.5: Non-linear simulink model of Cart inverted pendulum system

    We used this simulink model for the parameter estimation.

    Parameter Estimation

    As discussed before the drawback of first principle modelling is that there are lot of unknown constants and

    relations in the model description. Since we modelled our system using first principles we have to obtain

    these unknown parameters of the model by performing real-time experiments on the Cart inverted pendulum

    system. We are neglecting rotational viscous friction, and translational Coulomb friction in our model. Hence

    there will be always some difference between the model and the real setup. For example the non-presence of

    oscillations in real setup is caused by presence of dry (Coulomb) friction but in our model simulation we can

    find oscillation. Hence the only constants that we have to determine are the input to force gain km and the

    damping coefficient b (including viscous friction and the back-emf of the motor). The advantage of modelling

    by first principle is the model is valid for all sets of input output data and not just on the data set that was

    used for parameter estimation. Due to this we do not need to worry about which kind of input signal to

    take. A signal as simple as impulse should be enough in our case. Since our model is highly non-linear due

    the presence of various trigonometric term as well as due the presence of friction, to have better estimate

    of the parameters, we want to use Non-linear least square approach. The non-linear simulink model (refer

    to Fig 2.5) that was derived earlier is used for this estimation. We used Matlab function lsqnonlin for our

    identification. To do this identification we had to provide the initial values to the parameters. We used

    various input signal for this estimation with each data we got different values for km and b. Even for same

    data set if we chose different initial values for the parameters we got different values. When we used input to

    be a multi-input sine wave we got curve fitting with VAF (variance accounted for) of 96%. Figure 2.6 shows

    the curve fitting with the identification data. The values obtained for the input to force gain was km = 4.45

    and the value for damping coefficient b was found out to be 11.54.

    Model Validation

    Once we had obtained the parameter values, we validated these values against different set of input output

    data. We took a different set of input data and compared the output of our model with the calculated

    parameters against the actual setups output. The VAF value for the data validation was found to be 86%.

    Figure 2.7 shows the graph of validation data.

    Page 8 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 2.6: Model output with identification data

    Figure 2.7: Model output comparison with actual setup output for validation data

    Page 9 of 26

  • Chapter 3

    LQR Control

    Linearised Model

    Before proceeding with further analysis, we must linearize the state equations. The mathematical model of

    the system is nonlinear, it has to be linearized around some appropriate working point. Since the analysis

    and control design techniques we will be employing apply only to linear systems, this set of equations needs

    to be linearized. In case of availability of mathematical model of the system, linearization is performed by

    calculating first two members of corresponding Tylor series (function value and first derivation). Specifically,

    we will linearize the equations about the vertically upward equilibrium position, = 0, and will assume that

    the system stays within a small neighbourhood of this equilibrium. Focusing on small variations of about

    the equilibrium point 0:

    = 0 + (3.1)

    = (3.2)

    From a Taylor Series expansion, a first order approximation of any function of is

    f() f() + dfd

    (3.3)

    Also, because higher order terms are neglected

    2 0 (3.4)

    Hence

    2 0 (3.5)

    Pendulum Up ( = 0)

    For = 0, Equation 2.26 yields to first order

    cos cos (0) + ( sin 0) = 1sin sin (0) + (cos (0)) = 0

    (3.6)

    10

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    State Space Representation

    For linear state control of the inverted pendulum, it is necessary to convert the state equations to state space

    representation in the form:

    x = Ax+Bu

    To get the state-space form, equation 2.14 and 2.15 are linearized using eqn. 3.5 and 3.6, then they are

    rearranged into a series of first order differential equations. Since the equations are linear, they can then be

    put into the standard matrix form shown below.

    x

    x

    =

    0 1 0 0

    0 (I+ml2)b

    I(M+m)+Mml2m2gl2

    I(M+m)+Mml2 0

    0 0 0 1

    0 mlbI(M+m)+Mml2mgl(M+m)

    I(M+m)+Mml2 0

    x

    x

    +

    0(I+ml2)km

    I(M+m)+Mml2

    0mlkm

    I(M+m)+Mml2

    u

    y =

    [1 0 0 0

    0 0 1 0

    ]x

    x

    + [ 00]u

    (3.7)

    LQG Control

    The linear quadratic regulator (LQR) is a well-known design technique that provides practical feedback

    gains. A synthesis problem is formulated to minimize a criterion, which is a quadratic function of the states

    and the control signals. The problem is called the Linear Quadratic (LQ) control problem. The resulting

    optimal controller is linear. The LQ-controller can also be interpreted as a pole-placement controller.

    The solution of the LQ-control problem, if all the states are available, is the result of an algebraic Riccati

    equation, where the properties of LQ-controllers are also discussed. But since we cannot estimate all the

    states, we use a observer based LQR controller.

    Implementation

    We first linearise the system and then find out a state feedback gain that stabilizes the pendulum in the

    equilibrium point. In order to do this we check the rank of Controllability matrix.

    C = [B AB A2B A3B] (3.8)

    Rank of C should be 4 for the system to be controllable.This can be checked with matlab command ctrb.

    LQ- Controller can be implemented in matlab using lqr command.

    The LQ-Controller needs as input the weighted matrices: Q for the states and R for the inputs. Changing

    the relative magnitude between the elements in the weighting matrices means a compromise between the

    speed of the recovery and the magnitudes of the control signals.

    Looking at the function to minimize:

    J =

    Nk=1

    x(k)TQx(k) + u(k)

    TRu(k) (3.9)

    Q and R are symmetric weighting matrices that are positive semi-definite and positive definite respectively.

    Page 11 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    By increasing the weighting matrices relative to one another we can put emphasis on the state and control

    trajectories. We can obtain the value of K by using matlab function lqr giving different values of Q and

    R. The R matrix influences the control action. Keeping Q equals to the identical matrix, and amounting R

    unit by unit, the step response will become slower, less effort will be put in the control action. Leaving the

    R matrix equals to the unit, the control action increases if the Q is increased. The Q matrix acts on the

    states of the system. Q(1, 1) amounts to the cart displacement, Q(2, 2) corresponds to the cart displacement,

    Q(3, 3) to the pendulum angle and Q(4, 4) to the pendulum angular displacement. Since we are not bothered

    about the cart velocity and angular velocity of the cart we can keep Q(2, 2) and Q(4, 4) as zero. Since the

    constraint on cart position is difficult to meet, we choose Q(1, 1) Q(3, 3).We start the tuning with the value of Q = CTC and R = [1] and check the response. We will increase the

    weight matrix Q such that Q(1, 1) is always greater then Q(3, 3). The final value of Q and R after tuning

    for which the system was stable and was able to track the reference signal is given below:

    Q =

    450 0 0 0

    0 0 0 0

    0 0 150 0

    0 0 0 0

    , R = [5] (3.10)

    Observer Design

    To design the observer, we first check the rank of observability matrix.

    W =

    C

    CA

    CA2

    CA3

    (3.11)We observe that the rank of W is 4 and therefore we can design an observer to measure the states which are

    not currently measurable. i.e. the speed of the cart displacement and the angular velocity of the pendulum.

    We calculate the eigenvalues of the closed loop system and place the observer pole at 10 times the slowest

    pole. We found that the slowest closed loop pole was at -4.09 [before tuning], so we places the observer poles

    at

    P = [40,41,42,43] (3.12)We implement the placement of observer using the matlab command place. The final state space matrix of

    the closed loop plant is

    Ac = [ABK]Bc = B

    Cc = C

    Dc = D

    (3.13)

    Page 12 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.1: Simulink Model of LQR continuous time Observer based Model

    Observer state space matrix is

    Ahat = [A LC]Bhat = [B L]

    Chat =

    1 0 0 0

    0 1 0 0

    0 0 1 0

    0 0 0 1

    Dhat =

    0 0 0

    0 0 0

    0 0 0

    0 0 0

    (3.14)

    Where K is the solution of the riccati equation and L is the output of matlab command place used for

    observer pole placement.

    Now we implement the linearised closed loop plant with observer on the simulation using the above matrices,

    as shown in Figure 3.1

    Continious Time Simulation Results

    Given below the graph of Closed loop system response.

    We observe that the system stabilizes within 2 seconds in the simulation model. Now we proceed to convert

    the model into discrete time.

    Converting the continuous time model to discrete time

    The system must be converted to a discrete time system. To do so, it was needed the sampling frequency.

    Using the bode plot of the module of the open loop transfer function, it is possible to select the sampling

    frequency. The selection of the sampling frequency is important to not incur in aliasing problems. For

    Page 13 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.2: Continuous time LQR simulation model system response

    discrete-time systems, the Shannons sampling theorem, based on the Nyquist frequency, is used to avoid

    aliasing. A continuous time signal, that does not contain frequency components greater than cross over

    frequency (c), is uniquely determined if the sampling frequency s is higher than 2c.

    One way to measure the sampling time is the closed loop bandwidth. A good rule of thumb is to use sampling

    frequency to be in between 10 bandwidth to 30 bandwidth which can be determined by closed loop bodeplot. Another approach is to use sampling time to be in between risetime/4 to risetime/10.

    When we give a step input to the system, the rise time of the system is found to be 0.2 seconds. So we take

    the sampling period to be 0.01 seconds.

    We use the matlab command c2d to convert the state matrix in continuous time to discrete time. Use the

    same values of Q and R as continuous time and implement the LQ controller in discrete time using matlab

    command dlqr. Now we convert the observer poles in continuous time to discrete time using the conversion,

    z = ehs (3.15)

    where z is discrete time pole,

    s is continuous time pole and

    h is sampling frequency

    So the discrete time observer poles are

    P = [0.7, 0.72 , 0.73 , 0.69] (3.16)

    We repeat the same procedure as continuous time by using the place command to place the observer and

    create the discrete time LQcontroller with observer The discrete time closed loop state space model is given

    Page 14 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.3: Discrete time LQR simulation model

    by.

    Phic = [PhiGammaK]Gammac = Gamma

    Cdc = Cd

    Ddc = Dd

    (3.17)

    The observed state space model is given by

    Phihat = [Phi LCd]Gammahat = [Gamma,L]

    Cdhat =

    1 0 0 0

    0 1 0 0

    0 0 1 0

    0 0 0 1

    Ddhat =

    0 0 0

    0 0 0

    0 0 0

    0 0 0

    (3.18)

    Given below is the simulation of Discrete time LQG Controller.

    Challenges

    The discrete time controller with the same Q and R values gave good response on the simulation model

    where as when tested on the pendulum setup didnt stabilise the system. This happened because of high

    dynamics of the observer pole placed at 0.4. It created turbulent oscillation and destabilised the system.

    When we placed the observer poles near 0.7, the system oscillation reduced and it gave a smooth response.

    Page 15 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.4: Comparison of Disturbance rejection in the Simulation Model to Pendulum setup

    Comparison of LQG controller performance

    We compare the simulation output of LQG controller which is given an initial disturbance of 0.01 in angle

    with the disturbance rejection of the real setup. As seen in the figure 3.4 we observe that the disturbance

    rejection in simulation model is fast whereas in the setup it takes more time to settle down. This is because

    the simulation model does not consider the viscous force of the pendulum and the static friction in the cart.

    Now we test the reference tracking in the simulation model by changing the reference from 0 to 0.1

    for cart displacement. The output of the simulation is shown in figure 3.5 Figure 3.6 shows the reference

    tracking on the real setup. We observe there is a very small error of 0.02m during reference tracking. This

    error in the reference tracking is so less that the control input generated by it is not enough to overcome the

    static friction, hence unavoidable. Figure 3.7 and 3.6 show the control input and the observer output during

    reference tracking, respectively.

    Page 16 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.5: LQR Reference tracking on Simulation

    Figure 3.6: LQR Reference tracking on the cart pendulum setup

    Page 17 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 3.7: Control Output LQR Reference tracking on the cart pendulum setup

    Figure 3.8: Observer Output LQR Reference tracking on the cart pendulum setup

    Page 18 of 26

  • Chapter 4

    Model Predictive Control

    The design of model predictive controller for inverted pendulum system is based on the mathematical model

    of the system and its linearized version. Generally, the computation of control signal for model predictive

    controller (MPC) is based on minimization of quadratic criterion mentioned in the equation 4.1. Model

    Predictive Control takes into account of the following three ideas for its functioning:

    1. Explicit use of a model to predict the process output along a future time horizon.

    2. Calculation of a control sequence to optimize an objective function.

    3. A receding horizon strategy, so that at each instant the horizon is moved towards the future, which

    involves the application of the first control signal of the sequence calculated at each step.

    To design model predictive controller we used Matlabs Model predictive GUI based toolbox. First we importthe discretized state space model of the setup and define the manipulated variable as the u and and x as

    the measurable output. When we get to the tree structure on the design tool under the controller node we

    select the controller which contains multiple tabs such as Horizon, constraint and weight tuning. We then

    tune these parameters one by one. The tuning of these parameters has been described below.

    Sample time:

    As discussed before the selection of sample time is decided based on the cut-off frequency or rise time of

    the system. If we decrease the value of sampling time rejection of unknown disturbance usually improves.

    Usually very low value of sampling time increases the computational power significantly. In our case when we

    tried using sampling time of 0.01 second we did not encounter any computation problem and we continued

    with 0.01 sampling time.

    Prediction Horizon:

    The prediction horizon, Np, is the number of future control intervals the MPC controller must evaluate by

    prediction when optimizing its manipulated variables at control interval Ts. Generally value of Np is selected

    based on how fast you want your controller to respond that is we want our response time to be equal to the

    prediction horizon times the sampling time. As we have already designed LQG controller we have seen that

    achieving 2 seconds of settling time is possible. Hence we want our closed loop system to have a settling

    time similar to LQG, in range of 2 seconds. To achieve this we select our prediction horizon to be 200 as

    our sampling time is 0.01s. By going through various literature we realise that a prediction interval of 2 to 3

    second is good enough for a good controller. It is also know that low value of prediction interval can create

    an internally unstable controller hence we do not decrease this value.

    19

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Control horizon:

    Control horizon is interval after which a controller forces the control signal to become constant. In general Ncshould be very small compared to prediction horizon. An important effect of control horizon is the smoothing

    of the control signal and the control signal is forced towards steady state value which is important for steady

    state property. Another effect of decreasing Nc is, it decreases the computational effort drastically. The

    control horizon value should be more if there is dead time in the process. Since in our setup we do not find

    any dead time we chose Control horizon to be 30 (30*0.01=0.3s).

    Weight tuning:

    Model predictive controller (MPC) is based on minimization of quadratic criterion.

    J(k) = eTQ(k)e+ uTRu (4.1)

    where e is a vector of predicted control errors, u is a vector of future control signal samples and square matrices

    Q and R allows to set weighting of individual vector elements. MPC uses receding horizon principle: only

    a finite number of future values is used in the criterion and only the first element of the obtained control

    sequence is applied to the controlled system. Future outputs of the controlled system, and consequently

    control errors, are computed on base of the linear model. Since the system is described by state space model,

    future system outputs depend only on current states of the system and future control signals:

    y(k) = Cx(k) +Du (4.2)

    As the matrices Q and R are diagonal the predictive control criterion can be rewritten into the following

    form:

    J(k) = 1

    Nj=1

    [e1(k + j)]2

    + 2

    Nj=1

    [e2(k + j)]2

    + 3

    Ncj=1

    [u(k + j 1)]2 (4.3)

    where

    e1(i) = wr(i) r(i)e2(i) = 0 (i) = (i)

    Matlab control toolbox optimizes this objective function by converting it into Quadratic programming

    problem and gives the optimized control signal that is used to track the output signal. Since we had already

    designed the LQR controller we started tuning weights here by giving the values we had obtained in LQR

    controller i.e. weight on x as 450, weight on as 150 and weight on input as 1. When we simulated this

    scenario we were able to track the signal, but the control signal was very high. Hence we scaled all the

    weights and tuned it till control input reduced to value in between -1 and 1 which corresponded to value

    when all weights were scaled by 10. Hence the new weights were 4500 weight on x, 1500 weight on and

    150 weight on input u. The simulation result with these parameters are shown in the figure 4.1

    Page 20 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 4.1: Reference tracking in simulation after weight tuning of input signal

    It can be seen from the above figure that when the weight on input was low the control input was very

    high. Once we increased the weight on input the control input is well within the limit. Even though now the

    controller was able to do reference tracking, even for a small disturbance we were not able to do disturbance

    rejection and the system was becoming unstable. To overcome this we tried increasing the weight on and

    decreasing the weight on x. Hence with the weight of 1500 on x and 4500 on the model was able to do

    disturbance rejection.

    When we apply the controller with these parameter values in the real time setup we found out that it had

    lot of oscillation and the cart never became stationary, even the pendulum had oscillation. We realised that

    this was this was due to fact that there was high weight on the error in , because of which even for small

    error in the control input was very high and it was making the cart move rapidly. To overcome this we

    increased the weight on x till the oscillation stopped and the cart was able to track the reference. Hence the

    final weight that we obtained was 2500 on x, 4500 on and 150 on input u. Figure 4.3 shows the reference

    tracking for the setup and figure 4.2 shows the reference tracking in the simulation model. We observe that

    there is a very small steady state error in the reference tracking of the real-time setup and this is because

    the error is so small that the control signal generated by it cannot overcome static friction.

    Figure 4.4 shows the comparison between the disturbance rejection in the simulation to the pendulum setup.

    The simulation is given an initial disturbance of 0.01 radians whereas the pendulum setup is given distur-

    bance throughout the experiment.

    We observe that the disturbance in the pendulum setup takes more time to settle in comparison with the

    simulation. This same behaviour was observed in the LQG controller and is due to the model mismatch for

    the unaccounted viscosity of the pendulum and static friction of the cart.

    Page 21 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 4.2: Shows reference tracking in simulation after weight tunning

    Figure 4.3: Shows reference tracking in real setup, after tunning the MPC controller

    Page 22 of 26

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    Figure 4.4: Disturbance rejection in simulation and in real-time setup with MPC controller

    Page 23 of 26

  • Chapter 5

    Conclusion

    Modeling

    As discussed before there are two approaches to model a system: The First principle model and the black

    box model. We use the first principle modelling instead of the black box model this is because it is usually

    more reliable in comparison with the black box modelling and also the pendulum cart system can be easily

    modelled mathematically. The drawback of black box modelling is that it is generally valid only for the signal

    it was calculated from, which could be avoided by taking an input which persistently excites the system,

    but finding such a input is difficult. When modelling the system we neglect the rotational viscous friction,

    translational Coulomb friction and stiction for easy calculation. We observe that this approach gives us a

    good model with VAF of 96% for identification data and a VAF of 86% for validation data. This establishes

    that the model is reliable. For further improvement in the accuracy of the model we can model the coulomb

    friction as:

    Fxc = Fc.sign(x,)

    where Fc is coulomb friction constant. The negative sign is because friction acts against the movement of

    cart.

    LQR control

    Even though the implementation of a state feedback controller was simple in comparison with the MPC

    controller, the LQR controller yields really good results. The downside of this controller is that it requires

    really good model of the system. Hence system modelling should be reliable for this to work but if the system

    is really complex then modelling is not easy and it can become tedious. The model we used was accurate, so

    once we had the controller working in simulation, the same controller worked well on the real setup without

    much tuning. One problem we encountered in the real setup was the rigorous oscillations of the cart. This

    was because of an aggressive observer pole used for the state estimation was responding to noise. Once we

    made this observer poles less aggressive it was able to estimate the state and worked smoothly.

    Model Predictive control

    Implementing model predictive control was little tricky. Tuning the parameters to achieve the objective was

    the toughest part as most of the time it yielded infeasible solution. We began the tuning first by treating the

    system as SISO system with the constraint that should to be equal to zero to meet the controller objective.

    When we simulated the system treating this constraint as hard constraint, it yielded infeasible solution. This

    is due to the fact that the cart cannot move without disturbing the pendulum. So we modelled the system as

    24

  • Shekhar Gupta and Shwetha M R Integration Project SC4050

    SIMO system with constraint on the input signal to be between -1 and 1. This resulted in a feasible solution

    which was able to track the reference but was unstable for even small disturbance. Finally we removed this

    constraint and we increased the weight till the input signal was under the recommended limit of -1 to 1

    and then used a saturation block to be on safer side. Another problem we faced was that even though the

    controller was working in simulation it was not able to control the real setup. We re-tuned the controller to

    stabilise the system.

    Page 25 of 26

  • Bibliography

    [1] Karl Johan Astrom and Richard M. Murray. Feedback Systems : An Introduction for Scientists and

    Engineers.

    [2] Aarshita Joshi and Nimmy Paulose Discrete Time Model Predictive Control Approach for Inverted Pen-

    dulum System with Input Constraints

    [3] Petr Chalupa and Vladimir Bobal

    Modelling and Predictive Control of Inverted Pendulum

    [4] Control Tutorials for Matlab and Simulink

    http://ctms.engin.umich.edu/CTMS/index.php?aux=Home

    [5] Mathworks Tutorial for MPC Toolbox

    http://uk.mathworks.com/products/mpc/

    26