ENGR 058 (Control Theory) Final: 1) Define The System
ENGR 058 (Control Theory) Final: 1) Define The System
ENGR 058 (Control Theory) Final: 1) Define The System
You must:
print out and turn in this cover sheet (with your name and signature) along with your exam
spend at most three days on the exam
turn in the exam by noon. on Friday, May 17.
Name (printed):______________________
Signature:___________________________ Date:___________
This exam explores the design of controllers for an inverted pendulum system; often
called the broomstick balancing problem.. The exam is almost exclusively design. You
can do most of the exam as a single MATLAB file and give me the published output
(only a few of the problems require any derivation). If you do this, make sure the
individual problems are well separated (you can give each it's own subheading in the
published document). You can send a pdf if you don't have access to a color printer.
Do all problems, each counts equally toward your final grade.
a. Show that this can be represented by the state space system (with m=M=g=ℓ=1)
b. Define the state space system in MATLAB with θ as output. Call it "ssIPTheta" (i.e.,
ssIPTheta=ss(A,B,C,D);) (ss=State Space, IP=Inverted Pendulum,Theta=angle output).
2) Transfer function
a. Show that if the output is θ that the transfer function of the system is given by
If you use "tfdata", be sure to use "minreal" to cancel poles and zeros (the result may still
have a small error). Alternatively, you can use the state transition matrix, Φ(s) and evaluate
symbolically.
Use the variable GIPTheta in MATLAB when you define the function (G=transfer function,
IP=Inverted Pendulum, Theta=angle output). Note that the system has a RHP pole.
b. Plot the Bode diagram.
3) PD Design
Let's design a controller that is fast compared to system dynamics.
a. Use GIPTheta(s) and design a PD controller with a 60 degree phase margin at ω=20
rad/sec.
b. Use a Nyquist plot to verify that the system is stable (in the equation Z=N+P=0).
c. Verify the phase margin with a Bode plot.
d. Find pole locations of the closed loop system (call it GIP_PD_CL) and verify that they are in
the LHP.
5) Discrete Design
a. Use T=0.1 and design a discrete controller to have a phase margin of 60° near 2 radians
per second. (Since sampling is slower, I chose a correspondingly lower crossover
frequency).
b. Find the pole locations of the closed loop z-domain transfer function.
6) PD as State Control (The rest of the exam considers
only continuous time systems)
We'd like to see how the PD control responds to initial conditions, but that is difficult
with MATLAB when you have a transfer function representation of the system.
a. Show that state control of ssIPTheta with a gain vector k=[kp kd 0 0] is equivalent to PD
control for a system with no input (i.e., a regulator).
b. Use the gains from your continuous time PD controller to with ssIPTheta to make a
regulator. Call is ssPDReg.
c. Find the poles of the system with feedback (again "minreal" may be useful) and show they
are the same as for GIP_PD_CL.
d. Plot θ vs time for initial conditions
My result is below for comparison. Yours should be similar. This corresponds to the
situation where the system starts with the broomstick not at the vertical position - the cart
then positions itself to make the broomstick vertical.
e. Plot all 4 state variables for 10 seconds (the code below does this) and explain, verbally, the
system behavior (especially at long times).
%%
% Plot all four state variables
[y t x]=initial(ssPDreg,[1 0 0 0],10);
plot(t,x); legend('\theta','\thetaDot','x','xdot','Location','se')
8) Design an observer/controller
a. Modify the system ssIPThetaso that the output is "x" instead of "θ". Call the new system
ssIPx. Since the states are the same as for ssIPTheta, we can retain the same gain vector
for control.
b. Show that the system, ssIPx, is observable and controllable.
c. Find the gain required for an observer with poles that are 4 times further from the origin than
those from the closed loop system (i.e., -4±4j and -8±8j).
if the initial values for the estimates are all correct (i.e., errors are all zero).
b. Repeat if the initial values for the estimates are all zero. (The errors in the estimates should
all decay rapidly compared to system response).
Inverted pendulum
clear all
A=[0 1 0 0;
m*g/M+g/L 0 0 0;
0 0 0 1;
m*g/M 0 0 0];
B=[0 1/M/L 0 1/M]';
C=[1 0 0 0];
D=0;
sysIP=ss(A,B,C,D)
sysIP =
a=
x1 x2 x3 x4
x1 0 1 0 0
x2 2 0 0 0
x3 0 0 0 1
x4 1 0 0 0
b=
u1
x1 0
x2 1
x3 0
x4 1
c=
x1 x2 x3 x4
y1 1 0 0 0
d=
u1
y1 0
syms s
Phi = simple(inv(s*eye(4)-A))
GIP = simple(C*Phi*B)
[n,d]=numden(GIP);
GIPTheta=tf(sym2poly(n),sym2poly(d))
GIPTheta =
1
---------------------
s^2 - 6.661e-16 s - 2
GIP =
1/(s^2 - 2)
GIPTheta =
1
-------
s^2 - 2
Problem 3; PD design,
Part a) Analytic Method, PD
w1=20;
G_w1=evalfr(GIPTheta,j*w1);
theta=-180+60-angle(G_w1)*180/pi;
kd=sind(theta)/w1/abs(G_w1);
kp=cosd(theta)/abs(G_w1);
Gpd =
17.41 s + 201
nyquist(Gloop);
Part c)
margin(Gloop);
Part d)
GIP_PD_CL=feedback(Gloop,1)
damp(GIP_PD_CL)
GIP_PD_CL =
17.41 s + 201
-------------------
s^2 + 17.41 s + 199
T=0.01;
GIP_d = c2d(GIPTheta,T,'zoh'); % Convert Plant
Gpd_d = c2d(Gpd,T,'tustin'); % Convert controller
Gcl_d1 = minreal(feedback(GIP_d*Gpd_d,1));
damp(Gcl_d1)
[z,p,k]=zpkdata(GIP_PD_CL,'v');
p
exp(p*T)
p=
-8.7036 +11.1017i
-8.7036 -11.1017i
ans =
0.9110 + 0.1016i
0.9110 - 0.1016i
T=0.1;
GIP_d = c2d(GIPTheta,T,'zoh');
Gpd_d = c2d(Gpd,T,'tustin');
Gcl_d2 = minreal(feedback(GIP_d*Gpd_d,1));
damp(Gcl_d2);
GIP_w = d2c(GIP_d,'tustin');
w1=2;
G_w1=evalfr(GIP_w,j*w1);
theta=-180+60-angle(G_w1)*180/pi;
kd2=sind(theta)/w1/abs(G_w1);
kp2=cosd(theta)/abs(G_w1);
Gpd_w =
2.727 s + 2.461
Afb=A-B*[kp kd 0 0];
ssPDreg=ss(Afb, B, C, D)
damp(minreal(ssPDreg))
initial(ssPDreg,[1 0 0 0],2);
ssPDreg =
a=
x1 x2 x3 x4
x1 0 1 0 0
x2 -199 -17.41 0 0
x3 0 0 0 1
x4 -200 -17.41 0 0
b=
u1
x1 0
x2 1
x3 0
x4 1
c=
x1 x2 x3 x4
y1 1 0 0 0
d=
u1
y1 0
2 states removed.
[y t x]=initial(ssPDreg,[1 0 0 0],10);
plot(t,x);
legend('\theta','\thetaDot','x','xdot','Location','se')
As t increases, the system reaches a constant velocity with theta=0, so position is changing linearly with time.
rank(ctrb(sysIP))
rank(obsv(sysIP))
ans =
ans =
Part b) We can have the output, theta, equal to zero while velocity in x is constant and x is changing. So theta doesn't give
enough information to determine x. The system is not observable.
Part c
k=
36 30 -16 -24
ssStateControlTheta =
a=
x1 x2 x3 x4
x1 0 1 0 0
x2 -34 -30 16 24
x3 0 0 0 1
x4 -35 -30 16 24
b=
u1
x1 0
x2 1
x3 0
x4 1
c=
x1 x2 x3 x4
y1 1 0 0 0
d=
u1
y1 0
Part d
damp(ssStateControlTheta)
[y t x]=initial(ssStateControlTheta,[1 0 0 0]',10);
plot(t,x); legend('\theta','\thetaDot','x','xdot')
C=[0 0 1 0]
sysIPx=ss(A,B,C,D);
rank(ctrb(sysIPx))
rank(obsv(sysIPx))
C=
0 0 1 0
ans =
ans =
g=
1584
4676
24
290
sysObs =
a=
x1 x2 x3 x4 x5 x6 x7 x8
x1 0 1 0 0 0 0 0 0
x2 -34 -30 16 24 36 30 -16 -24
x3 0 0 0 1 0 0 0 0
x4 -35 -30 16 24 36 30 -16 -24
x5 0 0 0 0 0 1 -1584 0
x6 0 0 0 0 2 0 -4676 0
x7 0 0 0 0 0 0 -24 1
x8 0 0 0 0 1 0 -290 0
b=
u1
x1 0
x2 1
x3 0
x4 1
x5 0
x6 0
x7 0
x8 0
c=
x1 x2 x3 x4 x5 x6 x7 x8
y1 0 0 1 0 0 0 0 0
d=
u1
y1 0
[y t x]=initial(sysObs,[1 0 0 0 0 0 0 0]',10);
plot(t,x);
legend({'\theta','\thetaDot','x','xdot', 'e_1', 'e_2', 'e_3', 'e_4'})
[y t x]=initial(sysObs,[1 0 0 0 -1 0 0 0]',10);
plot(t',x);
legend({'\theta','\thetaDot','x','xdot', 'e_1', 'e_2', 'e_3', 'e_4'})
Problem 10; Tracker
Define augmented system
% %% Other inputs.
% t=linspace(0,40,1000); % Set time vector
% cmd = 0.1*(1+sawtooth(t*2*pi/20));
% cmd = 0.1*(1+cos(t*2*pi/20));
% [y t xa]=lsim(ssIPx_Tracker,cmd,t); % Perform simulation
% plot(t,cmd,'r:',t,xa);
% legend('cmd','\theta','\thetaDot','x','xdot','Extra State')
ka =
ssIPx_Tracker =
a=
x1 x2 x3 x4 x5
x1 0 1 0 0 0
x2 -154 -170 112 160 64
x3 0 0 0 1 0
x4 -155 -170 112 160 64
x5 0 0 1 0 0
b=
u1
x1 0
x2 0
x3 0
x4 0
x5 -1
c=
x1 x2 x3 x4 x5
y1 0 0 1 0 0
d=
u1
y1 0
clf
co=-ka*xa'; % Controller output
xcart=[-1 1 1 -1]*0.075;
cart=patch(xcart,[1 1 -1 -1]*0.2,[1 0.5 0.5]);
xline=[0 0]; yline=[0 2];
broom=line(xline,yline,[0 0],'Color',[0 0 1],'Linewidth',3);
xforce=[0 0];
force=line(xforce,[0 0],[0 0],'Color',[1 0 0],'Linewidth',2);
goal=line(0,0,0,'Color',[0 0 0],'Marker','o','MarkerFaceColor',[0 0 0]);
axis([-0.4 0.5 -1 3]);
for i=1:length(t),
set(cart,'Xdata',xcart+xa(i,3));
set(broom,'Xdata',xa(i,3)+[0 -2*sin(xa(i,1))],'Ydata',[0 2*cos(xa(i,1))]);
set(force,'Xdata',xa(i,3)+[0 co(i)/4]); % Display scaled force.
set(goal,'Xdata',cmd(i)); % Display goal
pause(0.001);
end
Published with MATLAB® R2012b