Simulating and Generating Structured Text Code for Rockwell Motion Instructions

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.

Create a Folder and Copy Relevant Files

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.

plccoderdemo_setup('plcdemo_motion_api_rockwell');

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.

load_system('MotionControllerExample');
open_system('MotionControllerExample/MotionController/Chart');

You can generate PLC Structured Text code for this subsystem by using the script file "plcgeneratemotionapicode"

plcgeneratemotionapicode('MotionControllerExample/MotionController');
   Created temporary model for codegeneration :MotionController0
   PLC code generation successful for 'MotionController0/MotionController'.
   Generated files:
   plcsrc/MotionController0.L5X

Clean Up

Run the following commands to close the model, remove files, and return to the original folder.

>> close_system('MotionControllerExample');

>> cleanup