Utility and Conversion Functions
AeroScript supplies functions for data handling and utility operations. This page includes information on how to convert between different data types, change units, use system timers, and generate random numbers.
Data Type Conversion
IMPORTANT: For more information about AeroScript data types, refer to Data Types and Variables.
Integer and Real Data Types
The AeroScript programming language automatically converts between real data types (IEEE 64-bit floating point) and integer data types (64-bit signed integer). If a function or a variable assignment expects a real data type and you provide an integer, one of the scenarios that follow occurs:
- If the integer data type can be represented as a real (no loss of precision), the conversion occurs automatically.
- If the integer data type cannot be represented as a real (because of having more than 53 bits of precision), the conversion causes a task error
If a function or a variable assignment expects an integer and you provide a real data type, one of the scenarios that follow occurs:
- If the real data type can be represented as an integer (no fractional component), the conversion occurs automatically.
- If the real data type cannot be represented as an integer (because of a fractional component), the conversion causes a task error.
If you want to do rounding or determine the integer and fractional components of a real data type, use one of the functions in the Math Functions topic.
The RealIsNan() function tells you if a real value is a not-a-number (NaN) value, and the RealIsInfinity() function tells you if a real value represents infinity.
The BitConvert*() functions convert an IEEE floating-point value to a bit value represented as an integer, or they convert a bit value represented as an integer to an IEEE floating-point value.
Returns whether the specified value is NaN.
Arguments
$value A 64-bit floating-point value.
Returns
Returns 1 if the real is NaN, 0 otherwise.
Returns whether the specified value is infinite.
Arguments
$value A 64-bit floating-point value.
Returns
Returns 1 if the real is +infinity or -infinity, 0 otherwise.
Stores the bit pattern of a 32-bit floating-point value into an unsigned 32-bit integer.
Arguments
$value The value from which to get the bit pattern.
Returns
The bit pattern that represents the 32-bit floating-point value.
Stores the bit pattern of a 64-bit floating-point value into a signed 64-bit integer.
Arguments
$value The value from which to get the bit pattern.
Returns
The bit pattern that represents the 64-bit floating-point value.
Converts a 32-bit integer bit pattern to its 32-bit floating-point representation.
Arguments
$value The bit pattern.
Returns
The 32-bit floating-point value that represents the specified bit pattern value.
Converts a 64-bit integer bit pattern to its 64-bit floating-point representation.
Arguments
$value The bit pattern.
Returns
The 64-bit floating-point value that represents the specified bit pattern value.
Axis Data Type
You can convert the axis data type to an axis index with the AxisToInteger() function. The returned value is an integer, but you can also assign it to a real variable.
To convert an axis index stored as an integer or real into an axis data type, use the special @ AeroScript language keyword. For example:
var $myAxis as axis = @0
Gets the index of the specified axis as an integer.
Arguments
$value The axis from which to get the index.
Returns
The index of the specified axis.
String Data Type
You can convert between a string data type and an axis, integer, or real data type with the functions in the String Functions topic. See the relevant string functions at the end of this section.
To convert an axis name stored as a string into an axis data type, use the special @ AeroScript language keyword. For example:
var $myStr as string = "X"
var $axis as axis = @$myStr
Returns the string representation of the specified axis value.
Arguments
$value The axis value to convert to a string.
Returns
The string representation of the specified axis.
Returns the string representation of the specified integer value.
Arguments
$value The integer value to convert to a string.
Returns
The string representation of the specified integer.
Returns the string representation of the specified real value.
Arguments
$value The real value to convert to a string.
Returns
The string representation of the specified real.
Returns the integer value of the specified string.
Arguments
$string The string from which to get the integer value.
Returns
The integer value of the specified string.
Returns the real value of the specified string.
Arguments
$string The string from which to get the real value.
Returns
The real value of the specified string.
Units Conversion
Controller positional units are usually specified in millimeters (mm), micrometers (µm), or degrees (deg), but you can configure them for any type of unit. Machine Setup configures each axis in your system to the units you specify. Because the controller internally stores positions in encoder counts, you can use the functions that follow to convert between units and counts. A value in counts is useful for some advanced controller features such as PSO.
IMPORTANT: If the ReverseMotionDirection Parameter is set to Enabled, the CountsToUnits() and UnitsToCounts() functions invert the sign of the returned value.
Returns the value in user units of a specified value in counts.
Arguments
$axis The axis to use when performing the conversion.
$counts The value in counts.
Returns
The value converted to user units.
Returns the value in counts of a specified value in user units.
Arguments
$axis The axis to use when performing the conversion.
$units The value in user units.
Returns
The value converted to counts.
Timers
You can measure the execution time of a section of an AeroScript program by clearing and reading one of the 32 system timers. Automation1 has 32 timers, and you can select them by entering their zero-based index number (0-31) as the timer number.
Each timer runs independently and continuously from the last time you zero it or the last controller reset.
Timer values are always returned in milliseconds. If the timer mode is set to TimerMode.Standard, the TimerRead() function returns an integer number of milliseconds. If the timer mode is set to TimerMode.Precise, the TimerRead() returns a decimal number of milliseconds with a resolution of 0.0001 milliseconds.
Sets the value of the specified timer to zero.
Arguments
$timerNum The timer to clear.
Gets the value of the specified timer.
Arguments
$timerNum The timer to read.
$timerMode The mode to use when reading the timer.
Returns
The value of the specified timer.
Random Number Generation
You can generate pseudo-random numbers in an AeroScript program. This capability can be useful for testing or simulation purposes. Each task uses a different pseudo-random number generator.
To use the random number generator, you must first provide a seed with the RandomSeed() function. Then every subsequent call to RandomNextInteger() or RandomNextReal() will return the next pseudo-random value.
- For RandomNextInteger(), the returned value is one of 32,768 unique values in the range of 0 to 32767.
- For RandomNextReal(), the returned value is one of 32,768 unique values in the range of 0.0 to 1.0.
For any given seed, the pseudo-random number generator generates the same sequence of values. When you reset the controller, the controller reseeds the pseudo-random number generator with a seed of 1.
Seed the pseudo-random number generator.
Arguments
$seed The number used to initialize the pseudo-random number generator.
Generate a pseudo-random integer.
Returns
A pseudo-random integer in the range [0, 32767].
Generate a pseudo-random real.
Returns
A pseudo-random real, uniformly-distributed in the range [0.0, 1.0] among 32,768 unique values.



