National Instruments Home Safety Product NI Motion User Manual

Motion Control  
TM  
NI-Motion User Manual  
NI-Motion User Manual  
November 2005  
371242B-01  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Important Information  
Warranty  
The media on which you receive National Instruments software are warranted not to fail to execute programming instructions, due to defects  
in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. National  
Instruments will, at its option, repair or replace software media that do not execute programming instructions if National Instruments receives  
notice of such defects during the warranty period. National Instruments does not warrant that the operation of the software shall be  
uninterrupted or error free.  
A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of the package before  
any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of returning to the owner parts which are  
covered by warranty.  
National Instruments believes that the information in this document is accurate. The document has been carefully reviewed for technical  
accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to make changes to subsequent  
editions of this document without prior notice to holders of this edition. 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.  
EXCEPT AS SPECIFIED HEREIN, NATIONAL INSTRUMENTS MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF  
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. CUSTOMERS RIGHT TO RECOVER DAMAGES CAUSED BY FAULT OR NEGLIGENCE ON THE PART OF  
NATIONAL INSTRUMENTS SHALL BE LIMITED TO THE AMOUNT THERETOFORE PAID BY THE CUSTOMER. NATIONAL INSTRUMENTS WILL NOT BE LIABLE FOR  
DAMAGES RESULTING FROM LOSS OF DATA, PROFITS, USE OF PRODUCTS, OR INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY  
THEREOF. This limitation of the liability of National Instruments will apply regardless of the form of action, whether in contract or tort, including  
negligence. Any action against National Instruments must be brought within one year after the cause of action accrues. National Instruments  
shall not be liable for any delay in performance due to causes beyond its reasonable control. The warranty provided herein does not cover  
damages, defects, malfunctions, or service failures caused by owner’s failure to follow the National Instruments installation, operation, or  
maintenance instructions; owner’s modification of the product; owner’s abuse, misuse, or negligent acts; and power failure or surges, fire,  
flood, accident, actions of third parties, or other events outside reasonable control.  
Copyright  
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying,  
recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National  
Instruments Corporation.  
Trademarks  
National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section  
on ni.com/legalfor more information about National Instruments trademarks.  
FireWire® is the registered trademark of Apple Computer, Inc. Other product and company names mentioned herein are trademarks or trade  
names of their respective companies.  
Patents  
For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software, the patents.txtfile  
on your CD, or ni.com/patents.  
WARNING REGARDING USE OF NATIONAL INSTRUMENTS PRODUCTS  
(1) NATIONAL INSTRUMENTS PRODUCTS ARE NOT DESIGNED WITH COMPONENTS AND TESTING FOR A LEVEL OF  
RELIABILITY SUITABLE FOR USE IN OR IN CONNECTION WITH SURGICAL IMPLANTS OR AS CRITICAL COMPONENTS IN  
ANY LIFE SUPPORT SYSTEMS WHOSE FAILURE TO PERFORM CAN REASONABLY BE EXPECTED TO CAUSE SIGNIFICANT  
INJURY TO A HUMAN.  
(2) IN ANY APPLICATION, INCLUDING THE ABOVE, RELIABILITY OF OPERATION OF THE SOFTWARE PRODUCTS CAN BE  
IMPAIRED BY ADVERSE FACTORS, INCLUDING BUT NOT LIMITED TO FLUCTUATIONS IN ELECTRICAL POWER SUPPLY,  
COMPUTER HARDWARE MALFUNCTIONS, COMPUTER OPERATING SYSTEM SOFTWARE FITNESS, FITNESS OF COMPILERS  
AND DEVELOPMENT SOFTWARE USED TO DEVELOP AN APPLICATION, INSTALLATION ERRORS, SOFTWARE AND  
HARDWARE COMPATIBILITY PROBLEMS, MALFUNCTIONS OR FAILURES OF ELECTRONIC MONITORING OR CONTROL  
DEVICES, TRANSIENT FAILURES OF ELECTRONIC SYSTEMS (HARDWARE AND/OR SOFTWARE), UNANTICIPATED USES OR  
MISUSES, OR ERRORS ON THE PART OF THE USER OR APPLICATIONS DESIGNER (ADVERSE FACTORS SUCH AS THESE ARE  
HEREAFTER COLLECTIVELY TERMED “SYSTEM FAILURES”). ANY APPLICATION WHERE A SYSTEM FAILURE WOULD  
CREATE A RISK OF HARM TO PROPERTY OR PERSONS (INCLUDING THE RISK OF BODILY INJURY AND DEATH) SHOULD  
NOT BE RELIANT SOLELY UPON ONE FORM OF ELECTRONIC SYSTEM DUE TO THE RISK OF SYSTEM FAILURE. TO AVOID  
DAMAGE, INJURY, OR DEATH, THE USER OR APPLICATION DESIGNER MUST TAKE REASONABLY PRUDENT STEPS TO  
PROTECT AGAINST SYSTEM FAILURES, INCLUDING BUT NOT LIMITED TO BACK-UP OR SHUT DOWN MECHANISMS.  
BECAUSE EACH END-USER SYSTEM IS CUSTOMIZED AND DIFFERS FROM NATIONAL INSTRUMENTS' TESTING  
PLATFORMS AND BECAUSE A USER OR APPLICATION DESIGNER MAY USE NATIONAL INSTRUMENTS PRODUCTS IN  
COMBINATION WITH OTHER PRODUCTS IN A MANNER NOT EVALUATED OR CONTEMPLATED BY NATIONAL  
INSTRUMENTS, THE USER OR APPLICATION DESIGNER IS ULTIMATELY RESPONSIBLE FOR VERIFYING AND VALIDATING  
THE SUITABILITY OF NATIONAL INSTRUMENTS PRODUCTS WHENEVER NATIONAL INSTRUMENTS PRODUCTS ARE  
INCORPORATED IN A SYSTEM OR APPLICATION, INCLUDING, WITHOUT LIMITATION, THE APPROPRIATE DESIGN,  
PROCESS AND SAFETY LEVEL OF SUCH SYSTEM OR APPLICATION.  
Download from Www.Somanuals.com. All Manuals Search And Download.  
About This Manual  
Conventions ...................................................................................................................xiii  
Documentation and Examples .......................................................................................xiv  
Chapter 1  
Software and Hardware Interaction.................................................................1-2  
NI Motion Controller Architecture..................................................................1-2  
NI Motion Controller Functional Architecture................................................1-4  
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  
NI SoftMotion Controller for Ormec ..............................................................3-1  
Using Control Loops to Tune Servo Motors .................................................................3-1  
Control Loop ...................................................................................................3-2  
PID Loop Descriptions......................................................................3-4  
Velocity Feedback...........................................................................................3-9  
NI Motion Controllers with Velocity Amplifiers............................................3-10  
© National Instruments Corporation  
v
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Contents  
Chapter 4  
NI 73xx Time Base ........................................................................... 4-5  
NI 73xx Arc Move Limitations ....................................................................... 4-13  
Status Display ................................................................................................. 4-14  
Chapter 5  
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  
vi  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
LabVIEW Code...............................................................................................6-10  
C/C++ Code.....................................................................................................6-10  
Algorithm ........................................................................................................6-14  
Chapter 7  
Overview........................................................................................................................7-1  
Arbitrary Contoured Moves...........................................................................................7-2  
Absolute versus Relative Contouring ...............................................7-4  
Chapter 8  
Reference Moves  
Reference Move Algorithm.............................................................................8-2  
Chapter 9  
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  
vii  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Contents  
Algorithm........................................................................................................ 10-11  
Camming Table............................................................................................... 10-12  
Master Offset .................................................................................... 10-17  
Chapter 11  
Algorithm ......................................................................................................................11-2  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Real-Time System Integration Bus (RTSI) ...................................................................12-37  
RTSI Implementation on the Motion Controller.............................................12-38  
Encoder Pulses Using RTSI ............................................................................12-39  
LabVIEW Code...............................................................................................13-10  
C/C++ Code.....................................................................................................13-11  
Speed Control Based on Analog Feedback Algorithm....................................13-14  
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  
ix  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Contents  
Onboard Subroutines..................................................................................................... 14-34  
Algorithm........................................................................................................ 14-34  
C/C++ Code .................................................................................................... 14-38  
Automatically Starting Onboard Programs ................................................................... 14-42  
Changing a Time Slice .................................................................................................. 14-42  
Scanning  
Connecting Straight-Line Move Segments ................................................................... 15-1  
Raster Scanning Using Straight Lines Algorithm........................................... 15-2  
LabVIEW Code............................................................................................... 15-3  
C/C++ Code .................................................................................................... 15-4  
NI-Motion User Manual  
x
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
LabVIEW Code...............................................................................................15-9  
C/C++ Code.....................................................................................................15-10  
User-Defined Scanning Path Algorithm..........................................................15-15  
Rotating Knife  
Algorithm ........................................................................................................16-3  
LabVIEW Code...............................................................................................16-4  
C/C++ Code.....................................................................................................16-5  
Appendix A  
Sinusoidal Commutation for Brushless Servo Motion Control  
Appendix B  
Initializing the Controller Programmatically  
Appendix C  
Technical Support and Professional Services  
Glossary  
Index  
© National Instruments Corporation  
xi  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
About This Manual  
This manual provides information about the NI-Motion driver software,  
including background, configuration, and programming information.  
The purpose of this manual is to provide a basic understanding of the  
NI-Motion driver software, and provide programming steps and examples  
to help you develop NI-Motion applications.  
This manual is intended for experienced LabVIEW, C/C++, or other  
developers. 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:  
<>  
Angle brackets that contain numbers separated by an ellipsis represent a  
range of values associated with a bit or signal name—for example,  
AO <3..0>.  
[ ]  
Square brackets enclose optional items—for example, [response].  
»
The » symbol leads you through nested menu items and dialog box options  
to a final action. The sequence File»Page Setup»Options directs you to  
pull down the File menu, select the Page Setup item, and select Options  
from the last dialog box.  
This icon denotes a tip, which alerts you to advisory information.  
This icon denotes a note, which alerts you to important information.  
This icon denotes a caution, which advises you of precautions to take to  
avoid injury, data loss, or a system crash.  
bold  
Bold text denotes items that you must select or click in the software, such  
as menu items and dialog box options. Bold text also denotes parameter  
names.  
© National Instruments Corporation  
xiii  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
About This Manual  
italic  
Italic text denotes variables, emphasis, a cross reference, or an introduction  
to a key concept. Italic text also denotes text that is a placeholder for a word  
or value that you must supply.  
monospace  
Text in this font denotes text or characters that you should enter from the  
keyboard, sections of code, programming examples, and syntax examples.  
This font is also used for the proper names of disk drives, paths, directories,  
programs, subprograms, subroutines, device names, functions, operations,  
variables, filenames, and extensions.  
monospace bold  
Monospace bold text indicates a portion of code with structural  
significance.  
monospace italic  
Monospace italic text indicates a portion of code that is commented out.  
Documentation and Examples  
In addition to this manual, NI-Motion includes the following  
documentation to help you create motion applications:  
Getting Started with NI-Motion for NI 73xx Motion Controllers—This  
document provides installation instructions and general information  
about the NI-Motion product.  
Getting Started: NI SoftMotion Controller for Ormec  
ServoWire SM Drives—Refer to this document for information about  
getting started with the NI SoftMotion Controller for Ormec.  
Getting Started: NI SoftMotion Controller for Copley CANopen  
Drives—Refer to this document for information about getting started  
with the NI SoftMotion Controller for CANopen.  
NI-Motion VI Help—Refer to this document for specific information  
about NI-Motion LabVIEW VIs.  
NI-Motion Function Help—Refer to this document for specific  
information about NI-Motion C/C++ functions.  
Measurement & Automation Explorer Help for Motion—Refer to this  
document for configuration information.  
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/.  
NI-Motion User Manual  
xiv  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
         
About This Manual  
NI Developer Zone (NIDZ)—Visit the NI Developer Zone, at  
ni.com/zone, for example programs, tutorials, technical  
presentations, the Instrument Driver Network, a measurement  
glossary, an online magazine, a product advisor, and a community area  
where you can share ideas, questions, and source code with motion  
developers around the world.  
Motion Hardware Advisor—Visit the National Instruments Motion  
Hardware Advisor at ni.com/devzone/advisors/motion/to  
select motors and stages appropriate to the motion control application.  
In addition to the NI Developer Zone, you can find NI-Motion C/C++  
and Visual Basic programming examples in the NI-Motion\  
FlexMotion\Examplesfolder where you installed NI-Motion. The  
default directory is ProgramFiles\NationalInstruments\  
NI-Motion.  
You can find LabVIEW example programs under examples\Motion  
in the directory where you installed LabVIEW. You can find  
LabWindows/CVIexamples under samples\Motionin the directory  
where you installed LabWindows/CVI.  
You can find the NI-Motion C/C++ and LabVIEW example code  
referenced in this manual in the NI-Motion\Documentation\  
Examples\NI-Motion User Manualfolder where you installed  
NI-Motion.  
© National Instruments Corporation  
xv  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Part I  
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:  
Introduction to NI-Motion  
Creating NI-Motion Applications  
© National Instruments Corporation  
I-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
1
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.  
National Instruments also offers the Motion Assistant and NI-Motion  
development tools for Visual Basic.  
NI-Motion Architecture  
The NI-Motion driver software architecture is based on the interaction  
between the NI motion controllers and a host computer. This interaction  
includes the hardware and software interface and the physical and  
functional architecture of the NI motion controllers.  
© National Instruments Corporation  
1-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 1  
Introduction to NI-Motion  
Software and Hardware Interaction  
NI Motion Assistant  
Graphical Prototyping Tool  
Creates ADE  
Code  
Measurement and  
Automation Explorer  
Configuration Utility  
Application Development Environments:  
LabVIEW, Visual Basic, and C++  
NI-Motion Driver Software  
Figure 1-1. NI Motion Control Hardware and Software Interaction  
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.  
NI 73xx Architecture  
NI 73xx controllers use a dual-processor architecture. The two processors,  
a central processing unit (CPU) and a digital signal processor (DSP), form  
the backbone of the NI motion controller. The controller plugs into a  
variety of slots, including PCI slots, or to a PC using a high-speed serial  
interface, such as IEEE 1394 (FireWire®).  
NI-Motion User Manual  
1-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
               
Chapter 1  
Introduction to NI-Motion  
The controller CPU is a 32-bit micro-controller running an embedded real  
time, multitasking operating system. This CPU offers the performance and  
determinism needed to solve most complex motion applications. The CPU  
performs command execution, host synchronization, I/O reaction, and  
system supervision.  
The DSP has the primary responsibility of fast closed-loop control with  
simultaneous position, velocity, and trajectory maintenance on multiple  
axes. The DSP also closes the position and velocity loops, and directly  
Motion I/O occurs in hardware on an FPGA and consists of  
limit/home switch detection, position breakpoint, and high-speed capture.  
This ensures very low latencies in the range of hundreds of nanoseconds  
for breakpoints and high-speed captures. Refer to Chapter 12,  
Synchronization, for information about breakpoints and high-speed  
capture.  
The motion controller processor is monitored by a watchdog timer, which  
is hardware that can be used to automatically detect software anomalies and  
reset the processor if any occur. The watchdog timer checks for proper  
processor operation. If the firmware on the motion controller is unable to  
process functions within 62 ms, the watchdog timer resets the motion  
controller and disallows further communications until you explicitly reset  
the motion controller. This ensures the real-time operation of the motion  
control system. The following functions may take longer than 62 ms to  
process.  
Save Defaults  
Reset Defaults  
Enable Auto Start  
Object Memory Management  
Clear Buffer  
End Storage  
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  
1-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 1  
Introduction to NI-Motion  
Figure 1-2 illustrates the physical architecture of the NI motion controller  
hardware.  
NI Motion Controller  
Host Computer  
Microprocessor  
Running a Real-Time  
Operating System  
Digital Signal  
Processor (DSP)  
PC  
Supervisory/  
Communications/  
User-defined Onboard  
Programs  
Control Loop and  
Trajectory Generation  
FPGAs  
Watchdog  
Timer  
Encoders and Motion I/O  
Figure 1-2. Physical NI Motion Controller Architecture  
Tip Because the NI SoftMotion Controller is not a hardware device, information about  
its architecture is not covered in this section. Refer to the NI SoftMotion Controller  
Architecture section for information about the functional architecture that is specific to the  
NI SoftMotion Controller.  
NI Motion Controller Functional Architecture  
Functionally, the architecture of the NI 73xx motion controllers and the  
NI SoftMotion Controller is generally divided into four components:  
supervisory control, trajectory generator, control loop, and motion I/O. For  
the NI SoftMotion Controller, the motion I/O component is separate from  
the controller. Refer to Figure 1-3 and Figure 1-4 for an illustration of how  
the components of the 73xx and NI SoftMotion Controller interact.  
NI-Motion User Manual  
1-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 1  
Introduction to NI-Motion  
Figure 1-3 shows the components of the NI 73xx motion controllers.  
Typical NI 73xx Motion Controller Architecture  
Supervisory Control  
To drive  
Trajectory Generation  
Host  
Bus  
Control Loop  
From  
feedback  
& sensors  
Microcontroller running RTOS/DSPs/FPGAs  
Figure 1-3. Typical NI 73xx Motion Controller Functional Architecture  
Figure 1-4 shows the components of the NI SoftMotion controller.  
NI SoftMotion Controller Architecture  
Software is separate from the I/O  
Supervisory Control  
To drive  
Trajectory Generation  
Host  
Bus  
Control Loop  
From  
feedback  
& sensors  
Any CPU on a real-time environment  
Figure 1-4. NI SoftMotion Controller Functional Architecture  
© National Instruments Corporation  
1-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 1  
Introduction to NI-Motion  
Figure 1-5 illustrates the functional architecture of NI motion controllers.  
Trajectory Generation  
(ms)  
Cruise  
k
Jer  
Jer  
k
Supervisory Control  
(ms)  
Control Loop (µs)  
(with Interpolation)  
Decel  
Accel  
User API  
Interface  
Time  
Set Point  
dt  
Supervisory  
Control  
Commands for  
Trajectory Generator  
Interpolation  
Output  
PID  
New  
Set Point  
Updated  
Event Monitoring Interface  
Updates Trajectory  
Generator Based on  
I/O And User  
I/O  
Sensor  
Response  
Figure 1-5. NI Motion Controller Functional Architecture  
The following list describes how each component of the 73xx controllers  
and the NI SoftMotion Controller functions:  
Supervisory control—Performs all the command sequencing and  
coordination required to carry out the specified operation  
System initialization, which includes homing to a zero position  
Event handling, which includes electronic gearing, triggering  
outputs based on position, updating profiles based on user defined  
events, and so on  
Fault Detection, which includes stopping moves on a limit switch  
encounter, safe system reaction to emergency stop or drive faults,  
watchdog, and so on  
Trajectory generator provides path planning based on the profile  
specified by the user  
Control loop—Performs fast, closed-loop control with simultaneous  
position, velocity, and trajectory maintenance on one or more axes  
NI-Motion User Manual  
1-6  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
         
