Main Content

Simulate and Generate Structured Text Code for Rockwell Automation Motion Instructions

This example shows how to model Rockwell Automation® motion instructions in Stateflow®. Generate structured text code for the modeled motion instructions by using Simulink® PLC Coder™.

Model Description

The model consists of a Stateflow® chart called MotionController. The MotionController chart consists of these components:

  • Controller1 and Controller2 subcharts that simulate the motion instruction.

  • Drive1 and Drive2 subcharts that simulate the motion of a drive and the axis on which motion control is performed.

  • MSF, MSO, and MAM graphical functions that define the respective motion instructions.

motion_control_chart.png

Open the model:

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

Generate Code

Generate structured text code for the chart by using the plcgeneratemotionapicode function:

warning('OFF', 'plccoder:plccg_ext:AutomaticTypeConversions');
plcgeneratemotionapicode('MotionControllerExample/MotionController');
Created temporary model for code generation :MotionController
### Generating PLC code for 'MotionController/MotionController'.
### Using model settings from 'MotionController' for PLC code generation parameters.
### Begin code generation for IDE studio5000.
### Emit PLC code to file.
### PLC code generation successful for 'MotionController/MotionController'.
### Generated files:
plcsrc/MotionController.L5X
warning('ON', 'plccoder:plccg_ext:AutomaticTypeConversions');

Clean Up Generated Files

To close the model and clean up the generated files:

close_system('MotionControllerExample');

See Also