Using ode4 solver in a sliding mode controller

14 visualizzazioni (ultimi 30 giorni)
I did a xls model in simulink and a matlab script for a SMC controller and I was expecting the same resutl for both, but is not exactly the same. After looking for both programs, I realized that I'm using a ode4 solver in the simulink xls and seems for me that this is the main issue (I saved the time vector from simuink and use it in the .mat, the results where the same)
I'm quite lost with ode's in matlab, and more if I have to solve this control algorithm... Please How can I use ode4 in my matlab script? I have searched in the forum and in matlab help and I have found this link, but I dont get the point on how to use the function:
I see that ode uses this fucntion to work where I have to use my starting time, time step, final time and initial conditions. I'm lostwith the F function part. I dont know how can I integrate this in my code.
yout = ODE4(F,t0,h,tfinal,y0)
attached bot scripts, Thanks in advance!
  3 Commenti
Sam Chak
Sam Chak il 4 Apr 2023
Modificato: Sam Chak il 4 Apr 2023
@Mikel, Thanks for your reply.
Have you tested the system using the ode45() solver?
I understand that the sinusoidal disturbance is always active. I purposely set to simulate the response of a Double Integrator under the influence of a full-state feedback input .
This allows me evaluate whether integration code in the m-file works as expected or not.
Using your integration code, the states appears to grow and oscillates after 40 seconds (significant to human eyes), and they explode after 60 seconds. However, this test system should be stable.

Accedi per commentare.

Risposta accettata

Sam Chak
Sam Chak il 5 Apr 2023
Modificato: Sam Chak il 5 Apr 2023
In MATLAB, I think these are the expexted results ,where the nonlinear state estimators and are able to rapidly track the true states and , respectively, within 0.2 sec.
I didn't change your design code for the high-gain sliding mode observer part, but I used the ode45() solver instead of your integration code.
% solving the ode
tspan = linspace(0, 2, 20001);
x0 = [1 -2 0 0];
[t, x] = ode45(@smc_obsv, tspan, x0);
% plotting the solution
plot(t, x), grid on,
legend({'$x_{1}$', '$x_{2}$', '$\hat{x}_{1}$', '$\hat{x}_{2}$'}, 'Interpreter', 'latex', 'fontsize', 20)
xlabel({'$t$'}, 'Interpreter', 'latex')
ylabel({'$\mathbf{x}$'}, 'Interpreter', 'latex')
% describing the ode
function xdot = smc_obsv(t, x)
xdot = zeros(4, 1);
% parameters
f = sin(2*t); % disturbance
c = 1.5; %
r = 2; % criterion: r > max(f)
s = c*x(1) + x(4); % sliding surface
u = - r*tanh(s/0.001) - c*x(4); % control input
r1 = 10; % high gain
z = x(3) - x(1); % estimation error
v1 = - r1*tanh(z/0.001); % rate of xhat_1
LPF = 1/0.01; % adapatation rate
v2 = (v1 - x(4))*LPF; % rate of xhat_2
xdot(1) = x(2);
xdot(2) = f + u;
xdot(3) = v1;
xdot(4) = v2;
  4 Commenti
Sam Chak
Sam Chak il 19 Apr 2023
If you are using the signum function, in the code, the system will become very stiff as .

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by