PD controller (Time domain)
143 views (last 30 days)
Show older comments
I would like to design a PD controller, to control a moving mass (=1Kg) along the x-axis so it moves from rest (point A) to another point B, like this:
I would appreciate any help!
2 Comments
Accepted Answer
Mathieu NOE
on 12 Mar 2021
hello again
so this is a modified code :
- the integration process computes the velocity first (from acceleration) , then the position (from the velocity)
- force can be limited , so you can have large gains from the controller (faster response) but you can then saturate the controller output to any given Fmax value. Results will look pretty much like a bang bang controller
- plot update by using handles (faster than re plotting the entire plot at each step)
- still need to figure out how to add the moving rectangle at the top of the figure
hope it helps
clf
clc
%Time:
t_ges = 2.5;
dt = 0.025;
t_vect = 0 : dt : t_ges;
%Initial position, Initial velocity, Initial acceleration:
q_0=0;
dq_0=0;
ddq_0=0;
%The position, velocity, acceleration:
q = q_0;
dq = dq_0;
ddq = dq_0;
%PD constants
Kp=10;
Kd=Kp/2;
% force limitation to Fmax (limitation of output of PD controller)
Fmax = 1;
%Matrices to store the calculate values:
n_times = length(t_vect);
q_Matrix = zeros(1, n_times);
dq_Matrix = zeros(1, n_times);
ddq_Matrix = zeros(1, n_times);
F_Matrix = zeros(1, n_times);
%// initiallize plot. Get a handle to graphic object
f = figure(1);
s1 = subplot(3,1,1);
p1 = plot(NaN,NaN,'b');
title('Position')
ylabel('m');
axis([0 t_ges -0.25 1.25]);%// freeze axes to their final size, to prevent Matlab from rescaling them dynamically
s2 = subplot(3,1,2);
p2 = plot(NaN,NaN,'b');
title('Velocity');
ylabel('m/s');
axis([0 t_ges -1 2]);%// freeze axes to their final size, to prevent Matlab from rescaling them dynamically
s3 = subplot(3,1,3);
p3 = plot(NaN,NaN,'b');
title('Force');
ylabel('N');
axis([0 t_ges -Fmax*1.25 Fmax*1.25]);%// freeze axes to their final size, to prevent Matlab from rescaling them dynamically
for ci = 1:n_times
%Velocity calculation:
dq = dq + dt * ddq;
dq_Matrix(1,ci) = dq;
%position calculation:
q = q + dt * dq;
q_Matrix(1,ci) = q;
%PD controller calculation: (closed-loop, with the reference is 1 meter (Point B))
F = Kp*(1-q) + Kd*(0-dq);
% force limitation (optionnal)
if abs(F)> Fmax
F = Fmax*sign(F);
end
F_Matrix(1,ci) = F;
%acceleration calculation:
ddq = F;
ddq_Matrix(1,ci) = ddq;
% update the plot
ind = (1:ci);
t_plot = t_vect(ind);
pause(0.01)
set(p1, 'XData', t_plot, 'YData', q_Matrix(ind));
set(p2, 'XData', t_plot, 'YData', dq_Matrix(ind));
set(p3, 'XData', t_plot, 'YData', F_Matrix(ind));
end
0 Comments
More Answers (1)
Mathieu NOE
on 11 Mar 2021
a very simple and straigthforward simulation without much science behind :
NB : controller and plant in series in the main path, unitary feedback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% original plant
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s = tf('s');
% Gs = 1.44e09/(s^2+5333*s+9.6e07);
Gs = 1/(s^2+0*s+0);
%PID
P= 10;
I= 0.0;
D= 1*P;
Ct = P+I/s+D*s/(1e-6*s+1);
figure()
Gscl = feedback(series(Ct,Gs),1);
step(Gscl);
legend('closed loop');
grid on;
See Also
Categories
Find more on Robotics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!