
Sampling Time Selection
Continuous to Discrete Conversion
Designing the Controller
Simulating the Closed-Loop Response
In this example, we will design a digital state space controller for the bus suspension control example. First we will convert the continuous time model to a discrete time model, and then use the pole placement method to design the controller. From the bus suspension state space modeling page, the state space model of the system is:


m1 = 2500; m2 = 320; k1 = 80000; k2 = 500000; b1 = 350; b2 = 15020; A = [0 1 0 0 -(b1*b2)/(m1*m2) 0 ((b1/m1)*((b1/m1)+(b1/m2)+(b2/m2)))-(k1/m1) -(b1/m1) b2/m2 0 -((b1/m1)+(b1/m2)+(b2/m2)) 1 k2/m2 0 -((k1/m1)+(k1/m2)+(k2/m2)) 0]; B = [0 0 1/m1 (b1*b2)/(m1*m2) 0 -(b2/m2) (1/m1)+(1/m2) -(k2/m2)]; C = [0 0 1 0]; D = [0 0]; sus = ss(A,B,C,D); step(sus*[0;1]*.1,0:0.0001:.005);This plot shows that the spring, K1 compresses very quickly, and exceeds our requirement of 5mm in response to a .1m step after only a little more than 0.001s. Therefore, we will set T=.0005s in order to give the controller a chance to respond.

Add the following code to your m-file:
T = .0005; sus_d = c2d(sus,T,'zoh')
MATLAB should return the following:
a = x1 x2 x3 x4 x1 1 0.0005 -3.1263e-06 -1.8022e-08 x2 -0.0034605 1 -0.012444 -7.3126e-05 x3 0.02338 5.8525e-06 0.97598 0.00049399 x4 0.77045 0.00019351 -0.91116 0.99977 b = u1 u2 x1 4.9989e-11 8.5058e-07 x2 1.9994e-07 0.0034605 x3 4.3748e-10 -0.02338 x4 1.7624e-06 -0.77045 c = x1 x2 x3 x4 y1 0 0 1 0 d = u1 u2 y1 0 0 Sampling time: 0.0005 Discrete-time system.

To add this, add the following commands in your m-file:
Ai = 1; Bi = T; Ci = 1; Di = T/2; [As,Bs,Cs,Ds]=ssdata(sus_d); Aa = [As, zeros(4,1); Bi*Cs, Ai]; Ba = [Bs; 0,0]; Ca = [Cs, 0]; Da = Ds; sus_di = ss(Aa,Ba,Ca,Da,T); [Ad,Bd,Cd,Dd] = ssdata(sus_di);
We first need to decide where to place the closed-loop poles. Since we get to place all five of the closed-loop poles, we can be very selective about where they go. In particular, we can place them to cancel all of the plant zeros, as well as give us the desired response. First, we will find the plant zeros by converting the plant's digital state equations to a transfer function, and then finding the roots of the numerator. We will use the tfdata command which takes a system (sus_d) as its argument and outputs a transfer function numerator and denominator. Since the suspension system (sus_d) has two inputs, only one input must be selected. Notice how the first input is selected in the following code.
Add the following code to your m-file:
sus1 = sus_di*[1;0]; %select the first input [num,den] = tfdata(sus1,'v'); z = roots(num)MATLAB will return the following:
zeros = -0.9929 1.0000 0.9986 + 0.0065i 0.9986 - 0.0065i
p1 = z(1); p2 = z(3); p3 = z(4); p4 = .9992; p5 = .5; K=place(Ad,Bd*[1;0],[p1 p2 p3 p4 p5])MATLAB will return the following:
place: ndigits= 15 K = 1.0e+09 * 0.0534 0.0000 1.0898 0.0011 1.8286
sys_cl = ss(Ad-Bd*[1;0]*K,Bd,Cd,Dd,T); step(-.1*sys_cl*[0;1],5);You should see the following plot.

We can see in this plot, that the overshoot is less than 5mm, and the response settles well within 5 seconds.
Tutorials