Project - Position control of mass spring damper system
Project - Speed Control of a Direct Current (DC) motor
Obtain the transfer function of a mass spring damper system and use it in the model. Add a PID controller to adjust the force on mass so that its position follows a reference signal.
Take m = 3.6; %kg k = 400; %N/m c = 100; %Ns/m
The reference signal is shown in the following figure.
Answer
Spring mass damper system
X2dot = [F(t) - c*x_dot - kx]/m
F(t) = Kp*(x_ref-x)+Ki*∫(x_ref-x)*dt+Kd*x_dot
x = position ( or displacement)
x_dot = velocity = dx/dt
x2dot = acceleration = d2x/dt2
matlab script
clc;
clear;
m = 3.6; % mass of spring mass damper system in Kg
c = 100; % damping cofficient of spring mass damper system in Ns/m
k = 400; % spring stifness on spring mass damper system in N/m
wn=sqrt(k/m); % natural frequency in Hz
zeta=c/(2*m*wn); % damping ratio
Kp=wn^2; % proportaional gain
Kd=2*zeta*wn; % derivative gain
Ki = 900; % integral gain
%% Transfer function
s=tf('s');
G = wn^2/(s^2+2*zeta*wn*s+wn^2);
simulink model

pulse parameter

time parameter to workspace

model setting

plot on matlab script
%% plot
figure(1);
subplot(511);plot(out.time,out.xref,'m-');grid;title('reference');
subplot(512);plot(out.time,out.u);grid;title('control');
subplot(513);plot(out.time,out.a);grid;title('acceleration');
subplot(514);plot(out.time,out.v);grid;title('velocity');
subplot(515);plot(out.time,out.x);grid;title('position');

figure(2);
plot(out.time,out.xref,'r--');grid;
plot(out.time,out.x,'b-');hold;grid;title('position with reference');

these figure 2 shows the position follows a reference signal.