You are on page 1of 50

Physical setup

Designing an automatic suspension system for a bus turns out to be an interesting control
problem. When the suspension system is designed, a 1/4 bus model (one of the four wheels) is
used to simplify the problem to a one dimensional spring-damper system. A diagram of this
system is shown below:

Where:
* body mass (m1) = 2500 kg,
* suspension mass (m2) = 320 kg,
* spring constant of suspension system(k1) = 80,000 N/m,
* spring constant of wheel and tire(k2) = 500,000 N/m,
* damping constant of suspension system(b1) = 350 Ns/m.
* damping constant of wheel and tire(b2) = 15,020 Ns/m.
* control force (u) = force from the controller we are going to design.

Design requirements:

A good bus suspension system should have satisfactory road holding ability, while still providing
comfort when riding over bumps and holes in the road. When the bus is experiencing any road
disturbance (i.e. pot holes, cracks, and uneven pavement),the bus body should not have large
oscillations, and the oscillations should dissipate quickly. Since the distance X1-W is very
difficult to measure, and the deformation of the tire (X2-W) is negligible, we will use the
distance X1-X2 instead of X1-W as the output in our problem. Keep in mind that this is an
estimation.
The road disturbance (W) in this problem will be simulated by a step input. This step could
represent the bus coming out of a pothole. We want to design a feedback controller so that the
output (X1-X2) has an overshoot less than 5% and a settling time shorter than 5 seconds. For
example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of
+/- 5 mm and return to a smooth ride within 5 seconds.

Equations of motion:

From the picture above and Newton's law, we can obtain the dynamic equations as the following:

Transfer Function Equation:

Assume that all of the initial condition are zeroes, so these equations represent the situation when
the bus wheel goes up a bump. The dynamic equations above can be expressed in a form of
transfer functions by taking Laplace Transform of the above equations. The derivation from
above equations of the Transfer Functions G1(s) and G2(s) of output,X1-X2, and two inputs,U
and W, is as follows.

Find the inverse of matrix A and then multiple with inputs U(s)and W(s) on the right hand side
as the following:

When we want to consider the control input U(s) only, we set W(s) = 0. Thus we get the transfer
function G1(s) as the following:
When we want to consider the disturbance input W(s) only, we set U(s) = 0. Thus we get the
transfer function G2(s) as the following:

Entering equations into MATLAB

We can put the above Transfer Function equations into MATLAB by defining the numerator and
denominator of Transfer Functions in the form, nump/denp for actuated force input and
num1/den1 for disturbance input, of the standard transfer function G1(s) and G2(s):

G1(s) = nump/denp
G2(s) = num1/den1

Now, let's create a new m-file and enter the following code:

m1=2500;
m2=320;
k1=80000;
k2=500000;
b1 = 350;
b2 = 15020;

nump=[(m1+m2) b2 k2];
denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
P=tf(nump,denp);

num1=[-(m1*b2) -(m1*k2) 0 0];


den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G2=tf(0.1*num1,den1);

Open-loop response

We can use MATLAB to display how the original open-loop system performs (without any
feedback control). Add the following commands into the m-file and run it in the MATLAB
command window to see the response of unit step actuated force input and unit step disturbance
input. Note that the step command will generate the unit step inputs for each input.

step(P)
From this graph of the open-loop response for a unit step actuated force, we can see that the
system is under-damped. People sitting in the bus will feel very small amount of oscillation and
the steady-state error is about 0.013 mm. Moreover, the bus takes an unacceptably long time to
reach the steady state (the settling time is very large). The solution to this problem is to add a
feedback controller to the system.

step(G2)
To see some details, you can change the axis:

axis([0 10 -.1 .1])

From this graph of open-loop response for 0.1 m step disturbance, we can see that when the bus
passes a 10 cm high bump on the road, the bus body will oscillate for an unacceptably long
time(100 seconds) with larger amplitude, 13 cm, than the initial impact. People sitting in the bus
will not be comfortable with such an oscillation. The big overshoot (from the impact itself) and
the slow settling time will cause damage to the suspension system. The solution to this problem
is to add a feedback controller into the system to improve the performance. The schematic of the
closed-loop system is the following:

From the above transfer functions and schematic, we can draw the bus-system block diagram as
the following:
From the schematic above we see that:

Plant = nump/denp

F * Plant=num1/den1

so that
F=num1/(den1*Plant)

PID Design Method for the Bus Suspension


System
Adding a PID controller
Plotting the closed-loop response
Choosing the gains for the PID controller

From the main problem, the dynamic equations in transfer function form are the following:

and the system schematic looks like:


For the original problem setup and the derivation of the above equations and schematic, please
refer to the bus modeling page.

We want to design a feedback controller so that when the road disturbance (W) is simulated by a
unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less
than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate
within a range of +/- 5 mm and will stop oscillating within 5 seconds.