Chapter 1  
Introduction to NI-Motion  
The control loop handles closing the position/velocity loop based on  
feedback, and it defines the response and stability of the system. For  
stepper systems, the control loop is replaced with a step generation  
component. To enable the control loop to execute faster than the  
trajectory generation, an interpolation component, or spline engine, the  
control loop interpolates between setpoints calculated by the trajectory  
generator. Refer to Figure 1-5 for an illustration of the spline engine.  
Motion I/O—Analog and digital I/O that sends and receives signals  
from the rest of the motion control system. Typically, the analog output  
is used as a command signal for the drive, and the digital I/O is used  
for quadrature encoder signals as feedback from the motor. The motion  
I/O performs position breakpoint and high speed capture. Also, the  
supervisory control uses the motion I/O to achieve certain required  
functionality, such as reacting to limit switches and creating the  
movement modes needed to initialize the system.  
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.  
This separation of I/O from the motion controller software components  
helps to lower system cost and improve reliability by improving  
connectivity. Open standards, such as IEEE 1394 and CANopen, are  
used to connect these components.  
NI SoftMotion Controller for Ormec  
When you use the NI SoftMotion Controller with an Ormec device, you can  
daisy chain up to 15 drives together and connect them to the real-time host.  
The real-time isochronous mode of the IEEE 1394 bus is used to transfer  
data between the drives and the host. Figure 1-6 shows the NI SoftMotion  
Controller component architecture that applies when the controller is used  
with an Ormec device.  
The supervisory control and trajectory generation loops execute every  
millisecond. If the control loop is configured to execute faster than every  
millisecond, the trajectory data is interpolated before the control loop  
uses it.  
© National Instruments Corporation  
1-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 1  
Introduction to NI-Motion  
NI SoftMotion Controller on Host Device*  
Ormec Drive  
I/O**  
Supervisory  
Control  
Trajectory  
Generation  
Control  
Loop  
IEEE 1394 Bus  
*Host device is a PC or PXI chassis running the  
LabVIEW Real-Time Module for RTX Targets  
**I/O includes encoder implementation  
Figure 1-6. NI SoftMotion Controller Functional Architecture for Ormec  
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.  
All I/O required by the motion controller is implemented by CANopen  
drives that support the Device Profile 402 for Motion Control. Currently,  
the NI SoftMotion Controller supports only CANopen drives from Copley  
Controls Corp. When used with CANopen devices, the Supervisory  
Control and Trajectory Generation components of the NI SoftMotion  
Controller execute in a real-time environment that is running LabVIEW  
Real-Time Module (ETS).  
If your motion control system uses 8 axes or fewer, the supervisory control  
and trajectory generation loops execute every 10 milliseconds. If your  
motion control system uses more than 8 axes, the supervisory control and  
trajectory generation loops execute every 20 milliseconds. When you use  
the NI SoftMotion Controller with a CANopen drive, the drive implements  
the control loop and interpolation.  
NI-Motion User Manual  
1-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 1  
Introduction to NI-Motion  
NI SoftMotion Controller  
on Host Device*  
CANopen Drive  
Supervisory Trajectory  
Spline  
Engine  
Control  
Loop  
I/O**  
Control  
Generation  
CAN Bus  
*Host device is a PC or PXI chassis running the  
LabVIEW Real-Time Module  
**I/O includes encoder implementation  
Figure 1-7. NI SoftMotion Controller Functional Architecture for CANopen  
In this configuration, the I/O and the control loop execute on the CANopen  
drive. The NI SoftMotion Controller uses an NI-CAN device to  
communicate to the CAN bus.  
NI SoftMotion Controller Communication Watchdog  
The supervisory control in the NI SoftMotion Controller continuously  
monitors all communication with the drives connected to the host. If any  
drive fails to update its data in the host loop update period, the axis  
corresponding to that drive is disabled and the communication watchdog  
status bit, which is returned by the Read Per Axis Status function, is set to  
TRUE. Similarly, all drives connected to the NI SoftMotion Controller are  
configured to go into a fault state if the data from the  
NI SoftMotion Controller is not updated every host loop update period on  
the drives.  
The communication watchdog functionality ensures that the NI SoftMotion  
Controller operates in real time.  
Tip To get an axis or axes out of the communication watchdog state, reset the  
NI SoftMotion Controller.  
© National Instruments Corporation  
1-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
2
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.  
© National Instruments Corporation  
2-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 2  
Creating NI-Motion Applications  
Determine the system requirements  
Getting Started with NI-Motion  
Determine the  
for NI 73xx Motion Controllers  
required mechanical system  
Connect the hardware  
Configure the controller using  
MAX  
Measurement & Automation  
Explorer Help for Motion  
Test the motion system  
Plan the moves  
Part III:  
Programming with NI-Motion  
Create the moves  
Add measurements with data  
and/or image acquisition (optional)  
Figure 2-1. Generic Steps for Designing a Motion Application  
Adding Measurements to an NI-Motion Application  
Figure 2-2 illustrates an expanded view of the topics covered in Part III,  
Programming with NI-Motion, of this manual. For information about items  
in the diagram, refer to Chapter 12, Synchronization.  
NI-Motion User Manual  
2-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 2  
Creating NI-Motion Applications  
1
Define control mechanism for I/O  
Breakpoints*  
High-speed capture**  
2b  
2a  
Define breakpoint position  
Define triggering input type  
Enable high-speed capture  
Read the captured position  
Enable a breakpoint  
Set data or image acquisition  
device to trigger on breakpoint  
Re-enable the breakpoint  
after each occurrence  
(absolute/relative/modulo  
breakpoints only)  
Re-enable high-speed capture  
after each occurrence  
(non-buffered high-speed  
capture only)  
Chapter 12:  
Synchronization  
* Breakpoints cause a digital output to change state when a specified position is reached  
by an encoder. Breakpoints are not supported by the NI SoftMotion Controller when it is  
used with an Ormec or CANopen device.  
** A high-speed capture records the position of an encoder when a digital line is used as  
a trigger. 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.  
Figure 2-2. Input/Output with Data and Image Acquisition  
© National Instruments Corporation  
2-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 2  
Creating NI-Motion Applications  
Note If you are using RTSI to connect your motion controller to a National Instruments  
data or image acquisition device, be aware that the NI SoftMotion Controller does not  
support RTSI.  
NI-Motion User Manual  
2-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Part II  
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:  
Tuning Servo Systems  
© National Instruments Corporation  
II-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
3
Tuning Servo Systems  
When your motion control system includes a servo motor, you must tune  
and calibrate the system to ensure proper performance. This chapter covers  
general information about tuning and calibrating your servo system using  
control loop parameters. Refer to Measurement & Automation Explorer  
Help for Motion for more information about and instructions for tuning  
servo motors in Measurement & Automation Explorer (MAX).  
NI SoftMotion Controller Considerations  
This section includes information you need if you are using the  
NI SoftMotion Controller.  
NI SoftMotion Controller for CANopen  
This chapter does not apply if you are using the  
NI SoftMotion Controller for CANopen because the control loop is  
implemented on the drive. Refer to the drive documentation for  
information about tuning the servo motors you are using with the CANopen  
drive.  
NI SoftMotion Controller for Ormec  
If you are using the NI SoftMotion Controller for Ormec with an Ormec  
ServoWire drive in position mode, you must tune the control loop using the  
drive configuration utility provided by Ormec.  
Using Control Loops to Tune Servo Motors  
Tuning maximizes the performance of your servo motors. A servo system  
uses feedback to compensate for errors in position and velocity.  
For example, when the servo motor reaches the desired position, it cannot  
stop instantaneously. There is a normal overshoot that must be corrected.  
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  
3-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
             
Chapter 3  
Tuning Servo Systems  
A properly tuned servo system exhibits overshoot as shown in Figure 3-1.  
Overshoot  
Commanded  
Position  
Time  
0
Settling Time  
Figure 3-1. Properly Tuned Servo Motor Behavior  
The amount of time required for the motors to settle on the commanded  
position is called the settling time. By tuning the servo motors, you can  
affect the settling time, the amount of overshoot, and various other  
performance characteristics.  
Control Loop  
NI motion servo control uses control loops to continuously correct errors in  
position and velocity. 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  
3-2  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
     
Chapter 3  
Tuning Servo Systems  
© National Instruments Corporation  
3-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 3  
Tuning Servo Systems  
PID Loop Descriptions  
The following are common variables relating to the PID control loop.  
Kp (Proportional Gain)  
The proportional gain (Kp) determines the contribution of restoring force  
that is directly proportional to the position error. This restoring force  
functions in much the same way as a spring in a mechanical system.  
Each sample period, the PID loop calculates the position error, which is the  
difference between the instantaneous trajectory position and the primary  
feedback position, and multiplies the position error by Kp to produce the  
proportional component of the 16-bit DAC command output.  
An axis with too small a value of Kp is unable to hold the axis in position  
and is very soft. Increasing Kp stiffens the axis and improves its disturbance  
torque rejection. However, too large a value of Kp often results in  
instability.  
Ki (Integral Gain)  
The integral gain (Ki) determines the contribution of restoring force that  
increases with time, ensuring that the static position error in the servo loop  
is forced to zero. This restoring force works against constant torque loads  
to help achieve zero position error when the axis is stopped.  
Each sample period, the position error is added to the accumulation of  
previous position errors to form an integration sum. This integration sum is  
scaled by dividing by 256 prior to being multiplied by Ki.  
In applications with small static torque loads, this value can be left at its  
default value of zero (0). For systems having high static torque loads, this  
value should be tuned to minimize position error when the axis is stopped.  
Although non-zero values of Ki cause reduced static position error, they  
tend to cause increased position error during acceleration and deceleration.  
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.  
NI-Motion User Manual  
3-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 3  
Tuning Servo Systems  
Kd (Derivative Gain)  
The derivative gain (Kd) determines the contribution of restoring force  
proportional to the rate of change (derivative) of position error. This force  
acts much like viscous damping in a damped spring and mass mechanical  
system. A shock absorber is an example of this effect.  
The PID loop computes the derivative of position error every derivative  
sample period. A non-zero value of Kd is required for all systems that use  
torque block amplifiers, where the command output is proportional to  
motor torque, for the servo loop operation to be stable. Too small a Kd  
value results in servo loop instability.  
With velocity block amplifiers, where the command output is proportional  
to motor velocity, it is typical to set Kd to zero or a very small positive  
value.  
Kv (Velocity Feedback)  
You can use a primary or secondary feedback encoder for velocity  
feedback. Setting the velocity feedback gain (Kv) to a value other than  
zero (0) enables velocity feedback using the secondary encoder, if  
configured, or the primary encoder if a secondary encoder is not  
configured.  
Kv is used to scale this velocity feedback before it is added to the other  
components in the 16-bit DAC command output. Kv is similar to derivative  
gain (Kd) except that it scales the velocity estimated from encoder  
resources only. The derivative gain scales the derivative of the position  
error, which is the difference between the instantaneous trajectory position  
and the primary feedback position. Like the Kd term, the velocity feedback  
derivative is calculated every derivative sample period and the contribution  
is updated every PID sample period.  
Velocity feedback is estimated through a combination of speed-dependent  
algorithms. Velocity is measured based on the time elapsed between each  
encoder count.  
Vff (Velocity Feedforward)  
The velocity feedforward gain (Vff) determines the contribution in the  
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  
3-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 3  
Tuning Servo Systems  
Velocity feedforward is an open-loop compensation technique and cannot  
affect the stability of the system. However, if you use too large a value for  
Vff, following error can reverse during the constant velocity portion, thus  
degrading performance, rather than improving it.  
Velocity feedforward is typically used when operating in PIVff mode  
with either a velocity block amplifier or substantial amount of velocity  
feedback (Kv). In these cases, the uncompensated following error is  
directly proportional to the desired velocity. You can reduce this following  
error by applying velocity feedforward. Increasing the integral gain (Ki)  
also reduces the following error during constant velocity but only at the  
expense of increased following error during acceleration and deceleration  
and reduced system stability. For these reasons, increasing Ki is not a  
recommended solution.  
Tip In PIVff mode, the Kd and Kv gains are set to zero.  
Velocity feedforward is rarely used when operating in PID mode with  
torque block amplifiers. In this case, because the following error is  
proportional to the torque required, rather than the velocity, it is typically  
much smaller and does not require velocity feedforward.  
Aff (Acceleration Feedforward)  
The acceleration feedforward gain (Aff) determines the contribution in the  
16-bit DAC command output that is directly proportional to the  
instantaneous trajectory acceleration. Aff is used to minimize following  
error (position error) during acceleration and deceleration and can be  
changed at any time to tune the PID loop.  
Acceleration feedforward is an open-loop compensation technique and  
cannot affect the stability of the system. However, if you use too large a  
value of Aff, following error can reverse during acceleration and  
deceleration, thus degrading performance, rather than improving it.  
Kdac  
Kdac is the Digital to Analog Converter (DAC) gain. Use the following  
equation to calculate Kdac:  
20 V  
Kdac = -----------  
216  
20 V represents the 10 V range in the motion controller.  
NI-Motion User Manual  
3-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 3  
Tuning Servo Systems  
Ga  
Ga is the Amplifier Gain.  
Kt  
Kt is the Torque Constant of the motor. Kt is represented in Newton Meters  
per Amp.  
1/J  
1/J represents the motor plus load inertia of the motion system.  
Ke  
Ke represents the conversion factor to revolutions. This may involve a  
scaling factor.  
Dual Loop Feedback  
Motion control systems often use gears to increase output torque, increase  
resolution, or convert rotary motion to linear motion. The main  
disadvantage of using gears is the backlash created between the motor and  
the load. This backlash can cause a loss of position accuracy and system  
instability.  
The control loop on the motion system corrects for errors and maintains  
tight control over the trajectory. The control loop consists of three main  
parts—proportional, integral and derivative—known as PID parameters.  
The derivative part estimates motor velocity by differentiating the  
following error (position error) signal. This velocity signal adds, to the  
loop, damping and stability. If backlash is present between the motor and  
the position sensor, the positions of the motor and the sensor are no longer  
the same. This difference causes the derived velocity to become ineffective  
for loop damping purposes, which creates inaccuracy in position and  
system instability.  
Using two position sensors for an axis can help solve the problems caused  
by backlash. As shown in Figure 3-3, one position sensor resides on the  
load and the other on the motor before the gears. 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  
3-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 3  
Tuning Servo Systems  
Σ
Σ
Figure 3-3. Dual Loop Feedback  
Tip You can enable dual-loop feedback on the NI motion controller by mapping an  
encoder as the secondary feedback for the axis, and then using the velocity feedback gain  
instead of the derivative gain to dampen and stabilize the system, as shown in Figure 3-4.  
Figure 3-4. Dual Loop Feedback Algorithm  
NI-Motion User Manual  
3-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 3  
Tuning Servo Systems  
Velocity Feedback  
You can configure the NI motion controller for velocity feedback using the  
Kv (velocity feedback) gain. Using Kv creates a minor velocity feedback  
loop. This is very similar to the traditional analog servo control method of  
using a tachometer for closing the velocity loop. This type of feedback is  
necessary for systems where precise speed control is essential.  
You can use a less expensive standard torque, or current mode, amplifier  
with the velocity feedback loop on NI motion controllers to achieve the  
same results you would get from using velocity amplifiers, as shown in  
Figure 3-5.  
Σ
Σ
Figure 3-5. Velocity Feedback  
Setting any non-zero value for Kv allows you to use the Kv term instead of  
or in addition to the Kd term to stabilize the system.  
Velocity feedback gain (Kv) is similar to derivative gain (Kd) except that it  
scales the velocity estimated from encoder resources only. The derivative  
gain scales the derivative of the position error, which is the difference  
between the instantaneous trajectory position and the primary feedback  
position. 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  
3-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 3  
Tuning Servo Systems  
in Addition to Kd  
Figure 3-6. Alternate Dual-Loop Feedback Algorithm  
NI Motion Controllers with Velocity Amplifiers  
Velocity amplifiers close the velocity loop using a tachometer on the  
amplifier itself, as shown in Figure 3-7. In this case, the controller must  
ensure that the voltage output is proportional to the velocity. Use the  
velocity feedforward term (Vff) to ensure that there is minimum following  
error during the constant velocity profiles.  
Figure 3-7. NI Motion Controllers with Velocity Amplifiers  
NI-Motion User Manual  
3-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 3  
Tuning Servo Systems  
Figure 3-8 describes how to use NI motion controllers with velocity  
amplifiers.  
Figure 3-8. NI Motion Controllers with Velocity Amplifiers Algorithm  
You typically use velocity feedforward when using controllers with  
velocity amplifiers. The uncompensated following error is directly  
proportional to the specified velocity. You can reduce the following error  
by applying velocity feedforward. Increasing the integral gain (Ki) also  
reduces the following error during constant velocity, but at the expense of  
increased following error during acceleration and deceleration and reduced  
system stability.  
Note National Instruments does not recommend increasing Ki.  
Velocity feedforward is rarely used when operating in PID mode with  
torque block amplifiers. In this case, following error is typically much  
smaller because it is proportional to the torque required rather than to the  
velocity. When operating in PID mode with torque block amplifiers,  
velocity feedforward is not required.  
© National Instruments Corporation  
3-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Part III  
Programming with NI-Motion  
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. Then, the  
task discussion details any aspects of creating the task that are specific to  
LabVIEW or C/C++ programming, complete with diagrams and code  
examples.  
Note The LabVIEW block diagrams and C/C++ code examples are designed to illustrate  
concepts, and do not contain all the logic or safety features necessary for most functional  
applications.  
Refer to the NI-Motion Function Help or the NI-Motion VI Help for  
detailed information about specific functions or VIs.  
Part III covers the following topics:  
What You Need to Know about Moves  
Straight-Line Moves  
Arc Moves  
Contoured Moves  
Reference Moves  
Blending Moves  
Electronic Gearing and Camming  
Acquiring Time-Sampled Position and Velocity Data  
© National Instruments Corporation  
III-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Part III  
Programming with NI-Motion  
Synchronization  
Torque Control  
Onboard Programs  
NI-Motion User Manual  
III-2  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
4
What You Need to Know about  
Moves  
This chapter discusses the concepts necessary for programming motion  
control.  
Move Profiles  
The basic function of a motion controller is to make moves. The trajectory  
generator takes in the type of move and the move constraints and generates  
points, or instantaneous positions, in real time. Then, the trajectory  
generator feeds the points to the control loop.  
The control loop converts each instantaneous position to a voltage or to  
step-and-direction signals, depending on the type of motor you are using.  
Move constraints are the maximum velocity, acceleration, deceleration, and  
jerk that the system can handle. The trajectory generator creates a velocity  
profile based on these move constraint values.  
There are two types of profiles that can be generated while making the  
move: trapezoidal and s-curve.  
Trapezoidal  
When you use a trapezoidal profile, the axes accelerate at the acceleration  
value you specify, and then cruise at the maximum velocity you load.  
Based on the type of move and the distance being covered, it may be  
impossible to reach the maximum velocity you set.  
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  
4-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 4  
What You Need to Know about Moves  
Velocity  
Time  
Figure 4-1. Trapezoidal Move Profile  
S-Curve  
The acceleration and deceleration portions of an s-curve motion profile are  
smooth, resulting in less abrupt transitions, as shown in Figure 4-2. This  
limits the jerk in the motion control system, but increases cycle time. The  
value by which the profile is smoothed is called the maximum jerk or  
s-curve value.  
Velocity  
Time  
Figure 4-2. S-Curve Move Profile  
Basic Moves  
There are four basic move types:  
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  
line. The move can be based on position or velocity  
Arc Move—Moves from point A to point B in an arc or helix  
NI-Motion User Manual  
4-2  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
       
