## EEE481 Homework 7

Problem 1

Consider the cart and pendulum system describing the evolution of the cart velocity, the

pendulum angle and the pendulum angular velocity (see details in

http://tsakalis.faculty.asu.edu/notes/models.pdf). The linearized equations around the unstable

equilibrium (angle 180deg, zero input, zero velocities) for the deviations of the state variables

from the linearization point, are:

(???? + ????) ????????

???????? = −???????????? + ????ℓ ????????

???????? + ????

????????

???????? = ????

????ℓ2 ????????

???????? = −???????????? + ????????ℓ???? + ????ℓ ????????

????????

The various constants are (all values in SI): friction coefficients ????????, ???????? = 0.1, pendulum mass ???? =

0.2, pendulum length ℓ = 0.2, cart total mass ???? = 0.4, gravitational constant ???? = 9.81.

The Force term is applied by the cart wheels driven by a DC motor with a model from the

applied voltage (say, -5:5Volts) to the force

???? = ???????? + ???? ????????

???????? + ????????????????, ???????????????? = ????????, ???? = ????????

????

Where the back-emf is taken as proportional to the motor angular velocity, which is also

proportional to the cart velocity, while the motor current generates the torque that is converted

to force by the wheels of radius r. The constants are motor resistance ???? = 5, inductance ???? =

0.1, emf/torque-constant ???? = 0.3, and wheel radius ???? = 0.1.

We want to design a controller for this system to stabilize the inverted pendulum and be able to

follow commands for the cart speed. We want to use a sequential approach where we first

stabilize the angle with an “inner-loop controller”. Then form the inner closed loop and design

an “outer loop controller” for the cart velocity.

There are two difficulties associated with this problem. One is that the angle subsystem has a

RHP pole and a zero at the origin. Its stabilization requires a controller with a RHP pole. We can

solve this as a modified PID problem where instead of the integrator we use a RHP pole

determined iteratively.

The other difficulty is technical, namely, how to create the various systems and loops without

leaving stray pole-zero cancellations (possibly in the RHP) and without resorting to tedious hand

calculations. (One approach for this is to implement the model in Simulink and use the “linmod”

command, and the other -taken here- is to work with the state space model using the

“feedback” command.)

1. Form the state-space description of the system with one input (Voltage) and three

outputs, (velocity, angle, Voltage). It is convenient to keep the voltage as an output to

make it easy to simulate with Matlab commands. We want to implement the controller

in DT with a sampling rate 100Hz. For this system, it is more convenient to follow the w-

plane approach, find the ZOH equivalent of the plant now and convert to the w-plane

and do not have to do corrections during the subsequent iterations.

2. Extract the angle subsystem (e.g., P(2), if the angle is the 2nd output) and design an

“inner-loop” stabilizing controller ???????? = ????(????????????+1)2

(????−????)(????????????+1), where “????” and the crossover

frequency are to be iterated to achieve a reasonable response (crossover should be

larger than the RHP poles, “????” should not be larger than the RHP pole). PM is to be

selected but large values are not very realistic (consider 40-50).

3. Form the inner loop system.

Hint: The Matlab command is

>> Pi=feedback(P*Ci,ss([1]),1,2);

The second argument is the feedback system, the third output is the index of the

P-inputs connected to the C-outputs (1, there is only one) and the fourth output is

the index of the P-outputs connected to the C-inputs (“2” for the angle being the

2nd output). Pi is a new system that has the same number of inputs and outputs,

the input is angle set-point and the outputs are the outputs of P.

4. Design a DT PID controller for the velocity (1st output, so P(1) subsystem).

Prefilter considerations: For step inputs, the linear control input becomes very large and

the angle can overshoot a lot. In practice, that is a problem because the input is limited

by the voltage constraints and if the angle becomes too large, the inverted pendulum will

fall (because of acceleration constraints). Here, it may be beneficial to consider a

prefilter, e.g., a lowpass filter ???? = 1

(????????+1) either first or second order roughly at the

bandwidth of the outer loop crossover. Design the controller for the filtered plant and

then include the filter in the controller. The objective is to keep the control input

amplitude and the angle excursions reasonable, without slowing down the loop too

much. For this size of cart-and-pendulum, we expect stabilization in a few seconds. Also,

keep in mind that the outer loop system has “negative gain”.

5. Form the outer loop system as in Part 3 and check the responses.

>> Po=feedback(Pi*Co,ss([1]),1,1);

The last argument “1” assumes that the first output is the cart velocity.

6. Since all the design was done in the w-plane, it is straightforward to discretize the

controllers (using Tustin) and form the feedback loops with the “feedback” command.

Provide the transfer functions of your controllers and plots of the relevant time and

frequency responses.

Problem 2

Consider the system

????(????) = −0.4???? + 4

????2 + 4???? + 4

1. Design a DT controller using the w-plane method for crossover 4 rad/s, PM = 45 degrees

and a sampling time of 10 Hz.

2. For an additive measurable disturbance at the plant output with transfer function

????(????) = 1

????+1 , design a DT feedforward controller H(z) to reduce the transient component

of the DT PID designed in Part 1. Use the “naïve” approach and comment on the benefit

of such a component for this case.

Problem 3

Consider the cart and pendulum system of Problem 1.

1. Design a DT state estimator (observer) for the system with outputs cart velocity and

pendulum angle. It is convenient here to use a LQ approach because of the multiple

outputs. Choose the estimator gain to achieve convergence faster than one second.

Hint: The state estimator has the form ????????+1 = ???????????? + ???????????? + ????(???????? − ????????) where

x,y are the estimated states and outputs and m is the measurements (the plant

y_k). The design equations are implemented in Matlab by the function “dlqr”

???? = ????????????????(????′, ????′, ???? ∗ ????2 + ???????? ∗ ???? ∗ ????′, ????)′

The design parameters have been simplified to to depend only on a gain factor

mu (such that larger mu yield higher bandwidth) and the sample time T. The

performance is characterized by eigenvalues of the observer eig(A-L*C) and its

Sensitivity (error system)

???????? = [???? − ????????, ????, ????, −????]

2. Design a DT state feedback to stabilize the cart-and-pendulum system. You may add an

offset to the velocity measurement to enable convergence to a nonzero velocity but do

not worry about integral action control.

Hint: The LQR problem minimizes the cost of states (x’Qx) and control inputs

(u’Ru), for the system

????????+1 = ???????????? + ????????????

Its solution is the linear state feedback

???????? = −???????????? => ????????+1 = (???? − ????????)????????

It is implemented in Matlab by the function “dlqr”, with syntax

???? = ????????????????(????, ????, ????′ ∗ ????, ????????)

The design parameters are Q = C’C (penalizing the output) and ???? which is the

penalty on the control input and serves as an inverse-gain parameter. When ????

decreases the controller bandwidth increases. The controller performance is

characterized by the eigenvalues of A-BK and the Sensitivity of the input to

disturbances at the plant input

???????? = [???? − ????????, ????, ????, −????]

3. Combine the state feedback with the state estimator to obtain an output feedback

controller. Illustrate the time and frequency responses of the controller.

Hint: The “model-based” controller uses the state feedback with the states

replaced by their estimates. The combined controller is (D=0)

????????+1 = ???????????? + ???????????? + ????(???????? − ????????) ; ???????? = −???????????? ; ???????? = ????????????

=> ????????+1 = ???????????? − ???????????????? − ???????????????? + ????(????????) ; ???????? = −???????????? ;

Thus, for negative feedback, the controller state-space representation becomes

[???? − ???????? − ????????, ????, ????, 0]

The controller has two inputs, the measured outputs of the system (m_k), and

one output, the control u_k. An external input (scaled reference) may be added

to the measurement m_k (i.e., the y_k of the plant). However, tracking of a

setpoint requires integral action which is not considered here.

Problem 4

Consider the cart and pendulum stabilized by the inner-outer PID controller of Problem 1. In the

context of refining the plant models in case of a change, we want to estimate the plant transfer

functions based on input-output data. The system is, of course, unstable and data cannot be

collected without a stabilizing controller.

Use the closed-loop system of Problem 1 with input reference velocity and outputs angle,

velocity, and voltage (control input). Apply a reference input (Random or Square Wave and

combinations) with maximum amplitude around 1. Add random noise to the outputs (angle,

velocity) at a level of 0.02 ~ 0.5 degrees.

N=10000;

t=(0:N-1)’*T;

rn=(rand(N,1)-.5); n1 =(rand(N,1)-.5)*0.02; n2 =(rand(N,1)-.5)*0.02;

r=sign(sin(6.28/10*t))/2+rn;

Y=lsim(Pdo,r); % Pdo created in Problem 1

plot(t,Y)

u=Y(:,3); y1=Y(:,1)+n1; y2=Y(:,2)+n2;

Design a batch parameter estimator to identify the transfer functions from the plant input “u” to

each output “yi” (angle, velocity). Look at the system equations to decide the order of the

estimated transfer functions. Try different filters for the input-output pairs and compare with

the known transfer functions. Could the estimates be used to redesign the controller