I'm trying to brush up on my understanding of controllers (PID,PD,etc). I've written a simple Matlab program that tries to simulate the control of a spring-mass-damper system with a PID controller (you can adjust gains, system properties, etc). Can anyone familiar in this area do a quick check of my program to see if they spot any obvious errors?
Thanks in advance! Dave
%PID simulation------------------- %mass in kg m=1; %spring constant in n/m k=10; %dampening coefficient d=.5;
%starting point x1=1; %initial velocity v=0; %time step dt=.01; %matrix index i=1;
%gains gainp=50; gaini=50; gaind=10;
%desired position x_desired=2; %integrated error, initial value=0 is=0;
x=x1; t=0; while t