This model shows how to model Rockwell motion api calls in Stateflow. This representation can then be further used for code generation using the "plcgeneratemotionapicode" function. For more information on this workflow, refer to the "Simulation and Code Generation of Motion Instructions" topic in the Simulink® PLC Coder™ documentation.
The following code will create a folder in your current working folder. The new folder will contain only the files that are relevant for this example. If you do not want to affect the current folder (or if you cannot generate files in this folder), change your working folder.
Open up the "MotionController" subsystem. Open the Stateflow® chart named "Chart" chart inside it. This chart implements the control logic for controlling the drives or the axes.
You can generate PLC Structured Text code for this subsystem by using the script file "plcgeneratemotionapicode"
warning('OFF', 'plccoder:plccg_ext:AutomaticeTypeConversions'); plcgeneratemotionapicode('MotionControllerExample/MotionController'); warning('ON', 'plccoder:plccg_ext:AutomaticeTypeConversions');
Created temporary model for codegeneration :MotionController0 PLC code generation successful for 'MotionController0/MotionController'.
Generated files: plcsrc/MotionController0.L5X
Run the following commands to close the model, remove files, and return to the original folder.