P
ar
t
1: P
rog
ra
m
ming
Moog Animatics SmartMotor™ Developer's Guide, Rev. L
Page 199 of 909
The same array space can be accessed with any combination of variable types and can be
viewed simply as the union of the data type arrays. Keep in mind how much space each
variable takes. Also, note that one type of variable can be written and another read from the
same space. For example, if the first four eight bit integers are assigned as follows:
ab[0]=0
ab[1]=0
ab[2]=1
ab[3]=0
They would occupy the same memory space as the first single 32-bit number or the first pair
of 16-bit numbers. The order is from least significant to most significant with ab[3] being the
most significant. Because of the way binary numbers work, this would make the 32-bit
variable al[0] equal to 65,536, as well as the 16-bit variables aw[0] equal to 0 and aw[1]
equal to 1.
A common use of the array variable type is to set up a buffer. In many applications, the
SmartMotor is tasked with inputting data about an array of objects and to do processing on
that data in the same order but not necessarily at the same time. Therefore, it may be
necessary to "buffer" or "store" that data until it is time for the SmartMotor to process it.
To set up a buffer, the programmer allocates a block of memory to it, assigns one variable to
an input pointer and another variable to an output pointer. Both pointers start out as zero and
increment as follows:
l
Every time data goes into the buffer, the input pointer increments.
l
Every time data is used, the output buffer likewise increments.
l
Every time a pointer increments, it is checked for exceeding the allocated memory
space and rolled back to zero in that event. It then continues to increment as data
comes in.
This is a first-in, first-out or FIFO circular buffer. There should be enough memory allocated
so that the input pointer never overruns the output pointer.
NOTE:
Every SmartMotor has a small solid-state disk drive for long term storage
of data, which is based on EEPROM technology. It can be written to and read from
more than one million times.
Array Variable Examples
The following are examples of different uses for array variables:
b=af[0]
'if af[0]=1.8, b=1; if af[0]=-1.8, b=-1
af[0]=SIN(57.3)
'Set float var af[0]to sine 57.3 degrees
af[7]=ATAN(af[6])*180/PI
'Set af[7] to arctan result converted to radians
af[4]=af[3]*(af[1]/af[2]-1)
'Standard hierarchical rules apply
af[0]=(a+b)/2+3.0
'if a=8 and b=1, af[0]=7.0
af[0]=(a+b)/2.0+3.0
'if a=8 and b=1, af[0]=7.5
af[5]=FSQRT(a)
'if a=63, af[5]=7.937253952
Part 1: Programming: Array Variable Examples