Introduction
This example shows how NI SoftMotion 2009 Function Blocks can be used in the LabVIEW State Chart Module.
Details
The key to this example is how local state data is managed within the state chart. This concept can be used generally for any state chart but is especially useful for SoftMotion Function Blocks as local state data is needed for the function block "execute" input.
When the state chart is initialized, an array of variants is created and passed to different states using the "StateData" internal control cluster. The number of elements in the variant array is based on the number of items in the "State" enum type definition (see Figure 2). By using a variant, any local state data that needs to be stored for subsequent state iterations can easily be flattened and stored into a variant. This is much more manageable and scalable than creating one very large cluster with all data from each state and storing it in the internal StateData type definition.
Figure 1. State Chart Diagram
Figure 2. Initializing StateData as an array of Variants (contents of "Init State Chart" state)
Figure 3. Entry Action for the "Init State Chart" state
Figure 4. Entry Action "Init State Chart" state code - initializing cluster for SoftMotion function block.
Figure 5. Static Action for the "Init State Chart" state - running SoftMotion initialization function blocks
Figure 6. Code inside Static Action for the "Init State Chart" state
For additional discussion on the SoftMotion execute inputs and busy and done outputs see NI SoftMotion 2009 State Machine Example
Additional Notes
Requirements:
NI LabVIEW 2009, NI LabVIEW SoftMotion Module 2009, NI LabVIEW State Chart Module 2009
See NI SoftMotion 2009 State Machine Example for a simpler example and detailed explanation of how to integrate SoftMotion function blocks into an application.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.