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!