The system model can be represented in MATLAB by creating a new m-file and entering the
following commands (refer to main problem for the details of getting those commands).

m1=2500;
m2=320;
k1 = 80000;
k2 = 500000;
b1 = 350;
b2 = 15020;

nump=[(m1+m2) b2 k2]
denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G1=tf(nump,denp);

num1=[-(m1*b2) -(m1*k2) 0 0];


den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G2=tf(num1,den1);

numf=num1;
denf=nump;
F=tf(numf,denf);

Adding a PID controller

Recall that the transfer function for a PID controller is:


where KP is the proportional gain, KI is the integral gain, and KD is the derivative gain. Let's
assume that we will need all three of these gains in our controller. To begin, we might start with
guessing a gain for each: KP=208025, KI=832100 and KD=624075. This can be implemented
into MATLAB by adding the following code into your m-file:

KD=208025;
KP=832100;
KI=624075;
contr=tf([Kd Kp Ki],[1 0]);
Now let's simulate the response of the system (the distance X1-X2) to a step disturbance on the
road. From the schematic above we can find the transfer function from the road disturbance W to
the output(X1-X2), and simulate:
sys_cl=F*feedback(F*G1,contr);

Plotting the closed-loop response

Now we have created the closed-loop transfer function in MATLAB that will represent the plant,
the disturbance, as well as the controller. Let's see what the closed-loop step response for this
system looks like before we begin the control process. Keep in mind that we are going to use a
0.1 m high step as our disturbance, to simulate this, all we need to do is to multiply sys_cl by
0.1. Add the following code your m-file:
t=0:0.05:5;
step(0.1*sys_cl,t)
title('closed-loop response to 0.1m high step w/ pid controller')

you should see the response (X1-X2) to a step W like this:


From the graph, the percent overshoot is 9mm, which is larger than the 5mm requirement, but
the settling time is satisfied, less than 5 seconds. To choose the proper gain that yields reasonable
output from the beginning, we start with choosing a pole and two zeros for PID controller. A
pole of this controller must be at zero and one of the zeros has to be very close to the pole at the
origin, at 1. The other zero, we will put further from the first zero, at 3, actually we can adjust the
second-zero's position to get the system to fulfill the requirement. Add the following command
in the m-file, so you can adjust the second-zero's location and choose the gain to have a rough
idea what gain you should use for KD,KP, and KI.
z1=1;
z2=3;
p1=0;
numc=conv([1 z1],[1 z2]);
denc=[1 p1];
contr=tf(numc,denc);
rlocus(contr*G1)
title('root locus with PID controller')
[K,p]=rlocfind(contr*G1)
you should see the closed-loop poles and zeros on the s-plane like this and you can choose the
gain and dominant poles on the graph by yourself:
We will explain root locus method in more detail in the "Root Locus" page.

Choosing the gains for the PID controller

Now that we have the closed-loop transfer function, controlling the system is simply a matter of
changing the KD,KP,and KI variab. From the figure above, we can see that the system has larger
damping than required, but the settling time is very short. This response still doesn't satisfy the
5% overshoot requirement. As mentioned before, this can be rectified by adjusting the KD, KP
and KI variab to find better response. Let's increase KP,KI,KD by a factor of 2 to see what will
happen. Go back to your m-file and multiply KP,KI,KD by 2 and then rerun the program, you
should get the following plot:
To compare this graph with the graph of low-gain PID controller, you can change the axis:

axis([0 5 -.01 .01])

Now we see that the percent overshoot and settling time meet the requirements of the system.
The percent overshoot is about 5% of the input's amplitude and settling time is 2 seconds which
is less than the 5 second requirement.
For this problem, it turns out that the PID design method adequately controls the system. This
can been seen by looking at the root locus plot. Such a task can be achieved by simply changing
only the gains of a PID controller. Feel free to play around with all three of the
parameters,KD,KP and KI, as we suggested, but you will most likely get the response to have
either large percent overshoot or very long settling time.

Root Locus Design Method for the Bus


Suspension System
Plotting the root locus
Adding a notch filter
Finding the gain from the root locus
Plotting closed-loop response

From the main problem, the dynamic equations in transfer function form are the following:

and the system schematic looks like:

For the original problem setup and the derivation of the above equations and schematic, please
refer to the bus modeling page.

If you are interested in running an animation of this example based on the control techniques
used in the root locus tutorial please go to the bus suspension animation page after completing
this tutorial.
We want to design a feedback controller so that when the road disturbance (W) is simulated by a
unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less
than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate
within a range of +/- 5 mm and will stop oscillating within 5 seconds.

The system model can be represented in MATLAB by creating a new m-file and entering the
following commands (refer to main problem for the details of getting those commands).

m1=2500;
m2=320;
k1 = 80000;
k2 = 500000;
b1 = 350;
b2 = 15020;

nump=[(m1+m2) b2 k2];
denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G1=tf(nump,denp);

