Best Practices for Simulink Simulation to Embedded Code

1 次查看(过去 30 天)
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.

回答(1 个)

Jonas
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:
strcmp('ert.tlc',get_param('model_name','SystemTargetFile'))
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.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by