Motion Control NI-Motion User Manual TM NI-Motion User Manual November 2005 371242B-01
support Worldwide Technical Support and Product Information ni.
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.
Contents About This Manual Conventions ...................................................................................................................xiii Documentation and Examples .......................................................................................xiv PART I Introduction Chapter 1 Introduction to NI-Motion About NI-Motion ...........................................................................................................1-1 NI-Motion Architecture ............................
Contents PART III Programming with NI-Motion Chapter 4 What You Need to Know about Moves Move Profiles ................................................................................................................ 4-1 Trapezoidal...................................................................................................... 4-1 S-Curve ........................................................................................................... 4-2 Basic Moves .........................................
Contents Chapter 6 Arc Moves Circular Arcs..................................................................................................................6-1 Arc Move Algorithm .......................................................................................6-3 LabVIEW Code ...............................................................................................6-4 C/C++ Code.....................................................................................................
Contents Chapter 10 Electronic Gearing and Camming Gearing .......................................................................................................................... 10-1 Algorithm ........................................................................................................ 10-2 Gear Master ...................................................................................... 10-4 LabVIEW Code........................................................................................
Contents Modulo Breakpoints (NI 7330, NI 7340 and NI 7390 only) .........................................12-21 Modulo Breakpoints Algorithm ......................................................................12-23 LabVIEW Code ...............................................................................................12-24 C/C++ Code.....................................................................................................12-25 High-Speed Capture..............................................
Contents C/C++ Code .................................................................................................... 14-6 Running, Stopping, and Pausing Onboard Programs .................................................... 14-8 Running an Onboard Program ........................................................................ 14-8 Stopping an Onboard Program........................................................................ 14-8 Pausing/Resuming an Onboard Program .................................
Contents Blending Straight-Line Move Segments........................................................................15-7 Raster Scanning Using Blended Straight Lines Algorithm.............................15-8 LabVIEW Code ...............................................................................................15-9 C/C++ Code.....................................................................................................15-10 User-Defined Scanning Path.............................................
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.
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.
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.
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.
Introduction to NI-Motion 1 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.
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 NI Motion Controller 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.
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.
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 PC Digital Signal Processor (DSP) Supervisory/ Communications/ User-defined Onboard Programs Control Loop and Trajectory Generation Watchdog Timer FPGAs Encoders and Motion I/O Figure 1-2.
Chapter 1 Introduction to NI-Motion Figure 1-3 shows the components of the NI 73xx motion controllers. Typical NI 73xx Motion Controller Architecture Trajectory Generation Host Bus Control Loop Analog & Digital I/O Supervisory Control To drive 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.
Chapter 1 Introduction to NI-Motion Figure 1-5 illustrates the functional architecture of NI motion controllers.
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.
Chapter 1 Introduction to NI-Motion NI SoftMotion Controller on Host Device* Supervisory Control Trajectory Generation Ormec Drive Control Loop I/O** 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.
Chapter 1 NI SoftMotion Controller on Host Device* Supervisory Control Introduction to NI-Motion CANopen Drive Trajectory Generation Spline Engine Control Loop I/O** 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.
Creating NI-Motion Applications 2 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.
Chapter 2 Creating NI-Motion Applications Determine the system requirements Getting Started with NI-Motion for NI 73xx Motion Controllers Determine the 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.
Chapter 2 Creating NI-Motion Applications 1 Define control mechanism for I/O Breakpoints* High-speed capture** 2a 2b Define breakpoint position Define triggering input type Enable a breakpoint Enable high-speed capture Set data or image acquisition device to trigger on breakpoint Read the captured position 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
Chapter 2 Creating NI-Motion Applications 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. Note NI-Motion User Manual 2-4 ni.
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.
Tuning Servo Systems 3 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).
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.
Tuning Servo Systems Figure 3-2.
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.
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.
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).
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.
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.
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.
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.
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.
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.
Part III Programming with NI-Motion NI-Motion User Manual • Synchronization • Torque Control • Onboard Programs III-2 ni.
What You Need to Know about Moves 4 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.
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.
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.
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.
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.
Chapter 4 What You Need to Know about Moves You can calculate this minimum velocity increment in RPM with the following formula: 1 1 minimum RPM = Vmin × ----- × 60 × --- R Ts 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 minimum RPM = MIN × --R You also can calculate the minimum velocity using the formula shown in the Calculation Based on Units column in Table 4-1.
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).
Chapter 4 What You Need to Know about Moves You can calculate the maximum velocity with the following equation: maximum velocity = Vmax 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 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.
Chapter 4 What You Need to Know about Moves You can calculate the minimum acceleration increment with the following formula: 1 2 minimum acceleration/deceleration = Amin × ----- Ts 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: 1 - -------------1 - 2 2 ---------
Chapter 4 What You Need to Know about Moves Table 4-3. Acceleration Update Rate in RPS/s Update Rate MAX Calculation Based on Units MIN 62.5 µs 2,048,000,000 counts/sec2 3906 counts/sec2 125 µs 2,048,000,000 counts/sec2 977 counts/sec2 187.5 µs 910,222,222 counts/sec2 434 counts/sec2 250 µs 512,000,000 counts/sec2 244 counts/sec2 312.5 µs 327,680,000 counts/sec2 156 counts/sec2 375 µs 227,555,556 counts/sec2 109 counts/sec2 437.
Chapter 4 What You Need to Know about Moves You can calculate the maximum RPS/s using the following equation: 1 2 1 maximum RPS/s = Amax × ----- × --- Ts R 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 MAX × --r For a typical servo axis with 2,000 counts or steps per revolution operating at the 250
Chapter 4 What You Need to Know about Moves 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. Note 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.
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.
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.
Straight-Line Moves 5 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).
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. You must load the move constraints only if they are different from what was previously loaded. Tip Figure 5-1.
Chapter 5 1 3 4 5 6 2 1 2 3 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Straight-Line Moves 7 4 5 6 8 9 10 Load S-Curve Time Set Operation Mode Load Target Position 12 11 7 8 9 Start Motion Read per Axis Status Motion Error Handler Figure 5-2.
Chapter 5 Straight-Line Moves 1 3 4 5 2 1 2 3 4 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 6 7 5 6 7 8 8 9 Load S-Curve Time Set Operation Mode Load Target Position Start Motion 10 11 9 10 11 12 12 Check Move Complete Status Read per Axis Status Read per Axis Status Motion Error Handler Figure 5-3. 2D Straight-Line Move in LabVIEW NI-Motion User Manual 5-4 ni.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 followi
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); } e
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_acceler
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)
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.
Chapter 5 Straight-Line Moves Algorithm Figure 5-4 is a generic algorithm applicable to both C/C++ and VI code. Figure 5-4.
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 5,000 10,000 Time Figure 5-5. Velocity Profile NI-Motion User Manual 5-12 ni.
Chapter 5 Straight-Line Moves LabVIEW Code 6 1 1 2 3 4 9 10 5 3 2 7 4 8 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Load S-Curve Time 5 6 7 8 Set Operation Mode Start Motion Read per Axis Status Load Velocity 11 12 9 10 11 12 Start Motion Read per Axis Status Stop Motion 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.
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 t
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 - initi
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_F
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.
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.
Chapter 5 Straight-Line Moves LabVIEW Code 6 1 1 2 3 4 5 3 2 9 7 8 4 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Load S-Curve Time 5 6 7 8 Set Operation Mode Start Motion Read per Axis Status Load Velocity Override 10 11 9 Read per Axis Status 10 Stop Motion 11 Motion Error Handler Figure 5-8.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 se
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 { /
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
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.
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.
Chapter 6 1 1 Positive Travel Angle Arc Moves 2 2 Negative Travel Angle Figure 6-3. Positive and Negative Travel Angles Arc Move Algorithm Load Velocity Load Acceleration/ Deceleration Move Constraints Load Circular Arc Radius, Start Angle, and Travel Angle Start Motion Loop Waiting for Move Complete Perform Measurements (Optional) Figure 6-4.
Chapter 6 Arc Moves LabVIEW Code 4 1 1 2 3 4 2 3 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 5 6 7 5 6 7 8 Load Circular Arc Start Motion Check Move Complete Status 10 9 8 Read per Axis Status 9 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.
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_veloci
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_r
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 3
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.
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.
Chapter 6 Arc Moves LabVIEW Code 5 2 1 1 2 3 4 6 4 3 8 7 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 5 6 7 8 9 Load Spherical Arc Start Motion Check Move Complete Status Read per Axis Status 11 10 9 Read per Axis Status 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.
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 count
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
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 coordin
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.
Chapter 6 Arc Moves LabVIEW Code 5 1 1 2 3 4 2 3 6 4 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 7 5 6 7 8 8 Load Helical Arc Start Motion Check Move Complete Status Read per Axis Status 9 11 10 9 Read per Axis Status 10 Read per Axis Status 11 Motion Error Handler 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.
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_acceler
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_c
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.
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 Cubic Spine Output to DACs or Stepper Output Figure 7-1.
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.
Chapter 7 Contoured Moves Contoured Move Algorithm Set Operation Mode • 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 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 Specify absolute or relative contouring Configure the buffer on the device Write Buffer Write the array of points and the number of p
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.
© National Instruments Corporation 1 2 3 4 7-5 1 Configure Vector Space Set Operation Mode Configure Buffer Write Buffer LabVIEW Code 2 3 4 5 6 7 8 7 8 9 10 11 9 Clear Buffer 10 Set Operation Mode 11 Motion Error Handler Figure 7-5.
Chapter 7 Contoured Moves 1 1 2 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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 mo
Chapter 7 Contoured Moves for(i=0;i
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
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,&resourc
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.
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.
Chapter 8 Reference Moves LabVIEW Code 1 1 2 3 2 3 4 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 5 4 5 6 6 Load S-Curve Time Find Reference Check Reference 7 8 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.
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.
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 = fle
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(bo
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.
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 move starts to decelerate • 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.
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. Velocity 1 2 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.
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. Velocity 1 2 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.
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.
NI-Motion User Manual 1 2 3 4 5 6 7 9-6 1 2 3 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Load S-Curve Time Set Operation Mode Load Vector Space Position LabVIEW Code 4 5 6 8 7 13 14 Start Motion Load Blend Factor Load Circular Arc Blend Motion Check Blend Complete Status Read per Axis Status Read per Axis Status 10 11 12 15 15 16 17 18 19 20 19 20 Load Vector Space Position Blend Motion Check Move Complete Status Read per Axis Status
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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.
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
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); nimcDisplayEr
Electronic Gearing and Camming 10 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.
Chapter 10 Electronic Gearing and Camming Algorithm Designate a Master Device Gearing Set the Gear Ratio 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 Enable gearing on the Slave Axis The slave axis now moves in proportion to the master device.
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 Move Master Position 1000 Master Position After Move 1010 Slave Position at Enable Move Slave Position After Move Slave Position 3000 3020 Figure 10-2.
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. When the gear ratio is changed on-the-fly, the slave axis moves at full torque to the new position. Note 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.
Chapter 10 Electronic Gearing and Camming LabVIEW Code 1 2 3 1 2 3 4 5 6 4 Configure Gear Master Load Gear Ratio Enable Gearing Wait Load Velocity Load Acceleration/Deceleration 5 7 8 9 10 11 12 6 7 8 9 10 11 12 Set Operation Mode Load Target Position Start Motion Wait for Move Complete Enable Gearing Single Axis Read per Axis Status Figure 10-4.
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; //-----------------------
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 //------------------
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 Slave Gear ratio = ∆ Slave/∆ Master ∆ Master Master Figure 10-5.
Chapter 10 Electronic Gearing and Camming Slave Master Cycle Begins to Repeat Master Ratio 1 Ratio Ratio 2 3 Ratio 4 Ratio 1 Ratio 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.
Chapter 10 Electronic Gearing and Camming 2 3 1 1 2 3 Conveyor belt Movement of the welder as it follows the object, and then returns to the initial position 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.
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.
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.
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 t1 2000 Se en gm gm en t2 Se 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.
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.
Chapter 10 Electronic Gearing and Camming Master 0 2000 4000 0 1000 2000 4000 Slave 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 2000 4000 6000 0 1000 2000 4000 6000 Slave Figure 10-14.
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.
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.
Chapter 10 Electronic Gearing and Camming Camming starts here at position 50 Master cycle begins 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 Without Master Offset 2000 Slave With Master Offset 1500 1000 Master Offset 500 0 0 2000 4000 6000 8000 10000 Master Figure 10-18.
Chapter 10 Electronic Gearing and Camming LabVIEW Code 1 2 3 6 4 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 7 5 8 9 8 9 10 11 12 13 10 11 12 13 Load Target Position Start Motion Wait for Move Complete Enable Camming Single Axis Clear Buffer Motion Error Handler Figure 10-19.
Chapter 10 Electronic Gearing and Camming u8 slaveAxis = 1; // Slave axis ID u8 buffer = 1; // Buffer to contain the cam table 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; // Communicati
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.
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.
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.
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.
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.
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 1 Acquire Trajectory Data 2 2 Read Trajectory Data 3 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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 resour
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
12 Synchronization You can synchronize NI motion controllers with NI data and image acquisition devices using breakpoints and high-speed captures. Timing and triggering with NI-Motion is always related to either position or velocity. Synchronizing position and velocity information with the external world allows you to coordinate measurements with moves. You can program the motion controller to trigger another device at specified positions using RTSI or a pin on the Motion I/O connector.
Chapter 12 Synchronization Table 12-1 shows the availability of breakpoint modes on each NI motion controller. Table 12-1.
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.
Chapter 12 Synchronization Buffered Breakpoint Algorithm Figure 12-1 shows the basic algorithm for implementing buffered breakpoints. Load Breakpoint Array • Set the buffer type to breakpoint positions • Total Points is the total number of breakpoint positions you want to load • Buffer Size is the size of the buffer you want to create on the device.
Chapter 12 Synchronization LabVIEW Code 3 1 1 2 3 2 Configure Buffer Write Buffer Configure Breakpoint 4 4 5 5 Enable Breakpoint Output Check Buffer 6 6 7 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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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.
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_
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.
Chapter 12 Synchronization LabVIEW Code 4 1 1 2 Configure Breakpoint Load Breakpoint Position 3 4 2 5 3 Enable Breakpoint Output Read per Axis Status 5 Motion Error Handler Figure 12-4.
Chapter 12 Synchronization Refer to Figure 12-5 for an example of how to route this breakpoint using RTSI. 5 1 1 2 Select Signal Configure Breakpoint 2 3 4 3 6 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.
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
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, &
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.
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. 1 1 2 Select Signal Configure Breakpoint 2 3 3 4 4 Load Breakpoint Position Enable Breakpoint Output 5 6 5 6 Read per Axis Status Motion Error Handler Figure 12-7.
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,
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 statu
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.
Chapter 12 Synchronization LabVIEW Code 1 1 2 3 Configure Breakpoint Load Breakpoint Position Load Breakpoint Modulus 2 3 4 5 6 4 5 6 Enable Breakpoint Output Load Target Position Start Motion 8 7 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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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
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,¤tPos); 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 ); //
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 nimcDisplayErro
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.
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.
Chapter 12 Synchronization LabVIEW Code 2 1 1 2 3 Configure Breakpoint Load Breakpoint Modulus 3 4 4 5 6 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 1 2 3 Select Signal Configure Breakpoint Load Breakpoint Modulus 4 4 5 5 Load Breakpoint Position Enable Breakpoint Output 6 7 6 7 Read per Axis Status Motion Error Handler Figure 12-15.
Chapter 12 Synchronization C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
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
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.
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
Chapter 12 Synchronization LabVIEW Code 4 1 1 2 3 Configure Buffer Configure High-Speed Capture Enable High-Speed Capture 2 5 6 7 3 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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 ////////////////////
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 totalPoints) break; capturedPositions[currentDa taPoint] = readBuffer[i]; printf("capture pos %d\n", capturedPositions[currentDataPoin t]); currentDataPoint++; } free(readBuffer); readBuffer = NULL;
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 ourceI
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.
Chapter 12 Synchronization LabVIEW Code 1 1 2 2 Configure High-Speed Capture Enable High-Speed Capture 3 4 3 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.
Chapter 12 2 1 1 2 3 Select Signal Configure High-Speed Capture Enable High-Speed Capture 3 4 4 5 Synchronization 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.
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
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 regu
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.
Chapter 12 Synchronization 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: Position breakpoint Destination: RTSI line Figure 12-22.
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. Source: RTSI line Destination: High-speed capture line Figure 12-25. High-Speed Capture Input Using RTSI NI-Motion User Manual 12-40 ni.
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.
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.
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.
Chapter 13 Torque Control LabVIEW Code 1 1 2 3 2 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 3 4 4 5 6 5 6 Set Operation Mode Load Target Position Start Motion 7 8 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.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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); Chec
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 dev
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.
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 1
Chapter 13 Torque Control LabVIEW Code 1 1 2 3 2 3 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration 4 4 5 6 5 Set Operation Mode Read ADC Load Target Position 6 7 7 8 9 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.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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
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
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.
Chapter 13 Torque Control LabVIEW Code 1 1 2 3 4 2 Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Set Operation Mode 3 4 5 5 6 7 6 Start Motion Read ADC Load Velocity 7 8 9 10 8 Start Motion 9 Read per Axis Status 10 Motion Error Handler Figure 13-8.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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 th
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,
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.
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.
Chapter 14 Onboard Programs I/O reaction Host communications pre-emptive tasks 2 ms time-sliced tasks Figure 14-1. Onboard Program Priority 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.
Chapter 14 1 2 3 Onboard Programs Write the program you want to load onto onboard memory. You can use any NI-Motion functions between Begin and End Store. 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.
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 Load Accel/Decel in RPS/s 5 6 7 Load Accel/Decel in RPS/s Start Motion End Program Storage Figure 14-4.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 14 Onboard Programs err = flex_load_rpsps(boardID, axis, NIMC_BOTH, 50.
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.
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. Similarly to the Stop Program function, Pause/Resume Program has no effect on moves that have started. Tip Automatic Pausing Any run-time error that occurs during execution automatically pauses the onboard program.
Chapter 14 Onboard Programs generator Run program reaction task communication task Onboard programs Figure 14-5. Executing Onboard Programs NI-Motion User Manual 14-10 ni.
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.
Chapter 14 Onboard Programs LabVIEW Code 1 3 4 5 6 7 8 9 2 1 2 3 Begin Program Storage Set Operation Mode Load Velocity in RPM 4 5 6 Load Target Position Select MOMO Wait on Condition 7 8 9 Start Motion End Program Storage Motion Error Handler Figure 14-7. Onboard Program Waiting for an I/O Line to Go Active C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly.
Chapter 14 Onboard Programs // Set the board ID boardID = 1; // Set the axis number axis = NIMC_AXIS1; //////////////////////////////// // Begin onboard program storage - program number 1 err = flex_begin_store(boardID, 1); CheckError; // Load Velocity in RPM err = flex_load_rpm(boardID, axis, 100.00, 0xFF); CheckError; // Load Acceleration and Deceleration in RPS/sec err = flex_load_rpsps(boardID, axis, NIMC_BOTH, 50.
Chapter 14 Onboard Programs 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_rea
Chapter 14 Onboard Programs Algorithm Begin store Put motion controller in store mode Set a label Read ADC Read the analog channel, and save value to an onboard variable Get velocity value Multiply ADC value by a scale factor to calculate velocity Check if value needs to be updated Update if last value is different from current value Jump to label No Jump to label if no update required. Else continue.
Chapter 14 Onboard Programs LabVIEW Code 8 1 2 3 4 5 9 10 11 14 15 6 7 1 2 3 4 5 Load Constant to Variable Load Constant to Variable Begin Program Storage Set Operation Mode Insert Program Label 6 7 8 9 10 Read ADC Multiply Variables Subtract Variables Jump to Label on Condition Load Velocity 12 11 12 13 14 15 13 Start Motion Read Variable Jump to Label on Condition End Program Storage Motion Error Handler Figure 14-9.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 14 Onboard Programs err = flex_read_adc16(boardID, NIMC_ADC1, 2); CheckError; //Multiply variable 2 (ADC value) with variable 1 (constant) // Save the result in variable 3 err = flex_mult_vars(boardID, 1, 2, 3); CheckError; //Subtract value in variable 3 from variable 4. The result is //unimportant, you just want to set the condition on board.
Chapter 14 Onboard Programs ////////////////////// // 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 & NI
Chapter 14 Onboard Programs Onboard Program Algorithm Figure 14-10 shows an onboard program waiting for an I/O line to go active before starting a move. Begin Store Put Controller in Store Mode Set a Label Load Move Parameters Load your Move Type Start Move Wait for Move Event Signal Jump to Label End Store End the Store Mode Figure 14-10. Using Labels with Onboard Programs NI-Motion User Manual 14-20 ni.
Chapter 14 Onboard Programs LabVIEW Code 1 2 4 3 5 6 9 7 1 2 3 4 5 Begin Program Storage Set Operation Mode Load Velocity in RPM Insert Program Label Load Target Position 6 7 8 9 Select MOMO Wait on Condition Start Motion Select MOMO 8 10 10 11 12 13 11 12 13 Wait on Condition Jump to Label on Condition End Program Storage Motion Error Handler Figure 14-11.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 14 Onboard Programs err = flex_load_target_pos(boardID, axis, 5000, 0xFF); CheckError; // Wait for line 1 on port 1 to go active to finish executing err = flex_wait_on_event(boardID, NIMC_IO_PORT1, NIMC_WAIT, NIMC_CONDITION_IO_PORT_MATCH, (u8)(1<<1)/*Indicates line 1*/, 0, NIMC_MATCH_ALL, 10000 /*time out*/, 0); CheckError; // Start the move err = flex_start(boardID, axis, 0); CheckError; // Wait for move to complete err = flex_wait_on_event(boardID, 0, NIMC_WAIT, NIMC_CONDITION_MOVE_COMPLETE, (u8
Chapter 14 Onboard Programs //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 } Math Operations NI-Motion always performs math operations on values stored in onboard variables, and all math operations set a global condition that the Jump to Label function uses to determine if the operation jumps to a particular label in the onboard program.
Chapter 14 Onboard Programs Figure 14-12. Reading an Indirect Variable Using indirect variables can be very useful in looping in onboard programs, as well as dynamically changing the input values to functions. Onboard Buffers You can use the memory on the NI motion controllers to create general-purpose buffers to read and write data, as shown in Figure 14-13.
Chapter 14 Onboard Programs Buffers are created from a dynamic pool of memory, so you must free the memory when the buffer is not required. This same pool of memory is used to store onboard programs in RAM. As the number or size of buffers increases, the available memory for storing onboard programs decreases. Algorithm Figure 14-14 shows the algorithm for using onboard buffers to store data.
Chapter 14 Onboard Programs I/O register for sending commands and reading data Read move complete status function execute from within host application Figure 14-15. Synchronizing Host Applications with Onboard Programs For example, consider a host application that reads an onboard variable that has been updated by an onboard program. Use the algorithm in Figure 14-16 to synchronize the host application with an onboard program, and read an onboard variable that has been updated by an onboard program.
Chapter 14 Onboard Programs LabVIEW Code This example moves axis 1 between target positions of 5000 and –5000. The host reads the target position only after the move has completed, and the new target position has been calculated. Figure 14-17 shows the code that runs as an onboard program.
Chapter 14 Onboard Programs Figure 14-18 shows the code that runs on the host. 1 1 Read Move Complete Status 2 2 Set User Status MOMO 3 3 Read Variable Figure 14-18. Synchronization Host Code in LabVIEW As the host is polling a register on the motion controller, it is not invoking the Host Communication Task on the real-time operating system on the motion controller. Therefore, the onboard programs executing are not preempted. In this situation, the onboard programs run deterministically.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 14 Onboard Programs err = flex_load_var(boardID, targetPosition, 1); CheckError; // Begin onboard program storage - program number 1 err = flex_begin_store(boardID, 1); // Set the operation mode to absolute position err = flex_set_op_mode(boardID, axis, NIMC_ABSOLUTE_POSITION); CheckError; // Set the velocity err = flex_load_velocity(boardID, axis, 10000, 0xFF); CheckError; // Insert Label number 1 err = flex_insert_program_label(boardID, 1); CheckError; // Load Target Position from onboard variab
Chapter 14 Onboard Programs err = flex_jump_on_event (boardID, 0, NIMC_CONDITION_TRUE, 0, 0, NIMC_MATCH_ALL, 1/*label number*/); CheckError; // End Program Storage err = flex_end_store(boardID, 1); CheckError; //-----------------------------------------------// Host program. This programs monitors the 13th bit in the move //complete status register and records the position the axis is //going to move to.
Chapter 14 Onboard Programs err = flex_read_var_rtn(boardID, 1, ¤tTargetPosition); CheckError; } Sleep (50); //Check every 50 ms }while (!(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move complete/following error/axis off return;// Exit the Application // Error Handling nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ do{ //Get the command ID, resource ID, and the error code of the //modal er
Chapter 14 Onboard Programs Onboard Subroutines You can create subroutines to run as onboard programs and execute them from within an onboard program. Algorithm Figure 14-19 shows an onboard program algorithm that checks the I/O line state to determine which onboard subroutine to execute. Main onboard program Check I/O line state Start program 2 Wait for program 2 to complete Start program 3 Wait for program 3 to complete Figure 14-19.
Chapter 14 Onboard Programs LabVIEW Code Figure 14-20 shows the main onboard program used to determine the subroutine call. 3 8 11 12 13 7 1 2 5 9 6 10 4 1 2 3 4 5 Begin Program Storage Insert Program Label Select MOMO Jump to Label on Condition Run Program 6 7 8 9 Wait on Condition Jump to Label on Condition Insert Program Label Run Program 10 11 12 13 Wait on Condition Jump to Label on Condition End Program Storage Motion Error Handler Figure 14-20.
Chapter 14 Onboard Programs Figure 14-21 shows the subroutine that causes the motor to rotate clockwise. 5 7 9 10 8 1 1 2 3 4 Begin Program Storage Set Operation Mode Load Target Position Load Velocity in RPM 2 5 6 7 3 4 6 Load Accel/Decel in RPS/sec Start Motion Select MOMO 8 Wait on Condition 9 End Program Storage 10 Motion Error Handler Figure 14-21. Clockwise Subroutine Using LabVIEW NI-Motion User Manual 14-36 ni.
Chapter 14 Onboard Programs Figure 14-22 shows the subroutine that causes the motor to rotate counter clockwise. 5 7 9 10 8 1 1 2 3 4 Begin Program Storage Set Operation Mode Load Target Position Load Velocity in RPM 2 5 6 7 3 4 6 Load Accel/Decel in RPS/sec Start Motion Select MOMO 8 Wait on Condition 9 End Program Storage 10 Motion Error Handler Figure 14-22.
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 examples folder on the NI-Motion CD for files that are complete and compile as is.
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; // Wait for move to complete err = flex_wait_on_event(boardID, 0, NIMC_WAIT, NIMC_CONDITION_MOVE_COMPLETE, 2/*Indicates axis 1*/, 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0); CheckError; // End Program Storage err = flex_end_store(boardID, 2); CheckError; //-----------------------------------------------// Onboard program 3.
Chapter 14 Onboard Programs CheckError; // Wait for move to complete err = flex_wait_on_event(boardID, 0, NIMC_WAIT, NIMC_CONDITION_MOVE_COMPLETE, 2/*Indicates axis 1*/, 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0); CheckError; // End Program Storage err = flex_end_store(boardID, 3); CheckError; //-----------------------------------------------// Onboard program 1. The main onboard program monitors an IO line //and based on state of the IO line executes onboard program 2 or //onboard program 3.
Chapter 14 Onboard Programs // Insert Label number 2 err = flex_insert_program_label(boardID, 2); CheckError; // Execute program 2 err = flex_run_prog(boardID, 2); CheckError; // Wait for program 2 to finish executing err = flex_wait_on_event(boardID, 2 /*program #*/, NIMC_WAIT, NIMC_CONDITION_PROGRAM_COMPLETE, 0, 0, NIMC_MATCH_ALL, 1000 /*time out*/, 0); CheckError; // Jump unconditionally to label 1 and check IO line again err = flex_jump_on_event (boardID, 0, NIMC_CONDITION_TRUE, 0, 0, NIMC_MATCH_ALL,
Chapter 14 Onboard Programs Automatically Starting Onboard Programs You can configure the onboard program to start automatically without calling the Run Program function. The onboard program runs as soon as the motion controller exits the reset state. To use this feature, save the onboard program to FLASH, and then call the Enable Auto Start function. The motion controller checks to see if the auto-start flag is set when it boots up.
Part IV Creating Applications Using NI-Motion You can combine the moves, input/output, and other functionality discussed in Part III, Programming with NI-Motion, to create complete motion control applications. The following chapters show examples of typical motion control applications and how they are implemented using NI-Motion.
15 Scanning The goal of the scanning application is to inspect a wafer under a fixed laser. Multiple detectors collect the scattered laser light and feed the data to an analysis system that maps any defects. The wafer rests on an XY stage that moves in two dimensions. The objective of the scan is to cover as much space on the wafer as possible in the shortest amount of time. Scanning a greater area increases the chances of detecting all defects.
Chapter 15 Scanning Raster Scanning Using Straight Lines Algorithm Configure the coordinate space Load move constraints Set operation mode Create the move segments Load move segment Start motion Loop waiting for move complete Check for errors Figure 15-2. Raster Scanning Using Straight Lines Algorithm The raster scanning algorithm for straight-line moves stops the motors after every segment of the move, so the cycle time is longer than other methods. NI-Motion User Manual 15-2 ni.
© National Instruments Corporation 1 2 3 4 1 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration LabVIEW Code 2 3 4 5 5 6 7 8 7 8 9 15-3 10 11 9 10 11 12 12 Check Move Complete Status Read per Axis Status Read per Axis Status Motion Error Handler Figure 15-3.
Chapter 15 Scanning C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 15 Scanning // Set the deceleration for the move (in counts/sec^2) err = flex_load_acceleration(boardID, vectorSpace, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk or s-curve in sample periods err = flex_load_scurve_time(boardID, vectorSpace, 100, 0xFF); CheckError; // Set the operation mode to absolute position err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_POSITION); CheckError; // Load the straight-line segments one by one for (i=0; i
Chapter 15 Scanning //Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr); CheckError; //Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) { err = csr & NIMC_MODAL_ERROR_MSG; CheckError; } Sleep(10); //Check every 10 ms }while (!moveComplete && !(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !(axisStatus & NIMC_AXIS_OFF_BIT)); //Exit on move complete/following //error/axis off if( (axisStatus & NIMC_FOLLOWING_ERROR_BIT) || (axisStatus & NIMC_AXIS_OFF
Chapter 15 Scanning Blending Straight-Line Move Segments Blending the straight-line move segments enables continuous motion, which decreases the cycle time of the scan. The cycle time is much faster because the motors are not forced to stop after each move segment. Figure 15-4 shows the path of the blended move segments. Figure 15-4. Blended Raster Scanning Path Refer to Chapter 9, Blending Moves, for information about using blending with NI-Motion.
Chapter 15 Scanning Raster Scanning Using Blended Straight Lines Algorithm Configure the coordinate space Load move constraints Set blend factor Set operation mode Create the move segments Load move segment Is this the first move segment? Blend motion Start motion Is this the last move segment? Loop waiting for move complete Loop waiting for blend complete Check for errors Check for errors Figure 15-5. Raster Scanning Using Blended Straight Lines Algorithm NI-Motion User Manual 15-8 ni.
© National Instruments Corporation 1 2 3 4 5 1 Configure Vector Space Load Velocity Load Acceleration/Deceleration Load Acceleration/Deceleration Load S-Curve Time LabVIEW Code 2 3 4 6 7 8 9 5 7 8 9 15-9 10 10 11 12 13 11 12 13 Check Move Complete Status Read per Axis Status Motion Error Handler Motion Error Handler Figure 15-6.
Chapter 15 Scanning C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 15 Scanning // Set the deceleration for the move (in counts/sec^2) err = flex_load_acceleration(boardID, vectorSpace, NIMC_DECELERATION, 100000, 0xFF); CheckError; // Set the jerk or s-curve in sample periods err = flex_load_scurve_time(boardID, vectorSpace, 100, 0xFF); CheckError; // Load the blending factor err = flex_load_blend_fact(boardID, vectorSpace, -1, 0xFF); CheckError; // Set the operation mode to absolute position err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_POSITION); Ch
Chapter 15 Scanning CheckError; }else{ // Check the blend complete status err = flex_check_blend_complete_status(b oardID, vectorSpace, 0, &complete); CheckError; } // Check the following error/axis off status for axis 1 err = flex_read_axis_status_rtn(boardID, NIMC_AXIS1, &status); CheckError; axisStatus |= status; // 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 registe
Chapter 15 Scanning 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_
Chapter 15 Scanning Figure 15-7. User-Defined Scanning Path Using the contoured move gives you the greatest amount of flexibility regarding the scan area and speed. However you lose the benefit of the trajectory generator of the NI motion controller. Refer to Chapter 7, Contoured Moves, for information about using contoured moves with NI-Motion. NI-Motion User Manual 15-14 ni.
Chapter 15 Scanning User-Defined Scanning Path Algorithm Set operation mode Configure onboard buffer Write buffer Write the array of points and number of points to the buffer Start motion Loop waiting for move complete Check the onboard buffer number of points consumed Write buffer Write remaining points to the buffer Clear the onboard buffer Used to store the points Figure 15-8.
NI-Motion User Manual 1 2 3 4 Configure Vector Space Set Operation Mode Configure Buffer Write Buffer LabVIEW Code 1 2 5 6 7 3 5 Start Motion Check Buffer Write Buffer 4 15-16 8 9 8 Clear Buffer 9 Set Operation Mode 10 Motion Error Handler Figure 15-9. Scanning Using Contouring 6 7 10 Chapter 15 Scanning ni.
Chapter 15 Scanning C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 15 Scanning vectorSpace = NIMC_VECTOR_SPACE1; // Configure a 2D vector space comprised of axes 1 and 2 err = flex_config_vect_spc(boardID, vectorSpace, NIMC_AXIS1, NIMC_AXIS2, NIMC_AXIS3); CheckError; // Set the operation mode to absolute position err = flex_set_op_mode(boardID, vectorSpace, NIMC_ABSOLUTE_CONTOURING); CheckError; // Configure buffer on motion controller memory (RAM) // Notice requested time interval is hardcoded to 10 milliseconds err = flex_configure_buffer(boardID, 1 /*buffer nu
Chapter 15 Scanning if(backlog >= 300){ downloadData = malloc(sizeof(i32)*backlog); dataCopied = 0; for(i=0;i numPoints) break; downloadData[i] = points[currentDataPoint]; currentDataPoint++; dataCopied++; } err = flex_write_buffer (boardID, 1 /*buffer number*/, dataCopied, 0, downloadData, 0xFF); free(downloadData); downloadData = NULL; CheckError; } } // Check the move complete status err = flex_check_move_complete_status (boardID, vectorSpace, 0, &moveComplete); Chec
Chapter 15 Scanning 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; // Free the buffer allocated on the motion controller memory err = flex_
16 Rotating Knife The purpose of this application is to cut a web with a rotating knife. The blade must cut precisely between labels on the web. Because the web material can stretch under certain conditions, it is not enough to cut the web at constant length, because the length of each label can vary. To accomplish this task, the web is marked one time per cycle at the required cutting location. The motion controller reads this mark using a sensor and performs the necessary correction.
Chapter 16 Rotating Knife B A A Synchronization Point B Correction Point Figure 16-1. Rotating Knife NI-Motion User Manual 16-2 ni.
Chapter 16 Rotating Knife Algorithm Initialize A = 0; B = 500 Set gear master = encoder 4; Slave = axis 1 Set gear ratio to 1:1 Assuming circumference of the blade = length of cut Load appropriate move constraints for the slave Needed for the superimposed (correction) move Set operation mode to be relative to captured position Also called registration move mode Enable gearing on slave axis After gearing is enabled, web can be started, which rotates the knife Loop waiting for move complete Enable high
Chapter 16 Rotating Knife LabVIEW Code 4 2 6 1 1 2 3 4 5 3 7 8 9 5 Configure Gear Master Load Gear Ratio Load Velocity in RPM Load Accel/Decel in RPS/s Set Operation Mode 6 7 8 9 Enable Gearing Single Axis Enable High-Speed Capture Read High-Speed Capture Status Motion Error Handler Figure 16-3. Rotating Knife Application Using LabVIEW Figures 16-4 and 16-5 show the remaining cases for the block diagram in Figure 16-3. 1 1 Read Captured Position 2 2 Load Target Position Figure 16-4.
Chapter 16 1 1 Read Position Rotating Knife 2 2 Start Motion Figure 16-5. Figure 16-3 Sequence Structure 2 C/C++ Code The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
Chapter 16 Rotating Knife // Set the axis number slaveAxis = NIMC_AXIS1; // Master is encoder 4 master = NIMC_ENCODER4; //////////////////////////////// //------------------------------------------------// Set up the gearing configuration for the slave axis //------------------------------------------------// Configure Gear Master err = flex_config_gear_master(boardID, slaveAxis, master); CheckError; //Load Gear Ratio 1:1 err = flex_load_gear_ratio(boardID, slaveAxis, NIMC_ABSOLUTE_GEARING, 1/*ratioNumera
Chapter 16 Rotating Knife { // Check the high-speed capture status/following error/axis //off status err = flex_read_axis_status_rtn(boardID, slaveAxis, &axisStatus); CheckError; // Read the communication status register and check the modal //errors err = flex_read_csr_rtn(boardID, &csr); CheckError; // Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) { err = csr & NIMC_MODAL_ERROR_MSG; CheckError; } }while (!(axisStatus & NIMC_HIGH_SPEED_CAPTURE_BIT) && !(axisStatus & NIMC_FOLLOWING_ERROR_BIT) && !
Chapter 16 Rotating Knife err = flex_start(boardID, slaveAxis, 0); CheckError; }// For loop return;// Exit the Application /////////////////// // Error Handling /////////////////// nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ 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,comm
Sinusoidal Commutation for Brushless Servo Motion Control A Sinusoidal commutation allows you to use less expensive servo motor drives with NI motion controllers that support this feature. Phase Initialization When the system is first powered on, the controller must determine the initial commutation phase. NI motion controllers support several methods of phase initialization, including Hall effect sensors, shake and wake, and direct set.
Appendix A Sinusoidal Commutation for Brushless Servo Motion Control Direct Set Direct set is an initialization method where the controller sets the current position as the specified phase angle. This initialization method is recommended only for a custom system with known initial phase angle. Whenever the axis is enabled, the controller must perform the phase initialization procedure to determine the phase.
Appendix A Sinusoidal Commutation for Brushless Servo Motion Control Troubleshooting Hall Effect Sensor Connections Complete the following steps if you have problems with Hall effect sensor connections. 1. Check the manuals that shipped with the hardware for connection procedures. 2. Perform a “shake and wake” phase initialization. During this process, the motor is driven to the zero degree phase position with the commanded voltage. Make sure the motor is clear of any limits before you start. 3.
B Initializing the Controller Programmatically You can initialize the motion controller from within a LabVIEW, Visual Basic, or C/C++ program, in addition to initializing controllers in Measurement & Automation Explorer (MAX). Refer to Table B-1 for the steps you must take to initialize a controller programmatically and the functions and VIs you use for each step. Table B-1. Steps for Programmatically Initializing Controllers Step Function and/or VI 1. Clear the power-up state.
Appendix B Initializing the Controller Programmatically Table B-1. Steps for Programmatically Initializing Controllers (Continued) Step Function and/or VI 10. Call halt on all axes to activate them. Use the Stop Motion VI with Stop Type (Decel) set to Halt stop. 11. Configure capture and compare settings. Use the VIs on the Motion I/O palette to configure the capture and compare settings. 12.
C Using the Motion Controller with the LabVIEW Real-Time Module Using NI-Motion on a real-time (RT) system is designed to be almost transparent for anyone familiar with NI-Motion. Using NI-Motion with RT requires the following hardware and software: • NI PXI chassis with an available PXI slot • NI PXI Motion controller • Host computer • LabVIEW Real-Time Module • One of the following motion software options: – NI-Motion (73xx controller support) – NI SoftMotion Controller 1.
Appendix C Using the Motion Controller with the LabVIEW Real-Time Module 6. If NI-Motion is not already installed, right-click within the dialog box and select Install Software. A dialog appears that lets you select what to download. Make sure the checkbox next to NI-Motion RT is selected. 7. Click OK and wait for the software to download. After the software downloads onto the remote system, complete the following steps to configure the remote NI motion controller. 1.
Appendix C Using the Motion Controller with the LabVIEW Real-Time Module To remove the mapped motion controller, browse to My System under Device and Interfaces. Right-click the mapped controller and select Unmap Remote Device. You should unmap devices when you no longer need to use them from the host machine.
Technical Support and Professional Services D Visit the following sections of the National Instruments Web site at ni.com for technical support and professional services: • Support—Online technical support resources at ni.
Glossary A A/D analog-to-digital absolute mode Treat the target position loaded as position relative to zero (0) while making a move. absolute position Position relative to zero. acceleration/ deceleration Measurement of the change in velocity as a function of time. Acceleration and deceleration describes the period when velocity is changing from one value to another. active high Signal is active when its value is high (1). active low Signal is active when its value is low (0).
Glossary binary Number system with a base of 2. buffer Temporary storage for acquired or generated data. bus Group of conductors that interconnect individual circuitry in a computer. Typically, a bus is the expansion vehicle to which I/O or other devices are connected. byte Eight related bits of data, an 8-bit binary number. Also used to denote the amount of memory required to store 1 byte of data. C CCW counter-clockwise—Implies the direction the motor rotates in.
Glossary E encoder Device that translates mechanical motion into electrical signals; used for monitoring position or velocity in a closed-loop system. encoder resolution Number of encoder lines between consecutive encoder marker or Z-bit indexes. If the encoder does not have an index output the encoder resolution can be referred to as lines per revolution. F F farad FIFO first-in, first-out filter parameters Indicates the control loop parameter gains (PID gains) for a given axis.
Glossary home switch (input) Physical position determined by the mechanical system or designer as the reference location for system initialization. Frequently, the home position is also regarded as the zero position in an absolute position frame of reference. host computer Computer in which the motion controller is installed, or that is controlling the remote system in which the motion controller is installed.
Glossary M m meters MCS Move Complete Status microstep Proportional control of energy in the coils of a Stepper Motor that allow the motor to move to or stop at locations other than the fixed magnetic/mechanical pole positions determined by the motor specifications.
Glossary P PCI peripheral component interconnect—a high-performance expansion bus architecture originally developed by Intel to replace ISA and EISA. PCI is achieving widespread acceptance as a standard for PCs and workstations; it offers a theoretical maximum transfer rate of 132 MB/s.
Glossary RPM revolutions per minute—Units for velocity. RPSPS or RPS/S revolutions per second squared—Units for acceleration and deceleration. RTR Ready to Receive S s seconds servo Specifies an axis that controls a servo motor. sinusoidal commutation Method of controlling current in the windings of a brushless servo motor by using the pattern of a sine wave to shape the smooth delivery of current to three motor inputs, each 120° out of phase from the next.
Glossary V V volts velocity mode Move the axis continuously at a specified velocity. W watchdog Timer task that shuts down, or resets, the motion control device if any serious error occurs. word Standard number of bits that a processor or memory manipulates at one time, typically 8-bit, 16-bit, or 32-bit. NI-Motion User Manual G-8 ni.
Index A C/C++ code, 15-4 LabVIEW code, 15-3 user-defined scan path, 15-13 algorithm, 15-15 C/C++ code, 15-17 LabVIEW code, 15-16 arc angles in degrees, 4-12 arc move circular, 6-1 algorithm, 6-3 C/C++ code, 6-4 LabVIEW code, 6-4 helical, 6-13 algorithm, 6-14 C/C++ code, 6-15 LabVIEW code, 6-15 spherical, 6-7 algorithm, 6-9 C/C++ code, 6-10 LabVIEW code, 6-10 arc moves, 6-1 architecture functional architecture of NI motion controllers, 1-4 NI SoftMotion Controller, 1-7 NI-Motion, 1-1, 1-7 automatically star
Index configuration tuning, 3-1 contoured move, 7-2 absolute versus relative, 7-4 algorithm, 7-3 C/C++ code, 7-6 data path, 7-1 LabVIEW code, 7-5 contoured moves, 7-1 control loop, 1-6, 3-2 acceleration feedforward, 3-6 derivative gain, 3-5 dual loop feedback, 3-7 algorithm, 3-8 Ga, 3-7 integral gain, 3-4 Kdac, 3-6 Kt, 3-7 proportional gain, 3-4 velocity feedback, 3-5, 3-9 algorithm, 3-10 velocity amplifiers, 3-10 velocity feedforward, 3-5 controlling torque, 13-1 conventions used in the manual, xiii count
Index C/C++ code, 10-5, 10-19 LabVIEW code, 10-5, 10-19 graphing data, 4-14 direct set, A-2 documentation, xiv conventions used in manual, xiii NI resources, D-1 related documentation, xiv drivers (NI resources), D-1 dual loop feedback, 3-7 algorithm, 3-8 H Hall effect sensors, A-1 troubleshooting, A-3 hardware functional architecture of NI motion controllers, 1-4 interaction with NI-Motion driver software, 1-2 helical arc move, 6-13 algorithm, 6-14 C/C++ code, 6-15 LabVIEW code, 6-15 help application no
Index L control loop, 3-2 acceleration feedforward, 3-6 derivative gain, 3-5 dual loop feedback, 3-7 algorithm, 3-8 Ga, 3-7 integral gain, 3-4 Kdac, 3-6 Kt, 3-7 proportional gain, 3-4 velocity feedback, 3-5, 3-9 algorithm, 3-10 velocity amplifiers, 3-10 velocity feedforward, 3-5 creating NI-Motion applications, 2-1 generic steps diagram, 2-2 I/O diagram, 2-3 documentation, xiv examples, xiv NI motion controller architecture control loop, 1-6 functional architecture, 1-4 functional architecture diagram, 1-
Index LabVIEW code, 5-19 velocity-based, 5-10 algorithm, 5-11 LabVIEW code, 5-13 straight-line moves, 4-1, 5-1 spherical, 6-7 algorithm, 6-9 C/C++ code, 6-10 LabVIEW code, 6-10 arc moves, 6-1 blending, 9-1 after delay, 9-4 after first move, 9-3 algorithm, 9-5 C/C++ code, 9-7 LabVIEW code, 9-6 superimposing, 9-2 camming, 10-1 contoured move absolute versus relative, 7-4 algorithm, 7-3 C/C++ code, 7-6 data path, 7-1 LabVIEW code, 7-5 contoured moves, 7-1 gearing, 10-1 algorithm, 10-2 C/C++ code, 10-5, 10-19
Index using onboard memory and data, 14-14 algorithm, 14-15 C/C++ code, 14-17 LabVIEW code, 14-16 writing, 14-3 output.
Index shake and wake, A-1 single-stepping onboard programs, 14-9 sinusoidal commutation, A-1 commutation frequency, A-2 determining counts per electrical cycle, A-2 phase initialization direct set, A-2 Hall effect sensors, A-1 shake and wake, A-1 troubleshooting Hall effect sensors, A-3 slave axis, 10-1, 10-4 software interaction with NI motion control hardware, 1-2 NI resources, D-1 software trigger using RTSI, 12-39 software/hardware interaction, 1-2 speed control, 13-14 algorithm, 13-14 C/C++ code, 13-1
Index LabVIEW code, 12-34 single algorithm, 12-33 C/C++ code, 12-35 LabVIEW code, 12-34 RTSI encoder pulses, 12-39 hardware implementation, 12-38 high-speed capture input, 12-40 software trigger, 12-39 using breakpoints with, 12-39 synchronizing host applications with onboard programs, 14-26 algorithm, 14-27 C/C++ code, 14-30 data flow, 14-27 LabVIEW code, 14-28 LabVIEW code, 5-13 straight-line moves, 4-1, 5-1 subroutines, onboard algorithm, 14-34 C/C++ code, 14-38 LabVIEW code, 14-35 supervisory control,
Index trajectory parameters acceleration in counts/s2, 4-8 acceleration in RPS/s, 4-9 arc angles in degrees, 4-12 velocity in steps/counts per second, 4-7 velocity override in percent, 4-11 travel angle, 6-2 troubleshooting (NI resources), D-1 tuning the motors, 3-1 U using data acquisition with NI-Motion, 2-3 image acquisition with NI-Motion, 2-3 using onboard memory and data, 14-14 algorithm, 14-15 C/C++ code, 14-17 LabVIEW code, 14-16 V variables, indirect, 14-24 velocity feedback, 3-5, 3-9 algorithm,