Legacy C code function o/p mismatch in simulink
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi,
I am facing a unique problem here, must be some mistake of mine but I'm not able to see it.
I am using a legacy c function which is a mathematical model of an engine providing thrust as output. Now here is the problem:
When I am running the function as a c project independently, with some constant i/p's for one sample time, it is giving me correct results. In Simulink, after reading the documentation, I've made a s-function using the s-function builder as well as the legacy code tool. I am running the model with the same set of constant i/p's for one sample time(solver:fixed step), it is giving some completely different results, whereas the same function when run in a c compiler is giving correct results. I'm trying all the mentioned methods as mentioned to create the s-functions, but it is ending with the same result.I've tried with all the fixed step solvers just to check, but its the same.
I have also tried creating a mex function which I am calling from an embedded matlab function, this one is giving me correct results! Since I don't want to include an embedded matlab function in my model, s-function is my preference.
My objective is to include this legacy function in an aerospace non-real time simulation model which I have already made which uses the fixed step ODE4(R-K method) as the solver.
Will be really glad if some one sheds any light on this.
Regards, Devjit
Answers (1)
Kaustubha Govind
on 6 Mar 2012
0 votes
It's hard to tell just from your description, but it looks like you might not be setting up your S-function correctly. What is your function's prototype? Have you ensured that the S-function's inputs and outputs have been configured with the right type/size? Have you examined the S-function mdlOutputs function to ensure that your function is getting called correctly?
4 Comments
Devjit Naha
on 7 Mar 2012
Kaustubha Govind
on 7 Mar 2012
A MEX-file can be treated like any other MATLAB function. You can either call it directly using an Interpreted MATLAB Function (http://www.mathworks.com/help/toolbox/simulink/slref/interpretedmatlabfunction.html) or from a C S-function using mexCallMATLAB (http://www.mathworks.com/help/techdoc/apiref/mexcallmatlab.html).
Kaustubha Govind
on 7 Mar 2012
With the legacy code tool, the input/output types/sizes are parsed from the OutputFcnSpec.
Devjit Naha
on 12 Mar 2012
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!