Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2013 SPiiPlus Training Class Mathematical and Signal Processing Functions 1.

Similar presentations


Presentation on theme: "© 2013 SPiiPlus Training Class Mathematical and Signal Processing Functions 1."— Presentation transcript:

1 © 2013 SPiiPlus Training Class Mathematical and Signal Processing Functions 1

2 © 2013 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: o I/O debouncing o Digital controllers and filters o Teach-and-go o Array processing o Error mapping o Kinematic transformations (forward and inverse) 2

3 © 2013 Assignment Command Assignment Command: o Assigning a value to a variable using an expression o ‘=‘ is used to separate the variable from the expression o 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 3

4 © 2013 Assignment Command Examples: GLOBAL INT tiVar GLOBAL REAL trVar GLOBAL INT tiArr(5) GLOBAL REAL trArr(7) GLOBAL INT tiArr2(10)(3) GLOBAL REAL trArr2(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 4 NameValue tiVar1 trVar2.0 tiArr(0)3 trArr(3)1.5 tiArr2(9)(0)4 trArr2(0)(3)2.6

5 © 2013 Unary Operators Unary operators are functions that act on one operand o - (unary minus)  Can be used with INT or REAL variables o ~ (inversion)  Can only be used with INT variables  REAL variables are converted to INT o ^ (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 5

6 © 2013 Unary Operators Examples: GLOBAL INT tiVar GLOBAL REAL trVar GLOBAL INT tiArr(3) GLOBAL REAL trArr(3) tiVar = 1 tiArr(0) = -tiVar tiArr(1) = ~tiVar tiArr(2) = ^tiVar trVar = 2.5 trArr(0) = -trVar trArr(1) = ~trVar trArr(2) = ^trVar 6 NameDecimalHex (rounded) tiArr(0)0xFFFFFFFF tiArr(1)-20xFFFFFFFE tiArr(2)00x00000000 NameDecimalHex (rounded) trArr(0)-2.50xFFFFFFFE trArr(1)-20xFFFFFFFD trArr(2)00x00000000

7 © 2013 Binary Operators Binary operators are functions that act on two operands 7  + (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)

8 © 2013 Binary Operators Examples: GLOBAL INT tiArr(5) GLOBAL REAL trArr(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 8 NameDecimalHex (rounded) tiArr(0)100x0000000A tiArr(1)2280x000000E4 tiArr(2)00x00000000 tiArr(3)2380x000000EE tiArr(4)2380x000000EE NameDecimalHex (rounded) trArr(0)200x00000014 trArr(1)500x00000032 trArr(2)00x00000000 trArr(3)50x00000005

9 © 2013 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. 9 OperatorOperation ()Brackets the expression.Bit selection - ~ ^Unary minus, Inversion, Logical not * /Multiplication, Division + -Addition, Subtraction = <> =Comparison & | ~Logical and bitwise AND, OR, XOR

10 © 2013 Order of Operations Examples: GLOBAL REAL 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 10 NameDecimal trArr(0)7 trArr(1)5 trArr(2)9 trArr(3)4.28571 trArr(4)5.83333 trArr(5)

11 © 2013 General Mathematical Functions ACSPL+ supports a set of standard mathematical functions. 11

12 © 2013 Trigonometric Functions ACSPL+ supports the standard list of trigonometric functions. All trigonometric function use radians (not degrees). 12  sin( angle )  cos( angle )  tan( angle )  asin( x )  acos( y )  atan( x / y )  atan2( x, y )

13 © 2013 Exponential and Logarithmic Functions ACSPL+ supports the standard exponential and logarithmic functions. 13

14 © 2013 Array Processing Functions ACSPL+ support some basic array processing functions 14  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

15 © 2013 Signal Processing Functions ACSPL+ supports some standard signal processing functions. 15  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

16 © 2013 Mapping / Interpolation Functions ACSPL+ supports some standard 1D mapping and interpolation functions. 16  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

17 © 2013 Mapping / Interpolation Functions ACSPL+ supports some standard 2D mapping and interpolation functions. 17  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

18 © 2013 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. 1.Load program “Programming 08 – DIODebouncing.prg” to the controller. o Should populate buffer 11 2.Open communication terminal and set it up to show DISP messages 3.Plot the variables di_signal and di_debounced on the scope o Set the time for 0.1 sec/div and the trigger on Auto 4.From the communication terminal start buffer 11 at line 1 (“ START 11, 1”). Follow the instructions on the screen 18

19 © 2013 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. 1.Load program “Programming 08 – AnalogFiltering.prg” to the controller. o Should populate buffer 12 2.Open communication terminal and set it up to show DISP messages 3.Plot the variables ai_in and ai_filt on the scope o Set the time for 0.1 sec/div and the trigger on Auto 4.From the communication terminal start buffer 12 at line 1 (“ START 12, 1”). Follow the instructions on the screen 19

20 © 2013 ACSPL+ Programming Example: 3 20

21 © 2013 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. 1.Open buffer 14 2.Write a program to give the desired results. You can create user-defined variables for the drive output command and the torque sensor input. 21


Download ppt "© 2013 SPiiPlus Training Class Mathematical and Signal Processing Functions 1."

Similar presentations


Ads by Google