QT calls Simulink auto-generated C + + code

Source: Internet
Author: User

The Simulink self-contained tools are used to generate C and C + + code, where C code can be used without modification for C engineering, and because the generated C + + code is a standard value code, and Qt is a C + + implementation, invoking Simulink-generated C + + programs can also work correctly.

Software version:

simulink:2016a

qt:5.7

1, build a simple mathematical operation model, this model has no input, only one output. As follows:

2, configuring the model

2.1 Set the model to a fixed step, run end time INF.

2.2 Set the output format to "Structure" or set it to another, such as an array

2.3 Select the code generation language C + +, set as follows, where the target file is GRT.TLC, which is generic real-time target.

2.4 Setting the Code interface in C + + class, there are some inexplicable errors that can be avoided in QT calls.

2.5 Check the settings, click the "Check Model" button in the 2.3 step, check the configuration is correct, if there is an error or warning, follow the recommended settings, the final result is as follows:

3, compile the model, CTRL+B or click the button below

4, after compiling will be in the current directory to generate the suffix Grt_rtw folder, which is the compiled program.

5, create a simple widght program in QT with the name Testmodel.

6, add the. h,.cpp file that you generated in step 4 to the QT project, and add all the dependent. h files (in the MATLAB installation file), and the resulting additions are as follows:

7, add the following code in the Mainwindow.cpp constructor (the associated variable declaration is not listed separately):

  New Testmodelclass ();    Pmodel, Initialize ();    Pmodel, Step ();    Qdebug ()<<"simulink output:"<<pModel->test_Y.Out2;

8, run the QT program output results as follows, and the expected consistency:

12

The above indicates that QT can invoke the C + + code of Simulink, and further the input of the model can be set in the QT program.

QT calls Simulink auto-generated C + + code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.