Sliding Mode Controller for the Double Integrator
22 次查看(过去 30 天)
显示 更早的评论
Hi, My name is Dayal, I am a student of College of Engineering Trivandrum (CET). I am now working on sliding mode control. I have taken a second-order system and tried to control it using sliding mode control. I have tried it in simulink and the system output is not reaching its set point and the phase portrait is going out from zero. So i leave it and tried to work in matlab. Am not familiar with matlab, so if any body have any idea about sliding mode control in matlab or simulink, please help me.
I have taken only a simple second-order system, its canonical representation is given by
A = [0 1;0 0]
B = [0; 1]
X = [x1; x2]
and the control law is given by U = sgn[sigma(x1, x2)]
where sgn(sgima) = 1 when sigma > 0, and -1 when sigma < 0.
If anybody has any idea to do it in simulink or in matlab, please help me...
1 个评论
Jetendra kumar Borra
2016-3-31
in simulink direct sign block is available, in m file write the code in if loop if s>0 f=1 else if s<0 f=-1 end, where f is sgn(s)
回答(2 个)
Sardar Shazali Sikander
2014-5-29
Dear Dayal, I have implemented SMC in simulink so I can try to help you but I think you have not given the full detail of your problem. Regards, Sardar Shazali
0 个评论
Sam Chak
2024-1-17
Hi @DAYAL ND
Not sure if you'll see this or not. After all, this problem was posed around 12 years ago. I rarely come across SMC codes on MATLAB Answers unless I search for them in the File Exchange. Simulink has a Sliding Mode Controller block that was introduced in R2018a, but I haven't tried it yet.
Here is the simulation of Sliding Mode Control for the Double Integrator in MATLAB. Please note that the discontinuous control action from classical sliding mode control will cause high-frequency oscillations around the sliding surface, a phenomenon known as 'chattering'.
%% Old Method: call specific ode solver
% tspan = [0 12]; % simulation time
% x0 = [0; 0]; % initial state values
% [t, x] = ode45(@odefcn, tspan, x0);
%% New Method: create an ode object (introduced in R2023b)
F = ode;
F.InitialValue = [0; 0];
F.ODEFcn = @odefcn;
sol = solve(F, 0, 12); % auto-select ode solver for this problem
t = sol.Time;
x = sol.Solution;
F % Display the ode object to identify the chosen solver
%% Plot results
figure(1)
plot(t, x), grid on
xlabel({'$t$ / sec'}, 'interpreter', 'latex', 'fontsize', 14)
ylabel({'$\mathbf{x}$'}, 'interpreter', 'latex', 'fontsize', 14)
title('Time responses of the states')
legend({'$x_{1}(t)$', '$x_{2}(t)$'}, 'interpreter', 'latex', 'location', 'best', 'fontsize', 14);
figure(2)
% plot(x(:,1), x(:,2)), grid on, axis([0 2 -1 1]) % Old method
plot(x(1,:), x(2,:)), grid on, axis([0 2 -1 1]) % New method
xline(1), yline(0)
xlabel({'$x$'}, 'interpreter', 'latex', 'fontsize', 14)
ylabel({'$\dot{x}$'}, 'interpreter', 'latex', 'fontsize', 14)
title('Phase Portrait shows Chattering')
%% Sliding Mode Control for Double Integrator
function [dxdt, u] = odefcn(t, x)
% State matrix
A = [0 1;
0 0];
% Input matrix
B = [0;
1];
% Setpoint (Reference signal)
sp = 1;
% Classical sliding mode control law
e1 = x(1) - sp; % Error signal
e2 = x(2);
sigma = e1 + e2; % Sliding surface
K = 1; % Switching gain
u = - K*sign(sigma);
% Matrix Differential Equation (2nd-order state-space)
dxdt = A*x + B*u; % x" = u
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!