My HW4
My HW4
x q1 q1 q2 q2
T
(3)
1
The input transformations is:
IJ
u (v a( x)) (8)
k
Where
MgL MgL k k k k MgL
a ( x) sin x1 ( x22 cos x1 ) ( x1 x3 )( cos x1 ) (9)
I I I I I J I
The control law:
v e(4) a3e(3) a2e a1e a0e (10)
Choose the positive constants ai, i=0,1,2,3 such that the equation
s 4 a3 s3 a2 s 2 a1s1 a0 0 (12)
x1 x2
x2 MgL sin x1 k ( x1 x3 )
I I
(16)
x3 x4
k 1
x4 ( x1 x3 ) + u
J J
This equation system (16) is described by the following function file "F4.m" in Matlab:
Matlab commands
function xdt=F4(t,x)
xdt=zeros(4,1);
z=zeros(4,1);
%Create parameters
I=0.0234;
M=0.5;
J=0.02;
2
L=0.75;
k=50;
g=9.81;
zd=1;zd1=0;zd2=0;zd3=0;zd4=1;
a0=60;a1=107;a2=59;a3=13;
%State transformation
z(1)=x(1);
z(2)=x(2);
z(3)=-M*g*(L/I)*sin(x(1)) -(k/I)*(x(1)-x(3));
z(4)=-M*g*(L/I)*x(2)*cos(x(1)) -(k/I)*(x(2)-x(4));
e=z(1) -zd;
ed=z(2) -zd1;
edd=z(3) -zd2;
eddd=z(4) -zd3;
%The control law
v=zd4 - a3*eddd - a2*edd - a1*ed - a0*e;
a=M*g*(L/I)*sin(x(1))*(x(2)^2+M*g*(L/I)*cos(x(1))+k/I)+(k/I)*(x(1
) -x(3))*(k/I+k/J+M*g*(L/I)*cos(x(1)));
%The input u
u=I*(J/k)*(v-a);
%Linear system in X-space
xdt(1,1)=x(2);
xdt(2,1)=-M*g*(L/I)*sin(x(1)) -(k/I)*(x(1) -x(3));
xdt(3,1)=x(4);
xdt(4,1)=(k/J)*(x(1) -x(3))+u/J;
end
To perform simulation system and plot the phase portrait, we use the “main3.m” file:
Matlab commands
clear all;
clc;
time=[0 50];
%Creat parameter
I=0.0234;
M=0.5;
J=0.02;
L=0.75;
3
k=50;
g=9.81;
x0=[0;0;0;0]; %initial conditions
[t,x]=ode45('F4' ,time,x0);
%X-SPACE
z1=x(:,1);
z2=x(:,2);
z3=(-M*g*L*(1/I))*sin(x(:,1)) -(k/I)*(x(:,1) -x(:,3));
z4=(-M*g*L*(1/I))*x(:,2).*sin(x(:,3)) -(k/I)*(x(:,2) -x(:,4));
figure(1);
legend1=plot(t,x(:,1),'-.b','linewidth',1);
hold on;
legend2=plot(t,x(:,2),'--r','linewidth',1);
legend3=plot(t,x(:,3),'-xm','linewidth',0.5);
legend4=plot(t,x(:,4),'b','linewidth',0.5);
grid;
xlabel('Time'); % name of horizontal axis
ylabel('X(t)'); % name of vertical axis
title('The time response of x'); % name of graph
legend([legend1,legend2,legend3,legend4],'x1','x2','x3','x4');
figure(2);
legend11=plot(t,z1,'-.b','linewidth',1);
hold on;
legend22=plot(t,z2,'--r','linewidth',1);
legend33=plot(t,z3,'b','linewidth',0.5);
legend44=plot(t,z4,'-xm','linewidth',0.5);
grid;
xlabel('Time'); % name of horizontal axis
ylabel('Z'); % name of vertical axis
title('The time response of Z'); % name of graph
legend([legend11,legend22,legend33,legend44],'z1','z2','z3','z4');
4
Results:
0.8
X(t)
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7 8 9 10
Time
Fig. 2: Response of X
30
Z
20
10
-10
0 1 2 3 4 5 6 7 8 9 10
Time
Fig. 3: Response of Z
5
Comments:
From Fig. 2, in X-Space with the initial condition (X0 = [0; 0; 0; 0] ) the linear system is stable
after a short period of time. The system is stable with the controller that was designed.