You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Design of Strong Prescribed Time (SPT) Controller for Manipulator (Example 2)
66 views (last 30 days)
Show older comments
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 Comments
Sam Chak
on 27 Jun 2024 at 9:31
Hi @controlEE
Your design workflow looks correct. Since the controller u depends on , you need to find first so that you can determine its time derivative later. However, also depends on . Therefore, you need to backstep and find so that you can find its time derivative . When you backstep to the end, you will need .
Just be careful when performing substitutions. Because there are multiple layers of substitutions, if you make a mistake at the beginning (such as ), it will create a chain of mistakes that will propagate forward to the controller u.
%% terms extracted from the original system
F1 = ...;
F2 = ...;
F3 = ...;
G1 = ...;
G2 = ...;
G3 = ...;
%% miscellaneous terms to be used in Eq.(23) and Eq.(26)
a = ...;
h = ...;
rho = ...; % ρ, bounded non-negative function derived to satisfy |ϕ(t,x)| ≤ ρ(t,x)
tau = ...; % τ
K1 = ...;
K2 = ...;
K3 = ...;
z1 = ...;
z2 = ...;
z3 = ...;
... % others
%% terms derived from Eq.(23) and their time derivatives
x1d = 0;
dotx1d = 0;
x2d = ...;
dotx2d = ...;
x3d = ...;
dotx3d = ...;
%% controller, according to Eq.(26)
u = ...;
The perturbing term is not a constant, but a bounded time-varying sine wave. This info is for designing , which is a bounded non-negative function created to satisfy the condition .
By the way, the authors performed coordinate transformation and the x-dot system is expressed in strict-feedback form.
Sam Chak
on 1 Jul 2024 at 11:35
Hi @controlEE
I have briefly reviewed the latest code, focusing on some critical terms. It appears that the authors' backstepping formulas and the "divide-and-conquer" coding guidance I had previously provided are not being followed. For instance, I am unable to locate the terms F1, F2, F3, G1, G2, and G3 within the code. This poses a challenge for me to thoroughly evaluate your implementation.
The code itself is meaningless if the underlying "step-by-step" backstepping control design is flawed. Providing a detailed, annotated step-by-step approach is essential, as it allows your "Supervisor" or "Software Development Manager" to review the code and ensure adherence to standard coding practices.
Regarding the code, the term in x3_d (which is not directly shown in the provided code) appears to be incorrect. Without the detailed "step-by-step" design, it is difficult to trace the reasoning behind this specific implementation of F2. Additionally, the derivation of "xdot_2_desire" is not clearly shown, as the mathematical time derivative is not explicitly presented.
controlEE
on 2 Jul 2024 at 10:59
Edited: controlEE
on 2 Jul 2024 at 17:47
Hi @Sam Chak , I calculated x3_dot , could you check the code and especially x3_dot and x2_dot . I tried to assign them accurately based on page 6 , Eq.23 , Eq.24 . I deleted the last comment because the code needs some modifications .
controlEE
on 5 Jul 2024 at 10:52
Hi @Sam Chak , Did u find the reason why we don't get a more ideal result ?
controlEE
on 7 Jul 2024 at 22:54
So why we don't get the ideal results ? Should we switch to another solver ?
Sam Chak
on 8 Jul 2024 at 8:12
Hi @controlEE
The most probable explanation is that the equations in your code may differ from those used by the authors. Unfortunately, without access to the authors' exact control law design equations for Example 2, we are unable to verify this.
Have you thoroughly checked to ensure that the equations in your code precisely follow the design methodology outlined in the paper? You need to show your every design step as outlined in order to thoroughly check it. Yes, "thoroughly"...
If you lump everything and write a single line equation in the code, it is very dificult to trace the substitutions and check it. I always DIVIDE and CONQUER it...
controlEE
on 21 Jul 2024 at 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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(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
ungefär 2 timmar ago
Hi @controlEE
The function or variable 'dRh' is not defined in the code.
Answers (0)
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)