Integrate existing C++ code into SimuLink model
17 次查看(过去 30 天)
显示 更早的评论
I am working with 3D simulation software called OrcaFlex to simulate platform motions at sea. Within this program I am using an external function through a DLL file, programmed in C++. This C++ code extracts data, performs a calculation and then inputs the results back into OrcaFlex.
I now want to extent the calculation part with for example a PID controller. I'd like to do this through SimuLink an eventually compile the resulting SimuLink model into a new DLL that can work with OrcaFlex.
Simply said I need a block that extracts data from the software using the existing C++ code, perform calculations using simple m files and then input the result back into the software again with existing C++ code.
My question is: how can I use functions or variables from the existing C++ code in my SimuLink model? I've seen options such as the S-Function builder and the Legacy Code Tool, but I'm not sure how these will work for me.
Thanks in advance!
0 个评论
采纳的回答
Kaustubha Govind
2012-7-10
I'm not entirely sure whether you want to perform your calculations with a Simulink model or using MATLAB commands (you mentioned both in your question). If it is only a Simulink model, it might be a good idea to generate a generic DLL from the model if you have the Embedded Coder product license. You need to use the ERT Shared Library Target (ert_shrlib.tlc) with your model to generate a DLL.
If you do indeed want to run MATLAB code, and OrcaFlex always runs on a machine with MATLAB installed, you can start the MATLAb Engine from your C/C++ driver application, send/receive data and run MATLAB commands.
6 个评论
Kaustubha Govind
2012-7-16
Here is an example of how you can call into the library. You basically call initialize at the beginning, terminate at the end, and the step function several times in between for each data sample.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!