Legacy C code function o/p mismatch in simulink
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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
0 个评论
回答(1 个)
Kaustubha Govind
2012-3-6
0 个投票
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 个评论
Devjit Naha
2012-3-7
Kaustubha Govind
2012-3-7
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
2012-3-7
With the legacy code tool, the input/output types/sizes are parsed from the OutputFcnSpec.
Devjit Naha
2012-3-12
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!