Error using InputOutputModel/feedback
16 views (last 30 days)
Show older comments
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 Comment
Sam Chak
on 11 Jul 2024 at 20:03
Hi @Jahir
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)
Answers (1)
Sam Chak
on 11 Jul 2024 at 20:28
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)
Gp2 = Gp(3,2)
%% PID Controllers
kp1 = -0.3025;
ki1 = 2.2766;
kd1 = 0.9694;
Tf1 = 0.1329;
Gc1 = pid(kp1, ki1, kd1, Tf1)
Gc2 = pidtune(Gp2, 'PIDF')
%% Closed-loop subsystems
CL1 = minreal(feedback(Gc1*Gp1, 1))
CL2 = minreal(feedback(Gc2*Gp2, 1))
%% Step responses
step(CL1), grid on
step(CL2), grid on
0 Comments
See Also
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!