PID controller simulation help

Sep 22, 2005 1 Replies

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


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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required