num1=[-(m1*b2) -(m1*k2) 0 0];


den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G2=tf(num1,den1);

numf=num1;
denf=nump;
F=tf(numf,denf);
We are now ready to design a controller using the root locus design method.

First let's see what the open loop poles of the system are:

R=roots(denp)
MATLAB should return:
R =
-23.9758 +35.1869i
-23.9758 -35.1869i
-0.1098 + 5.2504i
-0.1098 - 5.2504i

Therefore the dominant poles are the roots -0.1098+/-5.2504i, which are close to the imaginary
axis with a small damping ratio.

Plotting the root locus

The main idea of root locus design is to estimate the closed-loop response from the open-loop
root locus plot. By adding zeros and/or poles to the original system (adding a compensator), the
root locus and thus the closed-loop response will be modified. Let's first view the root locus for
the plant. In your m-file, add the following command and then run the file, you should get the
root locus plot below:
rlocus(G1)
z=-log(0.05)/sqrt(pi^2+(log(0.05)^2))
sgrid(z,0)

Note from the specification, we required the overshoot, %OS, to be less than 5% and damping
ratio, zeta, can be find from approximation damping ratio equation, z =
-log(%OS/100)/sqrt(pi^2+[log(%OS/100)^2]). The command sgrid is used to overlay the
desired percent overshoot line on the close-up root locus; you can find more information from
commands list.

From the plot above, we see that there are two pair of poles and zeros that are very close
together. These poles and zeros are almost on the imaginary axis, they might make the bus
system marginally stable, which might cause a problem. We have to make all of the poles and
zeros move into the left-half plane as far as possible to avoid an unstable system. We have to put
two zeros very close to the two poles on the imaginary axis of uncompensated system for pole-
and-zero cancellation. Moreover, we will put another two poles further to the left on the real axis
to get fast response.

Adding a notch filter

We will probably need two zeros near the two poles on the complex axis to draw the root locus,
leading those poles to the compensator zeros instead of to the plant zeros on the imaginary axis.
We'll also need two poles placed far to the left to pull the locus to the left. It seems that a notch
filter (2-lead controller) will probably do the job. Let's try putting the poles at 30 and 60 and the
zeros at 3+/-3.5i. In your m-file add the following lines of code:

z1=3+3.5i;
z2=3-3.5i;
p1=30;
p2=60;
numc=conv([1 z1],[1 z2]);
denc=conv([1 p1],[1 p2]);
contr=tf(numc,denc);

rlocus(contr*G1)
Rerun the m-file; you should get a new root locus plot looking like this:

Now let's change the axis to see the details of the root locus.
axis([-40 10 -30 30])
z=-log(0.05)/sqrt(pi^2+(log(0.05)^2))
sgrid(z,0)
Finding the gain from the root locus

Now that we have moved the root locus across the 5% damping ratio line, we can choose a gain
that will satisfy the design requirements. Recall that we want the settling time and the overshoot
to be as small as possible. Generally, to get a small overshoot and a fast response, we need to
select a gain corresponding to a point on the root locus near the real axis and far from the
imaginary axis or the point that the root locus crosses the desired damping ratio line. But in this
case, we need the cancellation of poles and zeros near the imaginary axis, so we need to select a
gain corresponding to a point on the root locus near the zeros and percent overshoot line. There
is a method to do this with the rlocfind command in MATLAB. Enter the following command into
the MATLAB command window:

[k,poles]=rlocfind(contr*G1)
Go to the plot and select the point at the position mentioned above (indicated by the cross on the
plot below:
You should see something similar to the following:
selected_point =

-2.9428 -13.0435i

K =

1.0678e+08

poles =

1.0e+02 *

-0.6322 + 6.1536i
-0.6322 - 6.1536i
-0.0294 + 0.1306i
-0.0294 - 0.1306i
-0.0292 + 0.0367i
-0.0292 - 0.0367i
Note that the value returned from your MATLAB command window may not be exactly the same,
but should at least have the same order of magnitude. This returned value can be used as the gain
for the compensator. Recall that the schematic of the system is the following:
and the closed-loop transfer function can be derived as following:

sys_cl=F*feedback(G1,k*contr);

Plotting the closed-loop response

Let's see what the closed-loop step response looks like with this compensator. Keep in mind that
we are going to use a 0.1 m high step as the disturbance. To simulate this, simply multiply
sys_cl by 0.1. Add the following commands into the m-file and put % marks in front of all
rlocus and rlocfind commands.

t=0:0.01:2;
step(0.1*sys_cl,t)
title('closed-loop response to 0.1m high step w/ notch filter')
and you should see the following plot:
From this plot we see that when the bus encounters a 0.1 m step on the road, the maximum
deviation of the bus body from the wheel (or the road) is about 3.75 mm, and the oscillations
settle in 2 seconds. Thus this response is satisfactory.

Note: A design problem does not necessarily have an unique answer. Using the root locus
method (or any other method) may result in many different compensators. For practice, you may
want to go back to the original open-loop root locus and try to find other good ways to add zeros
and poles to get a better response.

If you are interested in running an animation of the bus suspension example based on the control
techniques used in this tutorial please go to the Bus Suspension Animation Page.

Frequency Design Method for the Bus


Suspension System
Plotting the frequency response using the bode command
Adding a two-lead controller
Plotting the closed-loop response

From the main problem, the dynamic equations in transfer function form are the following:

and the system schematic is:


For the original problem and the derivation of the above equations and schematic, please refer to
the bus modeling page.

We want to design a feedback controller so that when the road disturbance (W) is simulated by a
unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less
than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate
within a range of +/- 5 mm and will stop oscillating within 5 seconds.

The system model can be represented in MATLAB by creating a new m-file and entering the
following commands (refer to the main problem for the details of getting those commands).

m1 = 2500;
m2 = 320;
k1 = 80000;
k2 = 500000;
b1 = 350;
b2 = 15020;

nump=[(m1+m2) b2 k2];
denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G1=tf(nump,denp);

num1=[-(m1*b2) -(m1*k2) 0 0];


den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+
(b2*k1) k1*k2];
G2=tf(num1,den1);

