I have a c-mex s-function block that is called from my Simulink model. This Simulink model also contains a block that contains a biomechanical model (it receives muscle activations as inputs, and outputs joint angles).
What I?m aiming to do: have my c-mex s-function (controller component) calculate activation output values that will, at each timestep, be applied to the biomechanical model. The biomechanical model will then calculate joint angle outputs, and return them to the c-mex s-function as inputs for the next timestep. From my current knowledge about this system, I believe that there are at least 2 possible ways to accomplish this:
a) Have the mdlOutputs() function within my c-mex s-function calculate the output activation values at each timestep, which should then be applied to the biomechanical model block that receives input from this c-mex s-function block. (Question: I know that mdlOutputs() executes at every timestep; how can I assure that the activation values just calculated in this timestep are the values being passed to the biomechanical model block? And, can I assume that the biomechanical model block will execute at every timestep, each time it receives a new set of input values, or is there some timer or other trigger mechanism that needs to be set up to assure this?)
b) Remove the biomechanical model block from my Simulink model. Instead, use a call to a function in an existing .dll that calls a non-Simulink version of this biomechanical model. Apparent advantage: it seems that I would have more control about when this model executes, rather than being tied to it executing following every mdlOutputs() execution at each timestep. (This is a concern, because I?m going to want to perform a series of episodes, with each episode consisting of an unknown number of mdlOutputs() executions, and it seems like flexibility in calling the model would be a good thing.) However, I could just be perceiving this function-call method as more ?controllable? than the Simulink block method ? can someone clarify whether there would be an advantage of using one method over the other? ~ One additional consideration: the .dll that contains the biomechanical model function I?d like to use is written in C++, whereas my c-mex s-function is, of course, in C. However, it doesn?t appear that there are many real syntax differences, apart from minor issues such as comment indicators, etc. In another part of my system, the ?extern C? keyword is used to make C++ code compatible with my C code, so I?m thinking that this *may* be an option here, as well.
Thanks for any input you have about which of the 2 methods above makes more sense for what I?m trying to accomplish.