You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Implementation of a multiple PI controller in Simulink
25 views (last 30 days)
Show older comments
Hi! I am having issues on creating a multiple PI-controller for a state-space model with two state variables as shown. This was a demo code from Matlab which is very similar to what I am trying to implement. The full state-space model equation is executed below from the given variables. When I create the simulink to implement multiple PI controller to tune both the state variable (X1 and X2), Simulink always shows an error that the dimensions doesn't match. Please see the error below.
a = [-0.5572,-0.7814;0.7814,0]; b = [1,-1;0,2]; c = [1.9691,6.4493]; sys = ss(a,b,c,0); step(sys)
>> sys
sys =
A =
x1 x2
x1 -0.5572 -0.7814
x2 0.7814 0
B =
u1 u2
x1 1 -1
x2 0 2
C =
x1 x2
y1 1.969 6.449
Accepted Answer
Birdman
on 26 Oct 2017
Edited: Birdman
on 26 Oct 2017
You have not entered the D matrix correctly. Your output is 1x1 scalar in the way you constructed your state space model because your C matrix is 1x2, the X vector is 2x1, then the multiplication will be 1x1 scalar. D matrix has to be 1x2 vector. DON'T USE ANY DEMUX AT THE OUTPUT SINCE YOUR OUTPUT IS 1x1. I made the same model and it worked for me without errors, in this case, enter your D matrix as:
D=[0 0];
28 Comments
Mr. NailGuy
on 26 Oct 2017
Hi, thanks for the reply. I did place a D matrix = [0 0] and this was the error I have. In the simulink model do you mean that I only need to remove the demux? How should I fed it back to the sum? Thanks
Mr. NailGuy
on 26 Oct 2017
Thanks, it looks like working now for the first model I posted but I don't understand what happens when I change the SS model like the one shown below. How many cascaded PI controller should I place for this model? Does the PI controller depends on the number of input to output? How would I see that on the SS model? I would appreciate your reply on this. Thanks
sys =
A =
x1 x2 x3 x4
x1 -0.07814 0.02234 0.0558 0
x2 0.007447 -0.06332 0 0.0558
x3 0.151 0 -0.1747 0.01741
x4 0 0.151 0.005802 -0.1632
B =
u1 u2
x1 0.0002325 0
x2 0 0.0002325
x3 0 0
x4 0 0
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 0 0
y2 0 0
y3 0 0
y4 0 0
Mr. NailGuy
on 26 Oct 2017
How would I decompose the signals (y1, y2) coming off from the state space model to feed it back on my system? Lets say I am only interested on y1, how would I get it from my SS model block without using demux?
Birdman
on 26 Oct 2017
Firstly, the number of PI controllers depend on the number of inputs you have and they will not be in cascade form. In this new system, you still have 2 inputs, 4 states, and you want to see 4 outputs which y=x vector. Now, according to this state space equation, you apply u1 input to the x1 state and u2 input to the x2 state. Therefore, there is a control loop going on with x1 and x2. Since you do not apply control signal to x3 and x4, it does not make any sense that you want to see them as output. If we reorganize the equation according to my perspective, you will change the C matrix.
C=
1 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0
At this point, you still have 4 outputs but the output vector will be
y=
x1
x2
0
0
If you still want to see x3 and x4, you keep the C matrix as you defined it, but you can suppress x3 and x4 with a terminator.(I will provide an example)
If you have 4 outputs, that means you have to seperate them WITH A DEMUX because x1 and x2 have different inputs, which means YOU SHOULD HAVE 2 PI CONTROLLERS. (If you are only interested in y1=x1, then you have to change your C matrix as C=[1 0 0 0]) If you look at the attached figure, you will see the structure according to your new example. There are 4 outputs, WHICH HAVE TO BE SEPARATED WITH A DEMUX, 2 inputs and the control scheme. Please note the signal dimensions.
REMEMBER, SYSTEMS WITH MULTIPLE OUTPUTS NEEDS TO USE DEMUX AND THE NUMBER OF PI CONTROLLERS DEPEND ON THE NUMBER OF INPUT(IN THIS EXAMPLE, 2) AND THEY WILL BE IN PARALLEL FORM.
Mr. NailGuy
on 26 Oct 2017
Thank you @cvklpstunc, you indeed explained it very well and very detailed. As a side question, is it possible to implement parallel PI/PID Control by only using the command line instead of placing it in Simulink? Also, how do we change the setpoint of a system by driving it on a certain value, e.g. 90 degrees Celsius? Is it placed on the step input? I would really appreciate any help or answer you may give.
Birdman
on 26 Oct 2017
It is possible to implement PI or PID control in command line. By typing:
Fpi=tf([Kp Ki],[1 0]);
Fpid=tf([Kd Kp Ki],[1 0]);
(THESE ARE IDEAL STRUCTURES AND YOU HAVE TO INSERT NUMERICAL VALUES, I JUST SHOWED AS AN EXAMPLE)
Please use a filter for PID when implementing it.
Imagine your system is shown with sys, you can create closed loop structure by:
Ts=feedback(Fpi*sys,1);
or
Ts=feedback(Fpid*sys,1);
Note that you have to convert your ss representation to tf by using
ss2tf
You can change the setpoint of a system by giving a step input. Your controller will generate the necessary control signal to the system if your controller's performance is good. You can use
step(Ts)
command.
Mr. NailGuy
on 26 Oct 2017
Thanks cvklpstunc, I thought I can directly use Ts=feedback(Fpid*sys,1) to the MIMO SS model?
Birdman
on 26 Oct 2017
Yes, but be careful with indexing since there will be multiple transfer function between each output and input.
Mr. NailGuy
on 26 Oct 2017
Hi cvklpstunc, thanks! Trying to figure it out. Since my current system already requires 5 inputs to control with PI control.
Mr. NailGuy
on 27 Oct 2017
Edited: Mr. NailGuy
on 27 Oct 2017
Hi cvklpstunc, I tried implementing the PI controller to my SS model with 5 inputs and 10 outputs but I couldn't get it using the command line and it was giving errors. Can you give me any solution to this? I tried using a stack PI but it doesn't work either. I don't know how to work with this. I posted my current SS model and I don't know how to use a PI controller to control each Input to Output. All my PI controller will have the same parameter (I guess) coz all the outputs must have similar response. I would appreciate any feedback you may have.
Mr. NailGuy
on 27 Oct 2017
Edited: Mr. NailGuy
on 27 Oct 2017
>> sys
sys =
A =
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
x1 -0.1954 0.1396 0 0 0 0.0558 0 0 0 0
x2 0.04654 -0.2024 0.1001 0 0 0 0.0558 0 0 0
x3 0 0.06006 -0.207 0.09118 0 0 0 0.0558 0 0
x4 0 0 0.06513 -0.2081 0.0872 0 0 0 0.0558 0
x5 0 0 0 0.06782 -0.1238 0 0 0 0 0.0558
x6 0.151 0 0 0 0 -0.2661 0.1088 0 0 0
x7 0 0.151 0 0 0 0.03626 -0.2715 0.07799 0 0
x8 0 0 0.151 0 0 0 0.04679 -0.2751 0.07104 0
x9 0 0 0 0.151 0 0 0 0.05074 -0.276 0.06794
x10 0 0 0 0 0.151 0 0 0 0.05284 -0.2103
B =
u1 u2 u3 u4 u5
x1 0.0002325 0 0 0 0
x2 0 0.0002325 0 0 0
x3 0 0 0.0002325 0 0
x4 0 0 0 0.0002325 0
x5 0 0 0 0 0.0002325
x6 0 0 0 0 0
x7 0 0 0 0 0
x8 0 0 0 0 0
x9 0 0 0 0 0
x10 0 0 0 0 0
C =
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
y1 1 0 0 0 0 0 0 0 0 0
y2 0 1 0 0 0 0 0 0 0 0
y3 0 0 1 0 0 0 0 0 0 0
y4 0 0 0 1 0 0 0 0 0 0
y5 0 0 0 0 1 0 0 0 0 0
y6 0 0 0 0 0 1 0 0 0 0
y7 0 0 0 0 0 0 1 0 0 0
y8 0 0 0 0 0 0 0 1 0 0
y9 0 0 0 0 0 0 0 0 1 0
y10 0 0 0 0 0 0 0 0 0 1
D =
u1 u2 u3 u4 u5
y1 0 0 0 0 0
y2 0 0 0 0 0
y3 0 0 0 0 0
y4 0 0 0 0 0
y5 0 0 0 0 0
y6 0 0 0 0 0
y7 0 0 0 0 0
y8 0 0 0 0 0
y9 0 0 0 0 0
y10 0 0 0 0 0
Continuous-time state-space model.
Mr. NailGuy
on 27 Oct 2017
A= [-0.195429488210779 0.139632891356814 0 0 0 0.0557965968539647 0 0 0 0;0.046544297118938 -0.202441856812835 0.100100962839933 0 0 0 0.0557965968539647 0 0 0;0 0.0600605777039597 -0.207039978754366 0.091182804196442 0 0 0 0.0557965968539647 0 0;0 0 0.06513057442603 -0.208127218644787 0.0872000473647922 0 0 0 0.0557965968539647 0;0 0 0 0.067822259061505 -0.123771952133381 0 0 0 0 0.0557965968539647;0.150978670161252 0 0 0 0 -0.266061010999781 0.108791562915143 0 0 0;0 0.150978670161253 0 0 0 0.0362638543050478 -0.271524527027716 0.0779912246380304 0 0;0 0 0.150978670161253 0 0 0 0.0467947347828183 -0.275107041631781 0.0710428587643246 0;0 0 0 0.150978670161253 0 0 0 0.0507448991173748 -0.275954138084438 0.0679397908824247;0 0 0 0 0.150978670161252 0 0 0 0.0528420595752192 -0.210312719356696]
Mr. NailGuy
on 27 Oct 2017
B=[0.000232485820224853 0 0 0 0;0 0.000232485820224853 0 0 0;0 0 0.000232485820224853 0 0;0 0 0 0.000232485820224853 0;0 0 0 0 0.000232485820224853;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0]
Mr. NailGuy
on 27 Oct 2017
C=[1 0 0 0 0 0 0 0 0 0;0 1 0 0 0 0 0 0 0 0;0 0 1 0 0 0 0 0 0 0;0 0 0 1 0 0 0 0 0 0;0 0 0 0 1 0 0 0 0 0;0 0 0 0 0 1 0 0 0 0;0 0 0 0 0 0 1 0 0 0;0 0 0 0 0 0 0 1 0 0;0 0 0 0 0 0 0 0 1 0;0 0 0 0 0 0 0 0 0 1]
Mr. NailGuy
on 27 Oct 2017
D=[0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0]
Birdman
on 27 Oct 2017
By the way, why command line? Simulink is more effective and useful for this process.
Mr. NailGuy
on 27 Oct 2017
Yeah you're right, however I need to get the min and max of my graph. I don't know how to use simulink for that. Could you provide me your email so I can send the whole code?:)Thanks
Birdman
on 27 Oct 2017
You can write a MATLAB Function and take your outputs and give them as input to the MATLAB Function in Simulink. Then inside, by using the min and max command of MATLAB, you can easily find the minimum and maximum of the graph.
Mr. NailGuy
on 27 Oct 2017
Now I saw the minmax block for Simulink. I will try it now and see how it goes :-)
Birdman
on 27 Oct 2017
Exactly, try those, and use Simulink always if possible for control processes.
Mr. NailGuy
on 27 Oct 2017
You're correct. Hope my Simulink works, if not then maybe I would ask for your help. I will send the code so you could have a check of it. You already gave me a big help.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)