Project - Position control of mass spring damper system
Solution 01.
Built a simulink model of spring-mass damper system controlled with PID controller shown below
We use pulse generator block to give the given input to the system with transfer function block for spring-mass damper system with gains for kp, ki and kd gains and other desired block as shown

NOTE :-Filename " spring_mass_damper_pid.mdl" having above simulink model file
The dynamics of the mass-spring-damper system can be described as follows:
F = m*x2_dot +c*x2+k*x1
where , m is the mass (kg),
c is the damping coefficient (Ns/m)
k is the spring constant (N/m),
x1 is the displacement of the mass from its equilibrium position (m),
x2 is the velocity of the mass (m/s)
x2_dot is the acceleration of the mass (m/s²)
F is the force applied to the mass (N).
To obtain the transfer function, we need to convert this second-order ordinary differential equation into the Laplace domain.The transfer function of the system is:
G(s)=1/ms2+cs+k
Use the State space method to get the matrices
To create state-space matrices A and B for the mass-spring-damper system with m=3.6,c=100, and k=400, we need to represent the system in state-space form.The state-space representation of a linear time-invariant system is given by the following set of first-order differential equations:
For the given mass-spring-damper system, the state-space representation is:


NOTE:- filename "pid_springmassdamper.m" is above matlab script file
Run the simulation for 27.5 sec. with controller connection to the system , the output shown below

Hence, we get a fine track for Ki=1500 Kp=K(1) and Kd=K(2) gain values.