How can I set a reference value in PID in Matlab code/script?

1 次查看(过去 30 天)
For example I have the following code which also include Transfer function. When I run this program, I want this program to tune my transfer function to a reference point of 0.1 however I have no clue how to do it.
clear all
clc
syms numerator denomenator Gp H Ts Gc Ka
numerator = [1];
denomenator = [1 0.3 0];
Gp = tf(numerator, denomenator)
H = [1];
Ts = feedback(Gp, H)
%%
Kp = 16;
Ki = 0;
Kd = 20;
Gc = pid(Kp, Ki, Kd)
Ka = 2;
Mc = feedback(Ka*Gc*Gp, H)
step(Mc)
hold on
grid on

回答(1 个)

Raj
Raj 2019-4-19
Since you have put "step(Mc)" the closed loop system Mc is showing step response plot and tracking the value '1'.
Your requirement is for your closed loop system to track a reference of 0.1. Use this:
t = 0:0.1:10; %Simulation runs for 10 seconds with 0.1 sec sampling time
u_ref = 0.1*ones(size(t)); %Reference signal
u_input=zeros(size(t)); % input signal to the closed loop system
% now feed the difference of input and reference signal to your closed loop system and see the time response.
% The closed loop system will track and settle at the reference signal.
lsim(Mc,u_ref-u_input,t)
Hope this is what you are asking. If not please elaborate on your problem statement.

类别

Help CenterFile Exchange 中查找有关 Classical Control Design 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by