3. (m) mass of the ball 0.11 kg
(R) radius of the ball 0.015 m
(d) lever arm offset 0.03 m
(g) gravitational acceleration 9.8 m/s^2
(L) length of the beam 1.0 m
(J) ball's moment of inertia 9.99e-6 kg.m^2
(r) ball position coordinate
(alpha) beam angle coordinate
(theta) servo gear angle
6. It should be noted that the above plant transfer function is a double integrator. As such it is
marginally stable and will provide a challenging control problem.
The transfer function can be implemented in MATLAB as follows:
m = 0.111;
R = 0.015;
g = -9.8; L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s’);
P_ball = -m*g*d/L/(J/R^2+m)/s^2
7. Analysis
create a transfer function model in MATLAB
m = 0.111;
R = 0.015;
g = -9.8; L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s’);
P_ball = -m*g*d/L/(J/R^2+m)/s^2
8. Pole zero plot
create a pole zero plot in MATLAB
m = 0.111;
R = 0.015;
g = -9.8; L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s’);
P_ball = -m*g*d/L/(J/R^2+m)/s^2
pzmap(P_ball)
The Ball and Beam system is a type II system which has two poles at the origin, as seen in the
pole/zero map below. Since the poles are not strictly in the left half plane, the open loop system will be
unstable as seen in the step response below
9. Open-loop step response
See open loop step response in MATLAB
m = 0.111;
R = 0.015;
g = -9.8; L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s’);
P_ball = -m*g*d/L/(J/R^2+m)/s^2
step(P_ball)
From this plot it is clear that the system is unstable in open-loop causing the ball to roll right off the
end of the beam. Therefore, some method of controlling the ball's position in this system is required.
12. What is
PIDCONTOLLER? A PID controller continuously calculates an error value e(t) as
the difference between a desired setpoint and a measured
process variable and applies a correction based on proportional,
integral, and derivative terms. PID is an initialism for
proportional-integral-derivative, referring to the three terms
operating on the error signal to produce a control signal.
14. GENERAL TIPS
FORDESIGNING A
PIDCONTROLLER
1. Obtain an open-loop response and determine what
needs to be improved
2. Add a proportional control to improve the rise time
3. Add a derivative control to reduce the overshoot
4. Add an integral control to reduce the steady-state
error
5. Adjust each of the gains Kp, Ki and Kd until you
obtain a desired overall response.
15. CLOSED-LOOP REPRESENTATION
The block diagram for this example with a controller and unity feedback of the ball's position is
shown below
The transfer function for a PID controller is:
16. PROPORTIONAL CONTROL
The closed-loop transfer function for proportional control with a proportional gain (Kp) equal to 100, can
be modeled by following lines of MATLAB code into a new m-file.
m = 0.111;
R= 0.015;
g = -9.8;
L= 1.0;
d = 0.03;
J = 9.99e-6;
S = tf('s');
P_ball = -m*g*d/L/(J/R^2+m)/s^2;
Kp = 1;
C = pid(kp);
sys_cl=feedback(C*P_ball,1);
Now, we can model the system's response to a step input of
0.25 m. Add the following line of code.
Step(0.25*sys_cl)
axis([0 70 0 0.5])
17. Output
PROPORTIONAL CONTROL
The system remains marginally stable
with the addition of a proportional gain
Try changing the value of Kp and note
that the system remains unstable
18. PROPORTIONAL DERIVATIVE CONTROL
Add a derivative term to the controller. Copy the
following lines of code to an m-file and run it to view
the system's response
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
P_ball = -m*g*d/L/(J/R^2+m)/s^2;
Kp = 10;
Kd = 10;
C = pid(Kp,0,Kd);
sys_cl=feedback(c*p_ball,1);
Now, we can model the system's response to a step
input of 0.25 m. Add the following line of code.
t=0:0.01:5;
step(0.25*sys_cl)
19. PROPORTIONAL DERIVATIVE CONTROL
Now the system is stable but the overshoot
is much too high
By increasing Kd we can lower the overshoot
and decrease the settling time slightly
Therefore, make Kd= 20
Kp = 10;
Kd = 20;
C = pid(Kp,0,Kd);
sys_cl=feedback(c*P_ball,1);
step(0.25*sys_cl)
Kd = 10
20. Kd = 20
Overshoot criterion is
met
Settling time needs
to come down a bit
To decrease the
settling time we may
try increasing the Kp
slightly to increase
the rise time. The
derivative gain Kd
can also be increased
to take off some of
the overshoot that
increasing Kp will
cause.
21. After playing with the gains a bit, the following step
response plot can be achieved with Kp= 15 and Kd= 40
Kp = 15;
Kd = 40;
C = pid(Kp,0,Kd);
sys_cl=feedback(c*p_ball,1);
step(0.25*sys_cl)
From this plot all the control objectives
have been met
Settling time less than 3 seconds
Overshoot less than 5%
23. OPEN-LOOP
ROOTLOCUS
The main idea of the root locus design is to estimate
the closed-loop response from the open-loop root locus
plot. By adding zeroes and/or poles to the original
system (adding a compensator), the root locus and thus
the closed-loop response will be modified.
24. MATLAB code in order to model the plant and plot the root locus is
m= 0.111;
R = 0.015;
g= -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
P_ball = -m*g*d/L/(J/R^2+m)/s^2;
rlocus(P_ball)
The system has two poles at the origin which
go off to infinity along the imaginary axes
25. The design criteria can be plotted onto the root locus using the sgrid command
This command generates a grid of constant damping ratio and natural frequency.
The damping ratio and natural frequency were found using the following equations
From the equations,
the damping ratio = 0.7
natural frequency =1.9
Our design Criteria is
Mp < 5% and Ts = 3 Sec
26. Sgrid(0.70, 1.9)
axis([-5 5 -2 2])
Plotting Sgrid on matlab
( the damping ratio = 0.7, natural frequency =1.9 )
The area between the two dotted diagonal lines
represents locations where the percent overshoot is
less than 5%.
The area outside the curved line represents locations
where the settling time is less than 3 seconds.
Note that no region of the plot falls within the design
criteria shown by these lines.
To remedy this and bring the root locus into the left-
hand plane for stability we will try adding a lead-
compensator to the system
27. let us add the controller to the plant and view the root locus.
We will position the zero near the origin to cancel out one of the poles.
The pole of our compensator will be placed to the left of the origin to pull the root locus further
into the left-hand plane.
LEAD COMPENSATOR
A first order lead compensator tends to shift the root locus into the left-hand plane.
Matlab code is
zo = 0.01;
po = 5;
C=tf([1 zo],[1 po]);
rlocus(c*P_ball)
sgrid(0.70, 1.9)
28. Matlab code is
zo = 0.01;
po = 5;
C=tf([1 zo],[1 po]);
rlocus(c*P_ball)
sgrid(0.70, 1.9)
SHIFTED
29. We have moved the root locus into the left-hand plane, we may select a gain that will satisfy our
design requirements. We can use the rlocfind command to help us do this. Add the code
[k,poles]=rlocfind(C*P_ball)
onto the end
SELECTING GAIN
After doing this, you should see the following output in
the MATLAB command window.
Select a point in the graphics window
selected_point =
-2.4917 + 1.0109
K =
34.7474
poles =
-2.4950 + 1.0109i
-2.4950 - 1.0109i
-0.0101
30. PLOTTING THE CLOSED-LOOP RESPONSE
This value of K can be put into the system and the
closed-loop response to a step input of 0.25 m can be
obtained.
Sys_cl=feedback(k*c*p_ball,1);
t=0:0.01:5;
figure
step(0.25*sys_cl,t)
From this plot we see that when a 0.25-m step
input is given to the system both the settling
time and percent overshoot design criteria are
met.
32. Frequency
DomainMethods
forController
Design
The open-loop transfer function of the plant for the ball
and beam experiment is given below:
The design criteria for this problem are:
Settling time less than 3 seconds
Overshoot less than 5%
33. Open-loopBode
Plot
• Adding a controller to the system changes the open-loop
Bode plot, therefore changing the closed-loop response.
• For obtaining the Bode Plot for this original open-loop
transfer function, we have to create a new m-file with the
following code and then run it in the MATLAB command
window.
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
P_ball = -m*g*d/L/(J/R^2+m)/s^2;
bode(P_ball)
34. • From this plot ,we see that the phase margin is
zero which in turn indicates our system is
unstable.
• If we want to increase the phase margin and we
can use a lead compensator controller to do this.
35. Phase-lead
controller
• A first order phase-lead compensator has the form given below:
• The phase-lead compensator will add positive phase to
our system over the frequency range 1/ a T and 1/T,
which are called the corner frequencies.
• The maximum added phase for one lead compensator is
90 degrees.
• For our controller design we need a percent overshoot
of less than 5%, which corresponds to a damping ratio
(rho) of 0.7
• Generally 100*rho will give you the minimum phase
margin needed to obtain your desired overshoot
• Therefore, we require a phase margin greater than 70
degrees.
36. To obtain T and α, the following steps can be applied
1. Determine the positive phase needed
2. Determine the frequency where the phase should be
added (center frequency)
3. Determine the constant a from the equation below:
4. Determine t and aT from the following equations:
For 70 degrees and center frequency = 1, = 0.176 and = 5.67
37. • Now, we can add our lead controller to the system and
view the bode plot.
phi=70*pi/180;
a=(1-sin(phi))/(1+sin(phi));
w=1;
T=1/(w*sqrt(a));
K = 1;
C = K*(1+T*s)/(1+a*T*s);
bode(C*P_ball)
You can see that our phase margin is now 70 degrees
38. • Let's check the closed-loop response to a step input of
0.25 m.
• Add the following to your m-file. You should get the
following plot:
sys_cl = feedback(C*P_ball,1);
t = 0:0.01:5;
step(0.25*sys_cl,t)
Although the system is now stable and
the overshoot is only slightly over 5%, the settling time is not satisfactory.
39. Increasing the gain will increase the crossover frequency
and make the response faster.
With K = 5, your response should look like:
K = 5;
C = K*(1+T*s)/(1+a*T*s);
sys_cl = feedback(C*P_ball,1);
bode(C*P_ball) step(0.25*sys_cl,t)
The response is faster, however, the overshoot is much too high.
Increasing the gain further will just make the overshoot worse.
40. ADDING MORE PHASE
We can increase our phase-lead compensator to decrease the overshoot
pm = 80;
w = 1;
K = 1;
%view compensated system bode plot
pmr = pm*pi/180;
a = (1 - sin(pmr))/(1+sin(pmr));
T = sqrt(a)/w;
aT = 1/(w*sqrt(a));
C = K*(1+aT*s)/(1+T*s);
figure
bode(C*P_ball)
%view step response
sys_cl = feedback(C*P_ball,1);
t = 0:0.01:5;
figure
step(0.25*sys_cl,t)
41. The overshoot is fine but the settling time is just a bit long
Try different numbers
42. Using the following values the design criteria was met
pm = 85;
w = 1.9;
K = 2;
%view compensated system bode plot
pmr = pm*pi/180;
a = (1 - sin(pmr))/(1+sin(pmr));
T = sqrt(a)/w;
aT = 1/(w*sqrt(a));
C = K*(1+aT*s)/(1+T*s);
figure
bode(C*P_ball)
%view step response
sys_cl = feedback(C*P_ball,1);
t = 0:0.01:5;
figure
step(0.25*sys_cl,t)
43. the design criteria was met
Settling time less than 3 seconds
Overshoot less than 5%
47. VARIABLES CAN ONLY BE ASSIGNED
TO FUNCTION BLOCK AS FUNCTIONS
OF U
SO LET.,
48.
49. Now lets make it into a subsystem and check the open-loop response
Assign values of
constants in
command window
50. Run for 10 sec and check output
SYSTEM IS BIBO
UNSTABLE
SO WE NEED TO ADD A CONTROLLER
TO MAKE THE SYSTEM STABLE
We are adding the root locus controller we
designed earlier to make it stable
Meaning the ball will roll off the beam
51. Root locus controller design
ADDING GAIN BLOCK OF 34.7 AND
ADDING LEAD COMPENSATOR BY ADDING A
ZERO AT 0.01 AND A POLE AT 5
THEN GIVE A UNIT NEGATIVE FEEDBACK AS
SHOWN IN FIG
52. Now lets run the stimulation for 10s and view the output
Yes. The system is stable
Also our design criterias are met
Max Peak Overshoot < 5%
Settling time < 3 Sec
Thus our stimulation is complete and success
53. P R E PA R E D BY
G ro u p 7
A LV I N S A J I G EO R G E
B H A R AT H V I N O D
A N I T H A K R
A S W I N K V
FA B N A N
S U B M I T T E D TO
D r M AT H E W P A B R A H A M
R E F E R E N C E : C T M S . E N G I N . U M I C H . E D U