PID controller simulation help

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

Reply to
dave.harper
Loading thread data ...

You could always give your system a unit step input and check its output against that produced by Matlab's step() function to help verify your simulation.

I have written a small note on PID for spring-mass-damper, here is the link:

formatting link
Nasser

Reply to
Nasser Abbasi

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.