RLC Circuit of February 10, 2011

From Class Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The problem was set up in class starting on February 10, 2011. The Octave script below simulates the control system using a full order observer for the states, and assuming that the output voltage is all that is available for measurement.

% This script simulates the RLC circuit from the notes of February 10,
% 2011.  It uses a full order observer.  It also shows how to reorder
% the states.  It includes a simulation of the system which is very
% interesting because it shows how there is a big error in the observer
% at first.

c=2 %Capacitance   
R=3 %Resistance
L=4 %Inductance
A=[[0 -1/L];[1/c -1/(R*c)]]
B=[1/L; 0]
C=[0 1]
D=0
sys1=ss(A,B,C,D);
T=fliplr(eye(2)); %Transformation Matrix for swapping states
Ar=T*A*T^(-1); %Transformed system
Br=T*B;
Cr=C*T^(-1);
sysr=ss(Ar,Br,Cr,0);
Rr=obsv(sysr); %Observability Matrix for swapped states
R=obsv(sys1); %Not swapped Observability Matrix
rank_r=rank(R); %Is the system observable
rank_rr=rank(Rr)
g=place(sys1,[-1.5 -2.5]); %Place the poles for the controller
printf("Check to see if the place did the right thing.")
printf("The poles after feedback are at: ")
controller_poles = eig(A-B*g)
K=place(A',C',[-33,-30.5])' %Place poles for the observer
% Note: you can see the observer problem with poles [-100,-105]
% and initial conditions [1 2 3 4]
Ahat=A-K*C;
printf("Check to see if the place did the right thing.")
printf("The poles of the observer are: ")
observer_poles = eig(Ahat)
Bhat=B;
%Make a concatinated system of the observer and system
Atot=[[A, -B*g];[K*C, Ahat-Bhat*g]]; 
Btot=[B;Bhat];
Ctot=eye(size(Atot));
systot=ss(Atot,Btot,Ctot);
polestot=pole(systot)
t=0:.0001:.5;
[X,Y]=lsim(systot, zeros(size(t))', t, [5 5 1 1]');
plot(t,X)
legend('x_1','x_2','xhat_1','xhat_2')
title('System and Observer Simulation')
xlabel('Time (seconds)')
% Check the transformed to error terms total system.
T=[[1 0 0 0];[0 1 0 0];[1 0 -1 0];[0 1 0 -1]];
TAtotTI=T*Atot*T^(-1);
polestot_transformed=eig(TAtotTI);

RLC control.png

The controller exacerbates the overshoot because the observer has significant error on one state variable until about .2 seconds. In order to help the situation, we can just not drive the circuit until the observer has caught up. This cuts the overshoot roughly in half.

RLC control delay.png

Reduced Order Observer Simulation

Here is the code for simulating the reduced order observer:

% This script is to design a reduced order observer and control
% system for our RLC Circuit.

clear

delta_t=.0001;
t_end=2;
x0=[5 5 0]'

c=2 %Capacitance   
R=3 %Resistance
L=4 %Inductance
A=[[0 -1/L];[1/c -1/(R*c)]]
B=[1/L; 0]
C=[0 1]
D=0
sys1=ss(A,B,C,D);
T=fliplr(eye(2)) %Transformation Matrix for swapping states
Ar=T*A*T^(-1) %Transformed system
Br=T*B
Cr=C*T^(-1)
sysr=ss(Ar,Br,Cr,0);
C1=Cr(1:1)
A11=Ar(1:1,1:1)
A12=Ar(1:1,2:2)
A21=Ar(2:2,1:1)
A22=Ar(2:2,2:2)
B1=Br(1:1)
B2=Br(2:2)
poles=[-20]
L=(place(A22',A12'*C1',poles))'
M=A21*C1^(-1)-L*C1*A11*C1^(-1)
H=B2-L*C1*B1 

G=place(sysr,[-1.5 -2.5]) %Place the poles for the controller
printf("Check to see if the place did the right thing.")
printf("The poles after feedback are at: ")
controller_poles = eig(Ar-Br*G)
G1=-G(1:1) % The minus is because we derived it with a u=+Gx and octave
           % uses u=-Gx
G2=-G(2:2) % The minus is because we derived it with a u=+Gx and octave
           % uses u=-Gx
F22=A22-L*C1*A12

Atot=[[A11+B1*G1,A12,B1*G2];[A21+B2*G1, A22, B2*G2];
    [L*C1*(A11+B1*G1)+H*G1+M*C1,L*C1*A12,L*C1*B1*G2+F22+H*G2]]; 
Btot=[0 0 0]' 

systot=ss(Atot,Btot);
polestot=pole(systot)
t=0:delta_t:t_end;
[X,Y]=lsim(systot, zeros(size(t))', t', x0);  

plot(t,X)
legend('xm','xum','xhatum')
title('Reduced Order Observer Simulation')
xlabel('Time (seconds)') 

Fixed! The notes that go with this work are from February 28 through March 4.