Overview
This guide demonstrates how to develop a motion control application using National Instruments' LabVIEW NI SoftMotion Module and NI 951x C-Series driver interface. The application utilizes the NI CompactRIO reconfigurable embedded system, along with LabVIEW, LabVIEW NI SoftMotion, and NI-Motion driver software, to execute a series of two-axis motions. In developing this application, you will learn the concepts and techniques for developing motion applications using the NI RIO Scan Interface. The RIO Scan Interface allows users to directly access the C-Series module within the LabVIEW Real-Time Module.
Required components
This guide requires the following software:
LabVIEW 2009 or later
LabVIEW Real-Time Module 2009 or later
NI-RIO 3.2.0 or later
LabVIEW NI SoftMotion Module 2009 or later
This guide also requires the following hardware:
The CompactRIO controller and a chassis that provides Scan Interface mode or the NI 9144 distributed chassis.
Two NI 9512 single-axis stepper driver interfaces
Controller power supply
Individual module power supply
Ethernet connection and cables
Even if you don't have the specified hardware, you can still follow the "LabVIEW NI SoftMotion Module Guide" section in this article to configure it offline and learn how to use the module in LabVIEW.
LabVIEW NI SoftMotion Module Overview
The LabVIEW NI SoftMotion Module allows you to build deterministic motion control applications using the function block programming paradigm and the RIO Scan Interface, leveraging the LabVIEW Real-Time Module. The RIO Scan Interface provides direct access to C-series modules from within the LabVIEW Real-Time Module.
This document covers application development for the NI 951x C-Series driver interface and RIO Scan Interface. For information on using NI 951x modules in LabVIEW FPGA Modules, please refer to the "NI 951x C-Series Modules and LabVIEW FPGA Getting Started Guide" on ni.com/manuals.
The dual-axis operation described in this guide requires the use of the NI SoftMotion function block, which can be achieved using the NI 9512 stepper driver interface in open-loop mode—without requiring additional feedback devices or other hardware connections.
The configuration parameters in this guide may not be suitable for actual motion systems. For demonstration purposes, we have minimized the hardware connections.
Hardware setup
Complete the following steps to set up the hardware for the applications described in this guide.
1. If you are not using an integrated controller and backplane, you will need to install the CompactRIO real-time controller on the field-programmable gate array (FPGA) backplane. Refer to the controller operation guide for information on installing the controller.
2. Install the NI 9512 stepper driver interface module in slots 1 and 2 of the chassis.
3. Connect the module to the power supply. Refer to the module's operating manual to select the appropriate power supply.
4. Connect the controller to a power supply and an Ethernet network with the same subnet, so it can be used as a development computer. Consult the controller's operating manual for information on connecting the controller to the power supply and Ethernet network.
5. Connect the module to the driver and other I/O. If possible, use the NI 9512-to-P7000 Stepper Drives Connectivity Bundle, the NI 951x Cable and Terminal Block Bundle, or use a custom cable for direct connection.
Install and configure software on the controller
Complete the following steps to install and configure the software on the controller.
1. On the development computer, launch the NI Measurement & Automation Explorer (MAX, NI Measurement & Automation Navigator) configuration tool.
2. In the configuration pane, select Controller under Remote Systems. If you do not see Controller, you may need to disable the firewall on your development computer.
3. Check if the serial number being identified matches the serial number on the device.
4. If you do not want to format the disk on the controller (that would delete all installed software and files), then power on the controller and skip to step 13.
5. Set the safety mode switch on the controller to the On position.
6. Power on the controller. If the controller is already powered on, press the Reset button on the controller to restart it.
7. Right-click the controller under Remote Systems in the Configuration pane and select Format Disk. Click Yes in the dialog box that appears.
8. After MAX completes disk formatting, switch the Safe Mode switch to the Off position and press the Reset button on the controller to restart.
9. Select the "Obtain an IP address automatically" radio button to assign an IP address; or select the "Use the following IP address" radio button to specify a static IP address in the IP address field.
10. Enter a descriptive name for the system in the name field.
11. Click "Apply" on the Network Settings tab to restart MAX.
12. When the new system name appears under Remote Systems, expand the controller entry in the list, right-click the software, and select Add/Remove Software.
13. Select the recommended software combination, which includes NI-RIO 3.2.0 or later, with NI Scan Engine support and the following additional features:
• LabVIEW NI SoftMotion Module
• NI Scan Engine support for LabVIEW NI SoftMotion Module software
• NI-Motion driver software
14. Click Next to install the selected software on the controller. If you need information about the recommended software combination, click Help.
15. After completing the software installation on the controller in MAX, close MAX.
Create a project in scan interface mode
The Scan Interface mode allows users to directly access C-Series modules from LabVIEW Real-Time. These modules appear in Scan Interface mode under the Chassis entry in the Project Browser window. Unlike most C-Series modules, the NI 951x interface is not configured directly in the Project Browser window, and the module does not support directly available I/O variables.
On the development computer, use LabVIEW project management VIs, targets, and I/O modules. Complete the following steps to create a LabVIEW project.
1. Start LabVIEW.
2. Click the project link in the startup window to display the project browser window. Alternatively, select File » New Project to display the project browser window.
3. Select Help and confirm that Show Instant Help is selected. Throughout the guide, you can consult Context Help for information on the items in the diagram.
4. Right-click the top-level project in the Project Browser window, and select New » Terminal and Device from the shortcut menu to display the Add Terminal and Device dialog box.
5. Confirm that a radio button on an existing terminal or device has been selected.
If you don't have the hardware installed, you can select the "New Terminal" or "Device" radio button to display a range of targets and devices that can be created without a physical object. This guide demonstrates similar offline configuration steps and teaches you how to use CompactRIO and LabVIEW.
6. Expand Real-Time CompactRIO.
7. Select the CompactRIO controller added to the project and click OK.
8. If you have already installed LabVIEW FPGA, a dialog box for selecting programming mode will appear. Select Scan Interface to put the system into scan interface mode.
Use the CompactRIO Properties dialog box to change the programming mode in an existing project. Right-click on the CompactRIO chassis in the Project Browser window and select Properties from the shortcut menu to display the dialog box.
9. If the "Find C-series modules?" dialog box appears, please click "Find".
10. Click Continue. LabVIEW will add the controller, chassis, and all modules to the project.
11. After LabVIEW completes the hardware search, select File » Save Project and save the project as 951x_Tutorial.lvproj.
After completing these steps, your LabVIEW project should look similar to Figure 1.
Figure 1. Project browser window, scanning interface mode.
Add NI SoftMotion resources to a LabVIEW project
Now let's create an NI SoftMotion resource that's bound to the C-series module. Use motion I/O resources instead of I/O variables in the VI. See the NI SoftMotion Module section in LabVIEW Help for more information about motion I/O resources and NI SoftMotion.
Add axes to the project
In the project, NI SoftMotion axes are bundled into dedicated C-series modules, and the I/O on the modules can be configured. To configure and use the NI 951x modules in scan interface mode, you must add the axis in the RT target and use the motion I/O resources associated with the axis in the VI.
To add an NI SoftMotion axis to your project, follow these steps:
1. Right-click the target in the project browser window and select New » NI SoftMotion Axis from the shortcut menu to open the Axis Manager dialog box, as shown in Figure 2.
2. Double-click to add an axis, associating both NI 9512 modules with the NI SoftMotion axis. The axis is automatically bound to an available module. You can double-click the axis name to rename it, giving it a descriptive name, but two different axes cannot use the same name.
Figure 2. Axis Manager dialog box
3. Click Modify Binding to open the Resource Binding dialog box. If necessary, change the hardware associated with this axis.
4. Click OK to close the Axis Manager dialog box. Add all axes to the Project Browser window. Only one axis can be associated with the same C-series module.
Add coordinates to the project
NI SoftMotion axes can form a coordinate space. A coordinate space is a logical, multi-dimensional combination of axes. Similar to axes, coordinate spaces can also contain associated I/O resources that can serve as resource inputs.
Complete the following steps to add coordinate space to your project:
1. Right-click the target in the Project Browser window and select New » NI SoftMotion Coordinate Space from the shortcut menu to open the Configure Coordinate Space dialog box.
2. Select Axis 1 and Axis 2 from the Available Axes column and move them to the Coordinate Axes column using the arrow icons.
Figure 3. Configuring Coordinate Space dialog box
When using coordinate resources, the target position and other coordinate information are contained in a one-dimensional matrix, where the axis information is arranged in the order in which the axes were added using the dialog box.
3. Click OK to close the Configure Coordinate Space dialog box.
At this point, your project contains the axes and coordinate space required by the application. Your LabVIEW project should resemble Figure 4.
Figure 4. Projects completed using sports resources
Axis configured with stepper drive interface module
This section describes how to configure the axes associated with the NI 9512 C Series module using the axis configuration dialog box. This dialog box includes configuration options for stepper drive command signals, feedback devices, motion and digital I/O, tracks, and axis settings. Figure 5 shows the axis configuration dialog box for the NI 9512 C Series module. Unconfigurable sections are shown in gray.
Figure 5. Axis configuration dialog box of NI 9512 module
Configure the axis by completing the following steps:
1. Right-click the axis in the project browser window and select Properties from the shortcut menu to open the axis configuration dialog box.
2. On the Axis Setup page, ensure that the loop mode is set to open loop. An axis configured in open loop mode will generate stepper outputs, but no feedback from the motor is required to confirm the position.
3. Also on the Axis Setup page, ensure that the Axis Enabled and Enable Drive on Transition to Active Mode checkboxes are checked. This configuration will automatically activate the axis when the VI is run.
To prevent automatic axis activation, these options must be disabled.
4. If the module does not contain physical signal connections, these input signals must be disabled to ensure proper system operation. To disable limit and boot signals, go to the Motion I/O page and remove the checkmarks from the Enable checkboxes in the Forward Limit, Reverse Limit, and Home sections.
5. Configure all additional I/O according to system requirements.
6. Click OK to close the axis configuration dialog box.
7. Repeat steps 1 through 6 to configure axis 2.
Note: Ensure all hardware is connected and powered on before deploying the project. Deploying the project switches the NI Scan Engine to Active mode and enables axes and drives (if they are already connected), allowing you to start motion immediately. Refer to the "Deploying and Running VIs on RT Targets" section in the LabVIEW Help for more information on configuration and troubleshooting techniques.
8. Right-click the controller project in the project browser window and select Deploy All from the shortcut menu to deploy the axes, coordinates, and axis settings as a real-time target.
Test the system using the interactive test panel.
Use the Interactive Test Panel to test and debug your motion system and configuration settings on selected axes. With the Interactive Test Panel, you can perform simple linear motion, monitor motion and I/O status information, change motion limits, obtain error and fault information from the system, and view displacement or velocity curves. If a feedback device is connected to the system, you can also obtain feedback position and position error information.
After configuring the axes, complete the following steps and use the axis configuration dialog box to test the settings.
1. Right-click the axis in the project browser window and select the Interactive Test panel from the shortcut menu.
2. Use the tabs to set the desired position, motion mode, and motion limits. Refer to the NI SoftMotion module section in LabVIEW Help for more details on the entries in this dialog box.
3. Click the Start button at the bottom of the dialog box and start the exercise according to the configured options.
4. Use the Status and Curve tabs to monitor its status during the movement.
Create a VI using the scan interface mode
In this section, we create a VI using the motion I/O resources of the modules added to the project. Refer to the Real-Time Module section in the LabVIEW Help for detailed information about scan interface modes and the NI Scan Engine.
Configure timed loop
Synchronizing the timed loop with the NI scan engine allows time-sensitive motion function modules to run at a specified scan rate. Any code within the timed loop is guaranteed to execute only once per scan cycle. Memory allocation within the timed loop must be minimized to avoid introducing unpredictable time delays into the system.
If your code doesn't need to run at the scan rate, you can use a while loop with the function of waiting for an integer multiple of the next millisecond to control the loop rate.
Complete the following steps to configure the timed loop:
1. Right-click the controller project in the project browser window and select New » VI from the shortcut menu to open a blank VI.
2. Place a timed loop in the block diagram of the VI.
3. Double-click the input node for the timed loop to open the Configure Timed Loop dialog box.
4. In the Looping Timer Source, set the source type to Synchronize to the Scan Engine. You can click the Help button for information on how to synchronize to the NI Scan Engine.
5. In the timing parameters, set the period to 5 scan cycles. This step is optional, but it allows the timing cycle to synchronize with the NI scan engine at a lower rate. The Configure Timing Cycle dialog box should be similar to that in Figure 7.
Figure 7. Configuring a timed loop
6. Click OK.
Create motion profile
This example uses NI SoftMotion Line and Read function blocks to create a simple motion profile and monitor motion position information.
Complete the following steps to set up your workout:
1. Place a Line function block inside the timed loop.
2. Right-click the execute control and select Create » Input Control from the shortcut menu to add a control for the input in the front panel.
3. Repeat step 2 and add controls for the inputs position, velocity, acceleration, and acceleration jerk in the front panel.
4. Connect the deceleration input to the acceleration input, and connect the deceleration jerk input to the acceleration jerk input. In some applications, the deceleration value may need to be different from the acceleration value, but in this application they are the same.
5. Drag the Coordinate Space 1 resource from the LabVIEW project to the block diagram outside the Timer Loop, and connect it to the resource input on the function block.
6. Place another Line function block inside the timed loop.
7. Connect the error terminal and resource terminal of the Line function block together.
8. Connect the completion output of the first Line function block to the execution input of the second Line function block.
9. Connect the velocity, acceleration, deceleration, acceleration jerk, and deceleration jerk inputs of the second Line function block to the control created in step 3. This will make the motion parameter values of the second function block the same as those of the first function block.
10. Right-click the location input and select Create » Input Control from the shortcut menu to add a second location information control to the front panel.
11. Add a merge error VI to the block diagram, and connect the error outputs of the Read function block and the second Line function block to the merge error VI.
12. Right-click the error output of the merge error VI, and select Create » Display Control from the shortcut menu to add a display control to the front panel.
13. Connect the error output to the edge of the timer loop.
14. Right-click on the loop channel created for error output and select Replace with shift register from the shortcut menu. This will pass the error message to the next loop iteration.
15. Connect the error output to the shift register on the other side of the timer loop.
16. Right-click the shift register and select Create » Constant from the shortcut menu to initialize the error cluster outside the timer loop. Because the final hardware will use LabVIEW Real-Time Modules, all function block arrays and clusters must be initialized outside the timer loop to avoid system jitter. Inside the timer loop, place a Read function block below the two Line function blocks.
Typically, location information is read and plotted on the host machine (rather than in a deterministic timed loop) by reading data published by the target. For simplicity, this example includes the data reading part.
17. Connect the resource and error outputs to the resource and error inputs of the first Line function block.
18. Create a constant for the position[] input and set the first two elements of the matrix to 0. Move the position[] constant out of the timer loop. This way, the array can be initialized without allocating memory for the function block.
19. Right-click the condition terminal of the timer loop and select Create » Input Control from the shortcut menu to add a stop button to the front panel. This will allow you to stop the VI from running at any time.
After completing the above steps, your block diagram should look similar to the one below:
Figure 8. Flowchart
Switch to the front panel.
23. In the position[] array, set the first two elements of the array to 5000. This will specify an xy coordinate (5000, 5000).
24. In the array at position [] 2, set the first two elements of the matrix to 0. This moves the x and y axes back to (0, 0).
25. Temporarily retain the default values for speed, acceleration, and jerk.
26. Add a waveform to the front panel.
27. Switch to the block diagram and connect the [] output terminal of the Read function block to the waveform display control. After completing the above steps, your front panel should resemble Figure 9.
Figure 9. Front panel
28. Save VI.
29. Save the project.
Publish, test and use VI
Complete the following steps to publish, test, and use the VI.
1. Run the VI. LabVIEW deploys the VI, along with all the modules and I/O variables used by the VI, to the controller.
2. Click the input control to start the task.
3. In the front panel, confirm that the location map is updating.
4. Click the Stop button to stop VI.
5. Modify any input parameter, then run the VI, and click the execution control again to see the results with different parameters.
Connect to servo and stepper drivers
The NI 951x C-Series drive interfaces for CompactRIO can directly connect to hundreds of stepper and servo drives/motors. These motion modules provide single-axis servo or stepper drive interface signals. Additionally, they offer a complete set of motion I/O, including origin and limit switch inputs, quadrature incremental encoded inputs for position feedback signals, and digital input and output lines. The NI 951x drive interface includes a processor that runs spline interpolation functions and NI's proprietary step size generation algorithm or control loop.
Let's look at how to connect to the NI P7000 series stepper driver. To learn how to connect to a third-party P-command stepper or servo driver, refer to the NI SoftMotion help file installed in the LabVIEW NI SoftMotion Module.
Connect to P7000 series stepper drive
This section describes how to connect the NI 9512 stepper driver interface to the P7000 series stepper drivers using the NI 9512-to-P7000 Stepper Drives Connectivity Bundle. The product includes a cable for directly connecting the NI 9512 D-Sub to the P7000 series stepper driver, and a 37-pin connector and cable for connecting the NI 9512 MDR connector to other I/O pins.
Complete the following steps to connect the NI 9512 driver interface to the P70530 DC driver or the P70360 AC driver and other I/O. Figure 10 shows a simplified connection diagram.
1. Install the module in the chassis according to the chassis documentation.
2. Using an NI 9512-to-P7000 cable, connect the D-sub connector module to the Command I/O connector on the P7000 series driver. This cable provides connection for the step output, drive enable output, and drive error signal.
3. Connect the power supply to the +24 V input of the direct connection cable on the NI 9512-to-P7000.
4. Using junction box cables, connect the MDR connector module to the 37-pin junction box.
5. Connect other I/O signals from the hardware device to the 37-pin junction box or a custom cable. Refer to Figure 11 for the junction box pinout.
a. Connect the Forward Limit, Reverse Limit, and Home inputs on the wiring block to the limit and home sensors.
b. If you are using an encoder to provide position information, connect the encoder input to the encoder.
c. Connect all additional I/O using the provided terminals.
6. Connect the driver power supply to the P7000 driver.
Figure 10. NI 9512-to-P7000 Series Driver Connection Diagram
Note: If only the MDR connector is connected to the junction box, all D-Sub signals on the junction box are no-connects (NC). Figure 11 shows the pinout of the 37-pin junction box when only the MDR connector is connected.
Figure 11. Pin assignment of the NI 9512 37-pin terminal block when only the MDR is connected.
7. Install the software in the controller, create a LabVIEW project, and add NI SoftMotion axes.
8. Right-click the axis in the project browser window and select Properties from the shortcut menu to open the axis configuration dialog box.
9. For the P7000 driver, change the default axis settings for the following items in the axis configuration dialog box:
a. Right-click the axis and select Properties from the shortcut menu to display the axis configuration dialog box.
b. On the stepper motor page, set the output mode to single-ended.
c. In the Drive Signals tab of the Motion I/O page, set the output mode of the drive enable signal to source output.
d. In the Digital I/O page, map the drive error/alarm to DI 1 and set the input mode to source input.
10. In the Project Browser window, click the Controller Project and select Deploy All to deploy the axis information.
Connected to servo drive
Servo axis configuration
Servo axes can only operate in closed-loop mode, so a feedback device is required. If you are using the NI 9514 or NI 9516 driver interface module, you must separately configure the feedback device, servo control loop, and servo drive command output. Figure 6 shows a portion of the axis configuration dialog box for the NI 9514 and NI 9516 C-series modules. Unconfigurable sections are shown in gray.
Figure 6. Axis configuration dialog boxes for NI 9514 and NI 9516 modules
Using the gain adjustment test panel
Use the Gain Tuning Test Panel to adjust the control loop settings and calculate the relative stability of the servo axes. Refer to the "Using the Gain Tuning Panel" section in the NI SoftMotion LabVIEW Help for more information about the Gain Tuning Panel and servo system tuning commands.
Right-click the axis in the project browser window and select Interactive Test Panel from the shortcut menu to access the gain adjustment panel.
What you have learned
This guide analyzes several concepts for developing motion applications using LabVIEW NI SoftMotion and NI 951x C-series modules, as follows:
The NI 951x module differs from most C-series modules in that when using the scan interface mode, it cannot be configured directly in the project browser window, and I/O variables cannot be directly accessed within the module.
You must use NI SoftMotion to add axes to the RT target and associate them with NI 951x modules in order to configure and use them in scan interface mode. You can then use the motion I/O resources associated with these axes in the VI.
NI SoftMotion axes are configured using the Axis Configuration dialog box.
NI SoftMotion function blocks allow you to create deterministic motion control applications using function block programming.
The NI SoftMotion function block provides status output for advanced status monitoring.