numf=num1;
denf=nump;
F=tf(numf,denf);

Plotting the frequency response using the bode command

The main idea of frequency-based design is to use the Bode plot of the open-loop transfer
function to estimate the closed-loop response. Adding a controller to the system changes the
open-loop Bode plot so that the closed-loop response will also change. Let's first draw the Bode
plot for the original open-loop transfer function. Add the following line of code to your m-file
and rerun:

w = logspace(-1,2);
bode(G1,w)
You should get the following bode plot:
For convenience in representing systems with different natural frequencies of the system, we
normalize and scale our findings before plotting the Bode plot, so that the low-frequency
asymptote of each term is at 0 dB. This normalization by adjusting the gain, K, makes it easier to
add the components of the Bode plot. The effect of K is to move the magnitude curve up
(increasing K) or down (decreasing K) by an amount 20*logK, but the gain, K, has no effect on
the phase curve. Therefore from the previous plot, K must be equal to 100 dB or 100,000 to
move the magnitude curve up to 0 dB at 0.1 rad/s. Go back to your m-file and add the following
line of code to your m-file before the bode command and rerun:

K=100000;
bode(K*G1,w)
You should get the following bode plot:
Adding a two-lead controller

From the Bode plot above, we see that the phase curve is concave at about 5 rad/sec. First, we
will try to add positive phase around this region, so that the phase will remain above the -180
degree line. Since a large phase margin leads to a small overshoot, we will want to add at least
140 degrees of positive phase at the area near 5 rad/sec. Since one lead controller can add no
more than +90 degrees, we will use a two-lead controller.

To obtain T and a, the following steps can be used:

1: Determine the positive phase needed :

Since we want 140 degrees total, we will need 70 degrees from each controller.
2: Determine the frequency where the phase should be added:
In our case this frequency should be 5.0 rad/sec.
3: Determine the constant a from the equation below, this determines the required space
between the zero and the pole for the desired maximum phase added.

4: Determine T and aT from the following equations, these determine the corner frequencies
so that the maximum phase will be added at the desired frequency.
Now let's put our 2-Lead controller into the system and see what the Bode plot looks like. Add
the following code to your m-file, and add a % in front of the previous bode command (if there is
one):

a = (1-sin(70/180*pi))/(1+sin(70/180*pi));
w=5;
T=1/(w*sqrt(a));
aT=sqrt(a)/w;
numc = conv([T 1], [T 1]);
denc = conv([aT 1], [aT 1]);
contr = tf(numc,denc);
margin(K*contr*G1)
You should get the following Bode plot:

From this plot we see that the concave portion of the phase plot is above -180 degrees now, and
the phase margin is large enough for the design criteria. Let's see how the output (the distance
X1-X2) responds to a bump on the road (W). Recall that the schematic of the system is:

and the closed-loop transfer function can be derived as follows:


sys_cl = F*feedback(G1,K*contr);

Plotting the closed-loop response

Let's see what the step response looks like now. Keep in mind that we are using a 0.1 m high step
as the disturbance. To simulate this, simply multiply the system by 0.1. Add the following code
into the m-file and rerun it. Don't forget to put % mark in front of all bode and margin
commands!

t=0:0.01:5;
step(0.1*sys_cl,t)
axis([0 5 -.01 .01])
and you should see the following plot:

The amplitude of response is a lot smaller than the percent overshoot requirement and the
settling time also is less than 5 seconds. Since we can see that an amplitude of the output's
response less than 0.0001 m or 1% of input magnitude after 4 seconds. Therefore we can say that
the settling time is 4 seconds from the above plot. From the Bode plot above, we see that
increasing the gain will increase the crossover frequency and thus make the response faster. We
will increase the gain and see if we can get a better response. Go back to your m-file and change
numc to numc=4*conv([T1 1],[T1 1]). Rerun the m-file and you should get the following plot:
From this plot we can see that the percent overshoot is about 0.15 mm less than the previous
plot's and the settling time also less than 5 seconds. This response is now satisfactory and no
more design iteration is needed

