Main Content

Generating Structured Text for a Feedforward PID Controller

This model shows the code generated for a Feedforward PID Controller implemented using Simulink library blocks.

mdl = 'plcdemo_pid_feedforward';
open_system(mdl);

This model contains the following subsystem which implements the Feedforward controller.

open_system('plcdemo_pid_feedforward/pid_feedforward');

You can generate PLC Structured Text code for this subsystem by right-clicking on the subsystem block and select PLC Code -> Generate Code for Subsystem Alternatively, you can use the following command

generatedFiles = plcgeneratecode('plcdemo_pid_feedforward/pid_feedforward');
### Generating PLC code for 'plcdemo_pid_feedforward/pid_feedforward'.
### Using <a href="matlab:configset.showParameterGroup('plcdemo_pid_feedforward', { 'PLC Code Generation' } )">model settings</a> from 'plcdemo_pid_feedforward' for PLC code generation parameters.
### Gathering test vectors for PLC testbench.
### Begin code generation for IDE <a href="matlab:configset.showParameterGroup('plcdemo_pid_feedforward', { 'PLC Code Generation' } )">codesys23</a>.
### Emit PLC code to file.
### Creating PLC code generation report <a href="matlab:web('/tmp/Bdoc21a_1606923_165517/tp4c0686f5/ex27575843/plcsrc/html/plcdemo_pid_feedforward/plcdemo_pid_feedforward_codegen_rpt.html')">plcdemo_pid_feedforward_codegen_rpt.html</a>.
### PLC code generation successful for 'plcdemo_pid_feedforward/pid_feedforward'.
### Generated files:
<a href="matlab: edit('./plcsrc/plcdemo_pid_feedforward.exp')">./plcsrc/plcdemo_pid_feedforward.exp</a>

After the code generation, the Diagnostic Viewer window is displayed with hyperlinks to the generated code files. You can open the generated files by clicking on the links.