How to customize a Built-in PID Block?

I am using a PID controller in a feedback system. I need to change the gain's multiplication type from element-wise to the matrix. I right clicked on the PID block then from link options, I disabled the link. Now after I looked under the mask, I could change the Gain's multiplication type. but after I save the model and run the simulation again everything goes back to its initial settings like I never applied any change! So my question is How can I customize the PID block in SIMULINK?

2 comentarios

Ryan G
Ryan G el 8 de Oct. de 2012
Since you are doing matrix multiplication are you implying that this will have more than 1 input to the PID?
Mike
Mike el 8 de Oct. de 2012
Yes, i have 6 inputs. 3 of them are positions and others are velocities.
i uploaded my model so you can take a look inside it easier. http://fs1.filegir.com/pamadour/model.zip run Main.m it will execute the model automatically. first the model should run without any errors because i am using my own PID block (blue block). then you can substitute this with the MATLAB's built-in block (it exists unattached above the model), although i have set all initial fcn's but still it doesn't work. please note that the PID gains are P, I and D which come from the workspace.

Iniciar sesión para comentar.

 Respuesta aceptada

Arkadiy Turevskiy
Arkadiy Turevskiy el 8 de Oct. de 2012
Editada: Arkadiy Turevskiy el 8 de Oct. de 2012

1 voto

Hello Mike,
At the moment, you won't be able to customize the standard PID block and still retain the automatic tuning functionality. The best workaround I can suggest is creating your own block for implementation, and using the standard block for tuning. Once the gain are tuned using the standard block, you can use them in your customized block. You could probably somewhat automate the process by using block callbacks and variants.
Arkadiy

2 comentarios

Mike
Mike el 8 de Oct. de 2012
Dear Arkadiy
Thanks for your answer but how can i use Standard block for tuning while using it causes errors in my system?
Standard blocks use element-wise multiplication which cause to dimension error. if the multiplication type is matrix no error will occur. you can look at my system here: http://fs1.filegir.com/pamadour/model.zip
Arkadiy Turevskiy
Arkadiy Turevskiy el 19 de Oct. de 2012
Hello Mike, PID Controller block in Simulink, as well as the PID Tuner, only work on SISO systems. For a MIMO system, you need to specify your controller as a set of SISO PID loops. PID Tuner would not be able to tune a multi-loop design, you will need to use tools from Robust Control Toolbox, like shown in this example.
Arkadiy

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Oct. de 2012
Editada: Azzi Abdelmalek el 4 de Oct. de 2012
I see your problem, but you can change these setting by code, just after loading your model named 'model.mdl'
set_param('model/PID Controller/Proportional Gain','Multiplication','Matrix(K*u)')
or you can associate this code with your model:
right click on your model- properties-callbacks-init Fcn (copy and paste the code)

10 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Oct. de 2012
Check the setting after simulation
Mike
Mike el 4 de Oct. de 2012
Dear Azzi
Thanks for the answer. i used your codes, after my model loaded i looked under the mask and everything was fine, i mean the multiplication type was changed to Matrix as i wanted so i got happy and executed my model but i got This Error:
Error in port widths or dimensions. Output port 1 of 'model/PID Controller/u' has 6 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
So i looked under the mask again and surprisingly i saw that the multiplication type is changed back to Element-Wise again! i really don't know why this happens, i will appreciate if you can provide me any further help.
Azzi Abdelmalek
Azzi Abdelmalek el 4 de Oct. de 2012
Editada: Azzi Abdelmalek el 4 de Oct. de 2012
Mike, This is another question. It's difficult to answer if we haven't your model. And I think, maby you should make the same change to Integral gain and Derivative Gain. Because their outputs will be additionned
Mike
Mike el 4 de Oct. de 2012
Azzi i had applied the same change on Integral and Derivative gains too.
i get this error because the multiplication type is not matrix.
before i run the model the Multiplication type is set to matrix but after i press the start button the multiplication type automatically changes back to element-wise so i get this error.
Azzi Abdelmalek
Azzi Abdelmalek el 4 de Oct. de 2012
Editada: Azzi Abdelmalek el 4 de Oct. de 2012
I don't think you did what I suggested:
  • In your model named model.mdl right click
  • then click on model properties
  • then click on Callbacks
  • then click on init fcn and place this code for your 3 gain
set_param('model/PID Controller/Proportional,...
Gain','Multiplication','Matrix(K*u)')
set_param('model/PID Controller/Integral,...
Gain','Multiplication','Matrix(K*u)')
set_param('model/PID Controller/Derivative,...
Gain','Multiplication','Matrix(K*u)')
Yes after simulation the setting will change, but no worries at the begening of each simulation, the above code will be executed
If you want keep the setting unchanged, place again the same code in callbacks stop - fcn
Mike
Mike el 5 de Oct. de 2012
Azzi i followed your answer step by step but unfortunately i got the same error. i uploaded my model so you can take a look inside it easier. http://fs1.filegir.com/pamadour/model.zip run Main.m it will execute the model automatically. first the model should run without any errors because i am using my own PID block (blue block). then you can substitute this with the MATLAB's built-in block (it exists unattached above the model), although i have set all initial fcn's but still it doesn't work. please note that the PID gains are P, I and D which come from the workspace.
Azzi Abdelmalek
Azzi Abdelmalek el 6 de Oct. de 2012
Editada: Azzi Abdelmalek el 6 de Oct. de 2012
Mike, I 'am getting, errors too, but it has nothing to do with the setting of Multiplication
If I find something, I will post it.
Mike
Mike el 6 de Oct. de 2012
Ok, thank you.
Azzi Abdelmalek
Azzi Abdelmalek el 6 de Oct. de 2012
Editada: Azzi Abdelmalek el 6 de Oct. de 2012
I think the setting vanishes just when the simultion start, not after like I said. I suggest to Edit mask of your PID block then unmask it. when you start simulations other errors will occur, asking about:
  • output/param (min/max). set them to []
  • datatype(etc...) set them to double
save the target of this link
Mike
Mike el 7 de Oct. de 2012
Thanks, but it is like the controller which I made by my own. I can't use PID Tuner in this case.

Iniciar sesión para comentar.

Babak
Babak el 3 de Oct. de 2012

0 votos

You don't want to edit Simulink's Built in blocks.
Instead you want to create your own custom blocks. You could do it with creating an S-function block and creating a mask for it or making a MATLAB based block which runs an m-file.

1 comentario

Mike
Mike el 3 de Oct. de 2012
Dear Babak
I can create a simple PID controller in Simulink. but the Matlab's built-in PID block has advanced features Like "Tune" which helps me to select the proper Gain coefficients by visualizing the overshoot, settling time.. etc.
that's why i need to find a way to customize the Simulink's built-in PID block.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by