National Instruments NI-Motion User Manual

Motion control
Table of Contents

Advertisement

Quick Links

Motion Control
NI-Motion
User Manual
TM
NI-Motion User Manual
November 2005
371242B-01

Advertisement

Table of Contents
loading

Summary of Contents for National Instruments NI-Motion

  • Page 1 Motion Control NI-Motion User Manual NI-Motion User Manual November 2005 371242B-01...
  • Page 2 For further support information, refer to the Technical Support and Professional Services appendix. To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback. © 2003–2005 National Instruments Corporation. All rights reserved.
  • Page 3 The reader should consult National Instruments if errors are suspected. In no event shall National Instruments be liable for any damages arising out of or related to this document or the information contained in it.
  • Page 4: Table Of Contents

    NI SoftMotion Controller Communication Watchdog ...1-9 Chapter 2 Creating NI-Motion Applications Creating a Generic NI-Motion Application ...2-1 Adding Measurements to an NI-Motion Application ...2-2 Chapter 3 Tuning Servo Systems NI SoftMotion Controller Considerations ...3-1 NI SoftMotion Controller for CANopen ...3-1 NI SoftMotion Controller for Ormec ...3-1...
  • Page 5 2D Straight-Line Move Code ... 5-7 Velocity-Based Straight-Line Moves ... 5-10 Algorithm ... 5-11 LabVIEW Code... 5-13 C/C++ Code ... 5-13 Velocity Profiling Using Velocity Override... 5-17 Algorithm ... 5-18 LabVIEW Code... 5-19 C/C++ Code ... 5-20 NI-Motion User Manual Programming with NI-Motion ni.com...
  • Page 6 Reference Move Algorithm...8-2 LabVIEW Code ...8-3 C/C++ Code...8-3 Chapter 9 Blending Moves Blending...9-1 Superimpose Two Moves ...9-2 Blend after First Move Is Complete ...9-3 Blend after Delay...9-4 Blending Algorithm...9-5 LabVIEW Code ...9-6 C/C++ Code...9-7 © National Instruments Corporation Contents NI-Motion User Manual...
  • Page 7 Relative Position Breakpoints Algorithm ... 12-13 LabVIEW Code... 12-14 C/C++ Code ... 12-14 Periodically Occurring Breakpoints ... 12-16 Periodic Breakpoints (NI 7350 only) ... 12-17 Periodic Breakpoint Algorithm ... 12-17 LabVIEW Code ... 12-18 C/C++ Code... 12-18 NI-Motion User Manual viii ni.com...
  • Page 8 C/C++ Code...13-16 Chapter 14 Onboard Programs Using Onboard Programs with the NI SoftMotion Controller ...14-1 Using Onboard Programs with NI 73xx Motion Controllers ...14-2 Writing Onboard Programs ...14-3 Algorithm ...14-4 LabVIEW Code ...14-5 © National Instruments Corporation Contents NI-Motion User Manual...
  • Page 9 Algorithm ... 14-34 LabVIEW Code... 14-35 C/C++ Code ... 14-38 Automatically Starting Onboard Programs ... 14-42 Changing a Time Slice ... 14-42 Creating Applications Using NI-Motion Chapter 15 Scanning Connecting Straight-Line Move Segments ... 15-1 Raster Scanning Using Straight Lines Algorithm... 15-2 LabVIEW Code...
  • Page 10 Sinusoidal Commutation for Brushless Servo Motion Control Appendix B Initializing the Controller Programmatically Appendix C Using the Motion Controller with the LabVIEW Real-Time Module Appendix D Technical Support and Professional Services Glossary Index © National Instruments Corporation Contents NI-Motion User Manual...
  • Page 11: About This Manual

    Code instructions and examples assume a working knowledge of the given programming language. This manual also assumes a general knowledge of motion control terminology and development requirements. This manual pertains to all NI motion controllers that use the NI-Motion driver software. Conventions The following conventions appear in this manual: <>...
  • Page 12: Documentation And Examples

    NI-Motion ReadMe—Refer to this HTML document for information about hardware and software installation and information about changes to the NI-Motion driver software in the current version. This document also contains last-minute information about NI-Motion. Application notes—For information about advanced NI-Motion concepts and applications, visit ni.com/appnotes.nsf/...
  • Page 13 • • In addition to the NI Developer Zone, you can find NI-Motion C/C++ and Visual Basic programming examples in the FlexMotion\Examples default directory is NI-Motion You can find LabVIEW example programs under in the directory where you installed LabVIEW. You can find LabWindows where you installed LabWindows/CVI.
  • Page 14: Parti I Introduction

    Introduction This user manual provides information about the NI-Motion driver software, motion control setup, and specific task-based instructions for creating motion control applications using the LabVIEW and C/C++ application development environments. Part I covers the following topics: • • © National Instruments Corporation...
  • Page 15: Introduction To Ni-Motion

    Introduction to NI-Motion About NI-Motion NI-Motion is the driver software for National Instruments 73xx motion controllers and the NI SoftMotion Controller. You can use NI-Motion to create motion control applications using the included library of LabVIEW VIs and C/C++ functions.
  • Page 16: Software And Hardware Interaction

    Chapter 1 Introduction to NI-Motion Software and Hardware Interaction Measurement and Automation Explorer Configuration Utility Note The last block in Figure 1-1 is not applicable to the NI SoftMotion Controller. NI Motion Controller Architecture This section includes information about the architecture for both the 73xx family of NI motion controllers and the NI SoftMotion Controller.
  • Page 17 • • • • • These functions are marked as non-real-time functions. Refer to the NI-Motion Function Help or the NI-Motion VI Help for more information. © National Instruments Corporation Save Defaults Reset Defaults Enable Auto Start Object Memory Management...
  • Page 18: Ni Motion Controller Functional Architecture

    Chapter 1 Introduction to NI-Motion Figure 1-2 illustrates the physical architecture of the NI motion controller hardware. Host Computer Because the NI SoftMotion Controller is not a hardware device, information about its architecture is not covered in this section. Refer to the...
  • Page 19 Figure 1-4 shows the components of the NI SoftMotion controller. Supervisory Control Host Any CPU on a real-time environment © National Instruments Corporation Typical NI 73xx Motion Controller Architecture Trajectory Generation Control Loop Figure 1-3. Typical NI 73xx Motion Controller Functional Architecture...
  • Page 20 Chapter 1 Introduction to NI-Motion Figure 1-5 illustrates the functional architecture of NI motion controllers. Supervisory Control (ms) User API Interface Supervisory Commands for Trajectory Generator Control Event Monitoring Interface The following list describes how each component of the 73xx controllers and the NI SoftMotion Controller functions: •...
  • Page 21: Ni Softmotion Controller Architecture

    • NI SoftMotion Controller Architecture The NI-Motion architecture for the NI SoftMotion Controller uses standard PC-based platforms and open standards to connect intelligent drives to a real-time host. In this architecture, the software components of the motion controller run on a real-time host and all I/O is implemented in the drives.
  • Page 22 Chapter 1 Introduction to NI-Motion NI SoftMotion Controller for CANopen When you use the NI SoftMotion Controller with a CANopen device, you can daisy chain up to 15 drives together and connect them to the real-time host. The real-time Process Data Objects (PDOs) defined by the CANopen protocol are used to transfer data between the drives and host.
  • Page 23: Ni Softmotion Controller Communication Watchdog

    The communication watchdog functionality ensures that the NI SoftMotion Controller operates in real time. To get an axis or axes out of the communication watchdog state, reset the NI SoftMotion Controller. © National Instruments Corporation NI SoftMotion Controller on Host Device* Trajectory...
  • Page 24: Creating Ni-Motion Applications

    Creating NI-Motion Applications This chapter describes the basic form of an NI-Motion application and its interaction with other I/O, such as a National Instruments data and/or image acquisition device. Creating a Generic NI-Motion Application Figure 2-1 illustrates the steps for creating an application with NI-Motion, and describes the generic steps required to design a motion application.
  • Page 25: Adding Measurements To An Ni-Motion Application

    NI-Motion User Manual Measurement & Automation Explorer Help for Motion Part III: Figure 2-1. Generic Steps for Designing a Motion Application NI-Motion, of this manual. For information about items Determine the system requirements Determine the required mechanical system Connect the hardware...
  • Page 26 High-speed captures are not supported by NI SoftMotion Controller for CANopen. You can use two high-speed captures per axis when you are using the NI SoftMotion Controller with an Ormec device. © National Instruments Corporation Define control mechanism for I/O Breakpoints*...
  • Page 27 Chapter 2 Creating NI-Motion Applications If you are using RTSI to connect your motion controller to a National Instruments Note data or image acquisition device, be aware that the NI SoftMotion Controller does not support RTSI. NI-Motion User Manual ni.com...
  • Page 28: Art

    Configuring Motion Control Motion control is divided into two parts: configuration and execution. Part II of this manual discusses configuring the hardware and software components of a motion control system using NI-Motion. Part II covers the following topic: • © National Instruments Corporation...
  • Page 29: Tuning Servo Systems

    The controller turns the motor in the opposite direction for the amount of distance equal to the detected overshoot. However, this corrective move also exhibits a small overshoot, which must also be corrected in the same manner as the first overshoot. © National Instruments Corporation NI-Motion User Manual...
  • Page 30: Control Loop

    You can configure the control loop to perform a Proportional, Integral and Derivative (PID) loop or a more advanced control loop, such as the velocity feedback (PIV) or velocity feedforward (PIVff) loops. NI-Motion User Manual Settling Time Figure 3-1. Properly Tuned Servo Motor Behavior ni.com...
  • Page 31 Chapter 3 Tuning Servo Systems © National Instruments Corporation NI-Motion User Manual...
  • Page 32: Pid Loop Descriptions

    This effect can be mitigated through the use of the Integration Limit parameter. Too high a value of Ki often results in servo loop instability. National Instruments therefore recommends that you leave Ki at its default value of zero until the servo system operation is stable. Then you can add a small amount of Ki to minimize static position errors.
  • Page 33 16-bit DAC command output that is directly proportional to the instantaneous trajectory velocity. This value is used to minimize following error during the constant velocity portion of a move and can be changed at any time to tune the PID loop. © National Instruments Corporation NI-Motion User Manual...
  • Page 34 Kdac Kdac is the Digital to Analog Converter (DAC) gain. Use the following equation to calculate Kdac: 20 V represents the ±10 V range in the motion controller. NI-Motion User Manual 20 V Kdac ----------- ni.com...
  • Page 35 The motor sensor is used to generate the required damping and the load sensor for position feedback. The mix of these two signals provides the correct position feedback with damping and stability. © National Instruments Corporation Chapter 3 Tuning Servo Systems NI-Motion User Manual...
  • Page 36 Figure 3-4. NI-Motion User Manual Figure 3-3. Dual Loop Feedback Figure 3-4. Dual Loop Feedback Algorithm...
  • Page 37: Velocity Feedback

    Like the Kd term, the velocity feedback derivative is calculated every derivative sample period, and the contribution is updated every PID sample period, as shown in Figure 3-6. © National Instruments Corporation Chapter 3 Figure 3-5. Velocity Feedback Tuning Servo Systems...
  • Page 38: Ni Motion Controllers With Velocity Amplifiers

    Use the velocity feedforward term (Vff) to ensure that there is minimum following error during the constant velocity profiles. NI-Motion User Manual in Addition to Kd Figure 3-6. Alternate Dual-Loop Feedback Algorithm Figure 3-7.
  • Page 39 National Instruments does not recommend increasing Ki. Note Velocity feedforward is rarely used when operating in PID mode with torque block amplifiers.
  • Page 40 You can use the C/C++ functions and LabVIEW VIs, included with NI-Motion, to configure and execute motion control applications. Part III of this manual covers the NI-Motion algorithms you need to use all the features of NI-Motion. Each task discussion uses the same structure. First, a generic algorithm flow chart shows how the component pieces relate to each other.
  • Page 41 Part III Programming with NI-Motion • • • NI-Motion User Manual Synchronization Torque Control Onboard Programs III-2 ni.com...
  • Page 42: What You Need To Know About Moves

    The velocity of the axis, or axes, in a coordinate space never exceeds the maximum velocity loaded. The axes decelerate to a stop at their final position, as shown in Figure 4-1. © National Instruments Corporation NI-Motion User Manual...
  • Page 43: S-Curve

    Basic Moves There are four basic move types: • • • NI-Motion User Manual Velocity Figure 4-1. Trapezoidal Move Profile Velocity Figure 4-2. S-Curve Move Profile Reference Move—Initializes the axes to a known physical reference such as a home switch or encoder index Straight-Line Move—Moves from point A to point B in a straight...
  • Page 44: Coordinate Space

    Multi-Starts versus Coordinate Spaces Coordinate spaces always start and end the motion of all axes simultaneously. You can use multi-starts to create a similar effect without © National Instruments Corporation Chapter 4 Contoured Move—Is a user-defined move; you generate the...
  • Page 45: Trajectory Parameters

    In coordinate spaces, this behavior is calculated automatically. Trajectory Parameters Use trajectory parameters to control the moves you program in NI-Motion. All trajectory parameters for servo axes are expressed in terms of quadrature encoder counts. Parameters for open-loop and closed-loop stepper axes are expressed in steps.
  • Page 46: Ni 73Xx Time Base

    Velocity values in RPM are converted to an internal 16.16 fixed-point format in units of counts (steps) per sample period (update period) before being used by the trajectory generator. NI-Motion can control velocity to 1/65,536 of a count or step per sample.
  • Page 47 250 µs update rate, the minimum RPM increment is You can calculate the maximum velocity in RPM with the following equation: where NI-Motion User Manual minimum RPM Vmin = 1/65,536 counts/sample or steps/sample Ts = sample period in seconds per sample...
  • Page 48 1 count/s or step/s. You cannot load fractional values. If you need to load a velocity slower than one count or step per second, use the Load Velocity in RPM function. © National Instruments Corporation Chapter 4 velocity ≤ (65,536 × deceleration) – acceleration ...
  • Page 49 437.5 µs 167,183,673 counts/sec 500 µs 128,000,000 counts/sec NI-Motion User Manual maximum velocity Vmax = 20 MHz for servos 8 MHz for steppers on a NI 7350 controller 4 MHz for steppers on a NI 7330, NI 7340, or NI 7390 motion controller velocity ≤...
  • Page 50 16.16 fixed-point format in units of counts/sample being used by the trajectory generator. Table 4-3 shows the minimum and maximum acceleration update rates in counts/sec © National Instruments Corporation Chapter 4 minimum acceleration/deceleration Amin = 1/65,536 counts/sample Ts = sample period in seconds per sample ...
  • Page 51 For a typical servo axis with 2,000 counts or steps per revolution operating at the 250 µs update rate, calculate the minimum RPS/s increment using the following equation: NI-Motion User Manual Table 4-3. Acceleration Update Rate in RPS/s 3906 counts/sec...
  • Page 52 (f32) data value from 0 to 150%, but velocity override is internally implemented as a velocity scale factor of 0 to 384 with an implicit fixed denominator of 256. NI-Motion uses the velocity override to increase the speed of the calculation for the sake of calculation speed—the division is a shift right by eight bits.
  • Page 53 What You Need to Know about Moves If the distance of the move is too small, it may not be possible to reach the Note commanded maximum move constraints. In such instances, NI-Motion adjusts the move constraints lower to reach the commanded position. NI 73xx...
  • Page 54: Ni 73Xx Arc Move Limitations

    Arc moves must use the following equations or an NIMC_invalidVelocityError where Arc moves must use the following equations or an NIMC_invalidAccelerationError where © National Instruments Corporation Chapter 4 What You Need to Know about Moves is generated: × × ≥...
  • Page 55: Timing Loops

    Chapter 4 What You Need to Know about Moves Timing Loops National Instruments recommends that you use the loop timings discussed in the following sections. Status Display When you are displaying status information to the user, such as position, move status, or velocity, an update rate faster than 60 ms has no value.
  • Page 56: Straight-Line Moves

    The straight-line move algorithm includes the following procedures: • • • © National Instruments Corporation Start position—Current position, normally held over from a previous move or initialized to zero End position—Also known as the target position, or where you want to move to Move constraints—Maximum velocity, maximum acceleration,...
  • Page 57 Start or Blend Move. You must load the move constraints only if they are different from what was previously loaded. NI-Motion User Manual Figure 5-1. Position-Based Straight-Line Move Algorithm ni.com...
  • Page 58 1 Load Velocity 2 Load Acceleration/Deceleration 3 Load Acceleration/Deceleration © National Instruments Corporation 4 Load S-Curve Time 5 Set Operation Mode 6 Load Target Position Figure 5-2. 1D Straight-Line Move in LabVIEW Chapter 5 Straight-Line Moves 7 Start Motion 8 Read per Axis Status...
  • Page 59 Straight-Line Moves 1 Configure Vector Space 2 Load Velocity 3 Load Acceleration/Deceleration 4 Load Acceleration/Deceleration NI-Motion User Manual 5 Load S-Curve Time 6 Set Operation Mode 7 Load Target Position 8 Start Motion Figure 5-3. 2D Straight-Line Move in LabVIEW...
  • Page 60: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. 1D Straight-Line Move Code // Main Function void main(void) ©...
  • Page 61 Chapter 5 Straight-Line Moves NI-Motion User Manual err = flex_load_scurve_time(boardID, axis, 1000, 0xFF); CheckError; // Set the operation mode err = flex_set_op_mode (boardID, axis, NIMC_ABSOLUTE_POSITION); CheckError; // Load Position err = flex_load_target_pos (boardID, axis, 5000, 0xFF); CheckError; // Start the move err = flex_start(boardID, axis, 0);...
  • Page 62 2D Straight-Line Move Code // Main Function void main(void) © National Instruments Corporation // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any modal errors if (csr & NIMC_MODAL_ERROR_MSG){ //Get the command ID, resource ID, and the...
  • Page 63 Chapter 5 Straight-Line Moves NI-Motion User Manual // Configure a 2D vector space comprised of axes 1 and 2 err = flex_config_vect_spc(boardID, vectorSpace, 1, 2, 0); CheckError; // Set the velocity for the move (in counts/sec) err = flex_load_velocity(boardID, vectorSpace, 10000, 0xFF);...
  • Page 64 © National Instruments Corporation CheckError; // Check the following error/axis off status for axis 1 err = flex_read_axis_status_rtn(boardID, 1, &status); CheckError; axisStatus |= status; // Check the following error/axis off status for axis 2 err = flex_read_axis_status_rtn(boardID, 2, &status); CheckError;...
  • Page 65: Velocity-Based Straight-Line Moves

    The sign of the loaded velocity specifies the direction of motion. Positive velocity implies forward motion and negative velocity implies reverse motion. You can change the move constraints during a velocity move. NI-Motion User Manual flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); else// Display regular error nimcDisplayError(err,0,0);...
  • Page 66: Algorithm

    Chapter 5 Straight-Line Moves Algorithm Figure 5-4 is a generic algorithm applicable to both C/C++ and VI code. Figure 5-4. Velocity-Based Straight-Line Move Algorithm © National Instruments Corporation 5-11 NI-Motion User Manual...
  • Page 67 The axis decelerates to a stop using the Stop Motion function. The velocity profile created in the example code is shown in Figure 5-5. NI-Motion User Manual Velocity 10,000 5,000 Figure 5-5.
  • Page 68: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation...
  • Page 69 Chapter 5 Straight-Line Moves NI-Motion User Manual i32 errorCode;// Error code // Set the board ID boardID = 3; // Set the axis number axis = NIMC_AXIS1; // Move time for the first segment moveTime1 = 5000; //milliseconds // Move time for the second segment moveTime2 = 10000;...
  • Page 70 © National Instruments Corporation // Check the following error/axis off status err = flex_read_axis_status_rtn(boardID, axis, &axisStatus); CheckError; // Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr); CheckError; // Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) err = csr &...
  • Page 71 Chapter 5 Straight-Line Moves NI-Motion User Manual CheckError; // Read the communication status register and check the modal // errors err = flex_read_csr_rtn(boardID, &csr); CheckError; // Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) err = csr & NIMC_MODAL_ERROR_MSG; CheckError;...
  • Page 72: Velocity Profiling Using Velocity Override

    For example, 120 percent of an original velocity of 10,000 changes the velocity to 12,000. The transition between velocities follows all other move constraints. © National Instruments Corporation flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); else// Display regular error nimcDisplayError(err,0,0);...
  • Page 73: Algorithm

    Figure 5-7 is a generic algorithm applicable to both C/C++ and VI code. Waits the duration of time you specified for the originally loaded velocity Waits the duration of time you specified for the newly loaded velocity Figure 5-7. Velocity Override Algorithm NI-Motion User Manual 5-18 ni.com...
  • Page 74: Labview Code

    LabVIEW Code 1 Load Velocity 2 Load Acceleration/Deceleration 3 Load Acceleration/Deceleration 4 Load S-Curve Time © National Instruments Corporation 5 Set Operation Mode 6 Start Motion 7 Read per Axis Status 8 Load Velocity Override Figure 5-8. Velocity-Based Move Using Velocity Override in LabVIEW...
  • Page 75: C/C++ Code

    Straight-Line Moves C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 76 © National Instruments Corporation // Set the deceleration for the move (in counts/sec^2) err = flex_load_acceleration(boardID, axis, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk (s-curve value) for the move (in sample periods) err = flex_load_scurve_time(boardID, axis, 100, 0xFF); CheckError;...
  • Page 77 Chapter 5 Straight-Line Moves NI-Motion User Manual }while (!(axisStatus) && !(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move //complete/following error/axis off //------------------------------------------------- // Second segment //------------------------------------------------- //Change the velocity to 80% of the initially loaded value err = flex_load_velocity_override(boardID, axis, 80, 0xFF);...
  • Page 78 © National Instruments Corporation err = flex_stop_motion(boardID, axis, NIMC_DECEL_STOP, 0); CheckError; // Reset velocity override back to 100% err = flex_load_velocity_override(boardID, axis, 100, 0xFF); CheckError; return;// Exit the Application /////////////////////////////////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any modal errors if (csr &...
  • Page 79: Arc Moves

    When you use an NI 73xx motion controller to move a motor in an arc, you can use only trapezoidal profiles. You do not use jerk to calculate the profile for arc moves. © National Instruments Corporation Arc Generation Cubic Spine Figure 6-1.
  • Page 80 • 1 Original Arc • NI-Motion User Manual Radius—Specifies the distance from the center of the arc to its edge Start Angle—Orients the arc on its plane using the starting point as an axis to spin around. Because the starting point for a new arc is fixed based on the current position, moving its center around the starting point alters the orientation of a new arc.
  • Page 81: Arc Move Algorithm

    1 Positive Travel Angle Arc Move Algorithm © National Instruments Corporation 2 Negative Travel Angle Figure 6-3. Positive and Negative Travel Angles Load Velocity Load Acceleration/ Deceleration Load Circular Arc Radius, Start Angle, and Travel Angle Start Motion Loop Waiting for Move Complete...
  • Page 82: Labview Code

    4 Load Acceleration/Deceleration C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 83 © National Instruments Corporation u16 commandID;// The commandID of the function u16 resourceID;// The resource ID i32 errorCode;// Error code /////////////////////////////// // Set the board ID boardID = 1; // Set the vector space number vectorSpace = NIMC_VECTOR_SPACE1; //////////////////////////////// // Configure a 2D vector space comprising of axes 1...
  • Page 84 Chapter 6 Arc Moves NI-Motion User Manual err = flex_check_move_complete_status(boardID, vectorSpace, 0, &moveComplete); CheckError; // Check the following error/axis off status for axis 1 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS1, &status); CheckError; axisStatus |= status; // Check the following error/axis off status for...
  • Page 85: Spherical Arcs

    A 3D spherical arc defines a 2D circular arc in the X'Y' plane of a coordinate system that is transformed by rotation in pitch and yaw from the normal 3D coordinate space (XYZ), as shown in Figures 6-6 and 6-7. © National Instruments Corporation flex_read_error_msg_rtn(boardID,&commandI D,&resourceID, &errorCode);...
  • Page 86 X'Y'Z' vector space rotates around the original Z-axis. The radius, start angle, and travel angle parameters also apply to a spherical arc that defines the arc in two dimensions. NI-Motion User Manual Figure 6-7. Changing Yaw by Rotating the Z Axis ni.com...
  • Page 87: Algorithm

    Algorithm © National Instruments Corporation Load Velocity Load Acceleration/ Deceleration Load Spherical Arc Radius, Start Angle, Travel Angle, Yaw, and Pitch Start Motion Loop Waiting for Move Complete Perform Measurements (Optional) Figure 6-8. Spherical Arc Algorithm Chapter 6 Arc Moves...
  • Page 88: Labview Code

    4 Load Acceleration/Deceleration C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 89 © National Instruments Corporation /////////////////////////////// // Set the board ID boardID = 1; // Set the vector space number vectorSpace = NIMC_VECTOR_SPACE1; //////////////////////////////// // Configure a 3D vector space comprising of axes 1, 2 and 3 err = flex_config_vect_spc(boardID, vectorSpace, NIMC_AXIS1, NIMC_AXIS2, NIMC_AXIS3);...
  • Page 90 Chapter 6 Arc Moves NI-Motion User Manual // Check the following error/axis off status for axis 1 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS1, &status); CheckError; axisStatus |= status; // Check the following error/axis off status for axis 2 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS2, &status);...
  • Page 91: Helical Arcs

    Figure 6-10. 1 Side View of Helix 2 Top View of Helix © National Instruments Corporation //Get the command ID, resource ID, and the error code of the //modal error from the error stack on the device flex_read_error_msg_rtn(boardID,&commandI...
  • Page 92: Algorithm

    Chapter 6 Arc Moves Algorithm NI-Motion User Manual Load Velocity Load Acceleration/ Deceleration Load Helical Arc Radius, Start Angle, Travel Angle, Linear Travel Start Motion Loop Waiting for Move Complete Perform Measurements (Optional) Figure 6-11. Helical Arc Algorithm 6-14 Move Constraints ni.com...
  • Page 93: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void){ © National Instruments Corporation...
  • Page 94 Chapter 6 Arc Moves NI-Motion User Manual // Set the board ID boardID = 1; // Set the vector space number vectorSpace = NIMC_VECTOR_SPACE1; //////////////////////////////// // Configure a 3D vector space comprising of axes 1, 2 and 3 err = flex_config_vect_spc(boardID, vectorSpace, NIMC_AXIS1, NIMC_AXIS2, NIMC_AXIS3);...
  • Page 95 © National Instruments Corporation err = flex_read_axis_status_rtn(boardID, NIMC_AXIS1, &status); CheckError; axisStatus |= status; // Check the following error/axis off status for axis 2 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS2, &status); CheckError; axisStatus |= status; // Check the following error/axis off status for...
  • Page 96 Chapter 6 Arc Moves NI-Motion User Manual flex_read_error_msg_rtn(boardID,&commandI D,&resourceID, &errorCode); nimcDisplayError(errorCode,commandID,res ourceID); //Read the communication status register flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); else// Display regular error nimcDisplayError(err,0,0); return;// Exit the Application 6-18 ni.com...
  • Page 97: Contoured Moves

    If the current position is 100, and the buffer is [10, 20, 30, 40], the contour move follows these points: [100, 110, 120, 130, 140]. © National Instruments Corporation User-Defined Cubic Spine Points Figure 7-1.
  • Page 98: Arbitrary Contoured Moves

    NI Motion Assistant prototyping tool can remap a user-defined trajectory based on specified move constraints, preserving move characteristics and move geometry. NI-Motion User Manual Point[n] = Point[n-1] + bufferPosition[n] – 1. For absolute position mode, the first position in the array passed to –...
  • Page 99: Contoured Move Algorithm

    Restore Operation Mode Set operation mode back to absolute position to clear contouring data © National Instruments Corporation Chapter 7 Set the Buffer Type as Position Total Points is the total number of countoured points you want to load...
  • Page 100: Absolute Versus Relative Contouring

    28. If the axis starts at position 10, it ends up at position 38 in both cases. NI-Motion User Manual Figure 7-3. Absolute Contouring Buffer Values Figure 7-4. Relative Contouring Buffer Values...
  • Page 101 Chapter 7 Contoured Moves © National Instruments Corporation NI-Motion User Manual...
  • Page 102: C/C++ Code

    1 Check Buffer C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual Figure 7-6.
  • Page 103 // Note requested time interval is hardcoded to 10 milliseconds err = flex_configure_buffer(boardID, 1 /*buffer number*/, vectorSpace, NIMC_POSITION_DATA, bufferSize, numPoints, NIMC_TRUE, 10, &actualInterval); CheckError; // Send the first 1,000 points of the data downloadData = malloc(sizeof(i32)*bufferSize); © National Instruments Corporation NI-Motion User Manual...
  • Page 104 Chapter 7 Contoured Moves NI-Motion User Manual for(i=0;i<bufferSize;i++){ downloadData[i] = points[currentDataPoint++]; err = flex_write_buffer(boardID, 1/*buffer number*/, bufferSize, NIMC_REGENERATION_NO_CHANGE, downloadData, 0xFF); free(downloadData); downloadData = NULL; CheckError; // Start Motion err = flex_start(boardID, vectorSpace, 0); CheckError; for(;;){ axisStatus = 0; // Check for available space and download remaining points // every 50 milliseconds Sleep(50);...
  • Page 105 © National Instruments Corporation CheckError; // Check the move complete status err = flex_check_move_complete_status(boardID, vectorSpace, 0, &moveComplete); CheckError; if(moveComplete) break; // Check for axis off status/following error or modal errors //Read the communication status register check the modal errors err = flex_read_csr_rtn(boardID, &csr);...
  • Page 106 Chapter 7 Contoured Moves NI-Motion User Manual // Free the buffer allocated on the motion controller memory err = flex_clear_buffer(boardID, 1/*buffer number*/); CheckError; return;// Exit the Application ////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 107: Reference Moves

    Available search operations include home switch, index pulse, forward limit switch, reverse limit switch, center, or run sequence. Refer to the NI-Motion VI Help or the NI-Motion Function Help for information about reference move options. © National Instruments Corporation...
  • Page 108: Reference Move Algorithm

    Chapter 8 Reference Moves Reference Move Algorithm NI-Motion User Manual Load Velocity Load Acceleration/ Deceleration Load Jerk Find Reference Typically a Find Home Loop Waiting for Find Complete Check Reference Find Reference Typically a Find Index Loop Waiting for Find Complete Check Reference Figure 8-1.
  • Page 109: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void){ © National Instruments Corporation...
  • Page 110 Chapter 8 Reference Moves NI-Motion User Manual //Variables for modal error handling u16 commandID;// The commandID of the function u16 resourceID;// The resource ID i32 errorCode;// Error code //Get the board ID printf("Enter the Board ID: "); scanf("%d", &scanVar); boardID=(u8)scanVar;...
  • Page 111 Exit the Application © National Instruments Corporation //Wait for Find Reference to complete on the axis AND also check //for modal errors at the same time //Read the current position of axis err = flex_read_pos_rtn(boardID, axis, &position); CheckError; //Display the current position of axis printf("\rAxis %d position: %10d", axis,...
  • Page 112 // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ else// Display regular error return;// Exit the Application NI-Motion User Manual //Get the command ID, resource ID, and the error code of the modal //error from the error stack on the device flex_read_error_msg_rtn(boardID,&commandID,&reso...
  • Page 113: Blending Moves

    Motion controllers can perform blending between two straight-line moves, between two arc moves, or between straight-line and arc moves. Blending does not work for reference and contoured moves. © National Instruments Corporation 2 End Point 3 Corner Rounded by Blending Figure 9-1.
  • Page 114: Superimpose Two Moves

    The velocity during the superimposition depends on the cruising velocity, deceleration, and jerk of the first move segment, and the jerk, acceleration, and cruising velocity of the second move segment. NI-Motion User Manual Superimpose the two moves by starting the second move as the first move starts to decelerate...
  • Page 115: Blend After First Move Is Complete

    Figure 9-3. 1 Blending Starts This type of blending is useful if you want to start two move segments, one after the other, with no delay between them. © National Instruments Corporation Velocity Figure 9-3. Blending after Move Complete Chapter 9...
  • Page 116: Blend After Delay

    Because two move segments are always used while blending, it is very important that you wait for the blend to complete before loading the next move segment you want to blend. NI-Motion User Manual Velocity 2 Blend is Complete Figure 9-4. Blending after a Delay...
  • Page 117: Blending Algorithm

    Blending Algorithm Figure 9-5 illustrates a generic algorithm for blending moves. © National Instruments Corporation Chapter 9 Load Move Segment 1 Coordinate Space, Move Constraints, etc. Start Motion Load Move Segment 2 Blend Motion Loop Waiting for Blend Complete Perform Measurements...
  • Page 118 Chapter 9 Blending Moves NI-Motion User Manual ni.com...
  • Page 119: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 120 Chapter 9 Blending Moves NI-Motion User Manual err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_POSITION); CheckError; // Load the first straight-line segments to position 5000, 5000 err = flex_load_vs_pos(boardID, vectorSpace, 5000, 5000, 0, 0xFF); CheckError; // Start the move err = flex_start(boardID, vectorSpace, 0);...
  • Page 121 © National Instruments Corporation err = csr & NIMC_MODAL_ERROR_MSG; CheckError; Sleep(50); //Check every 50 ms }while (!complete && !(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move //complete/following error/axis off // Load the final straightline segments to position 0, 0 err = flex_load_vs_pos(boardID, vectorSpace, 0, 0, 0, 0xFF);...
  • Page 122 Chapter 9 Blending Moves NI-Motion User Manual NIMC_AXIS_OFF_BIT)); //Exit on move complete/following error/axis off return;// Exit the Application /////////////////////////////////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ //Get the command ID, resource ID, and the...
  • Page 123: Electronic Gearing And Camming

    The superimposed move is added to the geared profile of the slave axis, which allows the slave axis to be synchronized on-the-fly. © National Instruments Corporation 10-1 NI-Motion User Manual...
  • Page 124: Algorithm

    Relative gearing allows you to change the gear ratio on-the-fly. The master move is calculated based on the master reference position, which is updated when gearing is enabled and is updated each time a new gear ratio is loaded. NI-Motion User Manual Set the Gear Ratio Enable gearing on the...
  • Page 125 For example, if the gear ratio is 2:1, the current master position is 1010, the current slave position is 3020, and the gear ratio is changed to 3:1, the slave axis jumps from 3020 to 3030 but the master position remains the same. © National Instruments Corporation Chapter 10 Master Position at Enable...
  • Page 126: Gear Master

    When an axis is geared to an ADC, the slave axis follows the binary value of the ADC as if it were a position. For example, if the binary code for 2 V is 6553, the slave axis tracks to this position. NI-Motion User Manual 10-4 ni.com...
  • Page 127: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation...
  • Page 128 Chapter 10 Electronic Gearing and Camming NI-Motion User Manual // Set the board ID boardID = 1; // Set the axis number slaveAxis = NIMC_AXIS1; // Master is encoder 4 master = NIMC_ENCODER4; //////////////////////////////// // Set up the gearing configuration for the slave...
  • Page 129 © National Instruments Corporation // Load the target position for the registration (superimposed) //move err = flex_load_target_pos(boardID, slaveAxis, 5000, 0xFF); CheckError; // Start registration move on the slave err = flex_start(boardID, slaveAxis, 0); CheckError; err = flex_wait_for_move_complete (boardID, slaveAxis, 0, 1000/*ms timeout*/, 20/*ms pollInterval*/, &moveComplete);...
  • Page 130: Camming

    These ratios are handled automatically by the motion controller, allowing precise switching of the gear ratios, as shown in Figure 10-6. Camming is used in applications where the slave axis follows a non-linear profile from a master device. NI-Motion User Manual Slave Figure 10-5. Master/Slave Ratio in Gearing 10-8...
  • Page 131 When the welding process is finished for one item, the welding point must quickly return to its initial position and the process repeats. © National Instruments Corporation 10-9 NI-Motion User Manual...
  • Page 132 If this application used gearing instead of camming, the latency, or delay, of loading a new gear ratio might cause an accumulation of position errors. NI-Motion User Manual position Figure 10-7. Welding Application First, it follows the material with the same speed as the conveyor belt.
  • Page 133: Algorithm

    The move profile is superimposed over the camming profile. Camming Superimposed Straight-line Move (optional) © National Instruments Corporation Designate a Master Camming Device Set the Master Cycle Configure the Buffer for Slave Positions Load the Slave Positions...
  • Page 134: Camming Table

    To move the welding point to its original position at the same time that the next part is in the correct position on the conveyor belt, the welding point must travel NI-Motion User Manual Time to dwell during welding...
  • Page 135 Table 10-1 shows that the camming cycle is 6,000 counts and is divided into equal length segments. Because the camming cycle is 6,000 counts, the master cycle must also be 6,000 counts. © National Instruments Corporation Slave 2000 1000 2000 Figure 10-10.
  • Page 136 Figure 10-13 shows that when the master axis moves to position 4,000, the gear ratio changes to –0.5. The slave axis travels half the distance that the master axis travels, and it travels in the opposite direction. NI-Motion User Manual Master 1000...
  • Page 137: Slave Offset

    Slave Offset In some camming applications, the slave axis might begin and end the camming cycle at different positions, as shown in Table 10-2. © National Instruments Corporation Chapter 10 Master 2000...
  • Page 138 1500 counts away from the starting position (0). With a slave offset of 500, the slave axis traverses the positions specified in the camming table, but it does not maintain the camming ratio. NI-Motion User Manual Figure 10-15. Camming without Offset 10-16...
  • Page 139: Master Offset

    Figure 10-16 shows that the master cycle intervals are offset by 50 counts. The master interval is shifted from 0, 2,000, 4,000, and 6,000 to 50, 2,050, 4,050, and 6,050. © National Instruments Corporation Chapter 10 Position = 50 When there is no master offset, the master cycle begins at position 0.
  • Page 140 Figure 10-16 and Figure 10-17. 2500 Without Master Offset 2000 1500 1000 NI-Motion User Manual Camming starts here at position 50 Master cycle begins at position 50. Figure 10-17. Camming Profile Starts when First Material Passes With Master Offset...
  • Page 141: Labview Code

    7 Load Move Constraint C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. /////////////// // Main Function void main(void) the camming process ©...
  • Page 142 TRUE, bufferInterval, &bufferInterval); positionSize, NIMC_REGENERATION_NO_CHANGE, positionArr, 0xFF); slaveAxis, TRUE, -1.0); can start the master NI-Motion User Manual u8 slaveAxis = 1; u8 buffer = 1; i32 positionArr[] = {0, 10000, 40000, 45000, 45000, NIMC_DATA data; i32 targetPos = 10000;...
  • Page 143 (csr & NIMC_MODAL_ERROR_MSG) // Get the command ID, resource and the error code of the modal //error from the error stack on the board © National Instruments Corporation err = flex_set_op_mode(boardID, slaveAxis, CheckError; // Set the maximum velocity data.doubleData = velocity;...
  • Page 144 Chapter 10 Electronic Gearing and Camming flex_read_error_msg_rtn(boardID, &commandID, &resourceID, &errorCode); nimcDisplayError(errorCode, commandID, resourceID); //Read the Communication Status Register flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); else// Display regular error nimcDisplayError(err,0,0); return;// Exit the Application NI-Motion User Manual 10-22 ni.com...
  • Page 145: Acquiring Time-Sampled Position And Velocity Data

    I/O reaction and host communication tasks. To achieve the best possible performance, keep host communications to a minimum when acquiring data. © National Instruments Corporation Step 1: Reads the position velocity...
  • Page 146: Algorithm

    1,024 samples per axis for four axes. You also can vary the time period between acquired samples from 3 ms to 65,535 ms. Algorithm NI-Motion User Manual Acquire Data Specify the number of axes, sample period, and number of samples...
  • Page 147 The data must be read one sample at a time. A four-axis sample uses the following pattern for returning the data. If you request 1,024 samples, you must read each of the 1,024 samples individually. © National Instruments Corporation Chapter 11 Acquiring Time-Sampled Position and Velocity Data Axis 1 position...
  • Page 148: Labview Code

    1 Acquire Trajectory Data C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual 2 Read Trajectory Data Figure 11-3.
  • Page 149 © National Instruments Corporation Chapter 11 Acquiring Time-Sampled Position and Velocity Data i32 axis1Positions[200];// Array to store the positions (1) i32 axis1Velocities[200];// Array to store velocities(1) i32 axis2Positions[200];// Array to store the positions (2) i32 axis2Velocities[200];// Array to store velocities(2) u16 numSamples = 200;// Number of samples...
  • Page 150 Chapter 11 Acquiring Time-Sampled Position and Velocity Data NI-Motion User Manual // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ //Get the command ID, resource ID, and the error code of the //modal error from the error stack on the device flex_read_error_msg_rtn(boardID,&commandI...
  • Page 151: Synchronization

    You can synchronize NI motion controllers with NI data and image acquisition devices using breakpoints and high-speed captures. Timing and triggering with NI-Motion is always related to either position or velocity. Synchronizing position and velocity information with the external world allows you to coordinate measurements with moves. You can program the motion controller to trigger another device at specified positions using RTSI or a pin on the Motion I/O connector.
  • Page 152: Absolute Breakpoints

    In certain cases, such as buffered and periodic breakpoints, the motion controller automatically re-enables the breakpoints. The implementation for absolute breakpoints is divided into the buffered breakpoint and single position breakpoint methods. NI-Motion User Manual Table 12-1. Breakpoint Modes on NI Motion Controllers NI 7350 12-2...
  • Page 153: Buffered Breakpoints (Ni 7350 Only)

    The motion controller automatically arms the next breakpoint in the buffer when the preceding breakpoint triggers. Therefore, enabling breakpoints occurs on a firmware-timed basis, which enables you to use a higher bandwidth. © National Instruments Corporation Chapter 12 12-3 Synchronization...
  • Page 154: Buffered Breakpoint Algorithm

    Write buffer (optional) Write remaining breakpoint positions to onboard buffer Clear buffer NI-Motion User Manual Load Breakpoint Array Set the buffer type to breakpoint positions Total Points is the total number of breakpoint positions you want to load Buffer Size is the size of the buffer you want to create on the device.
  • Page 155: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main function void main (void) © National Instruments Corporation...
  • Page 156 Chapter 12 Synchronization NI-Motion User Manual // Buffer resources i32 breakpointPositions[] = {1000, 1100, 1200, 1300, 1400, 1500, 1600}; u16 numberOfPoints = 7;// Number of breakpoints f64 actualInterval;// Required in the function call but not being //used f64 requestedInterval = 10.0;// Required in the function call but //not being used u32 backLog;// Number of space available in buffer...
  • Page 157 © National Instruments Corporation } while ((pointsDone != numberOfPoints) || (bufferState != NIMC_BUFFER_DONE)); // Clear the buffer err = flex_clear_buffer(boardID, buffer); CheckError; return; /////////////////////////////////////////////////// ///////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 158: Single Position Breakpoints

    Single Position Breakpoints Single position breakpoints execute one breakpoint per enabling. Single Position Breakpoint Algorithm Figure 12-3 shows the basic algorithm for implementing single position breakpoints. NI-Motion User Manual Configure breakpoint Configure breakpoint for absolute mode Load breakpoint position Absolute position where...
  • Page 159: Labview Code

    LabVIEW Code 1 Configure Breakpoint 2 Load Breakpoint Position © National Instruments Corporation 3 Enable Breakpoint Output 4 Read per Axis Status Figure 12-4. Single Position Breakpoint in LabVIEW 12-9 Chapter 12 Synchronization 5 Motion Error Handler NI-Motion User Manual...
  • Page 160: C/C++ Code

    RTSI line and the breakpoint line on the Motion I/O connector. C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 161 © National Instruments Corporation /////////////////////////////// // Set the board ID boardID = 1; // Set the axis number axis = NIMC_AXIS1; //////////////////////////////// // Route breakpoint 1 to RTSI line 1 err = flex_select_signal (boardID, NIMC_RTSI0 /*destination*/, NIMC_BREAKPOINT1/*source*/); CheckError; // Configure the breakpoint...
  • Page 162: Relative Position Breakpoints

    The relative NI-Motion User Manual Sleep (10); //Check every 10 ms }while (!(axisStatus & NIMC_POS_BREAKPOINT_BIT));...
  • Page 163: Relative Position Breakpoints Algorithm

    15,006; and 20,012. In this example, the axis moves three counts between a breakpoint and the subsequent re-enabling. For exact distances between breakpoints at high speeds, use Periodically Occurring © National Instruments Corporation Configure breakpoint Configure breakpoint for relative mode...
  • Page 164: Labview Code

    2 Configure Breakpoint C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 165 © National Instruments Corporation // Set the axis number axis = NIMC_AXIS1; /////////////////////////////// // Route breakpoint 1 to RTSI line 1 err = flex_select_signal (boardID, NIMC_RTSI1 /*destination*/, NIMC_BREAKPOINT1/*source*/); CheckError; // Configure Breakpoint err = flex_configure_breakpoint(boardID, axis, NIMC_RELATIVE_BREAKPOINT, NIMC_SET_BREAKPOINT, 0); CheckError;...
  • Page 166: Periodically Occurring Breakpoints

    Chapter 12 Synchronization Periodically Occurring Breakpoints NI-Motion allows you to program the motion controller to generate multiple breakpoints at fixed and exact intervals, regardless of the direction of travel or velocity. There are two ways to create periodically occurring breakpoints using NI-Motion functions, depending on which motion controller you have.
  • Page 167: Periodic Breakpoints (Ni 7350 Only)

    100, and the breakpoint period is set at 1,000, then the axis behaves as shown in Figure 12-8. Periodic Breakpoint Algorithm Figure 12-9 shows the basic algorithm for periodic breakpoints. © National Instruments Corporation –900 1100 2100...
  • Page 168: Labview Code

    3 Load Breakpoint Modulus C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 169 = flex_load_pos_bp(boardID,axis,bpPos,0xFF); CheckError; //Set the Period err = flex_load_bp_modulus(boardID,axis,bpPer,0xFF); CheckError; //Enable the breakpoint err = flex_enable_breakpoint(boardID,axis,NIMC_TRUE); CheckError; //Load a target position err = flex_load_target_pos(boardID,axis,targetPos,0xFF); CheckError; //Start the motion err = flex_start(boardID,axis,0); © National Instruments Corporation 12-19 NI-Motion User Manual...
  • Page 170 Chapter 12 Synchronization NI-Motion User Manual CheckError; printf("\n"); //Read the axis status err = flex_read_axis_status_rtn(boardID,axis,&axisStat us); CheckError; err = flex_read_pos_rtn(boardID,axis,&currentPos); CheckError; //Check the breakpoint bit bpStatus = !((axisStatus & NIMC_POS_BREAKPOINT_BIT)==0); //Check the profile complete bit profileStatus = !((axisStatus & NIMC_PROFILE_COMPLETE_BIT)==0);...
  • Page 171: Modulo Breakpoints (Ni 7330, Ni 7340 And Ni 7390 Only)

    500 and the breakpoint position to 0. If the breakpoint is enabled when the axis is at 710, the breakpoints at 1000 and 500 are both armed, as shown in Figure 12-11. © National Instruments Corporation nimcHandleError; // Check to see if there were any Modal Errors if (csr &...
  • Page 172 1500, 3500. If the breakpoint is enabled when the axis is at 2210, the breakpoints at 1500 and 3500 are both armed, as shown in Figure 12-12. Each time a breakpoint occurs, re-enable it to load the next breakpoint. NI-Motion User Manual –1000 –500 Figure 12-11.
  • Page 173: Modulo Breakpoints Algorithm

    Load breakpoint modulus Load breakpoint position Position where you want to trigger an event every time regardless of direction Enable breakpoint Wait for breakpoint to cause a trigger Figure 12-13. Modulo Breakpoints Algorithm © National Instruments Corporation 12-23 NI-Motion User Manual...
  • Page 174: Labview Code

    1 Configure Breakpoint 2 Load Breakpoint Modulus 1 Select Signal 2 Configure Breakpoint 3 Load Breakpoint Modulus NI-Motion User Manual 3 Load Breakpoint Position 4 Enable Breakpoint Output Figure 12-14. Modulo Breakpoint Using LabVIEW 4 Load Breakpoint Position 5 Enable Breakpoint Output Figure 12-15.
  • Page 175: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 176 Chapter 12 Synchronization NI-Motion User Manual err = flex_enable_breakpoint(boardID, axis, NIMC_TRUE); CheckError; // Check the move complete status/following error/axis off //status err = flex_read_axis_status_rtn(boardID, axis, &axisStatus); CheckError; // Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr);...
  • Page 177: High-Speed Capture

    The motion controller automatically arms the next high-speed capture, and writes the captured high-speed data into its onboard buffer. The enabling of high-speed capture occurs on a firmware-timed basis, which provides better frequency than the non-buffered high-speed capture method. © National Instruments Corporation nimcDisplayError(err,0,0); return;// Exit the Application 12-27...
  • Page 178: Buffered High-Speed Capture Algorithm

    Read buffer (optional) Read captured positions to free the buffer for more data to be written NI-Motion User Manual Set the buffer type to be high-speed capture positions Total Points is the total number of high-speed capture positions you...
  • Page 179: Labview Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation...
  • Page 180 Chapter 12 Synchronization NI-Motion User Manual u32 pointsDone;// Indicates the number of points that have been //consumed u16 bufferState;// Indicates the state of the onboard buffer u32 currentDataPoint = 0;// Indicates the next points to be read //from the buffer i32* readBuffer = NULL;// The temporary array that is...
  • Page 181 © National Instruments Corporation if (backlog > 0) readBuffer = (i32*)malloc(sizeof(i32)*backlog); // If captured position available in the buffer, read the //captured position from the buffer err = flex_read_buffer_rtn(boardID, 1/*buffer number*/, backlog, readBuffer); for(i=0;i<backlog;i++){ if(currentDataPoint > totalPoints) break; printf("capture pos %d\n", capturedPositions[currentDataPoin t]);...
  • Page 182: Non-Buffered High-Speed Capture

    Synchronization Non-Buffered High-Speed Capture Non-buffered high-speed capture allows you to configure a single high-speed capture event. For multiple high-speed captures, you must re-enable the high-speed capture each time it triggers. NI-Motion User Manual CheckError; return;// Exit the Application /////////////////////////////////////////////////// ////////////// // Error Handling nimcHandleError;...
  • Page 183: High-Speed Capture Algorithm

    High-Speed Capture Algorithm © National Instruments Corporation Configure high-speed capture Enable high-speed capture Wait for high-speed capture Read the high-speed capture status Do the required task on trigger This could be a starting move on an axis or vector space, or just reading...
  • Page 184: Labview Code

    To trigger the high-speed capture from a RTSI line, set the Destination parameter in Select Signal to High Speed Capture 1, as shown in Figure 12-20. NI-Motion User Manual 3 Read per Axis Status 4 Read Captured Position Figure 12-19. High-Speed Capture Using LabVIEW 12-34 ni.com...
  • Page 185: C/C++ Code

    The commandID of the function u16 resourceID;// The resource ID i32 errorCode;// Error code /////////////////////////////// // Set the board ID boardID = 1; // Set the axis number 12-35 Chapter 12 Synchronization folder on the NI-Motion CD for NI-Motion User Manual...
  • Page 186 Chapter 12 Synchronization NI-Motion User Manual axis = NIMC_AXIS1; //////////////////////////////// // Route HSC 1 to RTSI line 1 err = flex_select_signal (boardID, NIMC_HS_CAPTURE1 /*destination*/, NIMC_RTSI1/*source*/); CheckError; //Configure High-Speed Capture err = flex_configure_hs_capture(boardID, axis, NIMC_HS_LOW_TO_HIGH_EDGE, 0); CheckError; for(i=0; i<6; i++){ // Enable the high speed capture on axis err = flex_enable_hs_capture(boardID, axis, NIMC_TRUE);...
  • Page 187: Real-Time System Integration Bus (Rtsi)

    You can route phase A, phase B, and the index pulse of the encoder over RTSI. © National Instruments Corporation nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 188: Rtsi Implementation On The Motion Controller

    Host can read/update the buffers asynchronously Generate trigger (breakpoint) at a given position NI-Motion User Manual Write the captured position to the buffer or read the position from the buffer and enable the breakpoint. You must create the buffer. *NI 7350 only Figure 12-21.
  • Page 189: Position Breakpoints Using Rtsi

    Figure 12-23. Software Trigger Using RTSI You can use the Set I/O Port MOMO function to write directly to the RTSI lines to trigger other devices, as shown in Figure 12-24. © National Instruments Corporation Source: Destination: Position breakpoint Figure 12-22.
  • Page 190: High-Speed Capture Input Using Rtsi

    High-Speed Capture Input Using RTSI When the RTSI line receives the trigger from a data or image acquisition device, the corresponding high-speed capture occurs, as shown in Figure 12-25. NI-Motion User Manual Source: RTSI line Figure 12-25. High-Speed Capture Input Using RTSI 12-40...
  • Page 191: Torque Control

    In this mode, the torque or force sensor is connected to one of the analog inputs on the NI motion controller. That analog channel is used as the feedback sensor. © National Instruments Corporation Figure 13-1. Torque Control Using Analog Feedback Flowchart 13-1...
  • Page 192 +5 V, 0 V to 10 V, and –10 V to +10 V. When you use counts for entering the values of position, velocity, acceleration, and deceleration, you do not need to enter the counts/revolution value for the axis. Refer to the motion controller user manual for information about analog input ranges. NI-Motion User Manual 13-2 ni.com...
  • Page 193: Torque Control Using Analog Feedback Algorithm

    Torque Control Using Analog Feedback Algorithm © National Instruments Corporation Map the analog sensor as the primary feedback for the axis that is to maintain a constant torque or force Load target position in terms of volts. If you want to maintain 5 V, load 2047 counts.
  • Page 194: Labview Code

    Chapter 13 Torque Control LabVIEW Code 1 Load Velocity 2 Load Acceleration/Deceleration 3 Load Acceleration/Deceleration NI-Motion User Manual 4 Set Operation Mode 5 Load Target Position 6 Start Motion Figure 13-3. Torque Control Using Analog Feedback Using LabVIEW 13-4 7 Read per Axis Status 8 Motion Error Handler ni.com...
  • Page 195: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 196 Chapter 13 Torque Control NI-Motion User Manual err = flex_load_acceleration(boardID, axis, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk - s-curve time (in sample periods) err = flex_load_scurve_time(boardID, axis, 1000, 0xFF); CheckError; // Set the operation mode err = flex_set_op_mode (boardID, axis, NIMC_ABSOLUTE_POSITION);...
  • Page 197 © National Instruments Corporation }while (!moveComplete && !(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move complete/following error/axis off return;// Exit the Application /////////////////////////////////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 198: Monitoring Force

    For monitoring force, create an outer loop to monitor the torque sensor, and move the motor based on the value read from the torque sensor. NI-Motion User Manual Figure 13-4. Torque Control Using Analog Feedback Flowchart 13-8...
  • Page 199: Torque Control Using Monitoring Force Algorithm

    Torque Control Using Monitoring Force Algorithm © National Instruments Corporation Map the position sensor (encoder) as the primary feedback for the axis that is to maintain a constant torque or force Load move constraints: max velocity, max acceleration, and max...
  • Page 200: Labview Code

    Chapter 13 Torque Control LabVIEW Code 1 Load Velocity 2 Load Acceleration/Deceleration 3 Load Acceleration/Deceleration NI-Motion User Manual 4 Set Operation Mode 5 Read ADC 6 Load Target Position Figure 13-6. Torque Control Using Monitoring Force in LabVIEW 13-10 7 Start Motion...
  • Page 201: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 202 Chapter 13 Torque Control NI-Motion User Manual err = flex_load_acceleration(boardID, axis, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk (s-curve value) for the move (in sample periods) err = flex_load_scurve_time(boardID, axis, 100, 0xFF); CheckError; // Set the operation mode to velocity err = flex_set_op_mode(boardID, axis, NIMC_RELATIVE_POSITION);...
  • Page 203 © National Instruments Corporation Sleep (50); //Check every 50 ms }while (!(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on axis off return;// Exit the Application /////////////////////////////////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){...
  • Page 204: Speed Control Based On Analog Value

    Speed Control Based on Analog Feedback Algorithm The analog input could be connected to a force sensor, which ensures that the tension of a web being fed is maintained. NI-Motion User Manual Load move constraints Set operation mode Set to velocity mode...
  • Page 205: Labview Code

    LabVIEW Code 1 Load Velocity 2 Load Acceleration/Deceleration 3 Load Acceleration/Deceleration 4 Set Operation Mode © National Instruments Corporation 5 Start Motion 6 Read ADC 7 Load Velocity Figure 13-8. Speed Control Based on Analog Feedback Using LabVIEW 13-15 Chapter 13...
  • Page 206: C/C++ Code

    Torque Control C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 207 © National Instruments Corporation // Set the jerk (s-curve value) for the move (in sample periods) err = flex_load_scurve_time(boardID, axis, 100, 0xFF); CheckError; // Set the operation mode to velocity err = flex_set_op_mode(boardID, axis, NIMC_VELOCITY); CheckError; // Start the move err = flex_start(boardID, axis, 0);...
  • Page 208 Chapter 13 Torque Control NI-Motion User Manual Sleep (50); //Check every 50 ms }while (!(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on axis off return;// Exit the Application /////////////////////////////////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 209: Onboard Programs

    The jitter of the system increases with the number of devices used in your RT system. Enable only the devices you need to use for the current application. Because interrupts cause jitter, National Instruments recommends you configure your application to poll for data periodically rather than wait on an interrupt.
  • Page 210: Using Onboard Programs With Ni 73Xx Motion Controllers

    The onboard programs and housekeeping tasks are time-sliced among themselves. For greater control and determinism for the motion control system, National Instruments offers the LabVIEW Real-Time (RT) module motion control system, which consists of a PXI chassis, PXI motion controller or controllers, LabVIEW RT, and NI-Motion driver software.
  • Page 211: Writing Onboard Programs

    Note controllers. Almost all NI-Motion functions that execute on the host can run onboard. You can store up to 32 onboard programs on the motion controller. These onboard programs remain on the motion controller until you reset it. If you want the onboard programs to persist through a reset of the motion controller, save them to FLASH, as shown in Figure 14-2.
  • Page 212: Algorithm

    Chapter 14 Onboard Programs 1 Write the program you want to load onto onboard memory. You can use any NI-Motion functions between Begin and End Store. 2 Transfer the program to onboard RAM using the host communication handler. 3 Store the program to FLASH memory for more permanent storage (optional).
  • Page 213: Labview Code

    1 Begin Program Storage 2 Load Target Position 3 Load Velocity in RPM 4 Load Accel/Decel in RPS/s © National Instruments Corporation 5 Load Accel/Decel in RPS/s 6 Start Motion 7 End Program Storage Figure 14-4. Onboard Program in LabVIEW...
  • Page 214 Onboard Programs C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 215 © National Instruments Corporation err = flex_load_rpsps(boardID, axis, NIMC_BOTH, 50.00, 0xFF); CheckError; // Start the move err = flex_start(boardID, axis, 0); CheckError; // End Program Storage err = flex_end_store(boardID, 1); CheckError; return;// Exit the Application // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 216: Running, Stopping, And Pausing Onboard Programs

    You can pause an onboard program with a function call from the host, from the onboard program itself, or from another running onboard program. NI-Motion User Manual 14-8 ni.com...
  • Page 217: Automatic Pausing

    When the move is complete, the trajectory generator enables the I/O reaction task, which causes the onboard program to continue executing the next function in its sequence, as shown in Figure 14-5. © National Instruments Corporation Chapter 14 14-9 Onboard Programs...
  • Page 218 Chapter 14 Onboard Programs generator reaction Run program communication task task Onboard programs Figure 14-5. Executing Onboard Programs NI-Motion User Manual 14-10 ni.com...
  • Page 219: Onboard Program Conditional Execution Algorithm

    Onboard Program Conditional Execution Algorithm © National Instruments Corporation Begin store Put motion controller in store mode Load move parameters Load the move type Start move Wait for move event signal End store End the store mode Figure 14-6. Onboard Program Conditional Execution Algorithm...
  • Page 220: Labview Code

    3 Load Velocity in RPM C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual...
  • Page 221 = flex_start(boardID, axis, 0); CheckError; // Wait for move to complete err = flex_wait_on_event(boardID, 0, NIMC_WAIT, NIMC_CONDITION_MOVE_COMPLETE, (u8)(1<<axis), 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0); CheckError; // End Program Storage err = flex_end_store(boardID, 1); © National Instruments Corporation 14-13 NI-Motion User Manual...
  • Page 222: Using Onboard Memory And Data

    For example, you may want to update the velocity of an axis based on the analog voltage read from an ADC channel. This memory is statically allocated. NI-Motion User Manual CheckError; return;// Exit the Application ////////////////////// // Error Handling nimcHandleError;...
  • Page 223: Algorithm

    Algorithm Before you execute this program, set the operation mode of the axis to velocity mode. © National Instruments Corporation Begin store Put motion controller in store mode Set a label Read ADC Read the analog channel, and save value to an onboard variable...
  • Page 224: Labview Code

    1 Load Constant to Variable 2 Load Constant to Variable 3 Begin Program Storage 4 Set Operation Mode 5 Insert Program Label NI-Motion User Manual 6 Read ADC 7 Multiply Variables 8 Subtract Variables 9 Jump to Label on Condition 10 Load Velocity Figure 14-9.
  • Page 225: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 226 Chapter 14 Onboard Programs NI-Motion User Manual err = flex_read_adc16(boardID, NIMC_ADC1, 2); CheckError; //Multiply variable 2 (ADC value) with variable 1 (constant) // Save the result in variable 3 err = flex_mult_vars(boardID, 1, 2, 3); CheckError; //Subtract value in variable 3 from variable 4. The result is //unimportant, you just want to set the condition on board.
  • Page 227: Branching Onboard Programs

    To create loops, or conditional if statements, insert labels in the program you are storing and use the Jump to Label function to jump to that label based on the condition. © National Instruments Corporation ////////////////////// // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 228: Onboard Program Algorithm

    Chapter 14 Onboard Programs Onboard Program Algorithm Figure 14-10 shows an onboard program waiting for an I/O line to go active before starting a move. NI-Motion User Manual Begin Store Put Controller in Store Mode Set a Label Load Move Parameters...
  • Page 229: Labview Code

    1 Begin Program Storage 2 Set Operation Mode 3 Load Velocity in RPM 4 Insert Program Label 5 Load Target Position © National Instruments Corporation 6 Select MOMO 7 Wait on Condition 8 Start Motion 9 Select MOMO Figure 14-11. Continuously Executing Onboard Program in LabVIEW...
  • Page 230: C/C++ Code

    Onboard Programs C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 231 © National Instruments Corporation err = flex_load_target_pos(boardID, axis, 5000, 0xFF); CheckError; // Wait for line 1 on port 1 to go active to finish executing err = flex_wait_on_event(boardID, NIMC_IO_PORT1, NIMC_WAIT, NIMC_CONDITION_IO_PORT_MATCH, (u8)(1<<1)/*Indicates line 1*/, 0, NIMC_MATCH_ALL, 10000 /*time out*/, 0);...
  • Page 232: Math Operations

    Onboard Programs Math Operations NI-Motion always performs math operations on values stored in onboard variables, and all math operations set a global condition that the Jump to Label function uses to determine if the operation jumps to a particular label in the onboard program.
  • Page 233: Onboard Buffers

    You can use the memory on the NI motion controllers to create general-purpose buffers to read and write data, as shown in Figure 14-13. Host application © National Instruments Corporation Figure 14-12. Reading an Indirect Variable Reads data from the buffer asynchronously...
  • Page 234: Algorithm

    MustOn/MustOff (MOMO) protocol. Use these bits to synchronize an application running on the host computer with an onboard program, as shown in Figure 14-15. NI-Motion User Manual Set the buffer type to be high-speed capture positions Total Points is the total number of...
  • Page 235 13 to be set high on the device Read the onboard variable Set Bit 13 on MCS Continue execution Reset bit 13 to 0 of the next function Figure 14-16. Synchronization Algorithm © National Instruments Corporation 14-27 NI-Motion User Manual...
  • Page 236: Labview Code

    1 Load Constant to Variable 2 Load Constant to Variable 3 Begin Program Storage 4 Set Operation Mode 5 Load Velocity NI-Motion User Manual 6 Insert Program Label 7 Load Target Position 8 Start Motion 9 Select MOMO 10 Wait on Condition Figure 14-17.
  • Page 237 As the host is polling a register on the motion controller, it is not invoking the Host Communication Task on the real-time operating system on the motion controller. Therefore, the onboard programs executing are not preempted. In this situation, the onboard programs run deterministically. © National Instruments Corporation 14-29 NI-Motion User Manual...
  • Page 238: C/C++ Code

    Onboard Programs C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 239 // Set the 13th bit in the move complete status register so that //the host knows that the axis is about to reverse direction err = flex_set_status_momo(boardID, 0x20, 0); CheckError; // Jump unconditionally to load new target position © National Instruments Corporation 14-31 NI-Motion User Manual...
  • Page 240 Chapter 14 Onboard Programs NI-Motion User Manual err = flex_jump_on_event (boardID, 0, NIMC_CONDITION_TRUE, 0, 0, NIMC_MATCH_ALL, 1/*label number*/); CheckError; // End Program Storage err = flex_end_store(boardID, 1); CheckError; //------------------------------------------------ // Host program. This programs monitors the 13th bit in the move //complete status register and records the position the axis is //going to move to.
  • Page 241 © National Instruments Corporation err = flex_read_var_rtn(boardID, 1, &currentTargetPosition); CheckError; Sleep (50); //Check every 50 ms }while (!(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move complete/following error/axis off return;// Exit the Application // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr &...
  • Page 242: Onboard Subroutines

    If the I/O line is active, the main onboard program calls an onboard subroutine that rotates the motor clockwise. If the I/O line is inactive, the main onboard program calls an onboard subroutine that rotates the motor to counter clockwise. NI-Motion User Manual Start program 2 Figure 14-19. Onboard Subroutine Algorithm 14-34...
  • Page 243: Labview Code

    1 Begin Program Storage 2 Insert Program Label 3 Select MOMO 4 Jump to Label on Condition 5 Run Program © National Instruments Corporation 6 Wait on Condition 7 Jump to Label on Condition 8 Insert Program Label 9 Run Program Figure 14-20.
  • Page 244 Figure 14-21 shows the subroutine that causes the motor to rotate clockwise. 1 Begin Program Storage 2 Set Operation Mode 3 Load Target Position 4 Load Velocity in RPM NI-Motion User Manual 5 Load Accel/Decel in RPS/sec 6 Start Motion 7 Select MOMO Figure 14-21. Clockwise Subroutine Using LabVIEW 14-36...
  • Page 245 1 Begin Program Storage 2 Set Operation Mode 3 Load Target Position 4 Load Velocity in RPM © National Instruments Corporation 5 Load Accel/Decel in RPS/sec 6 Start Motion 7 Select MOMO Figure 14-22. Counter Clockwise Subroutine Using LabVIEW...
  • Page 246: C/C++ Code

    Onboard Programs C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 247 // Load Velocity in RPM err = flex_load_rpm(boardID, axis, 100.00, 0xFF); CheckError; // Load Acceleration and Deceleration in RPS/sec err = flex_load_rpsps(boardID, axis, NIMC_BOTH, 50.00, 0xFF); CheckError; // Start the move err = flex_start(boardID, axis, 0); © National Instruments Corporation 14-39 NI-Motion User Manual...
  • Page 248 Chapter 14 Onboard Programs NI-Motion User Manual CheckError; // Wait for move to complete err = flex_wait_on_event(boardID, 0, NIMC_WAIT, NIMC_CONDITION_MOVE_COMPLETE, 2/*Indicates axis 1*/, 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0); CheckError; // End Program Storage err = flex_end_store(boardID, 3); CheckError; //------------------------------------------------ // Onboard program 1.
  • Page 249 © National Instruments Corporation // Insert Label number 2 err = flex_insert_program_label(boardID, 2); CheckError; // Execute program 2 err = flex_run_prog(boardID, 2); CheckError; // Wait for program 2 to finish executing err = flex_wait_on_event(boardID, 2 /*program #*/, NIMC_WAIT, NIMC_CONDITION_PROGRAM_COMPLETE, 0, 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0);...
  • Page 250: Automatically Starting Onboard Programs

    I/O reaction time, even though host communications and I/O reaction have higher priorities than onboard programs because the motion controller must guarantee that every program runs for its allotted time per watchdog period. NI-Motion User Manual 14-42 ni.com...
  • Page 251: Creating Applications Using Ni-Motion

    You can combine the moves, input/output, and other functionality discussed in Part III, motion control applications. The following chapters show examples of typical motion control applications and how they are implemented using NI-Motion. • • © National Instruments Corporation Programming with...
  • Page 252: Connecting Straight-Line Move Segments

    You can increase the resolution of the scanning path by shortening the distance of the vertical straight-line moves. However, remember that increasing the resolution also increases the cycle time. © National Instruments Corporation Move the stage in a raster by connecting several straight-line move segments.
  • Page 253: Raster Scanning Using Straight Lines Algorithm

    Raster Scanning Using Straight Lines Algorithm The raster scanning algorithm for straight-line moves stops the motors after every segment of the move, so the cycle time is longer than other methods. NI-Motion User Manual Configure the coordinate space Load move constraints...
  • Page 254 Chapter 15 Scanning © National Instruments Corporation 15-3 NI-Motion User Manual...
  • Page 255 Scanning C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. # define d_numberOfSegments // Main Function void main(void){ NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 256 © National Instruments Corporation // Set the deceleration for the move (in counts/sec^2) err = flex_load_acceleration(boardID, vectorSpace, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk or s-curve in sample periods err = flex_load_scurve_time(boardID, vectorSpace, 100, 0xFF); CheckError; // Set the operation mode to absolute position err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_POSITION);...
  • Page 257 Chapter 15 Scanning NI-Motion User Manual //Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr); CheckError; //Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) err = csr & NIMC_MODAL_ERROR_MSG; CheckError; Sleep(10); //Check every 10 ms }while (!moveComplete &&...
  • Page 258: Blending Straight-Line Move Segments

    Figure 15-4 shows the path of the blended move segments. Refer to Chapter 9, with NI-Motion. © National Instruments Corporation Figure 15-4. Blended Raster Scanning Path Blending Moves, for information about using blending...
  • Page 259: Raster Scanning Using Blended Straight Lines Algorithm

    Chapter 15 Scanning Raster Scanning Using Blended Straight Lines Algorithm Start motion Loop waiting for move complete Check for errors NI-Motion User Manual Configure the coordinate space Load move constraints Set blend factor Set operation mode Create the move segments...
  • Page 260 Chapter 15 Scanning © National Instruments Corporation 15-9 NI-Motion User Manual...
  • Page 261: C/C++ Code

    Scanning C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. #define d_numberOfSegments // Main Function void main(void) NI-Motion User Manual u8 boardID;// Board identification number...
  • Page 262 © National Instruments Corporation // Set the deceleration for the move (in counts/sec^2) err = flex_load_acceleration(boardID, vectorSpace, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk or s-curve in sample periods err = flex_load_scurve_time(boardID, vectorSpace, 100, 0xFF); CheckError; // Load the blending factor err = flex_load_blend_fact(boardID, vectorSpace, -1, 0xFF);...
  • Page 263 Chapter 15 Scanning NI-Motion User Manual CheckError; }else{ // Check the blend complete status err = flex_check_blend_complete_status(b oardID, vectorSpace, 0, &complete); CheckError; // Check the following error/axis off status for axis 1 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS1, &status); CheckError; axisStatus |= status;...
  • Page 264: User-Defined Scanning Path

    The controller then interpolates the distance between your given points using a cubic spline algorithm. Figure 15-7 shows the scanning path used in the example that follows the figure. © National Instruments Corporation return;// Exit the Application // Error Handling nimcHandleError;...
  • Page 265 However you lose the benefit of the trajectory generator of the NI motion controller. Refer to Chapter 7, Contoured NI-Motion. NI-Motion User Manual Figure 15-7. User-Defined Scanning Path Moves, for information about using contoured moves with 15-14...
  • Page 266: User-Defined Scanning Path Algorithm

    User-Defined Scanning Path Algorithm © National Instruments Corporation Set operation mode Configure onboard buffer Write buffer Write the array of points and number of points to the buffer Start motion Loop waiting for move complete Check the onboard buffer number of points consumed...
  • Page 267 Chapter 15 Scanning NI-Motion User Manual 15-16 ni.com...
  • Page 268: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation u8 boardID;// Board identification number...
  • Page 269 Chapter 15 Scanning NI-Motion User Manual vectorSpace = NIMC_VECTOR_SPACE1; // Configure a 2D vector space comprised of axes 1 and 2 err = flex_config_vect_spc(boardID, vectorSpace, NIMC_AXIS1, NIMC_AXIS2, NIMC_AXIS3); CheckError; // Set the operation mode to absolute position err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_CONTOURING);...
  • Page 270 © National Instruments Corporation if(backlog >= 300){ downloadData = malloc(sizeof(i32)*backlog); dataCopied = 0; for(i=0;i<backlog;i++){ if(currentDataPoint > numPoints) break; downloadData[i] = points[currentDataPoint]; currentDataPoint++; dataCopied++; err = flex_write_buffer (boardID, 1 /*buffer number*/, dataCopied, 0, downloadData, 0xFF); free(downloadData); downloadData = NULL; CheckError; // Check the move complete status err = flex_check_move_complete_status (boardID, vectorSpace, 0, &moveComplete);...
  • Page 271 Chapter 15 Scanning NI-Motion User Manual err = flex_read_axis_status_rtn(boardID, NIMC_AXIS2, &status); CheckError; axisStatus |= status; if( (axisStatus & NIMC_FOLLOWING_ERROR_BIT) || (axisStatus & NIMC_AXIS_OFF_BIT) ){ break;//Break out of the for loop because an axis was killed //Set the mode back to absolute mode to get the motion...
  • Page 272: Rotating Knife

    This correction must occur after the blade has crossed position A so that the current cut is not damaged. To accomplish this goal, mark the correction point to be at position B, as shown in Figure 16-1. © National Instruments Corporation Electronic Gearing and Camming, for information about...
  • Page 273 Chapter 16 Rotating Knife A Synchronization Point B Correction Point Figure 16-1. Rotating Knife NI-Motion User Manual 16-2 ni.com...
  • Page 274: Algorithm

    Algorithm © National Instruments Corporation Initialize A = 0; B = 500 Set gear master = encoder 4; Slave = axis 1 Set gear ratio to 1:1 Assuming circumference of the blade = length of cut Load appropriate move constraints for the slave...
  • Page 275: Labview Code

    5 Set Operation Mode Figures 16-4 and 16-5 show the remaining cases for the block diagram in Figure 16-3. 1 Read Captured Position NI-Motion User Manual 6 Enable Gearing Single Axis 7 Enable High-Speed Capture 8 Read High-Speed Capture Status 9 Motion Error Handler Figure 16-3.
  • Page 276: C/C++ Code

    C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the NI-Motion CD for files that are complete and compile as is. // Main Function void main(void) © National Instruments Corporation Figure 16-5.
  • Page 277 Chapter 16 Rotating Knife NI-Motion User Manual // Set the axis number slaveAxis = NIMC_AXIS1; // Master is encoder 4 master = NIMC_ENCODER4; //////////////////////////////// //------------------------------------------------- // Set up the gearing configuration for the slave axis //------------------------------------------------- // Configure Gear Master err = flex_config_gear_master(boardID, slaveAxis, master);...
  • Page 278 © National Instruments Corporation // Check the high-speed capture status/following error/axis //off status err = flex_read_axis_status_rtn(boardID, slaveAxis, &axisStatus); CheckError; // Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr); CheckError; // Check the modal errors if (csr &...
  • Page 279 Chapter 16 Rotating Knife NI-Motion User Manual err = flex_start(boardID, slaveAxis, 0); CheckError; }// For loop return;// Exit the Application /////////////////// // Error Handling /////////////////// nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){...
  • Page 280: Sinusoidal Commutation For Brushless Servo Motion Control

    Ensure the system is away from any limits before performing shake and wake initialization. If the system has load or is moving against gravity, increase the shake and wake voltage. If there is significant jitter as the axis approaches zero, increase the duration. © National Instruments Corporation NI-Motion User Manual...
  • Page 281 Therefore, the commutation frequency is limited by the update rate of the control loop. To calculate the maximum commutation frequency supported at a particular PID update rate, use the following formula: NI-Motion User Manual counts per electrical cycle counts per electrical cycle...
  • Page 282 Troubleshooting Hall Effect Sensor Connections Complete the following steps if you have problems with Hall effect sensor connections. © National Instruments Corporation Appendix A Sinusoidal Commutation for Brushless Servo Motion Control Check the manuals that shipped with the hardware for connection procedures.
  • Page 283 8. Enable the axes, but leave them deactivated. Use the Enable Axes VI. 9. Load the appropriate control loop parameters. © National Instruments Corporation Function and/or VI Use the Clear Power Up Status VI. Use the Read Error Message VI.
  • Page 284 • Configure find reference settings • Configure DIO settings • Configure PWM settings • Gearing NI-Motion User Manual Function and/or VI Use the Stop Motion VI with Stop Type (Decel) set to Halt stop. Use the VIs on the Motion I/O palette to configure the capture and compare settings.
  • Page 285 Using the Motion Controller with the LabVIEW Real-Time Module Using NI-Motion on a real-time (RT) system is designed to be almost transparent for anyone familiar with NI-Motion. Using NI-Motion with RT requires the following hardware and software: • • •...
  • Page 286 NI motion controller. NI-Motion User Manual If NI-Motion is not already installed, right-click within the dialog box and select Install Software. A dialog appears that lets you select what to download. Make sure the checkbox next to NI-Motion RT is selected.
  • Page 287 To remove the mapped motion controller, browse to My System under Device and Interfaces. Right-click the mapped controller and select Unmap Remote Device. You should unmap devices when you no longer need to use them from the host machine. © National Instruments Corporation NI-Motion User Manual...
  • Page 288 Technical Support and Professional Services Visit the following sections of the National Instruments Web site at ni.com • • • If you searched your local office or NI corporate headquarters. Phone numbers for our worldwide offices are listed at the front of this manual. You also can visit...
  • Page 289 0 or 1. base address Memory address that serves as the starting address for programmable or I/O bus registers. All other addresses are located by adding to the base address. © National Instruments Corporation NI-Motion User Manual...
  • Page 290 API for the motion control devices. drive Electronic signal amplifier that converts motor control command signals into higher-voltage signals suitable for driving motors. driver Software that communicates commands to control a specific motion control device. NI-Motion User Manual ni.com...
  • Page 291 Mode of a stepper motor—For a two phase motor, this refers to alternately energizing two windings and then only one. In half step mode, alternate steps are strong and weak, but there is significant improvement in low-speed smoothness over the full-step mode. © National Instruments Corporation Glossary NI-Motion User Manual...
  • Page 292 Sensors that alert the control electronics that the physical end of travel is end-of-travel position near and that the motion must stop. (input) NI-Motion User Manual , used with units of , used with B in quantifying data or ni.com...
  • Page 293 Method of output capable of sinking current, but not sourcing current. open-loop Refers to a motion control system where no external sensors, or feedback devices, are used to provide position or velocity correction signals. © National Instruments Corporation Glossary NI-Motion User Manual...
  • Page 294 Sets the position breakpoint for an encoder in relative quadrature counts. relative position Destination or target position for motion specified with respect to the current location, regardless of its value. relative position mode Position relative to current position. NI-Motion User Manual ni.com...
  • Page 295 Any event that causes or starts some form of data capture. transistor-transistor logic © National Instruments Corporation Glossary NI-Motion User Manual...
  • Page 296 Timer task that shuts down, or resets, the motion control device if any serious error occurs. word Standard number of bits that a processor or memory manipulates at one time, typically 8-bit, 16-bit, or 32-bit. NI-Motion User Manual ni.com...
  • Page 297 , 4-8 acceleration in RPS/s, 4-9 acquiring data algorithm, 11-2 C/C++ code, 11-4 data path, 11-1 LabVIEW code, 11-4 adding, measurements to an NI-Motion application, 2-2 algorithms position-based straight-line move, 5-2 velocity-based straight-line move, 5-11 Amplifier Gain, 3-7 analog feedback...
  • Page 298 3-10 velocity amplifiers, 3-10 velocity feedforward, 3-5 controlling torque, 13-1 conventions used in the manual, xiii counts per electrical cycle, A-2 creating NI-Motion applications, 2-1 generic steps diagram, 2-2 I/O diagram, 2-3 data, acquiring time-sampled position and velocity algorithm, 11-2...
  • Page 299 LabVIEW code, 10-5, 10-19 graphing data, 4-14 Hall effect sensors, A-1 troubleshooting, A-3 hardware functional architecture of NI motion controllers, 1-4 interaction with NI-Motion driver software, 1-2 helical arc move, 6-13 algorithm, 6-14 C/C++ code, 6-15 LabVIEW code, 6-15 help...
  • Page 300 Kdac, 3-6 Kt, 3-7 proportional gain, 3-4 velocity feedback, 3-5, 3-9 algorithm, 3-10 velocity amplifiers, 3-10 velocity feedforward, 3-5 creating NI-Motion applications, 2-1 generic steps diagram, 2-2 I/O diagram, 2-3 documentation, xiv examples, xiv NI motion controller architecture control loop, 1-6...
  • Page 301 2-1, 2-2 documentation, xiv examples, xiv introduction, 1-1 using with data acquisition, 2-3 using with image acquisition, 2-3 NI-Motion applications adding measurements, 2-2 creating, 2-1, 2-2 NI-Motion architecture, 1-1, 1-7 onboard buffers algorithm, 14-26 data flow, 14-25 Index NI-Motion User Manual...
  • Page 302 LabVIEW code, 14-35 synchronizing host applications with, 14-26 algorithm, 14-27 C/C++ code, 14-30 data flow, 14-27 LabVIEW code, 14-28 NI-Motion User Manual using onboard memory and data, 14-14 algorithm, 14-15 C/C++ code, 14-17 LabVIEW code, 14-16 writing, 14-3 output. See synchronization...
  • Page 303 Kt, 3-7 proportional gain, 3-4 velocity feedback, 3-5, 3-9 algorithm, 3-10 velocity amplifiers, 3-10 velocity feedforward, 3-5 © National Instruments Corporation shake and wake, A-1 single-stepping onboard programs, 14-9 sinusoidal commutation, A-1 commutation frequency, A-2 determining counts per electrical cycle, A-2...
  • Page 304 LabVIEW code with RTSI, 12-10 high-speed capture, 12-27 buffered, 12-27 C/C++ code, 12-29 non-buffered algorithm, 12-33 C/C++ code, 12-35 NI-Motion User Manual LabVIEW code, 12-34 single algorithm, 12-33 C/C++ code, 12-35 LabVIEW code, 12-34 RTSI encoder pulses, 12-39 hardware implementation, 12-38...
  • Page 305 4-11 travel angle, 6-2 troubleshooting (NI resources), D-1 tuning the motors, 3-1 using data acquisition with NI-Motion, 2-3 image acquisition with NI-Motion, 2-3 using onboard memory and data, 14-14 algorithm, 14-15 C/C++ code, 14-17 LabVIEW code, 14-16...

Table of Contents