Effacer les filtres
Effacer les filtres

Design of Strong Prescribed Time (SPT) Controller for Manipulator (Example 2)

66 vues (au cours des 30 derniers jours)
controlEE
controlEE le 26 Juin 2024 à 10:00
Commenté : Sam Chak il y a environ 4 heures
I'm working on implementing a Strong Prescribed Time (SPT) controller for a manipulator in MATLAB. I've successfully designed the controller for the first example provided in a research paper. However, I'm facing challenges with the second example. Designing the SPT controller for the second example's manipulator dynamics.
The paper (Ding et al., 2023) outlines the SPT controller design procedure and manipulator dynamics.
type Exmp2.m
h=5; a = -0.15; history = @(t)[-0.2;0.1;0.1]; % Define the Rh function based on the given conditions Rh = @(t) (0 <= t & t < h) .* 0 + ... (h <= t & t <= 2*h) .* ((t-h).^5.*(2*h-t).^5) + ... (t > 2*h) .* 0; % Define the PDF gain function based on Rh W_c = integral(@(s) Rh(s) .* exp(2 * a * s), h, 2 * h); W = 1 / W_c; K_a_h = @(t) Rh(t) .* W .* exp(-a * (h - 2 * t)); % Define the delay differential equation dde = @(t,x,Z)manipulator_dynamics(t,x,Z,K_a_h); sol = dde23(dde, h, history, [0 40]); % Plot results figure; subplot(3,1,1); plot(sol.x, sol.y(1,:)); xlabel('Time (s)'); ylabel('x1 (error in q)'); title('State x1 vs Time'); subplot(3,1,2); plot(sol.x, sol.y(2,:)); xlabel('Time (s)'); ylabel('x2 (error in dq)'); title('State x2 vs Time'); subplot(3,1,3); plot(sol.x, sol.y(3,:)); xlabel('Time (s)'); ylabel('x3 (error in I)'); title('State x3 vs Time'); % DDE function function dxdt = manipulator_dynamics(t, x, Z, K_a_h) x1_d = 0; x2_d = 0; x3_d = 0; a = -0.15; % Example value tau = 81/83; % Example value h = 5; % Example value J = 1.625e-3; % kg·m² m = 0.506; % kg L0 = 0.305; % m R0 = 0.023; % m B0 = 16.25e-3; % N·m·s/rad L = 25e-3; % H R = 5; % Ω K_tau = 0.9; % N·m/A G = 9.81; % m/s² M0 = 0.434; % kg % Derived parameters M = J / K_tau + m * L0^2 / (3 * K_tau) + M0 * L0^2 / K_tau + 2 * M0 * R0^2 / (5 * K_tau); N = m * L0 * G / (2 * K_tau) + M0 * L0 * G / K_tau; B = B0 / K_tau; K_B = 0.9; Vp = 0.1 * sin(50 * pi *t); z1 = x(1) - x1_d; z2 = x(2) - x2_d; z3 = x(3) - x3_d; z3lag = Z(3,1) - x3_d; % Control input u = L * ((-a / (2 * (1 - tau))) * z3 + x3_d ... + R / L * x(3) + K_B / L * x(2) ... - 5 * sign(z3) ... - (K_a_h(t) / (2 * (1 - tau))) * (sig(z3 * (abs(z3lag)^(2 * (1 - tau)))))^(2 * tau - 1)); % Desired trajectory q_d = (pi / 2) * sin(t) * (1 - exp(-0.1 * t^2)); % Dynamics dxdt = [x(2); (N / M) * sin(q_d) - (N / M) * sin(x(1) + q_d) - (B / M) * x(2) + (1 / M) * x(3); -(R / L) * x(3) - (K_B / L) * x(2) + (1 / L) * u + Vp / L]; end function sigx = sig(x) tau = 81/83; sigx = sign(x) .* abs(x).^(2 * tau - 1); end
  10 commentaires
