Best Practices for Simulink Simulation to Embedded Code

1 view (last 30 days)
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.

Answers (1)

Jonas
Jonas on 5 May 2021
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.

Categories

Find more on Deployment, Integration, and Supported Hardware 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!