purpose of state-space with pid

Hi everyone! I am having problem that when I connect state space block to PID and take its output as feedback in simulink I get a plot that converges at reference value; now I have to do the same job in mfile I have done the coding for pid but I am not getting idea that; what is the purpose of state space connected with pid so that I can write code for it.

 Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 11 Oct 2012
Edited: Azzi Abdelmalek on 11 Oct 2012
clear,close
%your model and its input output
mot=tf(1,[1 1]),
model=ss(mot);
[F,h,c,d]=ssdata(model);
model.u='u'
model.y='y'
%your pid controller
r=pid(5,1/0.05,10)
r.u='e'
r.y='u'
%adding a reference r with som2=r-y
som1 = sumblk('e = r - y');
%global model with all conneection
modelg=connect(som1,r,model,'r','y')
%simulation
step(modelg)

27 Comments

Sir its giving error at model y='y' and the statement of error is 'Invalid property name y'
the first code or the second? have you control system toolbox?
First code sir and I am having control system toolbox.
clear then run my code and tell me which line is making error
azan
azan on 11 Oct 2012
Edited: azan on 11 Oct 2012
ok Sir and what about 'P' in your code?
first, did the first code work or no?
first code didn't work,however your code is running but I am not sure of the value P
p is the disturbance signal added to your output, you can set it to zero
I've tested the two codes, they both work
And sir I have to give input from my sensor and compare it with my reference value.Sir I need to know where that input value will be in this code.
why are 'nt you using simulink? how are you connecting your sensor to your computer and matlab?
azan
azan on 11 Oct 2012
Edited: azan on 11 Oct 2012
actually instead of sensor my image processing code is dong the job and it is done in mfile
strange but even your code is not running for p=0
forget a disturbance signal look at the edited answer
It is still not working at model.y='y'
which version of matlab are you using?
matlab 7.8(2009)a
when you click on >>model
what do you get?
a = x1 x1 -1
b = u1 x1 1
c = x1 y1 1
d = u1 y1 0
know, when you click model.u and model.y what is the result?
Sorry sir I couldn't get this what do you mean by clicking model.u and model.y? Now the error is 'Invalid property name "y". Type "help ltiprops" for more information on valid LTI properties.'
azan have you copied and past my code or what? because I see in your error message , model y (it's no my code) it's model.y (you missed a dote)
No it was just a typing mistake.I have written model.y Infact I have just copied your code
I can't explain what is going on, because, whe I run my code it works fine
Thank you sir for your time and effort I will try to figure it out
Sir code is working now and the issue was I had to write like this model.inputname='u' model.outputname='y'
Sir can you now tell me where is that input(e.g 6 taken from image processing part) in this code which I have to compare with the reference value

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!