controlEE
controlEE le 21 Juil 2024 à 9:27
Ok , here is the last implementation of the example ;
There is an error in Line 54 , Can you determine what the problem is ?
clear all
close all
clc
dt = 0.001;
tf = 5;
t = 0:dt:tf;
J = 1.625e-3;
m = 0.506;
M0 = 0.434;
L0 = 0.305;
R0 = 0.023;
B0 = 16.25e-3;
L = 25e-3;
R = 5e3;
G = 9.81;
Kt = 0.9;
Kb = Kt;
B = B0/Kt;
Vp = 0.1*sin(50*pi*t);
q = pi/2*sin(t).*(1-exp(-0.1*t.^2));
a = -0.15;
tau = 81/83;
h = 5;
x0 = [-0.2,-0.1,0.1];
x(1,:) = x0;
x1d = zeros(length(t),1);
x1dd = zeros(length(t),1);
dx1d = zeros(length(t),1);
M = J/Kt + m*L0^2/(3*Kt) + M0*L0^2/Kt + 2*M0*R0^2/(5*Kt);
N = m*L0*G/(2*Kt) + M0*L0*G/Kt;
B0 = B0/Kt;
delay = h/dt;
W = @(s) exp(a*s).*(s-h).^5.*(2*h-s).^5;
Wc = 1/(integral(W,h,2*h));
for i=2:length(t)
k = 0;
for j=1:length(x0)
if (t(i-1)-2*(length(x0)-j)*h)>=k*h && (t(i-1)-2*(length(x0)-j)*h)<(2*k+1)*h
Rh(i-1,j) = 0;
dR(i-1,j) = 0;
ddRh(i-1,j) = 0;
elseif (t(i-1)-2*(length(x0)-j)*h)>= (2*k+1)*h && (t(i-1)-2*(length(x0)-j)*h)<2*(k+1)*h
Rh(i-1,j) = (t(i-1)-2*(length(x0)-j)*h-h).^5.*(2*h-(t(i-1)-2*(length(x0)-j)*h));
dRh(i-1,j) = 5*((t(i-1)-2*(length(x0)-j)*h)-h).^4.*(2*h-(t(i-1)-2*(length(x0)-j)*h)).^5-5*((t(i-1)-2*(length(x0)-j)*h)-h).^5.*(2*h-(t(i-1)-2*(length(x0)-j)*h)).^4;
ddRh(i-1,j) = 20*((t(i-1)-2*(length(x0)-j)*h)-h).^3.*(2*h-(t(i-1)-2*(length(x0)-j)*h)).^3*((2*h-(t(i-1)-2*(length(x0)-j)*h)).^2+((t(i-1)-2*(length(x0)-j)*h)-h).^2)-50*((t(i-1)-2*(length(x0)-j)*h)-h).^4.*(2*h-(t(i-1)-2*(length(x0)-j)*h)).^4;
end
if t(i-1)<=2*(length(x0)-j)*h
K(i-1,j) = 0;
dK(i-1,j) = 0;
ddK(i-1,j) = 0;
elseif t(i-1)>=2*(length(x0)-j)*h
K(i-1,j) = Rh(i-1,j)*Wc*exp(-a*(h-2*(t(i-1)-2*(length(x0)-j)*h)));
dK(i-1,j) = exp(-a*(h-2*(t(i-1)-2*(length(x0)-j)*h)))*Wc*(2*a*Rh(i-1,j)+dRh(i-1,j));
ddK(i-1,j) = exp(-a*(h-2*(t(i-1)-2*(length(x0)-j)*h)))*Wc*(2*a*(2*a*Rh(i-1,j)+dRh(i-1,j))+2*a*dRh(i-1,j)+ddRh(i-1,j));
end
end
if(i-1-delay)<0
xd(i-1,:) = x0;
x1d_d(i-1) = x1d(1);
else
xd(i-1,:) = x(i-1-delay,:);
x1d_d(i-1) = x1d(i-1-delay);
end
z1d(i-1) = xd(i-1,1)-x1d_d(i-1);
if (i-1-2*delay)<-delay
xdd(i-1,:) = 0;
z1dd(i-1) = 0;
else
z1dd(i-1) = z1d(i-1);
xdd(i-1,:) = xd(i-1,:);
end
z1(i-1) = x(i-1,1)-x1d(i-1);
x2d(i-1) = -a*z1(i-1)-K(i-1,1)*z1d(i-1);
z2(i-1) = x(i-1,2)-x2d(i-1);
if(i-1-delay)<0
x2d_d(i-1) = -a*z1d(i-1);
else
x2d_d(i-1) = x2d(i-1-delay);
end
z2d(i-1) = xd(i-1,2)-x2d_d(i-1);
dz1d(i-1) = -a*z1d(i-1)+z2d(i-1);
dz1(i-1) = -a*z1(i-1)-K(i-1,1)*z1d(i-1)+z2(i-1);
z1(i) = z1(i-1)+(t(i)-t(i-1))*dz1(i-1);
dx2d(i-1) = -a*(-a*z1(i-1)-K(i-1,1)*z1d(i-1)+z2(i-1))-dK(i-1,1)*z1d(i-1)-K(i-1,1)*(-a*z1d(i-1)+z2d(i-1));
dq(i-1) = pi/2*cos(t(i-1))*(1-exp(-0.1*t(i-1)))+0.2*pi/2*sin(t(i-1))*t(i-1)*exp(-0.1*t(i-1));
x3d(i-1) = M*(-a*z2(i-1)-K(i-1,2)*z2d(i-1)-N/M*sin(q(i-1))+N/M*sin(x(i-1,1)+q(i-1))+B/M*x(i-1,2)+dx2d(i-1));
if(i-1-delay)<0
dx2d_d(i-1) = -a*(-a*z1d(i-1)+z2d(i-1));
qd(i-1) = q(1);
x3d_d(i-1) = M*(-a*z2d(i-1)-N/M*sin(qd(i-1))+N/M*sin(xd(i-1,1)+qd(i-1))+B/M*xd(i-1,2)+dx2d_d(i-1));
else
dx2d_d(i-1) = dx2d(i-1-delay);
x3d_d(i-1) = x3d(i-1-delay);
end
z3d(i-1) = xd(i-1,3)-x3d_d(i-1);
z3(i-1) = x(i-1,3)-x3d(i-1);
dz2(i-1) = -a*z2(i-1)-K(i-1,2)*z2d(i-1)+1/M*z3(i-1);
dz2d(i-1) = -a*z2d(i-1)+1/M*z3d(i-1);
z2(i) = z2(i-1)+(t(i)-t(i-1))*dz2(i-1);
ddx2d(i-1) = -a*(-a*dz1(i-1)-dK(i-1,1)*z1d(i-1)-K(i-1,1)*dz1d(i-1)+dz2(i-1))-ddK(i-1,1)*z1d(i-1)-dK(i-1,1)*dz1d(i-1)-dK(i-1,1)*(-a*z1d(i-1)+z2d(i-1))-K(i-1,1)*(-a*dz1d(i-1)+dz2d(i-1));
dx3d(i-1) = M*(-a*dz2(i-1)-dK(i-1,2)*z2d(i-1)-K(i-1,2)*dz2d(i-1)-N/M*dq(i-1)*cos(q(i-1))+(x(i-1,2)+dq(i-1))*cos(q(i-1)+x(i-1,1))+B/M*(-N/M*sin(x(i-1,1)+q(i-1))+N/M*sin(q(i-1))-B/M*x(i-1,2)+1/M*x(i-1,3))+ddx2d(i-1));
dz3(i-1) = -a/(2*(1-tau))*z3(i-1)-1/(2*(1-tau))*K(i-1,3)*abs(z3(i-1))^(2*tau-1)*sign(z3(i-1))*abs(z3d(i-1))^(2*(1-tau))+Vp(i-1)/L-0.1/L*sign(z3d(i-1));
z3(i) = z3(i-1)+(t(i)-t(i-1))*dz3(i-1);
u(i-1) = L*(-a/(2*(1-tau))*z3(i-1)+dx3d(i-1)+R/L*x3d(i-1)+Kb/L*x(i-1,2)-0.1/L*sign(z3(i-1))-K(i-1,3)/(2*(1-tau))*abs(z3(i-1))^(2*tau-1)*sign(z3(i-1))*abs(z3d(i-1))^(2*(1-tau)));
dx(i-1,1) = x(i-1,2);
dx(i-1,2) = N/M*sin(q(i-1))-N/M*sin(x(i-1,1)+q(i-1))-B/M*x(i-1,2)+1/M*x(i-1,3);
dx(i-1,3) = -R/L*x(i-1,3)-Kb/L*x(i-1,2)+1/L*u(i-1)+Vp(i-1)/L;
for j=1:length(x0)
x(i,j) = x(i-1,j)+(t(i)-t(i-1))*dx(i-1,j);
end
end
Unrecognized function or variable 'dRh'.
Sam Chak
Sam Chak il y a environ 4 heures
The function or variable 'dRh' is not defined in the code.

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by