Using Simulink signal as a function variable (Real time Control System)

3 views (last 30 days)
I am working with an existing model of a brushless DC motor in order to simulate a control system I want to use on an actual motor. I have modeled a Fuzzy Logic controller that uses the error and change in error in order to actively tune the Proportional and Integral gains of the PI-controller, which is already built into the motor model I have. My problem is that the model I am using defines the P and I gains as constants within an S-function that runs as part of the simulation, whereas I would like input my tuned gains (which are constantly updating based on the simulation progression) in real-time.
I was originally saving the gain values to variables in the workspace, but these do not update until the end of the sim, and therefore are not helpful. I would like to be able to call these updated gains into the control function of the system in real time. Is this possible to do with the existing model? I realize that the 'best' approach would normally be to re-make my own model and use the gains as input signals in the system. However, as this is merely for simulation purposes, it is not worthwhile for me to spend time doing this - I merely would like it as a proof-of-concept.

Answers (2)

Ryan G
Ryan G on 17 Jul 2012
Edited: Ryan G on 17 Jul 2012
You need to make sure the P and I gains are Tunable Parameters in the s-function. Based on what you have already written about your issue it sounds like they are not tunable.
  7 Comments
Ryan G
Ryan G on 17 Jul 2012
If you look at the script for the EML I wrote you see I utilize assignin. This updates the base workspace parameter. After that the set_param function is essentially triggering the block, in this case an s-function, to determine that it has updated the parameter and will re-check the workspace for that parameter and update accordingly.
Will
Will on 17 Jul 2012
How is it that the parameter is being updated from the signal in this case? I guess more generally, what sort of sink do I need for the output of my controller so that the output is assigned to the variable 'A'?

Sign in to comment.


Will
Will on 17 Jul 2012
Edited: Will on 17 Jul 2012
I've found some partial answers to my question, although it doesn't seem to address my individual case. In any event, they are posted below in the hopes that others may find it useful.
I also found a temporary workaround, although it's somewhat sloppy and greatly slows the simulation speed. I've added a set_param('model','SimulationCommand','update') line into my s-function code. The output signals from my controller are being written to workspace variables, and the line of code above forces the model to update each time around. As I said, somewhat sloppy, and it increases the simulation time by about 100x, so I'm continuing to look for other methods.
  4 Comments
Ryan G
Ryan G on 17 Jul 2012
If u is currently your input you can expand the mux with Kp and Ki and call it like:
Kp = u(5);
Ki = u(6);
This would of course depend on how big the input mux is and the position of those two values on the mux.
Will
Will on 18 Jul 2012
And all along my problem was the mux!
I wasn't aware that the u(x) was referencing the mux input x, I had thought that was a system function it was referencing. Also for a note to anyone doing the same thing, you have to change the sizes.NumInputs to agree with the size of your mux. Also, in my case, I ran into some data dependency errors with the action blocks within my subsystems. Those can be taken care of by adding in a memory block in the loop before the action subsystem is accessed.
Everything seems to be working great now, thanks again for your incredible help!

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!