Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

MATLAB Program for SLIDING MODE CONTROL


clc
clear all
x1(1)=0.1;%Initial condition for the first state i:e theta
x2(1)=0.1;%Initial condition for the second state i.e angular velocity theta_dot
h=0.01;% integration step size
M=0.5;%PENDULUM MASS
k=10;%controller gain
L=2.5;%length of cord
g=9.81;%gravitation constant
a=5;
t=0:h:20;%simulation time
for n=1:length(t) %loop for integrating the pendulum equation
    s(n)=a*x1(n)+x2(n);%defining the linear sliding surface
    u(n)=(M*L^2)*(-a*x2(n)+(L/g)*sin(x1(n)))-k*sign(s(n)); %Equivalent control, k is control gain, sign is signum function
   
    x1(n+1)=x1(n)+h*x2(n);%USING EULER APPROXIMATION OF INTEGRATION FOR EQUATION 1 x1_dot=x2
    x2(n+1)=x2(n)+h*(-(L/g)*sin(x1(n))+(1/(M*L^2))*u(n));%integrating second equation
   
end  %ending the running loop
figure(1)
plot(t,x1(1:end-1),'r')% Angle
figure(2)
plot(t,x2(1:end-1),'k')%Rate of change of angle
figure(3)
plot(t,u,'b')% Control input


No comments

Popular Posts