Chapter 4  
What You Need to Know about Moves  
Contoured Move—Is a user-defined move; you generate the  
trajectory, and the points loaded into the motion controller are splined  
to create a smooth profile  
The motion controller uses the specified move constraints, along with the  
move data, such as end position or radius and travel angle, to create a  
motion profile in all the moves except the contoured moves. Contoured  
moves ignore the move constraints and follow the points you have defined.  
Coordinate Space  
With the exception of the arc move, you can execute all basic moves on  
either a single axis or on a coordinate space. A coordinate space is a logical  
grouping of axes, such as the XYZ axis shown in Figure 4-3. Arc moves  
always execute on a coordinate space.  
If you are performing a move that uses more than one axis, you must  
specify a coordinate space made up of the axes the move will use, as shown  
in Figure 4-3.  
Z
X, Y, Z  
Y
X
Figure 4-3. 3D Coordinate Space  
Use the Configure Vector Space function to configure a coordinate space.  
This function creates a logical mapping of axes and treats the axes as part  
of a coordinate space.The function then executes the move generated by the  
trajectory generator on the vector, and treats all the move constraints as  
vector values.  
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  
4-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 4  
What You Need to Know about Moves  
grouping axes into coordinate spaces. Using a multi-start automatically  
starts all axes virtually simultaneously. To simultaneously end the moves,  
you must calculate the move constraints to end travel at the same time. 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. For servo axes, the encoder resolution,  
which is expressed in counts per revolution, determines the ultimate  
positional resolution of the axis.  
For stepper axes, the number of steps per revolution depends upon the type  
of stepper drive and motor you are using. For example, a stepper motor with  
1.8°/step (200 steps/revolution) used in conjunction with a 10X microstep  
drive has an effective resolution of 2,000 steps per revolution. Resolution  
on closed-loop stepper axes is limited to the steps per revolution or encoder  
counts per revolution, whichever value is more coarse.  
Floating-point versus fixed-point parameter representation and time base  
are two additional factors that affect the way trajectory parameters are  
loaded to the NI motion controller as compared to how they are used by the  
trajectory generators.  
The NI SoftMotion Controller uses a 64-bit floating point trajectory  
generator. The ranges for all move constraints are the full 64-bit range,  
which includes maximum velocity, maximum acceleration, maximum  
deceleration, maximum acceleration jerk, maximum deceleration jerk, and  
velocity override percentage. All arc parameters that use floating point also  
support the full 64-bit floating point range.  
NI 73xx Floating-Point versus Fixed-Point  
Note The information in this section applies only to NI 73xx motion controllers. These  
restrictions are not applicable to the NI SoftMotion Controller.  
You can load some trajectory parameters as either floating-point or  
fixed-point values, but the internal representation on the NI motion  
controller is always fixed-point. You must consider this functionality when  
working with onboard variables, inputs, and return vectors. This  
functionality also has a small effect on parameter range and resolution.  
NI-Motion User Manual  
4-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 4  
What You Need to Know about Moves  
NI 73xx Time Base  
Velocity and acceleration values are loaded in counts/s, RPM, RPS/s,  
steps/s, and so on, which are all functions of seconds or minutes. However,  
the trajectory generator updates target position at the Trajectory Update  
Rate, which is programmable with the Enable Axes function. This means  
that the range for these parameters depends on the update rate selected, as  
shown in the following examples.  
Table 4-1 lists minimum and maximum update rates for acceleration and  
velocity in various units.  
NI 73xx Velocity in RPM  
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.  
Table 4-1 shows the minimum and maximum velocity in counts/min. Use  
the formula shown in the Calculation Based on Units column to determine  
the counts/min value to RPM.  
Table 4-1. Velocity in Counts/Min  
Calculation Based  
Update Rate  
62.5 µs  
MIN  
MAX  
on Units  
14.648438 counts/min For servo motors, the  
RPMmax = MAX×1/r  
maximum counts/min is where r = counts/revolution  
1.2 billion independent  
of the update rate.  
125 µs  
7.324219 counts/min  
4.882813 counts/min  
3.662109 counts/min  
2.929688 counts/min  
2.441406 counts/min  
2.092634 counts/min  
1.831055 counts/min  
187.5 µs  
250 µs  
312.5 µs  
375 µs  
For stepper motors, the  
maximum counts/min  
value is dependent on the  
controller:  
RPMmin = MIN×1/r  
where r = counts/revolution  
437.5 µs  
500 µs  
• 480 million  
counts/min for 7350  
• 240 million  
counts/min for 7330,  
7340, and 7390  
© National Instruments Corporation  
4-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 4  
What You Need to Know about Moves  
You can calculate this minimum velocity increment in RPM with the  
following formula:  
1
Ts  
1
R
-----  
---  
minimum RPM = Vmin ×  
× 60 ×  
where  
Vmin = 1/65,536 counts/sample or steps/sample  
Ts = sample period in seconds per sample  
60 = number of seconds in a minute  
R = counts or steps per revolution  
or  
1
R
---  
minimum RPM = MIN ×  
You also can calculate the minimum velocity using the formula shown in  
the Calculation Based on Units column in Table 4-1.  
For a typical servo axis with 2,000 counts per revolution operating at a  
250 µs update rate, the minimum RPM increment is  
1
1
1
---------------  
---------------  
-----------  
×
× 60 ×  
= 0.00183105 RPM  
65,536  
250 µs  
2000  
or  
1
-----------  
3.662109 ×  
= 0.00183105 RPM  
2000  
You can calculate the maximum velocity in RPM with the following  
equation:  
1
R
---  
maximum RPM = Vmax × 60 ×  
where  
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  
R = counts/steps per revolution  
NI-Motion User Manual  
4-6  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
Chapter 4  
What You Need to Know about Moves  
and is constrained by acceleration/deceleration according to the following  
equation:  
velocity (65,536 × deceleration) – acceleration  
where velocity is in counts/sample and acceleration and deceleration are in  
counts/sample2.  
From the example, the maximum RPM is  
1
6
------------  
(20 × 10 ) × 60 ×  
= 600,000 RPM  
2,000  
RPM values stored in onboard variables are in double-precision IEEE  
format (f64).  
NI 73xx Velocity in Counts/s or Steps/s  
Velocity values in counts/s or steps/s are also converted to the internal  
16.16 fixed-point format in units of counts or steps per sample (update)  
period before being used by the trajectory generator. Although the motion  
controller can control velocity to 1/65,536 of a count or step per sample, it  
is impossible to load a value that small with the Load Velocity function, as  
shown in the following formula:  
1
Ts  
-----  
Velocity in counts or steps/s = Vmin ×  
where  
Vmin = 1/65,536 counts/sample or steps/sample  
Ts = sample period in seconds per sample  
Even at the fastest update rate, Ts = 62.5 × 10–6  
1
1
---------------  
--------------------------  
×
= 0.244 counts or steps/s  
6  
65,536  
62.5 × 10  
The Load Velocity function takes an integer input with a minimum value of  
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  
4-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 4  
What You Need to Know about Moves  
You can calculate the maximum velocity with the following equation:  
maximum velocity = Vmax  
Vmax = 20 MHz for servos  
where  
8 MHz for steppers on a NI 7350 controller  
4 MHz for steppers on a NI 7330, NI 7340, or NI 7390  
motion controller  
and is constrained by acceleration/deceleration according to the following  
equation:  
velocity (65,536 × deceleration) – acceleration  
where velocity is in counts/sample and acceleration and deceleration are in  
counts/sample2.  
NI 73xx Acceleration in Counts/s2  
Acceleration and deceleration values are converted to an internal  
16.16 fixed-point format in units of counts/s2 before being used by the  
trajectory generator.  
Table 4-2 shows the minimum and maximum acceleration update rates in  
counts/sec2.  
Table 4-2. Acceleration Update Rate in Counts/Sec2  
Calculation Based  
Update Rate  
MAX  
MIN  
on Units  
62.5 µs  
125 µs  
2,048,000,000 counts/sec2  
2,048,000,000 counts/sec2  
910,222,222 counts/sec2  
512,000,000 counts/sec2  
327,680,000 counts/sec2  
227,555,556 counts/sec2  
167,183,673 counts/sec2  
128,000,000 counts/sec2  
3906 counts/sec2  
977 counts/sec2  
434 counts/sec2  
244 counts/sec2  
156 counts/sec2  
109 counts/sec2  
80 counts/sec2  
61 counts/sec2  
Accelmax = MAX  
187.5 µs  
250 µs  
312.5 µs  
375 µs  
Accelmin = MIN  
437.5 µs  
500 µs  
NI-Motion User Manual  
4-8  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
   
Chapter 4  
What You Need to Know about Moves  
You can calculate the minimum acceleration increment with the following  
formula:  
2
1
Ts  
-----  
minimum acceleration/deceleration = Amin ×  
where  
Amin = 1/65,536 counts/sample2 or steps/sample2  
Ts = sample period in seconds per sample  
For a typical servo axis with 2,000 counts per revolution operating at the  
250 µs update rate, calculate the minimum acceleration/deceleration  
increment using the following equation:  
2  
1
1
×
= 244 counts/second2  
--------------  
--------------  
65536  
250µs  
You can calculate the maximum acceleration/deceleration using the  
following equation:  
2
1
Ts  
-----  
maximum acceleration/deceleration = Amax ×  
where  
Amax = 32 counts/sample2  
Ts = sample period in seconds per sample  
and is constrained according to the following equations:  
acceleration 256 × deceleration  
deceleration 65536 × acceleration  
NI 73xx Acceleration in RPS/s  
Acceleration and deceleration values in RPS/s are converted to an internal  
16.16 fixed-point format in units of counts/sample2 or steps/sample2 before  
being used by the trajectory generator.  
Table 4-3 shows the minimum and maximum acceleration update rates in  
counts/sec2.  
© National Instruments Corporation  
4-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 4  
What You Need to Know about Moves  
Table 4-3. Acceleration Update Rate in RPS/s  
Calculation Based  
on Units  
Update Rate  
MAX  
MIN  
2,048,000,000 counts/sec2  
2,048,000,000 counts/sec2  
910,222,222 counts/sec2  
512,000,000 counts/sec2  
327,680,000 counts/sec2  
227,555,556 counts/sec2  
167,183,673 counts/sec2  
128,000,000 counts/sec2  
62.5 µs  
125 µs  
3906 counts/sec2  
977 counts/sec2  
434 counts/sec2  
244 counts/sec2  
156 counts/sec2  
109 counts/sec2  
80 counts/sec2  
61 counts/sec2  
RPS/smax = MAX×1/r  
where r = counts/revolution  
187.5 µs  
250 µs  
312.5 µs  
375 µs  
RPS/smin = MIN×1/r  
where r = counts/revolution  
437.5 µs  
500 µs  
You can calculate the minimum acceleration increment in RPS/s with the  
following formula:  
2
1
Ts  
1
R
-----  
---  
RPS/s = Amin ×  
×
where  
Amin = 1/65,536 counts/sample2 or steps/sample2  
Ts = sample period in seconds per sample  
R = counts or steps per revolution  
or  
1
R
---  
RPM/s = MIN ×  
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:  
2  
1
1
1
---------------  
--------------  
-----------  
×
×
= 0.122070 RPS/s  
65,536  
250µs  
2000  
or  
1
-----------  
244 ×  
= 0.122  
2000  
NI-Motion User Manual  
4-10  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
 
Chapter 4  
What You Need to Know about Moves  
You can calculate the maximum RPS/s using the following equation:  
2
1
Ts  
1
R
-----  
---  
maximum RPS/s = Amax ×  
×
where  
Amax = 32 counts/sample2  
Ts = sample period in seconds per sample  
R = counts or steps per revolution  
and is constrained according to the following equations:  
acceleration 256 × deceleration  
deceleration 65536 × acceleration  
or  
1
r
--  
MAX ×  
For a typical servo axis with 2,000 counts or steps per revolution operating  
at the 250 µs update rate, calculate the maximum RPS/s increment using the  
following equation:  
2  
1
1
--------------  
-----------  
32 ×  
×
= 256,000 RPS/s  
250µs  
2000  
RPS/s values stored in onboard variables are in double-precision  
IEEE format (f64).  
NI 73xx Velocity Override in Percent  
The Load Velocity Override function takes a single-precision  
floating-point (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. The resolution for velocity override is  
therefore limited to 1/256, or about 0.39%.  
Note The conversion from floating-point to fixed-point is performed on the host  
computer, not on the motion controller. To load velocity override from an onboard variable,  
you must use the integer representation of 0 to 384, where 384 corresponds to 150%.  
© National Instruments Corporation  
4-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 4  
What You Need to Know about Moves  
Note If the distance of the move is too small, it may not be possible to reach the  
commanded maximum move constraints. In such instances, NI-Motion adjusts the move  
constraints lower to reach the commanded position.  
NI 73xx Arc Angles in Degrees  
The Load Circular Arc, Load Helical Arc, and Load Spherical Arc  
functions take angle parameters in degrees as double-precision  
floating-point values. These values are converted to an internal  
16.16 fixed-point representation where the integer part corresponds to  
multiples of 45° (for example, 360° is represented as 0x0008 0000).  
Use the following formula to convert from floating-point to fixed point:  
Angle in degrees  
---------------------------------------- = Q + R  
45°  
where  
Q = quotient, the integer multiple of 45°  
R = remainder  
·
R
45°  
--------  
Angle in 16.16 format = Q.  
× 65,536  
For example, 94.7° is represented in 16.16 format as follows:  
4.7°  
45°  
---------  
Angle in 16.16 format = 2.  
× 65,536 = 0x0002.1ABD  
The minimum angular increment is  
1
---------------  
× 45° = 0.000687°  
65.536  
Note The conversion from floating-point to fixed-point is performed on the host  
computer, not on the motion controller. To load arc functions from onboard variables,  
you must use the 16.16 fixed-point representation for all angles.  
NI-Motion User Manual  
4-12  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 4  
What You Need to Know about Moves  
NI 73xx Arc Move Limitations  
The following are limitations to the velocity and acceleration of arc moves.  
Arc moves must use the following equations or an  
NIMC_invalidVelocityErroris generated:  
V × P × 4 R  
and  
(V × P2 × 83,443)  
-------------------------------------------  
1,677,216 ≥  
16  
R × I  
where  
V = Velocity in counts/s  
P = PID sample rate in seconds  
I = Arc Interval (10 ms or 20 ms) in seconds  
R = Radius in counts  
Arc moves must use the following equations or an  
NIMC_invalidAccelerationErroris generated:  
A × P × 4 R  
and  
A × P3 × 83,443  
--------------------------------------  
65,536 ≥  
1  
R × I2  
where  
P = PID sample rate in seconds  
I = Arc Interval (10 ms or 20 ms) in seconds  
R = Radius in counts  
A = Acceleration/deceleration in counts/s2  
© National Instruments Corporation  
4-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
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.  
In fact, there is no need to update a display any faster than 22 Hz because  
the human eye can detect flicker only at refresh rates slower than 22 Hz.  
However, you might see flicker in monitors at around 60 Hz, because of  
interference with artificial light from light bulbs that run on a 60 Hz AC  
signal. The recommended standard is 60 ms because one might need  
multiple function calls within one loop to acquire all the necessary data.  
Graphing Data  
Event Polling  
When acquiring data for graphing or tracking purposes, a 10 ms update  
time suits most applications. MAX, for example, updates its motion graphs  
every 10 ms. This update time equates to 100 samples every second and  
provides enough resolution for typical applications. Consider how accurate  
the graph display is when choosing the timing for the loop.  
Use a polling interval of 5 ms when polling for a time-critical event that  
must occur before the program continues. This interval is fast enough to  
satisfy most time-critical polling needs, although certain high-speed  
applications may require a faster interval. Consider the allowable response  
time when choosing a polling interval.  
For example, to synchronize the motion with the acquisition in an  
application where a user places an object under the scan area and clicks a  
Scan button, you create periodic breakpoints every 10 counts to trigger a  
data acquisition over RTSI. In this example, the loop needs only to read the  
position and wait for the move to complete before ending the scan.  
Although the program polls for an event (move complete), no action is  
being triggered by the move complete. Because there is no need for  
instantaneous action, there is no need to update the position any faster than  
60 ms, and 60 ms is acceptable for monitoring the move complete status  
as well.  
NI-Motion User Manual  
4-14  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
               
5
Straight-Line Moves  
A straight-line move executes the shortest move between two points.  
Position-Based Straight-Line Moves  
Position-based straight-line moves use the specified target position to  
generate the move trajectory. For example, if the motor is currently at  
position zero, and the target position is 100, a position-based move creates  
a trajectory that moves 100 counts (steps).  
The controller requires the following information to move to another  
position in a straight line:  
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,  
maximum deceleration, and maximum jerk  
Tip When you are using the NI SoftMotion Controller, you can load separate acceleration  
and deceleration jerk values  
The motion controller uses the given information to create a trajectory that  
never exceeds the move constraints and that moves an axis or axes to the  
end position you specify. The controller generates the trajectory in real  
time, so you can change any of the parameters while the axes are moving.  
Straight-Line Move Algorithm  
The straight-line move algorithm includes the following procedures:  
Load target position—Specifies the end position  
Load the move constraints—Loads the velocity, acceleration,  
deceleration, and jerk values  
Start motion—Starts the move  
© National Instruments Corporation  
5-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 5  
Straight-Line Moves  
The start position is always the current position of the axis or axes. You can  
load the end position as either an absolute position to move to or as a  
position relative to the starting position. Although you can update any  
parameter while the move is in progress, the new parameter is used only  
after a subsequent Start or Blend Move.  
Tip You must load the move constraints only if they are different from what was  
previously loaded.  
Figure 5-1. Position-Based Straight-Line Move Algorithm  
NI-Motion User Manual  
5-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 5  
Straight-Line Moves  
6
1
5
3
4
2
7
8
9
10  
11  
12  
1
2
3
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
4
5
6
Load S-Curve Time  
Set Operation Mode  
Load Target Position  
7
8
9
Start Motion  
Read per Axis Status  
Motion Error Handler  
Figure 5-2. 1D Straight-Line Move in LabVIEW  
© National Instruments Corporation  
5-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 5  
Straight-Line Moves  
6
1
5
3
4
2
7
8
9
10  
11  
12  
1
2
3
4
Configure Vector Space  
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
5
Load S-Curve Time  
Set Operation Mode  
Load Target Position  
Start Motion  
9
Check Move Complete Status  
6
7
8
10 Read per Axis Status  
11 Read per Axis Status  
12 Motion Error Handler  
Figure 5-3. 2D Straight-Line Move in LabVIEW  
NI-Motion User Manual  
5-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
1D Straight-Line Move Code  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 moveComplete;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
////////////////////////////////  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
// Set the jerk - scurve time (in sample periods)  
© National Instruments Corporation  
5-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 5  
Straight-Line Moves  
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);  
CheckError;  
do  
{
axisStatus = 0;  
// Check the move complete status  
err = flex_check_move_complete_status(boardID,  
axis, 0, &moveComplete);  
CheckError;  
// Check the following error/axis off status for  
the axis  
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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
}while (!moveComplete && !(axisStatus &  
NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus &  
NIMC_AXIS_OFF_BIT));  
//Exit on move complete/following error/axis off  
return;// Exit the Application  
NI-Motion User Manual  
5-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
// Error Handling  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any modal errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
D, &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  
}
2D Straight-Line Move Code  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;  
u16 moveComplete;  
//Variables for modal error handling  
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  
vectorSpace = NIMC_VECTOR_SPACE1;  
© National Instruments Corporation  
5-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 5  
Straight-Line Moves  
// 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);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
// Set the jerk - scurve time (in sample periods)  
err = flex_load_scurve_time(boardID, vectorSpace,  
1000, 0xFF);  
CheckError;  
// Set the operation mode  
err = flex_set_op_mode (boardID, vectorSpace,  
NIMC_ABSOLUTE_POSITION);  
CheckError;  
// Load vector space position  
err = flex_load_vs_pos (boardID, vectorSpace,  
5000/*x Position*/, 10000/*y Position*/, 0/* z  
Position*/, 0xFF);  
CheckError;  
// Start the move  
err = flex_start(boardID, vectorSpace, 0);  
CheckError;  
do  
{
axisStatus = 0;  
// Check the move complete status  
err = flex_check_move_complete_status(boardID,  
vectorSpace, 0, &moveComplete);  
NI-Motion User Manual  
5-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
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;  
axisStatus |= status;  
// 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;  
}
}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 & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
D,&resourceID, &errorCode);  
nimcDisplayError(errorCode,commandID,res  
ourceID);  
//Read the communication status register  
© National Instruments Corporation  
5-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
flex_read_csr_rtn(boardID,&csr);  
}while(csr & NIMC_MODAL_ERROR_MSG);  
}
else// Display regular error  
nimcDisplayError(err,0,0);  
return;// Exit the Application  
}
Velocity-Based Straight-Line Moves  
Some motion applications require moves that travel in a straight line for a  
specific amount of time at a given speed. This type of move is known as  
velocity profiling or jogging.  
You can use a motion control application to move a motor at a given speed  
for a specific time, and then change the speed without stopping the axis.  
The sign of the loaded velocity specifies the direction of motion. Positive  
velocity implies forward motion and negative velocity implies reverse  
motion.  
Tip You can change the move constraints during a velocity move.  
NI-Motion User Manual  
5-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 5  
Straight-Line Moves  
Loading a second velocity and executing Start Motion causes the motion  
controller to accelerate or decelerate to the newly loaded velocity using the  
acceleration or deceleration parameters last loaded. 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.  
Velocity  
10,000  
Time  
5,000  
10,000  
Figure 5-5. Velocity Profile  
NI-Motion User Manual  
5-12  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
 
