![Galil Motion Control RIO-47 series
RIO-47100 Скачать руководство пользователя страница 68](http://html1.mh-extra.com/html/galil-motion-control/rio-47-series-rio-47100/rio-47-series-rio-47100_user-manual_558776068.webp)
Mathematical and Functional Expressions
Mathematical Operators
For manipulation of data, the RIO provides the use of the following mathematical operators:
Operator
Function
+
Addition
-
Subtraction
*
Multiplication
/
Division
&
Logical And (Bit-wise)
|
Logical Or (On some computers, a solid vertical line appears as a broken line)
( )
Parenthesis
%
Modulus
Mathematical operations are executed from left to right. Calculations within parentheses have
precedence.
Examples:
SPEED=7.5*V1/2
The variable, SPEED, is equal to 7.5 multiplied by V1 and divided
by 2
COUNT=COUNT+2
The variable, COUNT, is equal to the current value plus 2.
RESULT=Val1 -(@COS[45]*40)
Puts the value of Val1 - 28.28 in RESULT. 40 * cosine of 45 is
28.28
K=@IN[1]&@IN[2]
K is equal to 1 only if Input 1 and Input 2 are high
Note:
Mathematical operations can be done in hexadecimal as well as decimal. Just precede
hexadecimal numbers with a $ sign so that the RIO recognizes them as such.
Mathematical Operation Precision and Range
The controller stores non-integers in a fixed point representation (not floating point). Numbers are
stored as 4 bytes of integer and 2 bytes of fraction within the range of +/- 2,147,483,647.9999. The
smallest number representable (and thus the precision) is 1/65536 or approximately 0.000015.
Example:
Using basic mathematics it is known that 1.4*(80,000) = 112,000. However, using a basic
terminal, a DMC controller would calculate the following:
:var= 1.4*80000;'
Storing the result of 1.4*80000 in var
:MG var;'
Prints variable "var" to screen
111999.5117
:
The reason for this error relies in the precision of the controller. 1.4 must be stored to the
nearest multiple of 1/65536, which is 91750/65536 = 1.3999. Thus, (91750/65536)*80000 =
111999.5117 and reveals the source of the error.
By ignoring decimals and multiplying by integers first (since they carry no error), and then adding
the decimal back in by dividing by a factor of 10 will allow the user to avoid any errors caused by
the limitations of precision of the controller. Continuing from the example above:
:var= 14*80000;'
Ignore decimals
Chapter 5 Programming ▫ 68 RIO-47xxx Rev. 1.0r