Control Example Using Matlab
Control Example Using Matlab
Control Example Using Matlab
Cruise Control
mxbx u
State-space equations
The state-space representation is given by the
equations:
dx
A x Bu
dt
y C x Du
where
mx bx u
is
b
1
u
x
x
m
m
or
1 x 0
0
0 b 1 u
x
m x m
x
y 0 1 0 u
x
x
Design requirements
For this example, let's assume that
m = 1000kg
b = 50Nsec/m
u = 500N
Design requirements
When the engine gives a 500 Newton force, the car will reach a
maximum velocity of 10 m/s (22 mph).
An automobile should be able to accelerate up to that speed in less
than 5 seconds. Since this is only a cruise control system, a 10%
overshoot on the velocity will not do much damage. A 2% steadystate error is also acceptable for the same reason.
Rise time < 5 sec
Overshoot < 10%
Steady state error < 2%
this step response does not meet the design criteria placed on the
problem. The system is overdamped, so the overshoot response is
fine, but the rise time is too slow.
P controller
The first thing to do in this problem is to transform the state-space
equations into transfer function form.
m = 1000; b = 50; u = 500; A = [0 1; 0 -b/m] B = [0; 1/m] C = [0 1] D = 0
[num,den]=ss2tf(A,B,C,D)
Next, close the loop and add some proportional control to see if the
response can be improved.
k = 100;
[numc,denc] = cloop(k*num,den,-1);
function
%Closed-loop transfer
t = 0:0.1:20;
step(10*numc,denc,t) %for 10m/sec the signal used by
step
axis([0 20 0 10])
[num,den]=ss2tf(A,B,C,D)
Matlab should return the following to the command window:
num =
0
0.0010
den =
1.0000 0.0500
Step function
The step function is one of most useful functions in
Matlab for control design.
Given a system that can be described by either a
transfer function or a set of state-space equations,
the response to a step input can immediately be
plotted.
A step input can be described as a change in the
input from zero to a finite value at time t = 0.
By default, the step command performs a unit step
(i.e. the input goes from zero to one at time t = 0).
The basic command to use the step function is one
of the following
(depending if you have a set of state-space equations or a
transfer function form):
step(A,B,C,D)
step(num,den)
P controller
The steady state error is more than 10%,
and the rise time is still too slow.
Adjust the proportional gain to make the
response better.
but you will not be able to make
the steady state value go to 10m/sec
without getting rise times that are too
fast.
You must always keep in mind that you are designing a real system,
and for a cruise control system to respond 0-10m/sec in less than half
of a second is unrealistic.
To illustrate this idea, adjust the k value to equal 10,000, and you
should get the following velocity response:
P controller
The solution to this problem is to add some
integral control to eliminate the steady state
error.
Adjust k until you get a reasonable rise time.
For example, with k = 600, the response should now
look like:
PI controller
Remember, integral control makes the transient response worse, so adding too
much initially can make the response unrecognizable.
k = 600;
ki = 1; % small to get feeling for integral response
num1 = [k ki]; % PI has two gains
den1 = [1 0];
num2 = conv(num,num1); % convolution used to
multiply the
% polynomials representing the gains
den2 = conv(den,den1);
[numc,denc] = cloop(num2,den2,-1);
t = 0:0.1:20;
step(10*numc,denc,t)
axis([0 20 0 10])
PI controller
Now you can adjust
the ki value to reduce
the steady state error.
With ki = 40 and k
adjusted up a little
more to 800, the
response looks like
the following:
As you can see, this step
response meets all of the
design criteria, and
therefore no more iteration
is needed.
It is also noteworthy that
no derivative control was
needed in this example
Lets now add Drag and assume the friction to be non velocity
dependent (the static friction, proportional to normal force).
dv(t )
M
Cu (t ) Bv (t )
dt
2
- M
- B
- C
d (t )
(t ) u (t )
dt
2
:
:
max
max
C
B
CB
M
0 u (t ) 1
Simulink
]C = 6250 [N
]B = 2.5 [N/(m/s)2
]M = 1250 [Kg
: 0 ,1 - -
Saturation
From this window, choose the File menu, and then New
(Model).
Now we have a blank window, in which we will build our model.
This blank window and the library browser window, will be the
windows well work with.
Simulink Tutorial
As we can see, the Simulink library is divided into several
categories:
1.
2.
3.
4.
5.
6.
7.
8.
Simulink Tutorial
Now lets try something a little
bit more complicated.
First, build the following
system (you can find the Clock
module in the Sinks category.
The Trigonometric Function
and Sum modules reside in the
Math category):
Simulink Tutorial
Now, lets see if the
derivative is really a cosine.
Build the following system
(the Derivative module is
located in the Continuous
category):
Simulink Tutorial
This is because at time 0,
the derivative has no
prior information for
calculation
theres no initial value for
the derivative,
so at the first time step,
the derivative assumes
that its input has a
constant value (and so the
derivative is 0).
An other example
Lets say that we have a differential equation that we want
to model. The equation is:
A 0.5 A
A 0.5
0
Simulink Tutorial
double-click the
Integrator and choose
Initial Condition Source:
External.
Note that pressing ctrl
when clicking the mouse
button on a line, allows
you to split it into 2 lines:
Simulink
Automatic Cruise Control
C = 6250 [N]
B = 2.5 [N/(m/s)2]
M = 1250 [Kg]
- ,1 - 0 :
Saturation
0
.8
,P I ) PI (.
: :
. ) (t "" .
- "" ) (.