Chapter 5  
Straight-Line Moves  
LabVIEW Code  
6
7
9
10  
5
1
3
2
4
8
11 12  
1
2
3
4
Load Velocity  
5
6
7
8
Set Operation Mode  
Start Motion  
Read per Axis Status  
Load Velocity  
9
Start Motion  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
Load S-Curve Time  
10 Read per Axis Status  
11 Stop Motion  
12 Motion Error Handler  
Figure 5-6. Velocity-Based Straight-Line Move in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 moveTime1;// Time for the 1st segment  
i32 moveTime2;// Time for the 2nd segment  
i32 initialTime;  
i32 currentTime;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
© National Instruments Corporation  
5-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 5  
Straight-Line Moves  
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; //milliseconds  
//-------------------------------------------------  
//First segment  
//-------------------------------------------------  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// 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;  
// 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);  
CheckError;  
// Wait for the time for first segment  
initialTime = timeGetTime();  
NI-Motion User Manual  
5-14  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
do  
{
// 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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
// Get the current time and check if time is over  
for the first //segment  
currentTime = timeGetTime();  
if((currentTime - initialTime) >= moveTime1)  
break;  
Sleep (100); //Check every 100 ms  
}while (!(axisStatus) && !(axisStatus &  
NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus &  
NIMC_AXIS_OFF_BIT)); //Exit on following error/axis  
off  
//-------------------------------------------------  
// Second segment  
//-------------------------------------------------  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 6568, 0xFF);  
CheckError;  
// Start the move - to update the velocity  
err = flex_start(boardID, axis, 0);  
CheckError;  
// Wait for the time for second segment  
initialTime = timeGetTime();  
do  
{
// Check the following error/axis off status  
err = flex_read_axis_status_rtn(boardID, axis,  
&axisStatus);  
© National Instruments Corporation  
5-15  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
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;  
}
// Get the current time and check if time is over  
for the //second segment  
currentTime = timeGetTime();  
if((currentTime - initialTime) >= moveTime2)  
break;  
Sleep (100); //Check every 100 ms  
}while (!(axisStatus) && !(axisStatus &  
NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus &  
NIMC_AXIS_OFF_BIT)); //Exit on move  
complete/following error/axis off  
// Decelerate the axis to a stop  
err = flex_stop_motion(boardID, axis,  
NIMC_DECEL_STOP, 0);  
CheckError;  
return;// Exit the Application  
// Error Handling  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any modal errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
D,&resourceID, &errorCode);  
nimcDisplayError(errorCode,commandID,res  
ourceID);  
//Read the communication status register  
NI-Motion User Manual  
5-16  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
flex_read_csr_rtn(boardID,&csr);  
}while(csr & NIMC_MODAL_ERROR_MSG);  
}
else// Display regular error  
nimcDisplayError(err,0,0);  
return;// Exit the Application  
}
Velocity Profiling Using Velocity Override  
You also can use Load Velocity Override to shift from one velocity to  
another while executing moves. When you use this function, you indicate  
the new velocity in terms of a percentage of the originally loaded velocity  
instead of explicitly stating the velocity you want to change to.  
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  
5-17  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 5  
Straight-Line Moves  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 5  
Straight-Line Moves  
LabVIEW Code  
6
7
9
5
1
3
10  
Read per Axis Status  
10 Stop Motion  
11 Motion Error Handler  
11  
8
2
4
1
2
3
4
Load Velocity  
5
6
7
8
Set Operation Mode  
Start Motion  
Read per Axis Status  
Load Velocity Override  
9
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
Load S-Curve Time  
Figure 5-8. Velocity-Based Move Using Velocity Override in LabVIEW  
© National Instruments Corporation  
5-19  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 5  
Straight-Line Moves  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 moveTime1;// Time for the 1st segment  
i32 moveTime2;// Time for the 2nd segment  
i32 initialTime;  
i32 currentTime;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
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; //milliseconds  
////////////////////////////////  
//-------------------------------------------------  
//First segment  
//-------------------------------------------------  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
NI-Motion User Manual  
5-20  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 5  
Straight-Line Moves  
// 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;  
// 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);  
CheckError;  
// Wait for the time for first segment  
initialTime = timeGetTime();  
do  
{
// 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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
// Get the current time and check if time is over  
for the first //segment  
currentTime = timeGetTime();  
if((currentTime - initialTime) >= moveTime1)  
break;  
Sleep (100); //Check every 100 ms  
© National Instruments Corporation  
5-21  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
}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);  
CheckError;  
// Wait for the time for second segment  
initialTime = timeGetTime();  
do  
{
// 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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
// Get the current time and check if time is over  
for the second //segment  
currentTime = timeGetTime();  
if((currentTime - initialTime) >= moveTime2)  
break;  
Sleep (100); //Check every 100 ms  
}while (!(axisStatus) && !(axisStatus &  
NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus &  
NIMC_AXIS_OFF_BIT)); //Exit on move  
complete/following error/axis off  
// Decelerate the axis to a stop  
NI-Motion User Manual  
5-22  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 5  
Straight-Line Moves  
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 & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
© National Instruments Corporation  
5-23  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
6
Arc Moves  
An arc move causes a coordinate space of axes to move on a circular,  
spherical, or helical path. You can move two-dimensional vector spaces in  
a circle only on a 2D plane. You can move a 3D vector space on a spherical  
or helical path.  
Each arc generated by the motion controller passes through a cubic spline  
algorithm that ensures the smoothest arc. This also ensures negligible  
chordal error, which is error caused when two points on the surface of the  
arc join with each other using a straight line. A cubic spline algorithm  
generates multiple points between every two points of the arc, ensuring  
smooth motion, minimum jerk, and maximum accuracy at all times. The  
data path is shown in Figure 6-1.  
Output to DACs or  
Stepper Output  
Cubic Spine  
Arc Generation  
Figure 6-1. Arc Move Data Path  
Circular Arcs  
A circular arc defines an arc in the XY plane of a 2D or 3D coordinate  
space. The arc is specified by a radius, starting angle, and travel angle.  
Also, like all coordinate space moves, the arc uses the values of move  
constraints—maximum velocity, maximum acceleration, and maximum  
deceleration.  
Tip For the NI SoftMotion Controller, the arc generation also uses acceleration jerk and  
deceleration jerk while calculating the arc move.  
Note 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  
6-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 6  
Arc Moves  
To move axes in a circular arc, the motion controller needs the following  
information:  
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. For example, Figure 6-2 shows  
the effect of changing the start angle from 0° to 180°.  
1
0°  
180°  
2
1
Original Arc  
2
Arc with 180° Start Angle  
Figure 6-2. Rotating Start Angle  
Travel Angle—Indicates how far the arc travels in a 360° circle. For  
example, a travel angle of 90° executes a quarter-circle, a travel angle  
of 360° creates a full circle, and a travel angle of 720° creates two full  
circles. A positive travel angle always creates counterclockwise  
circular motion. A negative travel angle reverses the direction to create  
clockwise circular motion, as shown in Figure 6-3.  
NI-Motion User Manual  
6-2  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
       
