Error using InputOutpu​tModel/fee​dback

조회 수: 10 (최근 30일)
Jahir
Jahir 2024년 7월 11일
답변: Sam Chak 2024년 7월 11일
Hi,
I am new to designing controller. Here is my code
m = 4; %mass of the system
g = 9.8; %gravitational force
A = [0, 1, 0, 0;
-g/m, 0, 0, 0;
0, 0, 0, 1;
0, 0, -g/m, 0];
B = [0, 0;
1/m, 0;
0, 0;
0, 1/m];
C = eye(4); %identity matrix
D = [1,0;
0,1;
0,0;
0,0];
Kp = 1;
Ki = 1;
Kd = 1;
inputSignal = pid(Kp,Ki,Kd);
sys = ss(A,B,C,D);
closedLoop = feedback(sys*inputSignal,1);
It gives me below error
Error using InputOutputModel/feedback (line 137)
The first and second arguments of the "feedback" command must have compatible I/O sizes.
Error in pidmodel (line 29)
closedLoop = feedback(sys*inputSignal,1);
I am not sure what's wrong.
  댓글 수: 1
Sam Chak
Sam Chak 2024년 7월 11일
The error message you encountered is likely due to the fact that your system has two control inputs ( and ), but you have implemented a single PID controller (for by default). This creates a dimension mismatch when you used the feedback() command.
You may be wondering, "What should I do to resolve this error? Can I use two PID controllers in a single system?"
Without knowing the specific control objectives for your system, it is challenging to provide a definitive recommendation. However, if your goal is to simply "stabilize" the system without any specific measurable or quantifiable control targets, applying the Linear Quadratic Regulator (LQR) method with the standard Q, R weights may be the easiest approach. This is because the LQR method does not require the two-step design process of calculating the desired poles and then applying a pole-placement algorithm to compute the required control gains.
m = 4; % mass of the system
g = 9.8; % gravitational force
A = [0, 1, 0, 0;
-g/m, 0, 0, 0;
0, 0, 0, 1;
0, 0, -g/m, 0];
B = [0, 0;
1/m, 0;
0, 0;
0, 1/m];
C = eye(4); % identity matrix
D = [1, 0;
0, 1;
0, 0;
0, 0];
sys = ss(A, B, C, D)
sys = A = x1 x2 x3 x4 x1 0 1 0 0 x2 -2.45 0 0 0 x3 0 0 0 1 x4 0 0 -2.45 0 B = u1 u2 x1 0 0 x2 0.25 0 x3 0 0 x4 0 0.25 C = x1 x2 x3 x4 y1 1 0 0 0 y2 0 1 0 0 y3 0 0 1 0 y4 0 0 0 1 D = u1 u2 y1 1 0 y2 0 1 y3 0 0 y4 0 0 Continuous-time state-space model.

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

답변 (1개)

Sam Chak
Sam Chak 2024년 7월 11일
Here is a simple to demo to achieve steady-state errors using two PID controllers.
%% State-space system
m = 4; % mass of the system
g = 9.8; % gravitational force
A = [0, 1, 0, 0;
-g/m, 0, 0, 0;
0, 0, 0, 1;
0, 0, -g/m, 0];
B = [0, 0;
1/m, 0;
0, 0;
0, 1/m];
C = eye(4); % identity matrix (it means all states are measurable)
D = [1, 0;
0, 1;
0, 0;
0, 0];
sys = ss(A, B, C, D);
%% Decoupled Plant transfer functions for x1 (s.t. input u1) and x3 (s.t. input u2)
Gp = tf(sys);
Gp1 = Gp(1,1)
Gp1 = s^2 + 2.7 ---------- s^2 + 2.45 Continuous-time transfer function.
Gp2 = Gp(3,2)
Gp2 = 0.25 ---------- s^2 + 2.45 Continuous-time transfer function.
%% PID Controllers
kp1 = -0.3025;
ki1 = 2.2766;
kd1 = 0.9694;
Tf1 = 0.1329;
Gc1 = pid(kp1, ki1, kd1, Tf1)
Gc1 = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = -0.302, Ki = 2.28, Kd = 0.969, Tf = 0.133 Continuous-time PIDF controller in parallel form.
Gc2 = pidtune(Gp2, 'PIDF')
Gc2 = 1 s Kp + Ki * --- + Kd * -------- s Tf*s+1 with Kp = 136, Ki = 93.9, Kd = 42.7, Tf = 0.00839 Continuous-time PIDF controller in parallel form.
%% Closed-loop subsystems
CL1 = minreal(feedback(Gc1*Gp1, 1))
CL1 = 0.8749 s^4 + 5.662e-05 s^3 + 4.506 s^2 + 0.0001529 s + 5.787 ------------------------------------------------------------ s^4 + 0.9416 s^3 + 4.812 s^2 + 2.307 s + 5.787 Continuous-time transfer function.
CL2 = minreal(feedback(Gc2*Gp2, 1))
CL2 = 1306 s^2 + 4063 s + 2796 ------------------------------------------ s^4 + 119.1 s^3 + 1309 s^2 + 4355 s + 2796 Continuous-time transfer function.
%% Step responses
step(CL1), grid on
step(CL2), grid on

카테고리

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

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by