230 likes | 469 Views
SPiiPlus Training Class. Variable Management. What are ACSPL+ Variables?. Variables in ACSPL+ have the following attributes: Class (standard or user variable ) Name Scope (global or local) Lifetime Accessibility (read-write, read-only, protected) Type (integer or real) Size Value.
E N D
SPiiPlus Training Class Variable Management
What are ACSPL+ Variables? Variables in ACSPL+ have the following attributes: • Class (standard or user variable) • Name • Scope (global or local) • Lifetime • Accessibility (read-write, read-only, protected) • Type (integer or real) • Size • Value
Class ACSPL+ variables can be either standard or user defined • Standard variables can be used without declaration • Examples: FPOS (feedback position), MFLAGS (motor flags), AST (axis state) • User variables require declaration • Can be declared in any program buffer (including d-buffer)
Scope Global variables • Variables with global scope can be used in any program buffer and also in the Communication Terminal • All standard variables are global • Declaration of user global variable starts with the keyword “global” – not case sensitive • The above example declaration may be in several buffers, but each is considered to be the same variable
Scope Global variables • Global variables declared in d-buffer do not need re-declaration elsewhere
Scope Local variables • Local variables can be used only in the buffer they are declared • Declaration of local variables starts with the keyword “local”, or no keyword
Lifetime • Standard variables are always valid • User variables are valid as long as they reside in a buffer that has been successfully compiled since the variable’s declaration • If a variable declaration has been removed from a buffer which then gets re-compiled, the variable is no longer valid • Note: recompiling a buffer will clear whatever value a user variable declared in that buffer may have had • ACSPL+ READ and WRITE commands allow storage of user variables in controller flash memory (128MB capacity) • This allows storage and retrieval of data between power downs
Accessibility All user variables have read-write access and are not protected. Standard variables can be read-write or read-only • Read-write: All user variables and some standard variables • Examples; VEL, MFLAGS • Read-only: Standard variables with values that cannot be assigned • Examples; MST(motor state), FAULT • Note: protection can be applied to standard variables (not user) to prevent modification
Type Variables can be integer or real • Standard variables have pre-defined type (cannot be assigned) • User variable types need to be assigned • User variables can be converted from integer <–> real • Integer types are declared using INT keyword • Real types are declared using REAL keyword • Integer is signed 32 bit • Real is 64 bit, and corresponds to the standard double format of PC
Size Variables can be scalar (one element), one-dimensional, or two-dimensional arrays • Standard variables have pre-defined size (cannot be assigned). Example S_ERR is a scalar, and FAULT is an array of up to 64 elements (one for each axis)
Declaration How to declare user variables: • Several variables of the same type can be declared on the same line, separated by commas • Typically declared at top of program buffer, but not necessary • Global variables declared in the d-buffer do not require re-declaration in any other buffer • Global variables not declared in the d-buffer do require re-declaration in any other buffer they are used (but not re-definition) • Variable names must be alpha-numeric, and begin with a letter
Declaration Examples GLOBALREAL var1 ! Global real type scalar GLOBALINTaxisNumber! Global integer type scalar REAL arr1D(7) ! Local real type 1D array INT arr2D(3)(5) ! Local integer type 2D array LOCALREAL motor1, motor2, arrEx(4)(2)
Assignment Command The assignment command (=) is used to assign a value to ACSPL+ variables with read/write access. • User variables need to be declared first before assignment is allowed • Assignment to array variables (1-d, or 2-d) requires index reference • Integer variables allow bit assignments, and are usually used to monitor variable flags, and change digital output states • Assigning to a variable has the following limitations: • Assignment to read-only variable (for example, FPOS(0)) is prohibited without SETcommand. Example SETFPOS(0) = 1000sets the feedback position of axis 0 to 1000.
Assignment Command Assigning to arrays is done in base-zero. Example – how to populate an entire 4-element array:
Query Variables from the Terminal To read the value of a variable, use the “?” operator from the Terminal • For example, enter the following in the Terminal to query the value of axis 5 feedback position: ?FPOS(5) • To perform a calculation while querying, enclose it in parentheses, for example: ?(3.1*FPOS(5)+9) • To set variable precision, use % operator, for example;?{%3.3f}FPOS0
Bit Addressing Often it is required to read the state of an input, write the state of an output, read specific faults, etc. This is done via bit addressing • Variables can contain bits which have specific meaning. For example MST(3).#ENABLEDencodes whether or not axis 3 is enabled. • Bits can be referenced by number, or by bit name. For example MST(3).0 is equivalent to MST(3).#ENABLED • Digital I/O is accessed using bits of IN and OUT standard variables: • OUT(0).0 … OUT(0).7 • IN(0).0 … IN(0).7 • Implicit bit addressing supported • GLOBALINTuserVariable1; userVariable1 = 1 • MFLAGS(0).(userVariable1)
Bit Addressing How to use bit addressing to read/write digital input and output • Digital I/O is accessed using indices and bits of IN and OUT standard variables • IN and OUT are arrays whose index refers to EtherCAT node the digital I/O physically reside on. • For example OUT(3)are digital outputs on node 3 • Each member of the array has 32 bits, often not all are used • For example, node 1 has 8 digital inputs, they would be accessed like this: IN(0).0 … IN(0).7 • To set the second digital output of node 7 do OUT(7).1 = 1, and to clear do OUT(7).1 = 0 • Specific bits can be queried from the Terminal, for example ?IN(3).7will return the state of digital input 7 at node 3
Bit Addressing A useful way of reading and writing digital I/O is using binary or hexadecimal • In the Terminal, type ?B/IN(4) to see the state of digital inputs at node 4 in binary • The output will look something like this: 00000000,00000000,00000000,00010111indicating inputs 0, 1, 2, and 4 are active • To view in hex, do ?X/IN(4) • Can also be used for setting digital outputs. Enter any of the following to activate the first 8 outputs at node 5: • OUT(5) = 0b11111111 • OUT(5) = 0xFF • OUT(5) = 255
SP Variables Aside from ACSPL+ variables, lower-level servo processor variables exist in the controller called SP variables • SP variables are used to monitor low-level parameters such as commanded current, encoder counts, and others • Many are read/write and can be accessed using special ACSPL+ commands GETSP,SETSP • The variables look like “axes[0].command” (commanded current) • SP variables are easily accessed using: • Communication Terminal • Variables Manager and Watch • Scope
ACSPL+ Programming Example 1 Gantry-based vision system application requirements: • Axis names: x1, y1 • 3rd order motion parameters for both axes: • Velocity = 300mm/s • Acceleration = 3000mm/s^2 • Deceleration = 3000mm/s^2 • Jerk = 30000mm/s^3 Method • Declare and define global variables to represent axes • Define standard variables for axes motion parameters • Compile, run, and verify the values of the variables by querying from Communication Terminal (remember to use ? when querying)
ACSPL+ Programming Example 2 A new application specification states there will be a camera located somewhere in the stage’s range of travel and needs to be avoided. The camera can be treated as a rectangular region to avoid. • Rectangle min, max in x = -350, -250 • Rectangle min, max in y = 300, 400 Method • Create new variables representing this rectangle
ACSPL+ Programming Example 3 The application specification states that while the stage undergoes motion, computations need to be made based on motion data from the stage. Method • In one buffer, create local variables representing two (x,y) points for the stage to move back and forth between. • In another buffer create local array variables for data to be stored in. • Compile and run buffers • What do the array variables initialize to?