How to give input from sensor to pid in matlab (mfile)

조회 수: 3 (최근 30일)
Beenish Mazhar
Beenish Mazhar 2012년 10월 21일
I am trying to implement the system in matlab(mfile)which I have uploaded at:
My system has two portions Image processing(sensor) & control systems. The piece of code is:
clear,close
%your model and its input output
mot=tf(1,[1 1]),
model=ss(mot);
[F,h,c,d]=ssdata(model);
%your pid controller
r=pid(5,1/0.05,10)
sys.inputname='u'
sys.outputname='y'
Ci.inputname='e';
Ci.outputname='u';
som1 = sumblk('e = r - y');
%global model with all conneection
modelg=connect(som1,r,model,'r','y')
%simulation
step(modelg)
Above code is the model representing the PID then statespace and then its output as feedback but I have to give input from my sensor(image processing part e.g 3) and compare it with my reference value. I need to know where that input value will be adjusted in this code. Any guidance would be highly appreciated.

답변 (1개)

Arkadiy Turevskiy
Arkadiy Turevskiy 2012년 10월 23일
편집: Arkadiy Turevskiy 2012년 10월 23일
Your code does not make sense at the moment. Specific issues:
  1. You define input and output names for variables sys and Ci, as if they are meant to represent a plant and the controller, but your plant is stored in variable mot, and your controller is in variable r
  2. You use function connect in the wrong way - please see documentation on the input arguments and their right order
The correct code would be:
clear,close
%your model and its input output
mot=tf(1,[1 1]);
mot.inputname='u';
mot.outputname='y';
%your pid controller
r=pid(5,1/0.05,10);
r.inputname='e';
r.outputname='u';
% summation junction
som1 = sumblk('e = r - y');
%global model with all conneection
modelg=connect(mot,r,som1,'r','y');
%simulation
step(modelg);
% another way to do the same
step(feedback(r*mot,1));
Arkadiy
  댓글 수: 1
Beenish Mazhar
Beenish Mazhar 2012년 11월 5일
It was a certain typing mistake. My code is: clear,close
%your model and its input output
mot=tf(1,[1 1]),
Ci=pid(5,1/0.05,10)
[ne,de]=tfdata(mot,'v');
[A,B,C,D]=tf2ss(ne,de);
inputs = {'u'};
output = {'y'};
sys = ss(A,B,C,D,'inputname',inputs,'outputname',output);
sys.inputname='u';
sys.outputname='y';
Ci.inputname='e';
Ci.outputname='u';
%adding a reference r with som2=r-y
som1 = sumblk('e','r','y','+-');
%global model with all connection
modelg=connect(sys,Ci,som1,'r','y')
I have to add the value taken from sensor as mentioned above. How to adjust that in the above code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 PID Controller Tuning에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by