The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Strategy for interfacing c-mex s-function with external model
Replies: 5   Last Post: Jan 9, 2012 6:11 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Kate J.

Posts: 177
Registered: 6/9/11
Strategy for interfacing c-mex s-function with external model
Posted: Jan 9, 2012 3:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.