MATLAB Answers

Best Practices for Simulink Simulation to Embedded Code

조회 수: 2(최근 30일)
Alec Merolla
Alec Merolla 2021년 5월 4일
답변: Jonas 2021년 5월 5일
Does anyone know of an easy way to switch between simulation I/O in a model to C Caller/ user defined C code blocks? Right now it seems like two models would have to be maintained; one for simulated inputs and one for Embedded Coder code generation use where the outputs and inputs can be tied to the hardware. This becomes difficult for large models. Thanks in advance.


Jonas 2021년 5월 5일
The text book way of working is to develop your controller inside a separate Simulink model file, and then using a simulation harness model which has a model reference to that controller file, and then another embedded coder harness model which has a model reference to the same controller file. This way, you develop the same controller in simulation or embedded coder environment, but the controller content remains the same.
Alternatively, you can use Variant Subsystems where you switch between simulation and code generation using a variant object. You can manually switch the variant object, but you can also use a condition expression like:
This condition will be true when you are using the Configuration Parameters for code generation, and false in any other situation like simulation. Your controller is stored in file model_name.slx in this example.

Community Treasure Hunt

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

Start Hunting!

Translated by