A State-space Controller for a Bus Suspension


System
Designing the full-state feedback controller
Plotting the closed-loop response

From the main problem, the dynamic equations in state-space form are the following:
For the original problem setup and the derivation of the above equations, please refer to the
Modeling page.

We want to design a feedback controller so that when the road disturbance (W) is simulated by a
unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less
than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate
within a range of +/- 5 mm and will stop oscillating within 5 seconds.

The system model can be represented in MATLAB by creating a new m-file and entering the
following commands (refer to main problem for the details of getting those commands). We need
to define the A, B, C, D matrices by entering the following into the m-file:

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];
sys=ss(A,B,C,D);

Designing the full-state feedback controller

First, let's design a full-state feedback controller for the system. Assuming for now that all the
states can be measured (this assumption is probably not true but is sufficient for this problem),
the schematic of the system should be:
The characteristic polynomial for this closed-loop system is the determinant of (sI-(A-
B[1,0]'K)). Note that it's not sI-(A-BK) because the controller K can only control the force input
u but not the road disturbance W. Recall that our B matrix is a 4 x 2 matrix, and we only need
the first column of B to control u.

For this example, we have to use integral action to achieve zero steady-state error, so we add an
extra state which is . In reality the bus will eventually reach an equilibrium that
yields a zero steady-state error. The new states are X1, Y1, and Y2. Also the state-space
matrices, A,B,and C, after adding extra state change to be the following:

Aa=[0 1 0
0 0
-(b1*b2)/(m1*m2) 0 ((b1/m1)*((b1/m1)+(b1/m2)+(b2/m2)))-(k1/m1)
-(b1/m1) 0
b2/m2 0 -((b1/m1)+(b1/m2)+(b2/m2))
1 0
k2/m2 0 -((k1/m1)+(k1/m2)+(k2/m2))
0 0
0 0 1
0 0];
Ba=[0 0
1/m1 (b1*b2)/(m1*m2)
0 -(b2/m2)
(1/m1)+(1/m2) -(k2/m2)
0 0];
Ca=[0 0 1 0 0];
Da=[0 0];
sys=ss(Aa,Ba,Ca,Da);

Actually, there is a shortcut for MATLAB to achieve the same result.

Aa = [[A,[0 0 0 0]'];[C, 0]];


Ba = [B;[0 0]];
Ca = [C,0];
Da = D;
sys=ss(Aa,Ba,Ca,Da);

Add the above MATLAB code into the m-file. In this case, we treat the problem like a PID
controller design. The integral control is obtained from the new state. The proportional control is
obtained from a gain on Y1 or X1-X2. The direct derivative control of the output isn't possible,
since derivative of Y1 or X1-X2 isn't a state. Instead we use the derivative of X1, which is
available for feedback. (While X1 maybe hard to measure, could be obtained by integrating the
output of an accelerometer mounted on the bus.) It is similar to adding more damping to velocity
of oscillation of the bus. Add the following MATLAB code for controller K in the m-file:

K = [0 2.3e6 5e8 0 8e6]


We arrived at this value of the K, matrix by trial and error, adjusting the gain for derivative of
X1,Y1 and integral of Y1, as previously mentioned.

Plotting the closed-loop response

Looking at the schematic above again, we see that after adding the K matrix into the system, the
state-space equations become:

We can now obtain the closed-loop response by simply adding the following code into the m-
file. Note that we need to multiply B matrix by 0.1 to simulate 0.1 m high step disturbance:
t = 0:0.01:2;
sys_cl = ss(Aa-Ba(:,1)*K,-0.1*Ba,Ca,Da);
step(sys_cl*[0;1],t)
title('Closed-loop response to a 0.1 m step')

Running the m-file in the command window, you should see the following plot:
From the plot we see that the percent overshoot and settling time requirements are satisfied.
Moreover the steady-state error approaches zero as well. Therefore, we will determine that the
response is satisfactory. Feel free to play around with the gain for matrix K.

State Space Design for Digital Bus Suspension


Control
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:
Where:
* body mass (m1) = 2500 kg,
* suspension mass (m2) = 320 kg,
* spring constant of suspension system (k1) = 80,000 N/m,
* spring constant of wheel and tire (k2) = 500,000 N/m,
* damping constant of suspension system (b1) = 350 Ns/m.
* damping constant of wheel and tire (b2) = 15,020 Ns/m.
* control force (u) = force from the controller we are going to design.
The design requirements are:
Overshoot: Output (X1-X2) less than 5% of disturbance (W)
Settling time: Less than 5 seconds

Sampling Time Selection


The first step in the design of a discrete-time controller is to convert the continuous plant to its
discrete time equivalent. First, we need to pick an appropriate sampling time, T. In this example,
selection of sampling time is very important since a step in the road surface very quickly affects
the output. Physically, what happens is the road surface suddenly lifts the wheel, compressing
the spring, K2, and the damper, b2. Since the suspension mass is relatively low, and the spring
fairly stiff, the suspension mass rises quickly, increasing X2 almost immediately. Since the
controller can only see the effect of the disturbance after a complete sampling period, we have to
pick a sampling time, T, short enough so that the output (X1-X2) does not exceed the 5%
requirement in one sampling period. To pick the sampling period, we need to closely examine
the beginning of the step response. If you remember from the modeling page, the output quickly
goes negative in response to a step disturbance, and then begins to oscillate. We will simulate
just the beginning of this response by setting the time vector input to the step function to range
from 0 to .005. The response to a .1m step input is simulated by multiplying the B matrix by .1.
Create a new

Physical setup
Designing an automatic suspension system for a bus turns out to be an interesting control
problem. When the suspension system is designed, a 1/4 bus model (one of the four wheels) is
used to simplify the problem to a one dimensional spring-damper system. A diagram of this
system is shown below:

Where:
* body mass (m1) = 2500 kg,
* suspension mass (m2) = 320 kg,
* spring constant of suspension system(k1) = 80,000 N/m,
* spring constant of wheel and tire(k2) = 500,000 N/m,
* damping constant of suspension system(b1) = 350 Ns/m.
* damping constant of wheel and tire(b2) = 15,020 Ns/m.
* control force (u) = force from the controller we are going to design.

Design requirements:

A good bus suspension system should have satisfactory road holding ability, while still providing
comfort when riding over bumps and holes in the road. When the bus is experiencing any road
disturbance (i.e. pot holes, cracks, and uneven pavement),the bus body should not have large
oscillations, and the oscillations should dissipate quickly. Since the distance X1-W is very
difficult to measure, and the deformation of the tire (X2-W) is negligible, we will use the
distance X1-X2 instead of X1-W as the output in our problem. Keep in mind that this is an
estimation.

The road disturbance (W) in this problem will be simulated by a step input. This step could
represent the bus coming out of a pothole. We want to design a feedback controller so that the
output (X1-X2) has an overshoot less than 5% and a settling time shorter than 5 seconds. For
example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of
+/- 5 mm and return to a smooth ride within 5 seconds.

Building the Model


This system will be modeled by summing the forces acting on both masses (body and
suspension) and integrating the accelerations of each mass twice to give velocities and positions.
Newton's law will be applied to each mass. Open Simulink and open a new model window. First,
we will model the integrals of the accelerations of the masses.

 Insert an Integrator block (from the Linear block library) and draw lines to and from its
input and output terminals.
 Label the input line "a1" (for acceleration) and the output line "v1" (for velocity) To add
such a label, double click in the empty space just above the line.
 Insert another Integrator block connected to the output of the first.
 Draw a line from its output and label it "x1" (for position).
 Insert a second pair of Integrators below the first with lines labeled "a2", "v2", and "x2".

Next, we will start to model Newton's law. Newton's law for each of these masses can be
expressed as:
These equations can be represented with gain blocks (for 1/M1 and 1/M2) and two summation
blocks.
 Insert two Gain blocks, (from the Linear block library) one attached to the inputs of each
of the integrator pairs.
 Edit the gain block corresponding to M1 by double-clicking it and changing its value to
"1/m1".
 Change the label of this Gain block to "Mass 1" by clicking on the word "Gain"
underneath the block.
 Similarly, edit the other Gain's value to "1/m2" and it's label to "Mass 2". (You may want
to resize the gain blocks to view the contents. To do this, single click on the block to
highlight it, and drag one of the corners to the desired size.)

There are three forces acting on M1 (one spring, one damper, and the input, u) and five forces
acting on M2 (two springs, two dampers, and the input, u).
 Insert two Sum blocks (from the Linear block library), one attached by a line to each of
the Gain blocks.
 Edit the signs of the Sum block corresponding to M1 to "+--" to represent the three forces
(two of which will be negative)
 Edit the signs of the other Sum block to "++-++" to represent the five forces, one of
which will be negative.
Now, we will add in the forces acting on each mass. First, we will add in the force from Spring 1.
This force is equal to a constant, k1 times the difference X1-X2.

 Insert a sum block after the upper pair of integrators.


 Edit its signs to "+-" and connect the "x1" signal to the positive input and the "x2" signal
to the negative input.
 Draw a line leading from the output of the Sum block.
 Insert a Gain block above the "Mass1" block.
 Flip it left-to-right by single-clicking on it and selecting Flip Block from the Format
menu (or hit Ctrl-F).
 Edit the value of this gain to "k1" and label the block "Spring 1".
 Tap a line off the output of the last Sum block and connect it to the input of this gain
block.
 Connect the output of this gain block (the spring force) to the second input of the Mass 1
Sum block. This input should be negative since the Spring 1 pulls down on Mass 1 when
X1 > X2.
 Tap a line off the spring force line and connect it to the second input of the Mass 2 Sum
block. This input is positive since Spring 1 pulls up on Mass 2.
Now, we will add in the force from Damper 1. This force is equal to b1 times V1-V2.

 Insert a sum block below the Mass 1's first integrator.


 Flip it left-to-right, and edit it's signs to "+-".
 Tap a line off the "v1" line and connect it to the positive input of this Sum block.
 Tap a line off the "v2" line and connect it to the negative input of this Sum block.
 Insert a Gain block to the left of this Sum block and flip it left-to-right.
 Edit it's value to "b1" and label it "Damper 1".
 Connect the output of the new Sum block to the input of this gain block.
 Connect the output of this gain block (the damper force) to the third input of the Mass 1
Sum block. This input is negative, similar to Spring 1's force on Mass 1.
 Tap a line off Damper 1's force line and connect it to the first input (which is positive) of
Mass 2's Sum block.
Now we will add in the force from Spring 2. This force acts only on Mass 2, but depends on the
ground profile, W. Spring 2's force is equal to X2-W.

 Insert a Step block in the lower left area of your model window. Label it "W".
 Edit it's Step Time to "0" and it's Final Value to "0". (We will assume a flat road surface
for now).
 Insert a Sum block to the right of the W Step block and edit its signs to "-+".
 Connect the output of the Step block to the positive input of this Sum block.
 Tap a line off the "x2" signal and connect it to the negative input of the new Sum block.
 Insert a Gain block to the right of this Sum block and connect the Sum's output to the
new Gain's input.
 Change the value of the gain to "k2" and label it "Spring 2".
 Connect the output of this block (Spring 2's force) to the fourth input of Mass 2's Sum
block. This force adds in in the positive sense.
Next, we will add in the force from Damper 2. This force is equal to b2 times V2-d/dt(W). Since
there is no existing signal representing the derivative of W we will need to generate this signal.

 Insert a Derivative block (from the Linear block library) to the right of the W step block.
 Tap a line of the Step's output and connect it to the input of the Derivative block.
 Insert a Sum block after the Derivative block and edit it's signs to "+-".
 Connect the Derivative's output to the positive input of the new Sum block.
 Tap a line off the "v2" line and connect it to the negative input of this Sum block.
 Connect the output of this Sum block (Damper 2's force) to the fifth input of Mass 2's
Sum block. This force also adds in with positive sign.
The last force in the input U acting between the two masses.

 Insert a Step block in the upper left of the model window.


 Connect it's output to the remaining input of Mass 1's Sum block (with positive sign).
 Tap a line off this signal and connect it to the remaining input of Mass 2's Sum block
(with negative sign).
 Edit this Step block's Step Time to "0" and leave its Final Value "1".
 Label this Step block "U".
 Finally, to view the output (X1-X2) insert a Scope connected to the output of the
rightmost Sum block.
You can download a model file for the complete system here.

Open-loop response
To simulate this system, first, an appropriate simulation time must be set. Select Parameters from
the Simulation menu and enter "50" in the Stop Time field. 50 seconds is long enough to view
the open-loop response. The physical parameters must now be set. Run the following commands
at the MATLAB prompt:
m1=2500;
m2=320;
k1=80000;
k2=500000;
b1 = 350;
b2 = 15020;
Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished,
double-click on the scope and hit its autoscale button. You should see the following output.
Extracting a Linear Model into MATLAB
A linear model of the system (in state space or transfer function form) can be extracted from a
Simulink model into MATLAB. This is done through the use of In and Out Connection blocks and
the MATLAB function linmod. We will extract only the model from the input U to the output X1-
X2.

 First, replace the U Step block with an In Connection Block.


 Also, replace the Scope block with an Out Connection Block. (These blocks can be found
in the Connections block library). This defines the input and output of the system for the
extraction process.
Save your file as "suspmod.mdl" (select Save As from the File menu). MATLAB will extract the
linear model from the saved model file, not from the open model window. At the MATLAB
prompt, enter the following commands:

[A,B,C,D]=linmod('suspmodel')
[num,den]=ss2tf(A,B,C,D)
You should see the following output, providing both state-space and transfer function models of
the system.
A =

1.0e+003 *

0 0 0 0.0010
0 0 0.0010 0
0.2500 -1.8125 -0.0480 0.0011
-0.0320 0.0320 0.0001 -0.0001

B =

0
0
-0.0031
0.0004

C =

1 -1 0 0
D =

num =

0 0.0000 0.0035 0.0188 0.6250

den =

1.0e+004 *

0.0001 0.0048 0.1851 0.1721 5.0000


To verify the model extraction, we will generate an open-loop step response of the extracted
transfer function in MATLAB. Enter the following command in MATLAB.
step(num,den);
You should see the following plot which is equivalent to the Scope's output.

Implementing Full State Feedback


In the Bus Suspension Control State Space example a full-state feedback controller was designed
feeding back the following five states:

The controller used the following feedback gain matrix:


To implement this in Simulink, we will contain the open-loop system from earlier in this page in
a Subsystem block.
 Create a new model window.
 Drag a Subsystem block from the Connections block library into your new model
window.

 Double click on this block. You will see a blank window representing the contents of the
subsystem (which is currently empty).
 Open your previously saved model of the Bus Suspension system, suspmod.mdl.
 Select Select All from the Edit menu (or Ctrl-A), and select Copy from the Edit menu (or
Ctrl-C).
 Select the blank subsystem window from your new model and select Paste from the Edit
menu (or Ctrl-V). You should see your original system in this new subsystem window
(you may need to use the scroll bars to center on it).
 Label the In Connection block "U", and the Out Connection block "y1".
 Replace the W Step block with an In Connection block and label this block "W".
Now we will generate the other state outputs from the subsystem.

 Insert an Out block below the "y1" block and label it "d/dt(y1)", Tap a line off the line
leading into the Damper 1 gain block (V1-V2) and connect it to the d/dt(y1) Out block.
 Insert another Out block below the "d/dt(y1)" Out block and label it "x1".
 Tap a line off the "x1" line and connect it to this Out block.
 Insert another Out block below the "x1" Out block and label it "d/dt(x1)".
 Tap a line off the "v1" line and connect it to this Out block.
The final, extra, state needs to be generated, which is the integral of Y1.

 Insert an Integrator block above the "y1" Out block and connect its input with a line
tapped of the input to the "y1" Out block.
 Insert an Out block, label it "int(y1)", and connect it to the output of the new integrator.
Since the state outputs will be used to form a vector, it is important that they be numbered in the
right order.

 Edit the "x1" Out block and change its Port Number to "1".
 Similarly, change the "d/dt(x1)" Out block's port number to "2", "y1" Out's port number
to "3", "d/dt(y1)" Out's port number to "4", and "int(y1)" Out's port number to "5".
 The In blocks should be numbered such that "U" is "1" and "W" is "2". Some of these
numbers may already be correct.

 Close the Subsystem window. You should now see input and output terminals on the
Subsystem block.
 Name this block "Suspension Model".
 You should resize this block so that you can read all of the labels. To do this, highlight it
by single-clicking on it and drag one of the highlighted corners to the right size. Notice
that the model has two inputs and five outputs. Each input and output is a scalar signal in
this model.
Now, we will build a full-state feedback controller around the plant model. First, we need to
create a vector signal out of the five scalar outputs in order to multiply by the feedback gain
matrix K.

 Insert a Mux block (from the Connections block library) to the right of the Suspension
Model block. The Mux takes multiple inputs and combines them into a vector signal. By
default, the Mux has three inputs.
 Edit the Mux block and change the Number of Inputs to "5".
 Resize the Mux so that it is the same height as the Suspension Model block.
 Connect each of the Suspension Model's outputs to the Mux's inputs in order.

Now, we will close the loop.


 Insert a Matrix Gain block (from the Linear block library) below the Suspension Model
block.
 Flip the Matrix Gain left-to-right and edit its value to "K".
 Insert a Sum block to the left of the Suspension Model block.
 Edit its signs to "+-".
 Connect the output of the Matrix Gain to the negative input of the Sum block.
 Connect the output of the Sum block to the "U" input of the Suspension Model.

 Insert a Step block and connect it to the positive input of the Sum block.
 Label the step block "r" and edit its Step Time to "0" and its Final Value to "0" (we are
commanding the bust to stay level).
 Insert a Step block and connect it to the "W" input of the Suspension Model.
 Edit its Step Time to "0" and its Final Value to "-.1" (we are now assuming a 10cm deep
pothole).
 Insert a Scope block and tap a line off the "y1" output of the Suspension Model and
connect it to the Scope.
You can download our version of the closed-loop system here.

Closed-loop response
To simulate this system, first, an appropriate simulation time must be set. Select Parameters from
the Simulation menu and enter "2" in the Stop Time field. The design requirements included a
settling time of less than 5 sec, and the system actually settles in 2 sec. The physical parameters
must now be set. Run the following commands at the MATLAB prompt:
m1=2500;
m2=320;
k1=80000;
k2=500000;
b1 = 350;
b2 = 15020;
The last step is to assign values to the feedback gain matrix K. Execute the following command
at the MATLAB prompt.
K= [ 0 2.3e6 5e8 0 8e6 ];
Run the simulation (Ctrl-t or Start on the Simulation menu). When the simulation is finished,
double-click on the scope and hit its autoscale button. You should see the following output.

You might also like