220 likes | 446 Views
SPiiPlus Training Class. Mathematical and Signal Processing Functions. Mathematical and Signal Processing Functions.
E N D
SPiiPlus Training Class Mathematical and Signal Processing Functions
Mathematical and Signal Processing Functions ACSPL+ includes a large command set of built-in mathematical and signal processing functions. These functions allow for powerful algorithms to be written in minimal lines of code, including: • I/O debouncing • Digital controllers and filters • Teach-and-go • Array processing • Error mapping • Kinematic transformations (forward and inverse)
Assignment Command Assignment Command: • Assigning a value to a variable using an expression • ‘=‘ is used to separate the variable from the expression • An assignment command can only assign a value to a scalar variable, a single element of an array, or a specific bit of a scalar variable or single element of an array. Syntax: variable = expression variable.(bit) = expression 1d_array(index) = expression 2d_array(index1)(index2) = expression
Assignment Command Examples: GLOBAL INTtiVar GLOBALREAL trVar GLOBALINTtiArr(5) GLOBALREALtrArr(7) GLOBALINTtiArr2(10)(3) GLOBALREALtrArr2(12)(7) tiVar = 1 trVar = 1 * 2 tiArr(0) = tiVar + trVar trArr(3) = tiArr(0) / 2 tiArr2(9)(0) = tiArr(0) + trArr(3) trArr2(0)(3) = 1 + tiArr2(9)(0) * 0.4
Unary Operators Unary operators are functions that act on one operand • - (unary minus) • Can be used with INT or REAL variables • ~ (inversion) • Can only be used with INT variables • REAL variables are converted to INT • ^ (logical not) • Can only be used with Boolean (0,1) INT variables • REAL variables and non-Boolean INT variables are converted to Boolean INT variables
Unary Operators Examples: GLOBAL INT tiVar GLOBALREALtrVar GLOBALINT tiArr(3) GLOBALREALtrArr(3) tiVar = 1 tiArr(0) = -tiVar tiArr(1) = ~tiVar tiArr(2) = ^tiVar trVar = 2.5 trArr(0) = -trVar trArr(1) = ~trVar trArr(2) = ^trVar
Binary Operators Binary operators are functions that act on two operands • + (addition) • - (subtraction) • * (multiplication) • / (division) • & (and) • | (or) • ~ (xor) • = (equal to) • <> (not equal) • > (greater than) • >= (greater than or equal to) • < (less than) • <= (less than or equal to)
Binary Operators Examples: GLOBAL INT tiArr(5) GLOBALREALtrArr(5) tiArr(0) = 0b00001010 tiArr(1) = 0b11100100 tiArr(2) = tiArr(0) & tiArr(1) tiArr(3) = tiArr(0) | tiArr(1) tiArr(4) = tiArr(0) ~ tiArr(1) trArr(3) = 5 trArr(0) = trArr(3) * 4 trArr(1) = trArr(3) / 0.1 IF ( trArr(0) > trArr(1) ) trArr(2) = 1 ELSE trArr(2) = 0 END
Order of Operations ACSPL+ uses a standard order of operations. The following table shows the operator precedence from highest to lowest. Operators with the same precedence are evaluated from left to right.
Order of Operations Examples: GLOBALREAL trArr(6) trArr(0) = 1 + 2 * 3 trArr(1) = 1 * 2 + 3 trArr(2) = (1 + 2) * 3 trArr(3) = 5 * 6 / 7 trArr(4) = 5 / 6 * 7 IF( trArr(4) > trArr(3) * 1 + 2 - 5 ) trArr(5) = -1 ELSE trArr(5) = 1 END
General Mathematical Functions ACSPL+ supports a set of standard mathematical functions. • abs( in ) = Absolute value • ceil( in ) = Ceiling of a value • floor( in ) = Floor of a value • hypot( x, y ) = • pow( x, y ) = • sqrt( in ) = • sign( in ) = Sign of a value • roll( in, const) = Modulus of a value
Trigonometric Functions ACSPL+ supports the standard list of trigonometric functions. All trigonometric function use radians (not degrees). • sin( angle ) • cos( angle ) • tan( angle ) • asin( x ) • acos( y ) • atan( x / y ) • atan2( x, y )
Exponential and Logarithmic Functions ACSPL+ supports the standard exponential and logarithmic functions. • exp( in ) = • ldexp( x, y ) = • log( in ) = Natural logarithm • log10( in ) = Base 10 logarithm
Array Processing Functions ACSPL+ support some basic array processing functions • avg( ) = average of array elements • copy( ) Copies elements from one array to another • fill( ) Fills in an array with a constant value • max( ) = maximum entry in an array • maxi( ) = index of maximum entry in an array • min( ) = minimum entry in an array • mini( ) = index of minimum entry in an array
Signal Processing Functions ACSPL+ supports some standard signal processing functions. • deadzone( ) = signal with deadzone • dsign( ) = sign of signal with delay and ramp time • edge( ) = edge detection of signal • intgr( ) = integration of signal • lag( ) = state of signal (high or low) with positive and negative edge delays • sat( ) = signal with saturation range
Mapping / Interpolation Functions ACSPL+ supports some standard 1D mapping and interpolation functions. • map( ) 1D linear interpolation with uniformly spaced points • mapb( ) 1D B-spline interpolation with uniformly spaced points • maps( ) 1D Catmull-Rom spline interpolation with uniformly spaced points • mapn( ) 1D linear interpolation with non-uniformly spaced points • mapnb( ) 1D B-spline interpolation with non-uniformly spaced points • mapns( ) 1D Catmull-Rom spline interpolation with non-uniformly spaced points
Mapping / Interpolation Functions ACSPL+ supports some standard 2D mapping and interpolation functions. • map2( ) 2D linear interpolation with uniformly spaced points • map2b( ) 2D B-spline interpolation with uniformly spaced points • map2s( ) 2D Catmull-Rom spline interpolation with uniformly spaced points • map2n( ) 2D linear interpolation with non-uniformly spaced points • map2nb( ) 2D B-spline interpolation with non-uniformly spaced points • map2ns( ) 2D Catmull-Rom spline interpolation with non-uniformly spaced points
ACSPL+ Programming Example: 1 Digital Input Debouncing: A digital input from a mechanical pushbutton is used to tell a rotary stage to advance 2 rotations. In order to remove false triggers when the pushbutton is pressed and released, a debouncing mechanism is required. • Load program “Programming 08 – DIODebouncing.prg” to the controller. • Should populate buffer 11 • Open communication terminal and set it up to show DISP messages • Plot the variables di_signal and di_debounced on the scope • Set the time for 0.1 sec/div and the trigger on Auto • From the communication terminal start buffer 11 at line 1 (“START11, 1”). Follow the instructions on the screen
ACSPL+ Programming Example: 2 Analog Input Filtering: An analog input is being used as accelerometer feedback for increasing the performance of a stage. The accelerometer feedback should be low frequency (< 5 Hz), so it is desired to put a single-pole low pass filter at 50 Hz. • Load program “Programming 08 – AnalogFiltering.prg” to the controller. • Should populate buffer 12 • Open communication terminal and set it up to show DISPmessages • Plot the variables ai_in and ai_filt on the scope • Set the time for 0.1 sec/div and the trigger on Auto • From the communication terminal start buffer 12 at line 1 (“START12, 1”). Follow the instructions on the screen
ACSPL+ Programming Example: 3 X-Y Plane Rotation: • Load program “Programming 08 – XYRotation.prg” to the controller. • Should populate buffer 13 • Modify the program in order to allow the user to specify a rotation in degrees. • Test the program by rotating the plane 45 degrees, and 90 degrees, and running test X and Y axis moves. Hint: A 2-D rotation can be described by the following rotation matrix:
ACSPL+ Programming Example: 4 Simple Digital Controller: An application requires an EtherCAT drive to be run in torque mode in order to give a constant desired torque on a load. A simple PI controller is used with a torque sensor in order to give a steady effective torque. • Open buffer 14 • Write a program to give the desired results. You can create user-defined variables for the drive output command and the torque sensor input.