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.

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

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

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.

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.

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.