From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

NI SoftMotion 2009 LabVIEW State Chart Example

Code and Documents

Attachment

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.

softmotion_statechart_diagram.png

Figure 1. State Chart Diagram

softmotion_statechart_init_variant_array.png

Figure 2. Initializing StateData as an array of Variants (contents of "Init State Chart" state)

softmotion_statechart_init_motion_state.png

Figure 3. Entry Action for the "Init State Chart" state

softmotion_statechart_init_local_data.png

Figure 4. Entry Action "Init State Chart" state code - initializing cluster for SoftMotion function block.

softmotion_statechart_init_motion_state2.png

Figure 5. Static Action for the "Init State Chart" state - running SoftMotion initialization function blocks

softmotion_statechart_init_motion_state3.png

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.

Contributors