How to run a Simulink model converted to C++ in a different development environment

7 views (last 30 days)
I'm working on converting Simulink models into C++, and I'm trying to understand the basics right now. I have successfully generated C++ code that's packaged to be used in a different development environment, because the end goal is to not have MATLAB run the executable that's created. Here's the problem; I have no idea how to use the generated code. It's not like there's a file with a int main() function anywhere, that's left up to me. I don't know how to input values or read the output, so let's start with that. I want to be able to read a constant input (-9.81, in this case) from a txt file, and then write the output to a txt file. Once I understand how to initialize the model, and how to access the input/output signals, I think I'll be in the clear.
Here's the .slx file: https://drive.google.com/file/d/1Yq-fN3P92ckHZCFuGvTzQbFOBhRPoz9l/view?usp=sharing
https://www.mathworks.com/help/rtw/ug/relocate-code-to-another-development-environment.html <--- I've already tried reading this page, but I'm afraid I didn't understand it very well at all. It's all in C, and I'm far more comfortable with C++.
  1 Comment
le van tung
le van tung on 17 Dec 2019
I followed the video on youtube but it didn't work. Can you convert it for me? I am researching on this issue. What's your email?My email is levantungdktd@gmail.com Thank you so much.

Sign in to comment.

Answers (1)

Yoke Peng Leong
Yoke Peng Leong on 17 May 2018
You can refer to this page to see an example of how the inputs and outputs are defined in the H file relative to a model:
Although it is for C code, the structure is the same. In particular, if you go to the View the Generated Code section, you will see the main components that you will need in the main file called the entry point functions and the declaration of inputs, outputs, and other parameters in the H file.
You can read more about entry point functions here:
The initialize, step, and terminate functions are the three main components that you will have in the main function.
This page will provide an overview of the model execution process with more details:
In particular, there are a few pseudo codes that shows how the main function should look like when implementing the model under different settings.
Lastly, this page explains the standard data structure of the generated code:
These data are declared in the generated H file, which usually has the same name as the model name.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!