Digital Control Example: Designing Pitch Controller using State-Space method

In this digital control version of the pitch controller problem, we will use the state-space method to design the digital controller. If you refer to the Pitch Controller: Modeling page, the state-space model was derived as

The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta).

The design requirements are

• Overshoot: Less than 10%
• Rise time: Less than 2 seconds
• Settling time: Less than 10 seconds
• Steady-state error: Less than 2%

## Discrete state-space

The first thing to do here is to convert the continuous state-space model to discrete state-space. To do this, we will use the MATLAB function c2d. To use c2d, we need to specify three arguments: state-space system, sampling time (Ts), and the 'method'. You should already be familiar with how to construct a system from A, B, C, and D matrices. The sampling time should be smaller than 1/(30*BW), where BW is the closed-loop bandwidth frequency. The method we will use is the zero-order hold.

From the closed-loop Bode plot, the bandwidth frequency was determined to be approximately 2 rad/sec (see this yourself) . Thus, to be sure we have a small enough sampling time, we will use the sampling time of 1/100 sec/sample. Now we are ready to use the function c2d. Enter the following commands in an m-file.

```A = [-0.313 	56.7 	0;
-0.0139   -0.426 	0;
0 	56.7 	0];
B = [0.232;
0.0203;
0];
C = [0 0 1];
D = [0];

pitch = ss(A,B,C,D);

Ts=1/100;
pitch_d = c2d(pitch,Ts,'zoh')
```

Running this m-file in the MATLAB command window gives you the following four matrices.

```a =
x1           x2           x3
x1      0.99684       0.5649            0
x2  -0.00013849      0.99571            0
x3  -3.9309e-05      0.56579            1

b =
u1
x1    0.0023738
x2    0.0002024
x3   5.7438e-05

c =
x1           x2           x3
y1            0            0            1

d =
u1
y1            0

Sampling time: 0.01
Discrete-time system.

```

Now we have obtained the discrete state-space model of the form

## Controllability and observability

The next step is to check the controllability and the observability of the system. For the system to be completely state controllable, the controllability matrix

must have the rank of n. The rank of the matrix is the number of independent rows (or columns). In the same token, for the system to be completely state observable, the observability matrix

must also have the rank of n. Since our controllability matrix and observability matrix are 3x3, the rank of both matrices must be 3. The MATLAB function rank can give you the rank of each matrices. In an new m-file, enter the following commands and run it.

```F = [0.9968	0.05649		0
-0.0001	0.9957		0
0		0.5658		1];
G = [0.0024;
0.0002;
0.0001];
H = [0 0 1];
J = [0];

Ts = 1/100;
pitch_d = ss(F,G,H,J,Ts);

co = ctrb(pitch_d);
ob = obsv(pitch_d);

Controllability = rank(co)
Observability = rank(ob)
```

In the command window, you should see

```Controllability =

3

Observability =

3
```

This proves that our discrete system is both completely state controllable and completely state observable.

## Control design via pole placement

The schematic of a full-state feedback system is shown below.

where

• K=Control matrix
• x=State matrix (alpha, q, theta)
• de=-Kx=input
• R=Reference

In the continuous Pitch Controller: State-Space page, the Linear Quadratic Regulator (LQR) method was used to find the control matrix (K). In this digital version, we will use the same LQR method. This method allows you to find the optimal control matrix that results in some balance between system errors and control effort. Please consult your control textbook for details. To use this LQR method, we need to find three parameters: Performance index matrix (R), state-cost matrix (Q), and weighting factor (p). For simplicity, we will choose the performance index matrix equals 1 (R=1), and the state-cost matrix (Q) equals to H' x H. The weighting factor (p) will be chosen by trial and errors. The state-cost matrix (Q) has the following structure

```	Q  =

0 	0	0
0	0	0
0	0	1
```

Now we are ready to find the control matrix (K) and see the response of the system. First, let the weighting factor (p) equal 50. Enter the following commands into a new m-file and run it in the MATLAB command window.

```t = 0:0.01:10;
de = 0.2*ones(size(t));

F = [0.9968		0.05649		0
-0.0001		0.9957		0
0		        0.5658		1];
G = [0.0024;
0.0002;
0.0001];
H = [0 0 1];
J = [0];

p = 50;
Q = [0 0 0
0 0 0
0 0 p];
[K] = dlqr(F,G,Q,1)

Ts = 1/100;
sys_cl = ss(F-G*K,G,H,J,Ts);

[Y,T] = lsim(sys_cl,de);
stairs(T,Y)
```

After you run this m-file, you should see the control matrix (K) in the command window and the step response similar to the one shown below.

The rise time, the overshoot, and the settling time look satisfactory. However, there is a large steady-state error. This can be easily corrected by introducing the feedforwarding scaling factor (Nbar).

## Reference input

Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (K*x) to the reference (see the schematic shown above). Thus, we should not expect to see the output equals to the input. To obtain the desired output, we need to scale the reference input so that the output equals to the reference. This can be easily done by introducing a feedforwarding scaling factor called Nbar. The basic schematic with the Nbar is shown below.

Unfortunately, we can not use our user-defined function rscale to find Nbar because it is defined for continuous systems. But we can find it by trial and error. After several trials, Nbar equals 6.95 provided a satisfactory response. Try the following m-file and obtain the stairstep response shown below.

```t = 0:0.01:10;
de = 0.2*ones(size(t));

F = [0.9968	0.05649		0
-0.0001	0.9957		0
0		0.5658		1];
G = [0.0024;
0.0002;
0.0001];
H = [0 0 1];
J = [0];

p=50;
Q = [0 0 0
0 0 0
0 0 p];
[K,S,E] = dlqr(F,G,Q,1)

Nbar = 6.95;
Ts = 1/100;
sys_cl = ss(F-G*K,G*Nbar,H,J,Ts);

[x] = lsim(sys_cl,de);
stairs(t,x)
```

From this plot, we see that the Nbar factor eliminates the steady-state error. Now all design requirements are satisfied.

### Note: Assuming all states are measurable, an observer design will not be explained here.

Digital Control Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam

Pitch Control Examples
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink

Tutorials
MATLAB Basics | MATLAB Modeling | PID Control | Root Locus | Frequency Response | State Space | Digital Control | Simulink Basics | Simulink Modeling | Examples