Can anybody give me the idea for implementing PID control for dc motor using state space equations through ode45 solver?

10 views (last 30 days)
function dxdt = DIsystem(t, x)
dxdt = zeros(3, 1);
% construction of PID
r = 1; % reference signal
e = x(1) - r; % error signal
Kp = 1 + sqrt(2); % proportional gain
Ki = 1; % integral gain
Kd = 1 + sqrt(2); % derivative gain
u = - Kp*e - Ki*x(3) - Kd*x(2); % the PID thing
% the dynamics
A = [-b/J K/J ; -K/L -R/L]; % state matrix
B = [0; 1/(L*V)]; % input matrix
dxdt(1:2) = A*[x(1); x(2)] + B*u; % the Double Integrator system
dxdt(3) = e; % for integral action in PID
end
How to modify this equation to the dc motor equation?

Answers (1)

Sam Chak
Sam Chak on 2 Nov 2022
Not sure how your DI/dc motor system, but I think the following example should give you the basic idea.
tspan = [0 1];
x0 = [0 0 0];
[t, x] = ode45(@motor, tspan, x0);
plot(t, x(:,1)), grid on, xlabel('t')
function dxdt = motor(t, x)
dxdt = zeros(3, 1);
% construction of PID
r = 1; % reference signal
err = x(1) - r; % error signal
Kp = 3.49; % proportional gain
Ki = 52.8; % integral gain
Kd = 0.0512; % derivative gain
u = - Kp*err - Ki*x(3) - Kd*x(2); % the PID thing
% the dynamics
J = 3.2284E-6;
b = 3.5077E-6;
K = 0.0274;
R = 4;
L = 2.75E-6;
% V = ?;
% A = [-b/J K/J; -K/L -R/L]; % state matrix
% B = [0; 1/(L*V)]; % input matrix
A = [0 1; 0 -(b*R + K^2)/(J*R + b*L)]; % state matrix
B = [0; K/(J*R + b*L)]; % input matrix
dxdt(1:2) = A*[x(1); x(2)] + B*u; % the motor
dxdt(3) = err; % for integral action in PID
end

Community Treasure Hunt

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

Start Hunting!