structs as input to simulink s-function blocks
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
as a Simulink newbie I'm at a loss here, perhaps someone can give me some advice.
---- lengthy background information ---->
I've inherited a tool consisting of a Simulink model and some Matlab functions it is called from.
The tool is for parametrizing a vehicle controller and uses Simulink functions like operspec, findop and linearize to find operating points and linearizations of a vehicle model.
While the Simulink *.mdl look fairly simple, the vehicle model is coded in C and is massively parametrized, parameters being held in nested structs. The model code (shared code with standalone C-simulation) is capsuled in C S-functions.
The whole thing is working well at the present but has one massive drawback: knowledge of the simulation parameters is shared between Simulink S-function blocks by global variables: For example the C-struct actuator_par is used by 2 S-function blocks, StepActuators and StepVehicle. Both S-functions are linked against a shared library which holds a global C-struct actuator_par. This variable is initialized by a mex-function, linked against the same shared library and called from Matlab before initializing the Simulink model.
---- lengthy background information ----<
What I'm trying to do now is to get rid of the global C-variable commonication between blocks.
I have recently capsuled all relevant functions of the C-simulation into mex-Files including the tedious work of translating between C-structs and equivalent Matlab-structs, in order to be able to use the very same C-simulation code for parameter optimization utilizing the optimization toolbox.
Thus I hoped, I could do something along these lines (example):
- add actuator_par as S-function parameter to the block StepActuators
- define the M-struct actuator_par using the appropriate Mex-capsuled initialization routine, thus creating a struct variable in the matlab workspace
- access this variable from within the S-function block and translate it into a C-struct just as I do within the mex capsule, perhaps just substituting ssGetSFcnParam(S, 0) for prhs[0].
I tried this and the S-function compiles without warnings, operspec complains justly when there is no variable actuator_par defined within the Matlab base workspace. However when I provide actuator_par I get a new set of error messages that seem very non-descriptive to me, for example:
Conversion to logical from struct is not possible.
Error in opcond.AbstractOperatingPoint/update (line 56)
if RunParameterManager
Error in operspec (line 109)
So, before I try to figure out what this message means, can anybody tell me if my approach is even possible? I'm open to other suggestions, the main goal is to have all S-function blocks within the model have access to a set (constant) parameter C-structs and, if possible, a second set of (not constant) state C-structs.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Block and Blockset Authoring finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!