S-function Runtime-evaluation of parameters

3 visualizaciones (últimos 30 días)
Erik Voigt
Erik Voigt el 20 de Abr. de 2011
Hi
I have an S-function (written in c) which gets parameters through the S-function parameter-dialog. All parameters in this dialog are simply variables located in workspace. My ideal wish is now: When I change one of the parameters during simulation (by changing the corresponding workspace-variable) I want the S-function to use it without additional action. My solution so far is to mask the S-function and change a dummy-parameter inside this mask. This will force the mask to be initialized which again forces the S-function parameter-list to be evaluated, which again makes the updated values available inside the s-function.
It would be nice if I didn’t need to initialize the mask by doing this clicking around. Maybe some sort of “listener-functionality” exist?? Please note: Accessing the workspace from inside the S-function (which would solve this issue) is not an option due to code-generation-concerns.
Any good ideas?
Kind Regards Erik

Respuesta aceptada

Jarrod Rivituso
Jarrod Rivituso el 20 de Abr. de 2011
My understanding is that for efficiency reasons Simulink tries to avoid checking whether base workspace variables have changed during simulation.
You can force Simulink to check the workspace for parameter updates by updating the diagram (Edit -> Update Diagram). You can also do this from the command line:
>> set_param(gcs,'SimulationCommand','update')
I don't know if any true listener functionality currently exists.
  1 comentario
Erik Voigt
Erik Voigt el 26 de Abr. de 2011
Hi
First thanks for your reply. I think this community is really valuable and I relly like that people take time to handle other peoples problems. I will try to spend some time on this also now.
...and now the problem; yes I think this "update" is the only way, and its quiet easy for the user (no pseudo-mask needed). I will try to "sell" it internally here, lets see what they say.
KR
Erik

Iniciar sesión para comentar.

Más respuestas (2)

Paulo Silva
Paulo Silva el 20 de Abr. de 2011
On the S-Function try this:
eml.extrinsic('evalin');
var=evalin('base','var'); %var is a variable on the workspace
  1 comentario
Erik Voigt
Erik Voigt el 26 de Abr. de 2011
Hi
Thanks for your reply.
The old existing design does it this way (accesing the workspace from inside the S-function). But I wanted to remove this so it would work directly with the generated code (which is run on a dSPACE-system...just "another" HIL system). And I wanted to streamline the "data-connections" to the outside world, so everything comes in via parameters (before it was a mix).
KR
Erik

Iniciar sesión para comentar.


MarkB
MarkB el 21 de Abr. de 2011
This should be possible if you take two steps inside the S-function:
  1. You need to make the dialog parameters tuneable run-time parameters (This is a little bit complicated, but is covered by the documentation).
  2. You need to add a "mdlCheckParameters" function. This is an optional function for S-functions in general, but is likely required in your situation. Essentially, this function gets called when the S-function's dialog parameters get changed, and it provides you with an opportunity to "do whatever you need to do" (e.g. to validate the new values and propagate the effects of the changes to the rest of your code).
Although "mdlCheckParameters" will be called directly, it is also common and valid for your "mdlInitializeSizes" function to call it too, so that you don't have to have redundant code for validating the dialog parameters. (You don't generally call "mdlCheckParameters" blindly from "mdlInitializeSizes", because sometimes "mdlInitializeSizes" is being called just for propagating sizes, but there is an example in the documentation about the right checks to do in this case.)
  1 comentario
Erik Voigt
Erik Voigt el 26 de Abr. de 2011
Hi
Thanks for your reply.
I think I spend a whole working-day on setting this up, in the hope it would update automatically when the input-parameetr has changed (that it would actually listen for changes). But it is only updated when I update the diagram (see above). anopther issue is that this is not applicable in generated code for HIL-use, I have abandoned the idea and I continue to "poll" the parameters continously in a loop (with some delay so it will not slow down everything un-necesarily).
KR
Erik

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by