Chapter 6  
Arc Moves  
1
2
1
Positive Travel Angle  
2
Negative Travel Angle  
Figure 6-3. Positive and Negative Travel Angles  
Arc Move Algorithm  
Load Velocity  
Move  
Constraints  
Load Acceleration/  
Deceleration  
Load Circular Arc  
Radius, Start Angle,  
and Travel Angle  
Start Motion  
Loop Waiting for Move Complete  
Perform Measurements  
(Optional)  
Figure 6-4. Circular Arc Move Algorithm  
© National Instruments Corporation  
6-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 6  
Arc Moves  
LabVIEW Code  
4
5
6
1
2
3
7
8
9
10  
1
2
3
4
Configure Vector Space  
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
5
6
7
Load Circular Arc  
Start Motion  
Check Move Complete Status  
8
9
Read per Axis Status  
Read per Axis Status  
10 Motion Error Handler  
Figure 6-5. Circular Arc Move in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;  
u16 moveComplete;  
//Variables for modal error handling  
NI-Motion User Manual  
6-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 6  
Arc Moves  
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  
and 2  
err = flex_config_vect_spc(boardID, vectorSpace,  
NIMC_AXIS1, NIMC_AXIS2, 0);  
CheckError;  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, vectorSpace,  
10000, 0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
// Load Spherical Arc  
err = flex_load_circular_arc (boardID, vectorSpace,  
5000/*radius*/, 0.0/*startAngle*/,  
180.0/*travelAngle*/, 0xFF);  
CheckError;  
//Start the move  
err = flex_start(boardID, vectorSpace, 0);  
CheckError;  
do  
{
axisStatus = 0;  
//Check the move complete status  
© National Instruments Corporation  
6-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
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  
axis 2  
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS2, &status);  
CheckError;  
axisStatus |= status;  
// 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;  
}
}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 & NIMC_MODAL_ERROR_MSG){  
do{  
//Get the command ID, resource ID and the  
error code of the //modal error from the  
error stack on the device  
NI-Motion User Manual  
6-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
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  
}
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.  
Z
Y
X
Figure 6-6. Changing Pitch by Rotating the X Axis  
© National Instruments Corporation  
6-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 6  
Arc Moves  
Z
Y
X
Figure 6-7. Changing Yaw by Rotating the Z Axis  
In the transformed X'Y'Z' space, the 3D arc is reduced to a simpler 2D arc.  
The 3D arc is defined as a 2D circular arc in the X'Y' plane of a transformed  
vector space X'Y'Z'. This transformed vector space, X'Y'Z', is defined in  
orientation only, with no absolute position offset. Its orientation is relative  
to the XYZ vector space, and is defined in terms of pitch and yaw angles.  
When rotating through the pitch angle, the Y and Y' axes stay aligned with  
each other while the X'Z' plane rotates around them. When rotating through  
the yaw angle, the Y' axis never leaves the original XY plane, as the  
newly-defined 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  
6-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 6  
Arc Moves  
Algorithm  
Load Velocity  
Move  
Constraints  
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  
© National Instruments Corporation  
6-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 6  
Arc Moves  
LabVIEW Code  
5
6
2
4
1
9
3
7
8
10  
11  
1
2
3
4
Configure Vector Space  
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
5
Load Spherical Arc  
Start Motion  
Check Move Complete Status  
Read per Axis Status  
9
Read per Axis Status  
6
7
8
10 Read per Axis Status  
11 Motion Error Handler  
Figure 6-9. Spherical Arc Move in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;  
u16 moveComplete;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
NI-Motion User Manual  
6-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 6  
Arc Moves  
///////////////////////////////  
// 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);  
CheckError;  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, vectorSpace,  
10000, 0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
// Load Spherical Arc  
err = flex_load_spherical_arc (boardID, vectorSpace,  
5000/*radius*/, 45.0/*planePitch*/,  
45.0/*planeYaw*/, 0.0/*startAngle*/,  
180.0/*travelAngle*/, 0xFF);  
CheckError;  
//Start the move  
err = flex_start(boardID, vectorSpace, 0);  
CheckError;  
do  
{
axisStatus = 0;  
//Check the move complete status  
err = flex_check_move_complete_status(boardID,  
vectorSpace, 0, &moveComplete);  
CheckError;  
© National Instruments Corporation  
6-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
// 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);  
CheckError;  
axisStatus |= status;  
// Check the following error/axis off status for  
axis 3  
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS3, &status);  
CheckError;  
axisStatus |= status;  
//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;  
}
}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 & NIMC_MODAL_ERROR_MSG){  
do{  
NI-Motion User Manual  
6-12  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
//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  
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  
}
Helical Arcs  
A helical arc defines an arc in a 3D coordinate space that consists of a circle  
in the XY plane and synchronized linear travel in the Z-axis. The arc is  
specified by a radius, start angle, travel angle, and Z-axis linear travel.  
Linear travel is the linear distance traversed by the helical arc on the Z-axis,  
as shown in Figure 6-10.  
Z
X
Z
4
Y
X
Y
X
1
2
3
1
Side View of Helix  
2
Top View of Helix  
3
Isometric View of Helix  
4
Linear Travel  
Figure 6-10. Helical Arc  
© National Instruments Corporation  
6-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 6  
Arc Moves  
Algorithm  
Load Velocity  
Move  
Constraints  
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  
NI-Motion User Manual  
6-14  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 6  
Arc Moves  
LabVIEW Code  
5
6
1
9
2
3
4
7
8
10  
11  
1
2
3
4
Configure Vector Space  
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
5
6
7
8
Load Helical Arc  
Start Motion  
Check Move Complete Status 11 Motion Error Handler  
Read per Axis Status  
9
Read per Axis Status  
10 Read per Axis Status  
Figure 6-12. Helical Arc Move in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void){  
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;  
u16 moveComplete;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
© National Instruments Corporation  
6-15  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 6  
Arc Moves  
// 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);  
CheckError;  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, vectorSpace,  
10000, 0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
// Load Helical Arc  
err = flex_load_helical_arc (boardID, vectorSpace,  
5000/*radius*/, 0.0/*startAngle*/,  
720.0/*travelAngle*/, 5000 /*linear travel*/, 0xFF);  
CheckError;  
//Start the move  
err = flex_start(boardID, vectorSpace, 0);  
CheckError;  
do  
{
axisStatus = 0;  
//Check the move complete status  
err = flex_check_move_complete_status(boardID,  
vectorSpace, 0, &moveComplete);  
CheckError;  
// Check the following error/axis off status for  
axis 1  
NI-Motion User Manual  
6-16  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
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  
axis 3  
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS3, &status);  
CheckError;  
axisStatus |= status;  
//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;  
}
}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 & NIMC_MODAL_ERROR_MSG){  
do{  
//Get the command ID, resource ID, and the  
error code of the //modal error from the  
error stack on the device  
© National Instruments Corporation  
6-17  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 6  
Arc Moves  
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  
}
NI-Motion User Manual  
6-18  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
7
Contoured Moves  
A contoured move moves an axis or a coordinate space of axes in a pattern  
that you define. The trajectory generator on the motion controller is not  
used during a contoured move. The controller takes position data in the  
form of an array, and splines the data before outputting it to the DACs or  
stepper outputs, as shown in Figure 7-1.  
User-Defined  
Points  
Output to DACs or  
Stepper Output  
Cubic Spine  
Figure 7-1. Contoured Move Data Path  
Overview  
All positions in a contouring buffer are relative to the current position when  
starting. There is an assumed 0 point that the firmware adds to the front of  
the buffer of points. For example, if the contour buffer is [10, 20, 30, 40],  
the positions are [0, 10, 20, 30, 40] in the firmware.  
When a contour move starts it takes a snap shot of the current position  
according to the following equation:  
StartPosition = currentPosition.  
The start position is added to each point in the buffer to get the actual  
position to move through according to the following equation:  
Point = StartPosition + bufferPosition[n].  
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  
7-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
             
Chapter 7  
Contoured Moves  
The difference between absolute contouring and relative contouring is how  
the points in the buffer are treated. The previous example was of an absolute  
contour move. A relative contour move treats the points as deltas according  
to the following formula:  
Point[n] = Point[n-1] + bufferPosition[n]  
For a relative contour move that starts at position 100 and includes a buffer  
with the following values: [10, 20, 30, 40], the points the contour move  
follows are [100, 110, 130, 160, 200].  
For contoured moves, no two consecutive points can differ by more than  
215 – 1. For absolute position mode, the first position in the array passed to  
the controller must be less than 215 – 1, and any two consecutive points  
must be less than 215 – 1. For relative position mode, no point passed to the  
controller can be greater than 215 – 1.  
Arbitrary Contoured Moves  
Contoured moves are useful when you want to generate a trajectory that  
cannot be constructed from straight lines and arcs. To ensure that the  
motion is smooth with minimum jerk, the motion controller creates  
intermediate points using a cubic spline algorithm.  
The move constraints commonly used to limit other types of moves, such  
as maximum velocity, maximum acceleration, maximum deceleration,  
and maximum jerk, have no effect on contoured moves. However, the  
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  
7-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 7  
Contoured Moves  
Contoured Move Algorithm  
Set Operation Mode  
Specify absolute or  
relative contouring  
Set the Buffer Type as Position  
Total Points is the total number of  
countoured points you want to load  
Buffer Size is the size of the buffer you  
Configure the buffer  
on the device  
want to create on the device  
Set Old Data Stop to TRUE if you do  
not want old data to be used  
Requested Interval is the time interval  
between points  
Write Buffer  
Write the array of points and the  
number of points you are writing  
Start Motion  
Loop Waiting for Move Complete  
Update Contoured Data (Optional)  
Check the buffer on the device  
Number of points consumed  
Write Buffer  
Write remaining points  
to onboard buffer  
Perform Measurements  
(Optional)  
Clear the buffer that stores  
contoured move points  
Restore Operation Mode  
Set operation mode back to absolute  
position to clear contouring data  
Figure 7-2. Contoured Move Algorithm  
© National Instruments Corporation  
7-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 7  
Contoured Moves  
All contoured moves are relative, meaning motion starts from the position  
of the axis or axes at the time the contouring move starts. This behavior is  
similar to the way arc moves work. Depending on the operation mode you  
use, you can load absolute positions in the array or relative positions, which  
imply incremental position differences between contouring points.  
Absolute versus Relative Contouring  
If an axis starts at position 0 and uses either of the following sets of  
contouring points, the axis ends up at position 28. If the axis starts at  
position 10, it ends up at position 38 in both cases.  
1
1
3
2
6
10  
14  
18  
22  
25  
27  
2
28  
1
Figure 7-3. Absolute Contouring Buffer Values  
3
4
4
4
4
3
Figure 7-4. Relative Contouring Buffer Values  
NI-Motion User Manual  
7-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 7  
Contoured Moves  
© National Instruments Corporation  
7-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 7  
Contoured Moves  
1
2
1
Check Buffer  
2
Write Buffer  
Figure 7-6. Contoured Move True Case in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;// Temporary copy of status  
u16 moveComplete;// Move complete status  
i32 i;  
i32 points[1994] =NIMC_SPIRAL_ARRAY;// Array of 2D  
points to move  
u32 numPoints = 1994;//Total number of points to  
contour through  
i32 bufferSize = 1000;// The size of the buffer to  
allocate on the //motion controller  
f64 actualInterval;// The interval at which the  
motion controller can // really contour  
NI-Motion User Manual  
7-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 7  
Contoured Moves  
i32* downloadData = NULL;// The temporary array that  
is created to // download the points to the motion  
controller  
u32 currentDataPoint = 0;// Indicates the next point  
in the points // array to download  
i32 backlog;// Indicates the available space to  
download more //points  
u16 bufferState;// Indicates the state of the onboard  
buffer  
u32 pointsDone;// Indicates the number of points that  
have been // consumed  
u32 dataCopied = 0;// Keeps track of the points  
copied  
//Variables for modal error handling  
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  
and 2  
err = flex_config_vect_spc(boardID, vectorSpace,  
NIMC_AXIS1, NIMC_AXIS2, NIMC_NOAXIS);  
CheckError;  
//Set the operation mode to absolute position  
err = flex_set_op_mode(boardID, vectorSpace,  
NIMC_ABSOLUTE_CONTOURING);  
CheckError;  
// Configure buffer on motion controller memory (RAM)  
// 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  
7-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 7  
Contoured Moves  
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);  
// Check to see if there are more points to  
download  
if(currentDataPoint < numPoints){  
err = flex_check_buffer_rtn(boardID,  
1/*buffer number*/, &backlog,  
&bufferState, &pointsDone);  
CheckError;  
if(backlog >= 300){  
downloadData =  
malloc(sizeof(i32)*backlog);  
dataCopied = 0;  
for(i=0;i<backlog;i++){  
if(currentDataPoint >  
numPoints) break;  
downloadData[i] =  
points[currentDataPoint++];  
dataCopied++;  
}
err = flex_write_buffer (boardID, 1  
/*buffer number*/, dataCopied,  
NIMC_REGENERATION_NO_CHANGE,  
downloadData, 0xFF);  
free(downloadData);  
downloadData = NULL;  
NI-Motion User Manual  
7-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 7  
Contoured Moves  
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);  
CheckError;  
//Check the modal errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
// Check the motor off status on all the axes or  
axis  
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS1, &status);  
CheckError;  
axisStatus |= status;  
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 controller out of // contouring mode  
err = flex_set_op_mode(boardID, vectorSpace,  
NIMC_ABSOLUTE_POSITION);  
CheckError;  
© National Instruments Corporation  
7-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 7  
Contoured Moves  
// 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 & NIMC_MODAL_ERROR_MSG){  
do{  
// 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  
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  
}
NI-Motion User Manual  
7-10  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
8
Reference Moves  
Use reference moves to move the axes to a known starting location and  
orientation. Reference functions include Find Reference, Check Reference,  
Wait Reference, Read Reference Status, Load Reference Parameters, and  
Get Reference Parameters.  
Use the Check Reference function to determine if the Find Reference  
operation is complete. This function is often placed in a loop that continues  
until the status for the Find Reference operation is shown to be complete.  
You can use the Wait Reference function if there is no need to monitor the  
status of the Find Reference function.  
Find Reference Move  
Use a Find Reference move to initiate a search operation to find a reference  
position. 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  
8-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 8  
Reference Moves  
Reference Move Algorithm  
Load Velocity  
Load Acceleration/  
Deceleration  
Move  
Constraints  
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. Find Reference Move Algorithm  
NI-Motion User Manual  
8-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 8  
Reference Moves  
LabVIEW Code  
1
2
3
4
5
6
7
8
1
2
3
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
4
5
6
Load S-Curve Time  
Find Reference  
Check Reference  
7
8
9
Read per Axis Status  
Check Reference  
Motion Error Handler  
Figure 8-2. Find Reference Move in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void){  
u8 boardID;// Board identification number  
u8 axis;// Axis number  
f64 acceleration=100;// Acceleration value in RPS/s  
f64 velocity=200;// Velocity value in RPM  
u16 found, finding;// Check reference statuses  
u16 axisStatus;// Axis status  
u16 csr = 0;// Communication status register  
i32 position;// Current position of axis  
i32 scanVar;// Scan variable to read in values not  
supported by  
// the scanf function  
© National Instruments Corporation  
8-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 8  
Reference Moves  
//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;  
//Check if the device is at power up reset condition  
err = flex_read_csr_rtn(boardID, &csr);  
CheckError;  
if (csr & NIMC_POWER_UP_RESET ){  
printf("\nThe FlexMotion device is in the reset  
condition. Please initialize the device before  
");  
printf("running this example. The  
\"flex_initialize_controller\" function will  
initialize the ");  
printf("board with settings selected through  
Measurement & Automation Explorer.\n");  
return;  
}
//Get the axis number  
printf("Enter the axis: ");  
scanf("%d",&scanVar);  
axis=(u8)scanVar;  
//Flush the Stdin  
fflush(stdin);  
//Load acceleration and deceleration to the axis  
selected  
err = flex_load_rpsps(boardID, axis, NIMC_BOTH,  
acceleration, 0xFF);  
CheckError;  
//Load velocity to the axis selected  
err = flex_load_rpm(boardID, axis, velocity, 0xFF);  
CheckError;  
//Start the Find Reference move  
err = flex_find_reference(boardID, axis, 0,  
NIMC_FIND_HOME_REFERENCE);  
CheckError;  
NI-Motion User Manual  
8-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 8  
Reference Moves  
//Wait for Find Reference to complete on the axis AND  
also check //for modal errors at the same time  
do{  
//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,  
position);  
//Check if the axis has stopped because of axis  
off or following //error  
err = flex_read_axis_status_rtn(boardID, axis,  
&axisStatus);  
//Check if the reference has finished finding  
err = flex_check_reference(boardID, axis, 0,  
&found, &finding);  
CheckError;  
//Read the communication status register - check  
the modal //error bit  
err = flex_read_csr_rtn(boardID, &csr);  
CheckError;  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
flex_stop_motion(boardID,NIMC_AXIS1,  
NIMC_DECEL_STOP, 0);//Stop the Motion  
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
//test for find reference complete, following  
error, or axis //off status  
}while (!(axisStatus & (NIMC_FOLLOWING_ERROR_BIT |  
NIMC_AXIS_OFF_BIT)) && finding);  
printf("\nAxis %d position: %10d", axis, position);  
if (found)  
printf("\rAxis found reference");  
else  
printf("\rAxis did not find reference");  
printf("\n\nFinished\n");  
return;// Exit the Application  
© National Instruments Corporation  
8-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 8  
Reference Moves  
///////////////////////////////////////////////////////  
/////////////  
// Error Handling  
//  
nimcHandleError;  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
urceID, &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  
8-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
9
Blending Moves  
Use blending moves to create continuous motion between two or more  
move segments.  
Blending  
Blending, also called velocity blending, superimposes the velocity profiles  
of two moves to maintain continuous motion. Blending is useful when  
continuous motion between concatenated move segments is important.  
Examples of some applications that can use blending are scanning,  
welding, inspection, and fluid dispensing.  
Blending must occur on velocity profiles of two move segments, so the end  
positions of each move segment may or may not be reached. For example,  
if you are blending two straight-line moves that form a 90º angle, the  
blended move must round the corner to make the move continuous. In this  
case, the move never reaches the exact position where the two straight lines  
meet, but instead follows the rounded corner, as shown in Figure 9-1.  
2
3
1
1
Starting Position  
2
End Point  
3
Corner Rounded by Blending  
Figure 9-1. Two Blended Straight-Line 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  
9-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
             
Chapter 9  
Blending Moves  
There are three ways you can start the second move in a blend:  
Superimpose the two moves by starting the second move as the first  
Start the second move after the first profile is complete  
Start the second move after the first profile is complete and the added  
delay time has elapsed  
Refer to the Move Profiles section of Chapter 4, What You Need to Know  
about Moves, for more information about move profiles.  
Superimpose Two Moves  
Superimposing two moves is the most common use of blending. In this  
case, the motion controller tries to maintain continuous motion by  
superimposing the two move segments such that the second move segment  
starts its profile while the first move is decelerating, as shown in  
Figure 9-2.  
1
2
3
Velocity  
Time  
1
Blending Starts  
2
Blend is Complete  
3
Actual Velocity  
Figure 9-2. Superimposing 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  
9-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 9  
Blending Moves  
Blend after First Move Is Complete  
Blending moves after the first move is complete causes the first move  
segment to come to a complete stop before starting the profile of the second  
segment, as shown in Figure 9-3.  
1
2
Velocity  
Time  
1
Blending Starts  
2
Blend is Complete  
Figure 9-3. Blending after Move Complete  
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  
9-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 9  
Blending Moves  
Blend after Delay  
You can blend two moves after a delay at the end of the first move, as  
shown in Figure 9-4.  
1
2
Velocity  
Time  
3
1
Blending Starts  
2
Blend is Complete  
3
User-Defined Delay  
Figure 9-4. Blending after a Delay  
Blending in this manner is useful if you want to start two move segments  
after a deterministic delay. The two move segments can be either  
straight-line moves or arc moves.  
Because blending occurs on velocity profiles, the effect of reaching the end  
positions of the move segments and the maximum velocity depends on the  
velocity, acceleration, deceleration, and jerk loaded for the two move  
segments.  
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  
9-4  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
     
Chapter 9  
Blending Moves  
Blending Algorithm  
Figure 9-5 illustrates a generic algorithm for blending moves.  
Load Move Segment 1  
Coordinate Space,  
Move Constraints, etc.  
Start Motion  
Load Move Segment 2  
Blend Motion  
Loop Waiting for Blend Complete  
Perform Measurements  
(Optional)  
Load Move Segment n  
Blend Motion  
Loop Waiting for Blend Complete  
Perform Measurements  
(Optional)  
Figure 9-5. Blending Algorithm  
© National Instruments Corporation  
9-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 9  
Blending Moves  
NI-Motion User Manual  
9-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 9  
Blending Moves  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 vectorSpace;// Vector space number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 status;  
u16 complete;//Move or blend complete status  
//Variables for modal error handling  
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 coordinate space comprised of axes 1,  
and 2  
err = flex_config_vect_spc(boardID, vectorSpace,  
NIMC_AXIS1, NIMC_AXIS2, NIMC_NOAXIS);  
CheckError;  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, vectorSpace, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in counts/sec^2)  
err = flex_load_acceleration(boardID, vectorSpace,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// 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, 1,  
0xFF);  
CheckError;  
// Set the operation mode to absolute position  
© National Instruments Corporation  
9-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 9  
Blending Moves  
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);  
CheckError;  
// Load Circular Arc - making a counter-clockwise  
semi-circle  
err = flex_load_circular_arc (boardID, vectorSpace,  
5000/*radius*/, 0.0/*startAngle*/,  
180.0/*travelAngle*/, 0xFF);  
CheckError;  
// Blend the move  
err = flex_blend(boardID, vectorSpace, 0);  
CheckError;  
// Wait for blend to complete before loading the next  
segment  
do  
{
axisStatus = 0;  
// Check the blend complete status  
err = flex_check_blend_complete_status(boardID,  
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;  
// Check the following error/axis off status for axis  
2
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS2, &status);  
CheckError;  
axisStatus |= status;  
//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)  
NI-Motion User Manual  
9-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 9  
Blending Moves  
{
}
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);  
CheckError;  
// Wait for move to complete because this is the final  
segment  
do  
{
axisStatus = 0;  
// Check the move complete status  
err = flex_check_move_complete_status(boardID,  
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;  
// Check the following error/axis off status for axis  
2
err = flex_read_axis_status_rtn(boardID,  
NIMC_AXIS2, &status);  
CheckError;  
axisStatus |= status;  
//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(50); //Check every 50 ms  
}while (!complete && !(axisStatus &  
NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus &  
© National Instruments Corporation  
9-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 9  
Blending Moves  
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){  
do{  
//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,  
&resourceID, &errorCode);  
nimcDisplayError(errorCode,commandID,resou  
rceID);  
//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  
9-10  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
10  
Electronic Gearing and  
Camming  
Use electronic gearing or camming to synchronize the movement of one or  
more slave axes to the movement of a master device, which can be an  
encoder, ADC, or the trajectory of another axis. The movement of the slave  
axes may be at a higher or lower gear ratio than the master. For example,  
every turn of the master axis may cause a slave axis to turn twice.  
Gearing  
Electronic gearing allows one slave motor to be driven in proportion to a  
master motor or feedback sensor, such as an encoder or torque (analog)  
sensor.  
As the slave follows the master position at a constant ratio, the effect is  
similar to that of two axes mechanically geared.  
Electronic gearing has several advantages over mechanical gears. The most  
notable is flexibility because you can change gear ratios on-the-fly. The  
other major advantage to electronic gearing is that you can superimpose a  
move over a geared axis. 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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 10  
Electronic Gearing and Camming  
Algorithm  
The device can be one of the following:  
the trajectory generator of another axis  
an encoder driven externally  
• αν analog sensor connected to one  
of the analog channels of the motion  
controller  
Designate a Master Device  
Set the Gear Ratio  
Gearing  
Enable gearing on the  
Slave Axis  
The slave axis now moves in  
proportion to the master device.  
Load Move Constraints  
Set Operation Mode  
Load Target Position  
Superimposed  
Straight-line Move  
(optional)  
Start Motion on Slave Axis  
Figure 10-1. Electronic Gearing Algorithm  
The gear ratio is used to determine how far the slave axis must move in  
proportion to the master when gearing is enabled. The gear ratio can be  
absolute or relative.  
Slave axis move = Master axis position × Gear ratio  
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  
10-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
For example, if you have a gearing ratio of 2:1 (slave:master), the slave  
moves 20 counts when the master device moves 10 counts.  
Master Position at Enable  
Master Position  
Move  
After Move  
Master Position  
1000  
1010  
Slave Position at Enable  
Slave Position  
After Move  
Move  
3000  
Slave Position  
3020  
Figure 10-2. Relative Gearing at Enable  
Absolute gearing behaves similarly to relative gearing in that when gearing  
is enabled, the slave axis follows the master axis movement as it is defined  
by the gear ratio. The difference between relative and absolute gearing is  
that the reference position calculated for the master axis is updated only  
when gearing is enabled. This difference is apparent when the gear ratio is  
updated on-the-fly.  
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.  
Master Position  
at Enable  
Master Position  
After Move  
Move  
Master Position  
1000 1010  
Slave Position  
After Gear Change  
Slave Position  
at Enable  
Jump  
Slave Position  
3000  
3020 3030  
Slave Position  
After Move  
Figure 10-3. Absolute Gearing at Gear Ratio Change  
© National Instruments Corporation  
10-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 10  
Electronic Gearing and Camming  
Changing a gear ratio on-the-fly during absolute gearing allows you to  
quickly synchronize the slave axis with the master axis.  
Note When the gear ratio is changed on-the-fly, the slave axis moves at full torque to the  
new position.  
Gear Master  
An axis can be geared to another axis, or to an encoder or ADC.  
When you gear an axis to another axis, the slave axis follows the trajectory  
generation of the master axis. For example, if you manually move the  
master axis, the slave axis does not move because the trajectory generator  
of the master axis is not active.  
When you gear an axis to an encoder, or feedback device, the slave axis  
follows the feedback generated by the encoder. If the encoder detects  
movement, the slave moves proportionally to information returned by the  
encoder. For example, if you twist the master axis connected to the encoder,  
the slave axis also turns because it is using the position information  
gathered by the encoder.  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
LabVIEW Code  
1
2
3
4
5
6
7
8
9
10  
11  
12  
1
2
3
4
5
6
Configure Gear Master  
Load Gear Ratio  
Enable Gearing  
Wait  
Load Velocity  
Load Acceleration/Deceleration  
7
8
9
Set Operation Mode  
Load Target Position  
Start Motion  
10 Wait for Move Complete  
11 Enable Gearing Single Axis  
12 Read per Axis Status  
Figure 10-4. Tracking an Encoder Using Electronic Gearing with Superimposed Move  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID; // Board identification number  
u8 slaveAxis; // Slave axis number  
u8 master; // Gear master  
u16 csr = 0; // Communication status register  
u16 moveComplete;  
//Variables for modal error handling  
u16 commandID;// The command ID of the function  
u16 resourceID;// The resource ID of the function  
i32 errorCode;// Error code  
///////////////////////////////  
© National Instruments Corporation  
10-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 10  
Electronic Gearing and Camming  
// 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  
axis  
err = flex_config_gear_master(boardID, slaveAxis,  
master);  
CheckError;  
//Load Gear Ratio 3:2  
err = flex_load_gear_ratio(boardID, slaveAxis,  
NIMC_RELATIVE_GEARING, 3/* ratioNumerator*/, 2/*  
ratioDenominator*/, 0xFF);  
CheckError;  
//-------------------------------------------------  
// Enable gearing on slave axis  
//-------------------------------------------------  
err = flex_enable_gearing_single_axis (boardID,  
slaveAxis, NIMC_TRUE);  
CheckError;  
// Wait for 5,000 ms (5 seconds)  
Sleep(5000);  
//-------------------------------------------------  
// Set up the move parameters for the superimposed  
move  
//-------------------------------------------------  
// Set the operation mode to relative  
err = flex_set_op_mode(boardID, slaveAxis,  
NIMC_RELATIVE_POSITION);  
CheckError;  
// Load velocity in counts/s  
err = flex_load_velocity(boardID, slaveAxis, 10000,  
0xFF);  
CheckError;  
// Load acceleration and deceleration in counts/s^2  
err = flex_load_acceleration(boardID, slaveAxis,  
NIMC_BOTH, 100000, 0xFF);  
CheckError;  
NI-Motion User Manual  
10-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 10  
Electronic Gearing and Camming  
// 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);  
CheckError;  
//-------------------------------------------------  
// Disable gearing on slave axis  
//-------------------------------------------------  
err = flex_enable_gearing_single_axis (boardID,  
slaveAxis, NIMC_FALSE);  
CheckError;  
return;// Exit the Application  
///////////////////////  
// Error Handling  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
© National Instruments Corporation  
10-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 10  
Electronic Gearing and Camming  
Camming  
Electronic camming operates similarly to electronic gearing in that the  
move distance of an axis is proportional to the move distance of its master  
device. Camming differs from gearing in how the master/slave ratio is  
handled by the motion controller. Gearing is used in applications where a  
constant gear value creates a linear slave position profile, as shown in  
Figure 10-5.  
Slave  
Gear ratio = Slave/Master  
Master  
Master  
Figure 10-5. Master/Slave Ratio in Gearing  
Camming creates a more flexible profile by using more master/slave ratios.  
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  
10-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
Slave  
Master Cycle  
Begins to Repeat  
Master  
Ratio Ratio Ratio Ratio  
Ratio Ratio  
1
2
3
4
1
2
Figure 10-6. Multiple Camming Gear Ratios  
An example of a motion control system that can benefit from the flexibility  
of electronic camming is welding parts as they travel on a conveyor belt.  
Figure 10-7 shows that the welding point moves to the first position, and  
then welds the material for a couple of seconds. Because the conveyor belt  
keeps moving at a constant rate, the welding point must follow the material  
at the same speed as the conveyor belt during the weld process. 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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 10  
Electronic Gearing and Camming  
3
1
2
Conveyor belt  
Movement of the welder as it follows the object, and then returns to the initial  
position  
3
Welding point  
Figure 10-7. Welding Application  
In this application, the master device is the position encoder attached to the  
conveyor belt, and the slave axis is the actuator that moves the welding  
point. The slave axis repeatedly performs a two-segment movement:  
1. First, it follows the material with the same speed as the conveyor belt.  
2. Next, it returns to the initial position as the next material approaches.  
Each segment of the move is represented with a gear ratio that dictates how  
fast and which direction the welding point is moving in relative to the  
conveyor belt.  
This application requires the slave axis to switch from one ratio to the other  
at the correct master position, otherwise the welding process is not  
repeatable. 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  
10-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 10  
Electronic Gearing and Camming  
Algorithm  
Similar to gearing, in a camming application, a slave axis can perform any  
move when camming is enabled. The move profile is superimposed over  
the camming profile.  
Designate a Master  
Camming Device  
The device can be one of the following:  
an axis  
an encoder  
an analog sensor  
Set the Master Cycle  
Configure the Buffer  
for Slave Positions  
Camming  
Load the Slave Positions  
to the Cam Table  
Set the Master and  
Slave Offset (optional)  
Enable Camming  
The slave axis now moves in  
proportion to the master device.  
Load Move Constraints  
Set Operation Mode  
Load Target Position  
Superimposed  
Straight-line Move  
(optional)  
Start Motion on Slave Axis  
Figure 10-8. Camming Algorithm  
© National Instruments Corporation  
10-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 10  
Electronic Gearing and Camming  
Camming Table  
When a camming operation is active, the slave axis follows a profile that is  
established using a list of master and slave positions pairs, called the  
camming table. Refer to Table 10-1 for an example of a camming table.  
Figure 10-9 shows that, in the welding example defined in Figure 10-7, the  
conveyor belt is moving at 1,000 counts/s and the parts to be welded are  
6,000 counts apart. To weld the part, the welding point must follow the part  
down the conveyor belt for 2 seconds.  
Time to dwell  
during welding  
(2 seconds)  
6,000  
counts  
between  
welding  
spots  
Conveyor belt speed  
(1000 counts/s)  
Figure 10-9. Welding Application Time and Speed Constraints  
In this welding application, the slave axis must follow the part with the  
same velocity as the conveyor belt while welding is in progress. Because it  
takes two seconds to weld each part, the welding point and conveyor belt  
have both moved 2,000 counts by the time the welding is complete. This  
part of the welding application creates the first move segment.  
For the second move segment, the welding point must return to its original  
position so that it can weld the next part on the conveyor belt. 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  
10-12  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
   
Chapter 10  
Electronic Gearing and Camming  
2,000 counts in the opposite direction of the conveyor belt at half the speed  
that the conveyor belt is traveling at. Figure 10-10 shows the move profile  
of the first and second move segments.  
Slave  
2000  
1000  
Master  
2000  
4000  
6000  
Figure 10-10. First and Second Move Segment Profile  
Table 10-1 shows the camming table that corresponds to the move profile  
in Figure 10-10  
.
Table 10-1. Welding Application Cam Table  
Master  
Time  
(seconds)  
Position  
(counts)  
Slave Position  
(counts)  
Ratio*  
0
2
4
6
0
0
2000  
4000  
6000  
2000  
1000  
0
1
–0.5  
–0.5  
* Ratio = SlaveDistance / MasterDistance  
Table 10-1 shows that the camming cycle is 6,000 counts and is divided into  
equal length segments.  
Tip Because the camming cycle is 6,000 counts, the master cycle must also be  
6,000 counts.  
© National Instruments Corporation  
10-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
Each row of data defines a gear ratio. The camming profile is repeated after  
a camming cycle is completed. The master position is always interpreted  
inside the modulus defined by the camming cycle.  
For example, initially, the master axis moves from 0 to 1000. The gear ratio  
used for this move is 1:1 because the master position is in the 0 to 2000  
interval. With a gear ratio of 1:1, the slave axis moves at the same speed as  
the master device to position 1000.  
Figure 10-11 shows that the master position in this interval is inside the  
modulus.  
Master  
0
0
1000  
1000  
Slave  
Figure 10-11. Master and Slave Positions at Enable  
Figure 10-12 shows that if the master axis moves to position 2000, the gear  
ratio does not change because the current master position is still inside the  
0 to 2000 interval.  
Master  
0
0
1000  
1000  
2000  
2000  
Slave  
Figure 10-12. Master Axis Moves within Interval  
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  
10-14  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
Master  
Slave  
0
0
2000  
4000  
4000  
1000 2000  
Figure 10-13. Gear Ratio Change  
Figure 10-14 shows that when the master reaches position 6000, the slave  
axis moves back the original position, and the camming cycle begins again.  
Master  
0
0
2000  
4000  
4000  
6000  
6000  
Slave  
1000 2000  
Figure 10-14. Camming Cycle Repeats  
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.  
Table 10-2. Camming Profile with and without Slave Offset  
Master Position  
(counts)  
Slave Position  
(counts)  
0
0
2000  
4000  
6000  
2000  
1000  
500  
© National Instruments Corporation  
10-15  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 10  
Electronic Gearing and Camming  
Figure 10-15 shows that, after three camming cycles, the slave axis end  
position is 500 counts away from the starting position (0) with the slave  
offset, and that without the slave offset, the slave axis end position is  
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.  
Without Offset  
With Offset  
Figure 10-15. Camming without Offset  
NI-Motion User Manual  
10-16  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 10  
Electronic Gearing and Camming  
Master Offset  
If the material and welding point are not initially aligned, as shown in  
Figure 10-16, the master offset must be applied to consider the position  
difference.  
Position = 0  
Position = 50  
When there is no master offset,  
the master cycle begins at  
position 0.  
Figure 10-16. Misaligned Material and Welding Point  
Without the master offset, the master device position is already inside the  
first interval as soon as the first material passes the welding point.  
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  
10-17  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
Camming starts  
here at position 50  
at position 50.  
Figure 10-17. Camming Profile Starts when First Material Passes  
Figure 10-18 shows the camming profile used for the application portrayed  
in Figure 10-16 and Figure 10-17.  
2500  
2000  
1500  
1000  
500  
Without Master Offset  
With Master Offset  
Master Offset  
0
0
2000  
4000  
6000  
8000  
10000  
Master  
Figure 10-18. Camming Profiles with and without Master Offset  
NI-Motion User Manual  
10-18  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 10  
Electronic Gearing and Camming  
LabVIEW Code  
1
2
3
6
7
8
4
5
9
10  
11  
12  
13  
1
2
3
4
5
6
7
Configure Camming Master  
Configure Buffer  
Write Buffer  
Enable Camming Single Axis  
Wait in a Sequence Structure  
Set Operation Mode  
Load Move Constraint  
8
9
Load Target Position  
Start Motion  
10 Wait for Move Complete  
11 Enable Camming Single Axis  
12 Clear Buffer  
13 Motion Error Handler  
Figure 10-19. Axis to Axis Camming  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
///////////////  
// Main Function  
void main(void)  
{
// Locals  
u8 boardID = 1;  
// Board ID as assigned by MAX  
f64 bufferInterval = 0; // Ignored  
// Master axis information  
u8 masterAxis = 2;  
// Master axis ID  
f64 camCycle = 70000; // Position cycle to repeat  
the camming process  
// Slave axis information  
© National Instruments Corporation  
10-19  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 10  
Electronic Gearing and Camming  
u8 slaveAxis = 1;  
u8 buffer = 1;  
cam table  
// Slave axis ID  
// Buffer to contain the  
i32 positionArr[] = {0, 10000, 40000, 45000, 45000,  
40000, 10000, 0}; // Position array  
u32 positionSize = sizeof(positionArr) / sizeof(i32);  
// Number of positions in the array  
NIMC_DATA data;  
// Generic data structure  
i32 targetPos = 10000; // Position to move to  
f64 velocity = 10000; // Velocity limit for this move  
u16 moveComplete;  
// For error handling  
u16 csr;  
// Communication status  
u16 commandID;  
// Command ID that causes the  
error  
u16 resourceID;  
the failed command  
i32 errorCode;  
controller  
// Resource ID that is set on  
// Error code from the  
// Configuring camming profile.  
// Configure the cam master & master cycle  
err = flex_configure_camming_master(boardID,  
slaveAxis, masterAxis, camCycle);  
CheckError;  
// Configure the cam table  
err = flex_configure_buffer(boardID, buffer,  
slaveAxis, NIMC_CAMMING_POSITION, positionSize,  
positionSize, TRUE, bufferInterval, &bufferInterval);  
CheckError;  
// Write the data to the buffer  
err = flex_write_buffer(boardID, buffer,  
positionSize, NIMC_REGENERATION_NO_CHANGE, positionArr,  
0xFF);  
CheckError;  
// Enable camming immediately  
err = flex_enable_camming_single_axis(boardID,  
slaveAxis, TRUE, -1.0);  
CheckError;  
// At this point camming is engaged or started. You  
can start the master  
// axis or insert other functionality here.  
Sleep(5000);  
NI-Motion User Manual  
10-20  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 10  
Electronic Gearing and Camming  
// Configure the superimposed move (optional)  
// Set to absolute mode  
err = flex_set_op_mode(boardID, slaveAxis,  
NIMC_ABSOLUTE_POSITION);  
CheckError;  
// Set the maximum velocity  
data.doubleData = velocity;  
err = flex_load_move_constraint(boardID, slaveAxis,  
TnimcMoveConstraintVelocity, &data);  
CheckError;  
// Set the target position  
err = flex_load_target_pos(boardID, slaveAxis,  
targetPos, 0xFF);  
CheckError;  
// Start the master axis movement  
err = flex_start(boardID, slaveAxis, 0x0);  
CheckError;  
// Wait for move to complete  
err = flex_wait_for_move_complete (boardID,  
slaveAxis, 0x1, 20000, 20, &moveComplete);  
CheckError;  
// Error Handling  
//  
nimcHandleError; //NIMCCATCHTHIS:  
// Disable camming  
flex_enable_camming_single_axis(boardID, slaveAxis,  
FALSE, -1.0);  
// Clear (delete) the buffer  
flex_clear_buffer(boardID, buffer);  
// Check to see if there were any Modal Errors  
flex_read_csr_rtn(boardID, &csr);  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
do  
{
// Get the command ID, resource and the error code of the  
modal  
//error from the error stack on the board  
© National Instruments Corporation  
10-21  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
11  
Acquiring Time-Sampled  
Position and Velocity Data  
NI motion controllers can acquire a buffer of position and velocity data that  
is firmware-timed. After you command the motion controller to acquire  
position and velocity data, a separate acquire data task is created in the  
real-time operating system that reads time-sampled position and velocity  
data into a FIFO buffer on the motion controller. You can read data in from  
this buffer asynchronously from the host computer, as shown in  
Figure 11-1.  
Step 1: Reads the  
position velocity  
Acquire data task  
Step 2: Copies position and  
velocity data to FIFO buffer  
Step 3: Reads data from  
the buffer asynchronously  
Figure 11-1. Acquire Data Path  
The acquire data task has higher priority than any onboard programs or  
housekeeping tasks, but it has a lower priority than the 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  
11-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 11  
Acquiring Time-Sampled Position and Velocity Data  
The FIFO buffer is of a fixed size that can accommodate 4,096 samples for  
one axis. One sample consists of position data, in counts or steps, and  
velocity data, in counts/s or steps/s. As you increase the number of axes  
from which you are acquiring data, you also decrease the total number of  
samples you can acquire per axis. For example, you can acquire up to  
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  
Acquire Data  
Specify the number of axes, sample  
period, and number of samples  
Wait for Time = Sample Period  
Wait until at least one sample  
has been achieved  
Loop if Wait Period > Sample Period  
Read One Sample  
Wait more than the sample period  
to allow the controller to fill the FIFO  
Figure 11-2. Acquire Data Algorithm  
NI-Motion User Manual  
11-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 11  
Acquiring Time-Sampled Position and Velocity Data  
The data must be read one sample at a time. A four-axis sample uses the  
following pattern for returning the data.  
Axis 1 position  
Axis 1 velocity  
Axis 2 position  
Axis 2 velocity  
Axis 3 position  
Axis 3 velocity  
Axis 4 position  
Axis 4 velocity  
If you request 1,024 samples, you must read each of the 1,024 samples  
individually.  
© National Instruments Corporation  
11-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 11  
Acquiring Time-Sampled Position and Velocity Data  
LabVIEW Code  
Figure 11-3 acquires data for two axes, 200 samples, and three  
milliseconds apart.  
1
2
3
1
Acquire Trajectory Data  
2
Read Trajectory Data  
3
Motion Error Handler  
Figure 11-3. Acquire Data Using LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u16 csr = 0;// Communication status register  
i32 i;  
u16 axisMap;// Bitmap of axes for which data is  
requested  
NI-Motion User Manual  
11-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
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  
i32 returnData[4];// Need size of 4 for 2 axes worth  
of data  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Axes whose data needs to be acquired  
axisMap = ((1<<1) | (1<<2)); // Axis 1 and axis 2  
////////////////////////////////  
err = flex_acquire_trajectory_data(boardID, axisMap,  
numSamples, 3/* ms time period*/);  
CheckError;  
Sleep(numSamples * 3/* ms time period*/);  
for(i=0; i<numSamples; i++){  
Sleep (2);  
// Read the trajectory data  
err = flex_read_trajectory_data_rtn(boardID,  
returnData);  
CheckError;  
// Two axes worth of data is read every sample  
axis1Positions[i] = returnData[0];  
axis1Velocities[i] = returnData[1];  
axis2Positions[i] = returnData[2];  
axis2Velocities[i] = returnData[3];  
}
return;// Exit the Application  
//////////////////////  
// Error Handling  
//  
nimcHandleError; //NIMCCATCHTHIS:  
© National Instruments Corporation  
11-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 11  
Acquiring Time-Sampled Position and Velocity Data  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
NI-Motion User Manual  
11-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
12  
Synchronization  
You can synchronize NI motion controllers with NI data and image  
acquisition devices using breakpoints and high-speed captures.  
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. This  
functionality is called breakpoints, which are divided into Absolute  
Breakpoints, Relative Position Breakpoints, and Periodically Occurring  
Breakpoints.  
In some cases, it may be necessary to synchronize position with some  
measurement occurring external to the motion controller. For example,  
you might be aligning two fiber optic cables, in which case the maximum  
optical power needs to correspond with the alignment position. To align the  
fibers, the external device that is recording the optical power must trigger  
the motion controller so that positions and optical power measurements can  
be synchronized and analyzed. This functionality is known as High-Speed  
Capture or trigger inputs. The motion controller can be triggered by  
another device using RTSI or externally using a pin on the Motion I/O  
connector. When triggered, the motion controller can latch the current  
position of the encoder, which can be read and recorded.  
© National Instruments Corporation  
12-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 12  
Synchronization  
Table 12-1 shows the availability of breakpoint modes on each NI motion  
controller.  
Table 12-1. Breakpoint Modes on NI Motion Controllers  
NI 7340, NI 7330, and  
Breakpoint Mode  
Absolute*  
Relative*  
NI 7350  
NI 7390  
Y
Y
Y
N
Y
Y
Y
N
Y
N
Periodic  
Modulus  
Buffered  
* Available in buffered and single operation for NI 7350 and in single operation only for  
all other controllers  
Note If you are using a data or image acquisition device with your motion control system,  
be aware that the NI SoftMotion Controller does not support the RTSI bus.  
Note Breakpoints are not supported on the NI SoftMotion Controller.  
Note When you are using the NI SoftMotion Controller with an Ormec device, you can  
use two high speed captures per axis.  
Absolute Breakpoints  
Absolute position breakpoints allow you to trigger external activities as  
the motors reach specified positions. For example, if you need to use an  
image acquisition device to capture an image from a certain position while  
the device under test is in continuous motion, the motion controller must be  
able to trigger the image acquisition device as it reaches those positions.  
The current position is continuously compared against the specified  
breakpoint position by the encoder circuitry to produce a latency of less  
than 100 ns.  
After a breakpoint triggers, you must re-enable it for the breakpoint to work  
again. 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  
12-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
Note All breakpoints can be affected by jitter in the motion control system. For example,  
if you have a very small breakpoint window, the jitter in the motion control system could  
cause the position to change enough to reach the breakpoint when a breakpoint is not  
intended. Increase the size of the breakpoint window to compensate for system jitter.  
Buffered Breakpoints (NI 7350 only)  
Instead of enabling breakpoints in your application at the software level,  
you can create a buffer of breakpoints that you can pre-load into the motion  
controller. 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  
12-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
Buffered Breakpoint Algorithm  
Figure 12-1 shows the basic algorithm for implementing buffered  
breakpoints.  
Load Breakpoint Array  
Configure the onboard buffer  
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.  
Write buffer  
Write the array of breakpoint  
positions and the number of points  
Set Old Data Stop to TRUE if you do not  
want old data to be used  
Requested Interval = 0  
Configure breakpoint  
for buffered mode  
Enable the breakpoint  
Loop checking for buffered breakpoints usage  
Update breakpoint array  
Check the onboard buffer  
(optional)  
Check the number of  
breakpoints consumed  
Write buffer (optional)  
Write remaining breakpoint  
positions to onboard buffer  
Clear buffer  
Figure 12-1. Buffered Breakpoint Algorithm  
NI-Motion User Manual  
12-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 12  
Synchronization  
LabVIEW Code  
3
1
2
4
5
6
7
1
2
3
Configure Buffer  
Write Buffer  
Configure Breakpoint  
4
5
Enable Breakpoint Output  
Check Buffer  
6
7
Clear Buffer  
Motion Error Handler  
Figure 12-2. Buffered Position Breakpoint in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main function  
void main (void)  
{
// Resource variables  
u8boardID = 1;// Board identification number  
u8axis = NIMC_AXIS1;// Axis number  
u8 buffer = 1;// Buffer number  
// Modal error handling variables  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
u16 csr = 0;// Communication status  
© National Instruments Corporation  
12-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
// 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  
u16 bufferState;// Buffer state  
u32 pointsDone;// Number of breakpoints done or  
consumed  
// Configure the buffer for buffered breakpoint  
err = flex_configure_buffer(boardID, buffer,axis,  
NIMC_BREAKPOINT_DATA, numberOfPoints,  
numberOfPoints,NIMC_TRUE, requestedInterval,  
&actualInterval);  
CheckError;  
// Write the breakpoint position to the buffer  
err = flex_write_buffer(boardID, buffer,  
numberOfPoints, NIMC_REGENERATION_NO_CHANGE,  
breakpointPositions, 0xFF);  
CheckError;  
// Configure the breakpoint to be buffered breakpoint  
err = flex_configure_breakpoint(boardID, axis,  
NIMC_ABSOLUTE_BREAKPOINT, NIMC_PULSE_BREAKPOINT,  
NIMC_OPERATION_BUFFERED);  
CheckError;  
// Enable the breakpoint  
err = flex_enable_breakpoint(boardID, axis,  
NIMC_TRUE);  
CheckError;  
// Poll the status of the buffer, if you have more  
breakpoint //positions to write, insert  
flex_write_buffer call here.  
do  
{
// Check the buffer status  
err = flex_check_buffer_rtn(boardID, buffer,  
&backLog, &bufferState, &pointsDone);  
CheckError;  
Sleep(50);  
NI-Motion User Manual  
12-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
} 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 & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
© National Instruments Corporation  
12-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
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.  
Configure breakpoint  
Configure breakpoint  
for absolute mode  
Load breakpoint position  
Absolute position where  
you want to trigger an event  
Enable breakpoint  
Wait for  
breakpoint to occur  
Load a new  
breakpoint position  
Figure 12-3. Single Position Breakpoint Algorithm  
NI-Motion User Manual  
12-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
LabVIEW Code  
4
5
1
2
3
1
2
Configure Breakpoint  
Load Breakpoint Position  
3
4
Enable Breakpoint Output  
Read per Axis Status  
5
Motion Error Handler  
Figure 12-4. Single Position Breakpoint in LabVIEW  
© National Instruments Corporation  
12-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
Refer to Figure 12-5 for an example of how to route this breakpoint  
using RTSI.  
5
6
1
2
3
4
1
2
Select Signal  
Configure Breakpoint  
3
4
Load Breakpoint Position  
Enable Breakpoint Output  
5
6
Read per Axis Status  
Motion Error Handler  
Figure 12-5. Single Position Breakpoint With RTSI Using LabVIEW  
After the breakpoint is routed through RTSI, the trigger appears on both  
the 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 examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 breakpointPosition[3] = {10000, 15000, 20000};  
i32 i;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
NI-Motion User Manual  
12-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
///////////////////////////////  
// 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  
err = flex_configure_breakpoint(boardID, axis,  
NIMC_ABSOLUTE_BREAKPOINT /*mode*/,  
NIMC_SET_BREAKPOINT /*action*/,  
NIMC_OPERATION_SINGLE /*single operation*/);  
CheckError;  
for(i=0; i<3; i++){  
// Load breakpoint position - where breakpoint  
should occur  
err = flex_load_pos_bp(boardID, axis,  
breakpointPosition[i], 0xFF);  
CheckError;  
// Enable the breakpoint on axis 1  
err = flex_enable_breakpoint(boardID, axis,  
NIMC_TRUE);  
CheckError;  
do  
{
// Check the breakpoint 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 for modal errors  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
© National Instruments Corporation  
12-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
}
Sleep (10); //Check every 10 ms  
}while (!(axisStatus & NIMC_POS_BREAKPOINT_BIT));  
// Wait for breakpoint to be triggered  
}
return;// Exit the Application  
//////////////////////  
// Error Handling  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
Relative Position Breakpoints  
Relative position breakpoints trigger events based on a change in position  
relative to the position at which the breakpoint was enabled.  
Instead of keeping track of absolute positions and the current position,  
you can use relative breakpoints to specify the breakpoint relative to the  
position where the breakpoint is enabled.  
For example, if you are creating a motion control system to control the  
two-dimensional movement of a microscope, you might use relative  
position breakpoints to move the microscope a specific distance in a  
direction, and then hit a breakpoint that triggers a camera snap. The relative  
NI-Motion User Manual  
12-12  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
breakpoint is useful in this example because the current position is not  
important. The application must move the axis a specific number of counts  
from wherever it is, and then generate a breakpoint.  
Note All breakpoints can be affected by jitter in the motion control system. For example,  
if you have a very small breakpoint window, the jitter in the motion control system could  
cause the position to change enough to reach the breakpoint when a breakpoint is not  
intended. Increase the size of the breakpoint window to compensate for system jitter.  
Relative Position Breakpoints Algorithm  
Figure 12-6 shows the basic algorithm for relative breakpoints.  
Configure breakpoint  
Configure breakpoint  
for relative mode  
Load breakpoint position  
Relative position where  
you want to trigger an event  
Enable breakpoint  
Wait for breakpoint  
to cause a trigger  
Figure 12-6. Relative Position Breakpoints Algorithm  
Notice that relative breakpoints are not ideal for periodic breakpoints.  
There is a latency between the time a breakpoint generates and is  
re-enabled. If the axis is moving at sufficient velocity, the breakpoint  
re-enables only after the axis has moved slightly. Because a relative  
breakpoint generates relative to the position the axis was in when the  
breakpoint was enabled, the latency between generation and re-enabling  
For example, the actual breakpoints might occur at positions 5,000; 10,003;  
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 Buffered Breakpoints (NI 7350 only) or  
Periodically Occurring Breakpoints.  
© National Instruments Corporation  
12-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 12  
Synchronization  
LabVIEW Code  
In this example, a breakpoint generates and then is re-enabled 5,000 counts  
from where the move starts. The following code examples are designed to  
illustrate the relative breakpoint algorithm only. These examples are not  
complete.  
5
4
1
2
3
6
1
2
Select Signal  
Configure Breakpoint  
3
4
Load Breakpoint Position  
Enable Breakpoint Output  
5
6
Read per Axis Status  
Motion Error Handler  
Figure 12-7. Relative Position Breakpoint with RTSI Using LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 breakpointPosition = 5000;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
NI-Motion User Manual  
12-14  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
// 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;  
// Load breakpoint position, which is position where  
breakpoint should occur  
err = flex_load_pos_bp(boardID, axis,  
breakpointPosition, 0xFF);  
CheckError;  
for(;;){  
// Enable the breakpoint on axis 1  
err = flex_enable_breakpoint(boardID, axis,  
NIMC_TRUE);  
CheckError;  
do  
{
// Check the breakpoint 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 for modal errors  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
Sleep (10); // Check every 10 ms  
}while (!(axisStatus & NIMC_POS_BREAKPOINT_BIT));  
// Wait for breakpoint to be triggered  
}
© National Instruments Corporation  
12-15  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
return;// Exit the Application  
///////////////////////////////////////////////////  
// Error Handling  
//  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
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.  
For the NI 7350 controller, use periodic breakpoints. For NI 7330, NI 7340,  
and NI 7390 controllers, use modulo breakpoints.  
Note All breakpoints can be affected by jitter in the motion control system. For example,  
if you have a very small breakpoint window, the jitter in the motion control system could  
cause the position to change enough to reach the breakpoint when a breakpoint is not  
intended. Increase the size of the breakpoint window to compensate for system jitter.  
NI-Motion User Manual  
12-16  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 12  
Synchronization  
Periodic Breakpoints (NI 7350 only)  
Periodic breakpoints require that you specify an initial breakpoint and an  
ongoing repeat period. When enabled, the periodic breakpoints begin when  
the initial breakpoint occurs. From then on, a new breakpoint occurs each  
time the axis moves a distance equal to the repeat period, with no  
re-enabling required.  
For example, if an axis is enabled at position zero, the initial breakpoint is  
set for position 100, and the breakpoint period is set at 1,000, then the axis  
behaves as shown in Figure 12-8.  
–900 100 1100  
2100  
3100  
Direction  
= Current Position  
= Breakpoint  
= Armed Breakpoint  
Figure 12-8. Periodic Breakpoint Every 1,000 Counts/Steps  
Periodic Breakpoint Algorithm  
Figure 12-9 shows the basic algorithm for periodic breakpoints.  
Configure breakpoint  
Load breakpoint bosition  
Load the initial breakpoint  
Load breakpoint modulus  
Load the breakpoint period  
Enable breakpoint  
Figure 12-9. Periodic Breakpoint Algorithm  
© National Instruments Corporation  
12-17  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 12  
Synchronization  
LabVIEW Code  
1
2
3
4
5
6
7
8
1
2
3
Configure Breakpoint  
Load Breakpoint Position  
Load Breakpoint Modulus  
4
5
6
Enable Breakpoint Output  
Load Target Position  
Start Motion  
7
8
Read per Axis Status  
Motion Error Handler  
Figure 12-10. Periodic Breakpoint Output  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID; //Board Identification number  
u8 axis; // Axis  
u16 csr* 0; // Communication Status Register  
u8 profileStatus; // Profile Complete Status  
u8 bpStatus; // Breakpoint found Status  
i32 bpPos; // Breakpoint Position  
i32 bpPer; // Breakpoint Period  
i32 targetPos; // Target Position  
i32 currentPos; // Current Position  
u16 axisStatus; // Status of the axis  
NI-Motion User Manual  
12-18  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
//Variables for modal error handling  
u16 commandID; // The commandID of the function  
u16 resourceID; // The resource ID  
i32 errorCode;  
//Get the board ID  
printf("Enter the Board ID: ");  
scanf("%u", &boardID);  
//Get the axis number  
printf("Enter a axis number: ");  
scanf("%u",&axis);  
//Get the Target Position  
printf("Enter a target position: ");  
scanf("%ld",&targetPos);  
//Get the Breakpoint Position  
printf("Enter a breakpoint position: ");  
scanf("%ld",&bpPos);  
//Get the Breakpoint Period  
printf("Enter a breakpoint period: ");  
scanf("%ld",&bpPer);  
//Configure the breakpoint to be absolute  
err =  
flex_configure_breakpoint(boardID,axis,NIMC_PERIODI  
C_BREAKPOINT,NIMC_NO_CHANGE,0);  
CheckError;  
//Load the position to start breakpoints  
err = 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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
CheckError;  
printf("\n");  
do  
{
//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);  
printf("Current Position=%10d Breakpoint  
Status=%d Profile  
Complete=%d\r",currentPos,bpStatus,profileStatus  
);  
//Check for modal errors  
err = flex_read_csr_rtn(boardID,&csr);  
CheckError;  
//Check the modal errors  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
flex_stop_motion(boardID,NIMC_VECTOR_SPA  
CE1, NIMC_DECEL_STOP, 0);//Stop the  
Motion  
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
}while(!profileStatus);  
printf("\nFinished.\n");  
return; // Exit the Application  
///////////////////////////////////////////////////  
//////////////////////  
// Error Handling  
//  
NI-Motion User Manual  
12-20  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
nimcHandleError;  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//Get the command ID, resource and the  
error code of the modal  
//error from the error stack on the board  
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  
}
Modulo Breakpoints (NI 7330, NI 7340 and NI 7390 only)  
Modulo breakpoints use a breakpoint window, which defines an area  
around the current position. The two breakpoints around the current  
position are always enabled.  
The breakpoint modulus creates a repeat period for the breakpoints, and the  
breakpoint position is the offset from absolute zero.  
For example, to create a breakpoint every 500 counts, set the repeat period  
to 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  
12-21  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
–1000  
–500  
0
500  
1000  
= Current Position  
= Breakpoint  
= Armed Breakpoint  
Figure 12-11. Breakpoint Modulus of 500  
As another example, if you set the breakpoint repeat period to be 2000  
counts and the offset to be –500, breakpoints occur at –4500, –2500, –500,  
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.  
–4000 –2000  
0
2000  
4000  
–4500  
–2500  
–500  
1500  
3500  
= Current Position  
= Breakpoint  
= Armed Breakpoint  
Figure 12-12. Breakpoint Modulus of 2000 with an Offset of 500  
Each time a breakpoint occurs, re-enable it to load the next breakpoint.  
NI-Motion User Manual  
12-22  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
Modulo Breakpoints Algorithm  
Figure 12-13 shows the basic algorithm for modulo breakpoints.  
Configure breakpoint  
Configure breakpoint for modulo mode  
Load breakpoint repeat period  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 12  
Synchronization  
LabVIEW Code  
2
1
3
4
5
6
1
2
Configure Breakpoint  
Load Breakpoint Modulus  
3
4
Load Breakpoint Position  
Enable Breakpoint Output  
5
6
Read per Axis Status  
Motion Error Handler  
Figure 12-14. Modulo Breakpoint Using LabVIEW  
1
2
3
4
5
6
7
1
2
3
Configure Breakpoint  
Load Breakpoint Modulus  
4
5
Load Breakpoint Position  
Enable Breakpoint Output  
6
7
Read per Axis Status  
Motion Error Handler  
Figure 12-15. Modulo Breakpoint with RTSI Using LabVIEW  
NI-Motion User Manual  
12-24  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// 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_RTSI1  
/*destination*/, NIMC_BREAKPOINT1/*source*/);  
CheckError;  
//Configure Breakpoint  
err = flex_configure_breakpoint(boardID, axis,  
NIMC_MODULO_BREAKPOINT, NIMC_SET_BREAKPOINT,  
NIMC_OPERATION_SINGLE);  
CheckError;  
// Load Breakpoint Modulus - repeat period  
err = flex_load_bp_modulus(boardID, axis, 500,  
0xFF);  
CheckError;  
// Load Breakpoint Position - position at which  
breakpoint should //occur every modulo  
err = flex_load_pos_bp(boardID, axis, 0, 0xFF);  
CheckError;  
for(;;){  
// Enable the breakpoint on axis 1  
© National Instruments Corporation  
12-25  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
err = flex_enable_breakpoint(boardID, axis,  
NIMC_TRUE);  
CheckError;  
do  
{
// 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);  
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 (!(axisStatus & NIMC_POS_BREAKPOINT_BIT));  
// Wait for breakpoint to be triggered  
}
return;// Exit the Application  
//////////////////////  
// Error Handling  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
urceID, &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  
NI-Motion User Manual  
12-26  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
nimcDisplayError(err,0,0);  
return;// Exit the Application  
}
High-Speed Capture  
Some motion control applications require that you execute a move and  
record the locations where external triggers happen. To accomplish this,  
you must use the high-speed capture functionality of NI motion controllers.  
The implementation for high-speed capture is divided into the buffered and  
non-buffered high-speed capture methods.  
Buffered High-Speed Capture (NI 7350 only)  
Buffered high-speed capture lets you create a buffer that holds captured  
positions that you can read asynchronously from the motion controller.  
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  
12-27  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 12  
Synchronization  
Buffered High-Speed Capture Algorithm  
Configure high-speed capture  
Set the buffer type to be high-speed  
capture positions  
Total Points is the total number of  
high-speed capture positions you  
want to store  
Buffer Size is the size of the buffer  
you want to create on the board  
Set Old Data Stop to TRUE if you do  
not want old data to be used  
Configure a buffer  
on the controller  
Enable high-speed capture  
Loop checking for captured data array usage  
Read captured position  
Check buffer on the device  
(optional)  
Check number of captured  
positions available to read  
Read buffer (optional)  
Read captured positions to free  
the buffer for more data to be written  
Figure 12-16. Buffered High-Speed Capture Algorithm  
NI-Motion User Manual  
12-28  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 12  
Synchronization  
LabVIEW Code  
4
5
6
7
1
2
3
1
2
3
Configure Buffer  
Configure High-Speed Capture  
Enable High-Speed Capture  
4
5
Check Buffer  
Read Buffer  
6
7
Clear Buffer  
Motion Error Handler  
Figure 12-17. Buffered High-Speed Capture in LabVIEW  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// Axis number  
u16 csr = 0;// Communication status register  
i32 bufferSize = 100;// The size of the buffer to  
allocate on the //motion controller  
u32 totalPoints = 100;// The number of high speed  
capture to //acquire  
i32 capturedPositions[100];// Array to store the  
captured //positions  
f64 actualInterval;// The interval at which the  
motion controller can //really contour  
u32 backlog;// Indicates the available space for  
captured positions  
© National Instruments Corporation  
12-29  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 12  
Synchronization  
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  
created to //read captured positions  
u32 i;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
////////////////////////////////  
// Configure buffer on motion controller memory (RAM)  
// Notice requested time interval is hardcoded to 10  
milliseconds  
err = flex_configure_buffer(boardID, 1 /*buffer  
number*/, axis, NIMC_HS_CAPTURE_READBACK,  
bufferSize, totalPoints, NIMC_TRUE, 10,  
&actualInterval);  
CheckError;  
// Configure High-Speed Capture  
err = flex_configure_hs_capture(boardID, axis,  
NIMC_HS_LOW_TO_HIGH_EDGE, NIMC_OPERATION_BUFFERED);  
CheckError;  
// Enable the high-speed capture on axis  
err = flex_enable_hs_capture(boardID, axis,  
NIMC_TRUE);  
CheckError;  
do  
{
err = flex_check_buffer_rtn(boardID, 1/*buffer  
number*/, &backlog, &bufferState, &pointsDone);  
CheckError;  
// Check backlog for captured position in buffer  
NI-Motion User Manual  
12-30  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
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;  
capturedPositions[currentDa  
taPoint] = readBuffer[i];  
printf("capture pos %d\n",  
capturedPositions[currentDataPoin  
t]);  
currentDataPoint++;  
}
free(readBuffer);  
readBuffer = NULL;  
CheckError;  
}
// Check for axis off status/following error or  
any modal //errors; 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(60);// Check every 60 ms  
} while (bufferState != NIMC_BUFFER_DONE);  
// Free the buffer allocated on the motion controller  
memory  
err = flex_clear_buffer(boardID, 1/*buffer  
number*/);  
© National Instruments Corporation  
12-31  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
CheckError;  
return;// Exit the Application  
///////////////////////////////////////////////////  
//////////////  
// Error Handling  
//  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//Get the command ID, resource ID, and the  
error code of the //modal error from the  
error stack on the device  
err = flex_read_error_msg_rtn(boardID,  
&commandID, &resourceID, &errorCode);  
nimcDisplayError(errorCode,commandID,res  
ourceID);  
//Read the communication status register  
err = flex_read_csr_rtn(boardID,&csr);  
}while(csr & NIMC_MODAL_ERROR_MSG);  
}
else// Display regular error  
nimcDisplayError(err,0,0);  
return;// Exit the Application  
}
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  
12-32  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 12  
Synchronization  
High-Speed Capture Algorithm  
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  
the captured position and recording it  
Read the captured position  
(optional)  
Figure 12-18. High-Speed Capture Algorithm  
© National Instruments Corporation  
12-33  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
LabVIEW Code  
1
2
3
4
1
2
Configure High-Speed Capture  
Enable High-Speed Capture  
4
Read per Axis Status  
Read Captured Position  
Figure 12-19. High-Speed Capture Using LabVIEW  
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  
12-34  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 12  
Synchronization  
1
2
3
4
5
1
2
3
Select Signal  
Configure High-Speed Capture  
Enable High-Speed Capture  
4
5
Read per Axis Status  
Read Captured Position  
Figure 12-20. High-Speed Capture with RTSI Using LabVIEW  
C/C++ Code  
The following section includes C/C++ code for executing a high-speed  
capture, as well as using RTSI to execute a high-speed capture. The  
following example code is not necessarily complete, and may not compile  
if copied exactly. Refer to the examplesfolder on the NI-Motion CD for  
files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID; // Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 capturedPositions[6]; // Array to store the  
captured positions  
i32 i;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
© National Instruments Corporation  
12-35  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 12  
Synchronization  
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);  
CheckError;  
do  
{
// Check the high-speed capture 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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
Sleep (10); //Check every 10 ms  
}while (!(axisStatus &  
NIMC_HIGH_SPEED_CAPTURE_BIT));  
// Wait for high-speed capture to be triggered  
err = flex_read_cap_pos_rtn(boardID, axis,  
&capturedPositions[i]);  
CheckError;  
return;// Exit the Application  
//////////////////////  
// Error Handling  
NI-Motion User Manual  
12-36  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 12  
Synchronization  
//  
nimcHandleError; //NIMCCATCHTHIS:  
// Check to see if there were any Modal Errors  
if (csr & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
Real-Time System Integration Bus (RTSI)  
RTSI is a dedicated high-speed digital bus designed to facilitate system  
integration by low-level, high-speed, real-time communication between  
National Instruments devices.  
Many applications, such as scanning and alignment, synchronize  
measurements made with data and image acquisition devices with position  
and velocity. This synchronization requires high speeds with low latencies.  
Using RTSI, the NI motion controller can share high-speed digital signals  
with NI data acquisition devices, NI image acquisition devices, digital I/O,  
or other NI motion devices with no external cabling and without consuming  
bandwidth on the host bus. The RTSI bus also has built-in switching, so you  
can route signals to and from the bus on-the-fly using software.  
In addition to the breakpoint and high speed capture signals, you can route  
encoder pulses over the RTSI lines, which serves as a way to trigger an  
external device on every change in the encoder channels. You can route  
phase A, phase B, and the index pulse of the encoder over RTSI.  
© National Instruments Corporation  
12-37  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 12  
Synchronization  
You also can create a software trigger by writing to the RTSI lines directly  
from software.  
You can route position breakpoints and encoder pulses using the RTSI bus  
to trigger other devices. You also can configure data and image acquisition  
devices to trigger high-speed captures on the NI motion controllers using  
the RTSI bus.  
RTSI Implementation on the Motion Controller  
You can configure an onboard buffer on the motion controller and use the  
buffered high-speed capture or breakpoint functionality to synchronize the  
motion application with data or image acquisition.  
As shown in Figure 12-21, the I/O reaction task automatically re-enables  
the breakpoints or high-speed captures on the NI 7350 motion controller.  
On NI 7340 motion controllers, you must write an onboard program or use  
the host to perform the same re-enabling tasks.  
Write the captured position to the buffer  
or read the position from the buffer and enable  
the breakpoint. You must create the buffer.  
Host can read/update  
the buffers asynchronously  
To/From  
data/image  
acquisition device  
*NI 7350 only  
Latches position on  
Generate trigger (breakpoint)  
external trigger  
at a given position  
(high-speed capture)  
Figure 12-21. RTSI Implementation on the Motion Controller  
NI-Motion User Manual  
12-38  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
     
Chapter 12  
Position Breakpoints Using RTSI  
You can use the Select Signal function to route position breakpoints using  
one of the RTSI lines. In this case, the motion controller triggers the  
external device at a given position, as shown in Figure 12-22.  
Source:  
Destination:  
Position  
RTSI line  
breakpoint  
Figure 12-22. Position Breakpoint Using RTSI  
Encoder Pulses Using RTSI  
You may need to trigger the external device to acquire data every encoder  
phase or on an encoder index pulse, as shown in Figure 12-23.  
Source: Encoder  
Destination:  
phase A, phase B,  
RTSI line  
or index  
Figure 12-23. Encoder Pulses Using RTSI  
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.  
Source: RTSI  
software port  
Destination:  
RTSI line  
Figure 12-24. Software Trigger Using RTSI  
© National Instruments Corporation  
12-39  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
                 
Chapter 12  
Synchronization  
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.  
Destination:  
High-speed  
capture line  
Source: RTSI line  
Figure 12-25. High-Speed Capture Input Using RTSI  
NI-Motion User Manual  
12-40  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
13  
Torque Control  
To maintain constant torque or force, the sensor that returns the feedback  
to the motion controller must return a value proportional to the torque or  
force. The motion controller operates torque-control and position-control  
systems in much the same way. The main difference is that the feedback in  
position-control systems returns the current position, while the feedback in  
torque-control systems returns a voltage proportional to the current force or  
torque.  
You can implement force feedback on NI motion controllers using either  
analog feedback or by monitoring force.  
Note The NI SoftMotion Controller does not support analog feedback.  
Analog Feedback  
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.  
Figure 13-1. Torque Control Using Analog Feedback Flowchart  
© National Instruments Corporation  
13-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
         
Chapter 13  
Torque Control  
Tuning the control loop with a force sensor, which is an analog feedback  
sensor, produces the same results as with a position feedback sensor.  
Depending upon the resolution you are using, the system may require  
higher gains to ensure a faster response. NI motion controllers have 12-bit  
or 16-bit analog inputs, whose ranges can be set from 0 V to 5 V, 5 V to  
+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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
Torque Control Using Analog Feedback Algorithm  
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. This applies to a 5 V range  
for ADC Channel & 12-bit ADC  
Load move constraints:  
max velocity, max  
acceleration, and max  
deceleration in volts  
Set operation mode  
Set to absolute mode  
Start motion  
Loop waiting for move complete  
Update target position  
(optional)  
Start motion  
(optional)  
Figure 13-2. Torque Control Using Analog Feedback Algorithm  
© National Instruments Corporation  
13-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
LabVIEW Code  
1
2
3
4
5
6
7
8
1
2
3
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
4
5
6
Set Operation Mode  
Load Target Position  
Start Motion  
7
8
Read per Axis Status  
Motion Error Handler  
Figure 13-3. Torque Control Using Analog Feedback Using LabVIEW  
NI-Motion User Manual  
13-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
u16 moveComplete;  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
////////////////////////////////  
//-------------------------------------------------  
//Is is assumed that the axis being moved has an ADC  
channel mapped //as its primary feedback. Position is  
treated as binary volts. //Hence velocity is loaded  
in binary volts/sec and acceleration as //binary  
volts/sec^2.  
//-------------------------------------------------  
// Set the velocity for the move (in binary  
volts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in binary  
volts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in binary  
volts/sec^2)  
© National Instruments Corporation  
13-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
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);  
CheckError;  
// Load Position corresponding to the voltage which  
you want the //motor to maintain (2047 ~ 5V in this  
example)  
err = flex_load_target_pos (boardID, axis, 2047,  
0xFF);  
CheckError;  
//Start the move  
err = flex_start(boardID, axis, 0);  
CheckError;  
do  
{
axisStatus = 0;  
//Check the move complete status  
err = flex_check_move_complete_status(boardID,  
axis, 0, &moveComplete);  
CheckError;  
// Check the following error/axis off status for  
axis 1  
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 & NIMC_MODAL_ERROR_MSG;  
CheckError;  
NI-Motion User Manual  
13-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
}
}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 & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
© National Instruments Corporation  
13-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
Monitoring Force  
You can use this second force-feedback mode if you have a position sensor  
on the motor, in addition to the torque sensor. The control loop on the  
motion controller closes the position and velocity loops as usual. Use MAX  
to map the encoder as the feedback device for the axis.  
Figure 13-4. Torque Control Using Analog Feedback Flowchart  
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  
13-8  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 13  
Torque Control  
Torque Control Using Monitoring Force Algorithm  
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  
deceleration  
Set operation mode  
Set to relative mode  
Loop reading the analog channel that is  
connected to the force or torque sensor  
Read analog sensor  
Check against  
required value  
Update target position  
(optional)  
Start motion  
(optional)  
Figure 13-5. Torque Control Using Monitoring Force Algorithm  
© National Instruments Corporation  
13-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
LabVIEW Code  
1
2
3
4
5
6
7
8
9
1
2
3
Load Velocity  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
4
5
6
Set Operation Mode  
Read ADC  
Load Target Position  
7
8
9
Start Motion  
Read per Axis Status  
Motion Error Handler  
Figure 13-6. Torque Control Using Monitoring Force in LabVIEW  
NI-Motion User Manual  
13-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 constant;// Constant force  
i16 adcValue;// ADC value read  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
// constant force needed to be maintained  
// corresponds to 5V for a +/- 5V ADC settings  
constant = 2047;  
////////////////////////////////  
//-------------------------------------------------  
//Is is assumed that the axis being moved has an  
encoder mapped as //its primary feedback  
//-------------------------------------------------  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
© National Instruments Corporation  
13-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
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);  
CheckError;  
do  
{
// Read the ADC channel number 1 and calculate the  
position to //be updated  
err = flex_read_adc16_rtn(boardID, NIMC_ADC1,  
&adcValue);  
CheckError;  
if( (constant - adcValue) != 0){  
err = flex_load_target_pos(boardID, axis,  
(constant - adcValue), 0xFF);  
CheckError;  
// Move based on delta force  
err = flex_start(boardID, axis, 0);  
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);  
CheckError;  
// Check the modal errors  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
NI-Motion User Manual  
13-12  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
}
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){  
do{  
//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  
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  
}
© National Instruments Corporation  
13-13  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
Speed Control Based on Analog Value  
In a system where a feed roll must run at speeds based on an input voltage,  
the algorithm to maintain the speed consists of reading the analog voltage  
connected to one of the analog channels on the motion controller, and  
updating the speed of the axis based on the value of the voltage read. In this  
system, the feedback is a normal position sensor, such as an encoder.  
Speed Control Based on Analog Feedback Algorithm  
Load move constraints  
Set operation mode  
Set to velocity mode  
Start motion  
Loop waiting for move complete  
Read analog input  
Compute new velocity  
based on analog input  
Load new velocity  
Figure 13-7. 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  
13-14  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
Chapter 13  
Torque Control  
LabVIEW Code  
1
2
3
4
5
6
7
8
9
10  
1
2
3
4
Load Velocity  
5
6
7
Start Motion  
Read ADC  
Load Velocity  
8
9
Start Motion  
Read per Axis Status  
10 Motion Error Handler  
Load Acceleration/Deceleration  
Load Acceleration/Deceleration  
Set Operation Mode  
Figure 13-8. Speed Control Based on Analog Feedback Using LabVIEW  
© National Instruments Corporation  
13-15  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis;// Axis number  
u16 csr = 0;// Communication status register  
u16 axisStatus;// Axis status  
i32 constant;// Constant multiplier  
i16 adcValue;// ADC value read  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
// constant to multiply the ADC value read to  
calculate the //required velocity  
constant = 10;  
////////////////////////////////  
// Set the velocity for the move (in counts/sec)  
err = flex_load_velocity(boardID, axis, 10000,  
0xFF);  
CheckError;  
// Set the acceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_ACCELERATION, 100000, 0xFF);  
CheckError;  
// Set the deceleration for the move (in  
counts/sec^2)  
err = flex_load_acceleration(boardID, axis,  
NIMC_DECELERATION, 100000, 0xFF);  
CheckError;  
NI-Motion User Manual  
13-16  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 13  
Torque Control  
// 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);  
CheckError;  
do  
{
// Read the ADC channel number 1 and calculate the  
velocity to //be updated  
err = flex_read_adc16_rtn(boardID, NIMC_ADC1,  
&adcValue);  
CheckError;  
// Set the velocity based on the ADC value read  
err = flex_load_velocity(boardID, axis, (adcValue  
* constant), 0xFF);  
CheckError;  
// Update the velocity  
err = flex_start(boardID, axis, 0);  
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);  
CheckError;  
// Check the modal errors  
if (csr & NIMC_MODAL_ERROR_MSG)  
{
err = csr & NIMC_MODAL_ERROR_MSG;  
CheckError;  
}
© National Instruments Corporation  
13-17  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 13  
Torque Control  
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){  
do{  
//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  
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  
}
NI-Motion User Manual  
13-18  
Download from Www.Somanuals.com. All Manuals Search And Download.  
ni.com  
14  
Onboard Programs  
This chapter provides information about how onboard programs work for  
the NI SoftMotion Controller and for NI 73xx motion controllers.  
Using Onboard Programs with the NI SoftMotion  
Controller  
To use onboard programs with the NI SoftMotion Controller, use the  
LabVIEW Real-Time Module (RT) to target your application to run in the  
same environment as the NI SoftMotion Controller.  
Because the NI SoftMotion Controller onboard program shares the same  
processor and system resources with the NI SoftMotion Controller, ensure  
you consider the following points before running your application in  
LabVIEW RT:  
Ensure that your top level VI is configured to run at normal, above  
normal, or high priority. If you are targeting LabVIEW RT for ETS,  
use the timed loop instead of changing the priority of your top level VI.  
Follow the guidelines in the LabVIEW Real-Time Module User  
Manual. The guidelines regarding memory allocation and using shared  
resources are especially important.  
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.  
You can further decrease the jitter under ETS by configuring the  
Ethernet mode to be polling. You configure these settings for the RT  
controller in Measurement & Automation Explorer (MAX).  
Under LabVIEW RT, the NI SoftMotion Controller runs in the  
background at time critical priority. The NI SoftMotion Controller is  
designed to consume less than 40% of the processor bandwidth. The  
rate at which the NI SoftMotion Controller updates its data is typically  
1 KHz for Ormec and 100 Hz for CANopen.  
© National Instruments Corporation  
14-1  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 14  
Onboard Programs  
Using Onboard Programs with NI 73xx  
Motion Controllers  
You can use the real-time operating system on the NI 73xx motion  
controller to run custom programs. This functionality allows you to offload  
some motion-specific tasks from the host processor and onto the motion  
controller. Using onboard variables, which are global data on the device,  
arithmetic and loop operations, and efficient wait functions, you can write  
onboard programs to execute parts of the motion application with almost  
no host interaction. You can execute up to 10 onboard programs  
simultaneously.  
Onboard programs have the least priority in a preemptive multitasking  
environment running on the embedded microprocessor because the primary  
function of the embedded processor is supervisory control and I/O reaction.  
Instead, the onboard programs run in a time-sliced manner at the lowest  
priority. Each onboard program gets a default time slice of  
two milliseconds, after which it relinquishes control of the processor to the  
next onboard program or housekeeping task.  
The host communication and I/O reaction tasks take higher priority than the  
onboard programs and housekeeping tasks, as shown in Figure 14-1.  
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.  
NI-Motion User Manual  
14-2  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 14  
Onboard Programs  
I/O reaction  
Host communications  
pre-emptive tasks  
2 ms time-sliced tasks  
Figure 14-1. Onboard Program Priority  
Note If you continuously poll data from the host, the onboard program gets preempted and  
has less time to run. To keep this from happening, insert a small delay in the polling loops  
on the host. Refer to the Timing Loops section of Chapter 4, What You Need to Know about  
Moves, for information about programming delays in the loops.  
Writing Onboard Programs  
Note This section and the sections that follow it apply only to the NI 73xx motion  
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.  
© National Instruments Corporation  
14-3  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
       
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
3
Transfer the program to onboard RAM using the host communication handler.  
Store the program to FLASH memory for more permanent storage (optional).  
Figure 14-2. Writing Onboard Programs  
Algorithm  
Begin store  
Put motion controller in store mode  
Load move parameters  
Load the move type  
Start move  
End store  
End the store mode  
Figure 14-3. Basic Onboard Program Algorithm  
NI-Motion User Manual  
14-4  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
     
Chapter 14  
Onboard Programs  
LabVIEW Code  
1
2
3
4
5
7
6
1
2
3
4
Begin Program Storage  
Load Target Position  
Load Velocity in RPM  
5
6
7
Load Accel/Decel in RPS/s  
Start Motion  
End Program Storage  
Load Accel/Decel in RPS/s  
Figure 14-4. Onboard Program in LabVIEW  
© National Instruments Corporation  
14-5  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 14  
Onboard Programs  
C/C++ Code  
The following example code is not necessarily complete, and may  
not compile if copied exactly. Refer to the examplesfolder on the  
NI-Motion CD for files that are complete and compile as is.  
// Main Function  
void main(void)  
{
u8 boardID;// Board identification number  
u8 axis; // Axis number  
u16 csr = 0;// Communication status register  
//Variables for modal error handling  
u16 commandID;// The commandID of the function  
u16 resourceID;// The resource ID  
i32 errorCode;// Error code  
///////////////////////////////  
// Set the board ID  
boardID = 1;  
// Set the axis number  
axis = NIMC_AXIS1;  
////////////////////////////////  
//------------------------------------------------  
// Onboard program 1. This onboard program moves axis  
one clockwise //5,000 counts (steps). To execute this  
onboard program call the //Run Program function.  
//------------------------------------------------  
// Begin onboard program storage - program number 1  
err = flex_begin_store(boardID, 1);  
CheckError;  
// Set the operation mode to relative  
err = flex_set_op_mode(boardID, axis,  
NIMC_RELATIVE_POSITION);  
CheckError;  
// Load Target Position to move clockwise 5,000  
counts(steps)  
err = flex_load_target_pos(boardID, axis, 5000,  
0xFF);  
CheckError;  
// Load Velocity in RPM  
err = flex_load_rpm(boardID, axis, 100.00, 0xFF);  
CheckError;  
// Load Acceleration and Deceleration in RPS/sec  
NI-Motion User Manual  
14-6  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
   
Chapter 14  
Onboard Programs  
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 & NIMC_MODAL_ERROR_MSG){  
do{  
//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  
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  
}
© National Instruments Corporation  
14-7  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
Chapter 14  
Onboard Programs  
Running, Stopping, and Pausing Onboard Programs  
Use the Run Program, Stop Program, and Pause/Resume Program  
functions to run, stop, and pause an onboard program that resides in the  
onboard memory of a motion controller.  
Running an Onboard Program  
Run Program executes previously stored programs from RAM or FLASH.  
Typically, you must call the Run Program function from the host, because  
it is not possible for an onboard program to run itself. However, it is  
possible to configure the motion controller to automatically run an onboard  
program upon powering up the motion control system. You also can call an  
onboard program from another onboard program using the Run Program  
function.  
Note Recursively calling an onboard program generates an error.  
Stopping an Onboard Program  
Stop Program ends the execution of an onboard program that is currently  
running.  
Stopping an onboard program using the Stop Program function completely  
ends execution. It is not possible to resume execution of the stopped  
onboard program, but you can re-run the program from the beginning.  
You can stop an onboard program with a Stop Program function call from  
the host or from another onboard program.  
Note It is not possible for an onboard program to stop itself.  
Tip Stopping an onboard program is different from stopping the motion of the axis or  
axes. When you stop an onboard program, any moves that have started continue to run. You  
must separately call the Stop Motion function to stop the motion of the axis or axes.  
Pausing/Resuming an Onboard Program  
The Pause/Resume Program function suspends execution of a running  
onboard program, or resumes execution of a previously paused onboard  
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  
Download from Www.Somanuals.com. All Manuals Search And Download.  
             
Chapter 14  
Onboard Programs  
You can resume an onboard program with a function call from the host or  
from another running onboard program.  
Note It is not possible for an onboard program to resume itself.  
Tip Similarly to the Stop Program function, Pause/Resume Program has no effect on  
moves that have started.  
Automatic Pausing  
Any run-time error that occurs during execution automatically pauses the  
onboard program.  
An onboard program also pauses automatically when it executes the Start  
function or the Blend Motion function on an axis that has been stopped by  
the host, or when an axis is stopped due to a limit, home, software limit, or  
following error condition.  
Single-Stepping Using Pause  
You can use the Pause/Resume Program function to effectively single-step  
through an onboard program. To single-step, add a Pause/Resume Program  
call after each function, and then resume the onboard program from the  
host.  
Conditionally Executing Onboard Programs  
You can set conditions that affect the execution of the onboard programs.  
For example, you may want the onboard program to wait until a specific  
event occurs, and then continue executing.  
The Wait on Condition function allows you to create onboard programs that  
wait for events, such as move complete and blend complete. These onboard  
programs can send functions to start moves and wait for moves to complete.  
The onboard program uses almost no processor time while waiting for an  
event such as move complete. 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  
14-9  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.  
           
Chapter 14  
Onboard Programs  
generator  
reaction  
task  
Run program  
communication  
task  
Onboard programs  
Figure 14-5. Executing Onboard Programs  
NI-Motion User Manual  
14-10  
ni.com  
Download from Www.Somanuals.com. All Manuals Search And Download.  
 
Chapter 14  
Onboard Programs  
Onboard Program Conditional Execution Algorithm  
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  
© National Instruments Corporation  
14-11  
NI-Motion User Manual  
Download from Www.Somanuals.com. All Manuals Search And Download.