G-Code Programming

The AeroScript programming language has Aerotech G-code dialect, which is based on the RS-274 G-code standard. You can use the Aerotech G-code dialect to configure and do different types of motion on the controller. You can do most of the same actions that you can do with the Aerotech G-code dialect by calling AeroScript functions. But to do some actions you cannot use AeroScript and must use the Aerotech G-code dialect. You can also create custom G-codes and M-codes to use in your program.

The AeroScript example program that follows uses the Aerotech G-code dialect with a controller that has axes that are named X and Y.

G90  // Configure the specified target positions as absolute
// Configure time units as seconds.
G76

// Configure the task to operate in rapid point-to-point motion mode.
G00

// Move axes X and Y to the absolute position (5, 10)
// with each axis moving at a rate of 100 units/second.
X5 Y10 XF100 YF100 G01 // Configure the task to operate in coordinated linear motion mode F50 // Configure the feedrate of coordinated motion to be 50 units/second // Move the X and Y axes such that their path creates a square N10 X5 Y20 N20 X-5 Y20 N30 X-5 Y10 N40 X5 Y10

G-code Program Lines

A G-code program line in AeroScript can have these elements:

  • An optional N-code. For more information, refer to the N-codes section of this topic.
  • Zero or more G-codes or any other G-code concepts that you can specify to G-codes. For more information, refer to the G-codes section of this topic.
  • An optional M-code. For more information, refer to the M-codes section of this topic.
  • An optional AeroScript comment at the end of the line.

G-code Concepts

Most concepts in the Aerotech G-code dialect are not case sensitive, so upper-case letters and lower-case letters have the same meaning. For example, G1 and g1 have the same meaning when you specify them on a G-code program line. The only concept in the Aerotech G-code dialect that is case-sensitive is the name of an axis that is used by the controller. For example, if you have a controller with an axis named X and an axis named x, then the program lines that follow do motion on different axes.

G1 X10
G1 x10

Leading zeros are permitted in most Aerotech G-code dialect concepts if you specify an integer literal value. For example, G1 and G01 have the same meaning when you specify them on a G-code program line.

Most concepts in the Aerotech G-code are whitespace insensitive and you can have zero, one, or more spaces or tabs between G-code letters and numerical values. For example, the program lines that follow have the same meaning.

G1X10F20
G1 X10 F20
G 1 X 10 F 20

N-codes

N-codes are used as line numbers for G-code program lines. N-codes are optional on G-code program lines. If you specify an N-code on a program line, you must specify it before all other elements on the program line.

N1 G91 G1 X25

All N-code values in a program must be unique. N-codes operate similarly to AeroScript labels. Thus, you can specify N-codes to an AeroScript goto() statement.

goto N03
N01 X10 Y15
N02 X11 Y13
N03 X12 Y12.5

G-codes

G-codes contain the letter G followed by a literal integer, such as G0 or G2. The table that follows lists all of the G-codes that are supported in the Aerotech G-code dialect.

Table: Supported G-codes

G-code Description
G0 Executes a rapid point-to-point positioning move on the specified axes.
G1 Executes a coordinated linear move on the specified axes.
G2 Executes a circular arc move in the clockwise direction on the specified axes in the first coordinate plane.
G3 Executes a circular arc move in the counterclockwise direction on the specified axes in the first coordinate plane.
G4 Suspends the execution of the task for the duration that you specify, in seconds.
G8 Causes the G-code motion that you specify on the same program line to immediately accelerate to the programmed feedrate.
G9 Causes the G-code motion command that you specify on the same program line to decelerate to zero velocity when the axes get to their target position.
G12 Executes a circular arc move in the clockwise direction on the specified axes in the second coordinate plane.
G13 Executes a circular arc move in the counterclockwise direction on the specified axes in the second coordinate plane.
G16 Configures the set of axes that are used for the first coordinate plane for G2 and G3 commands.
G17 Configures the task to use the first set of axes of the first coordinate system for G2 and G3 commands.
G18 Configures the task to use the second set of axes of the first coordinate system for G2 and G3 commands.
G19 Configures the task to use the third set of axes of the first coordinate system for G2 and G3 commands.
G26 Configures the set of axes that are used for the second coordinate plane for G12 and G13 commands.
G27 Configures the task to use the first set of axes of the second coordinate system for G12 and G13 commands.
G28 Configures the task to use the second set of axes of the second coordinate system for G12 and G13 commands.
G29 Configures the task to use the third set of axes of the second coordinate system for G12 and G13 commands.
G40 Deactivates cutter radius compensation mode on the task.
G41 Activates cutter radius compensation left mode on the task.
G42 Activates cutter radius compensation right mode on the task.
G43 Specifies the radius that the task uses in cutter radius compensation mode.
G44 Specifies the axes that comprise the X-Y or X-Y-Z plane when a cutter compensation mode is active on the task.
G53 Disables work offsets.
G54 Enables work offset 1.
G55 Enables work offset 2.
G56 Enables work offset 3.
G57 Enables work offset 4.
G58 Enables work offset 5.
G59 Enables work offset 6.
G60 Configures the task to use the acceleration duration that you specify for coordinated motion while operating in time-based ramping mode.
G61 Configures the task to use the deceleration duration that you specify for coordinated motion while operating in time-base ramping mode.
G63 Configures the task to operate with the sinusoidal acceleration and deceleration ramping type for coordinated motion.
G64 Configures the task to operate with the linear acceleration and deceleration ramping type for coordinated motion.
G65 Configures the task to use the acceleration rate that you specify for coordinated motion while operating in rate-based ramping mode.
G66 Configures the rate that the task uses to perform coordinated motion to decelerate dominant axes.
G67 Configures the task to use time-based ramping to accelerate and decelerate axes during coordinated motion.
G68 Configures the task to use rate-based ramping to accelerate and decelerate axes during coordinated motion.
G69 Configures the task to operate with the S-curve acceleration and deceleration ramping type for coordinated motion.
G70 Configures the task to treat distances and feedrates that you specify in G-code commands as being English units.
G71 Configures the task to treat distances and feedrates that you specify in G-code commands as being metric units.
G75 Configures the task to treat feedrates that you specify in G-code commands as being distance units per minute.
G76 Configures the task to treat feedrates that you specify in G-code commands as being distance units per second.
G82 Clears the program position offset on the specified axis. The program position will be restored to the current axis position.
G90 Configures the task to operate in the absolute target mode.
G91 Configures the task to operate in the incremental target mode.
G92 Sets the program position of the specified axes. All moves that specify an absolute target-position will be relative to the new program position.
G93 Configures the task for inverse time feedrate mode. Values specified to the F command are interpreted as the inverse amount of time that the controller should take to complete the distance specified in the move.
G94 Configures the task for normal feedrate mode. Values specified to the F command are interpreted as distance units per unit of time.
G95 Configures the task to interpret feedrates that you specify with the F command or the E command as units per spindle revolution.
G96 Configures the task to interpret the S command as the tangential speed, or the speed on the surface, of the spindle axis. You must specify surface speed and a radial axis to this command.
G97 Configures the task to interpret the S command in velocity units.
G98 Enables inverse dominance mode on the task.
G99 Disables inverse dominance mode on the task.
G100 Disables spindle shutdown mode on the task.
G101 Enables spindle shutdown mode on the task.
G108 Enables velocity blending mode on the task.
G109 Disables velocity blending mode on the task.
G114 Enables optional pause mode on the task.
G115 Disables optional pause mode on the task.
G118 Configures the center point coordinates that you specify to a coordinated arc motion command to be in absolute user units.
G120 Configures the task to disable the effects of manual feedrate override (MFO) and the feedhold state during asynchronous motion.
G121 Configures the task to enable the effects of manual feedrate override (MFO) and the feedhold state during asynchronous motion.
G143 Activates cutter offset compensation positive mode on the task.
G144 Activates cutter offset compensation negative mode on the task.
G149 Deactivates cutter offset compensation mode on the task.
G150 Disables part scaling mode on the task.
G151 Enables part scaling mode on the task.
G153 Suppresses work offsets for the G-code motion that you specify on the same program line.
G165 Configures the rate that the task uses to perform coordinated motion to accelerate dependent axes.
G166 Configures the rate that the task uses to perform coordinated motion to decelerate dependent axes.
G359 Sets the wait mode to wait the minimum amount of time between motion blocks.
G360 Sets the wait mode to wait for all motion to be done between motion blocks.
G361 Sets the wait mode to wait for all motion to be done and for all axes to be in position between motion blocks.

Doing Motion

The G0, G1, G2, G3, G12, and G13 G-code commands execute rapid point-to-point moves, coordinated linear moves, coordinated arc moves, or coordinated linear and arc moves put together.

G0 G-code: Rapid, Point-to-Point Motion

Use the G0 command to execute a rapid, point-to-point move on one or more axes when it is not necessary to coordinate more than one axis. This type of motion lets the axes move at different speeds and get to their endpoints at different times.

Syntax G0 <axis point> [<axis feedrates>]
Example G0 X10 Y20 XF100 YF50

Use the DefaultAxisSpeed Parameter to configure the default speed that an axis will move during point-to-point motion. You can also specify an axis name followed by the ‘F’ character, then a numerical expression to configure the speed of an axis during point-to-point motion. For example, if your system has an axis named X, then you can specify XF100 on a program line that contains the G0 command or on its own program line to set the speed of the X axis to 100 user units per second.

The G0 command has the same functionality as the MoveRapid() AeroScript function. For more information, refer to the MoveRapid() function in Rapid Motion.

G1 command: Coordinated Linear Motion

Use the G1 command to execute a coordinated linear move on the specified axes. A linear move creates a line in vector space. In this mode, axes move from their starting positions to their commanded positions in a coordinated fashion. This means that the axes that you command all start motion at the same time and stop motion at the same time because the axes follow a path that consists of a straight line.

Syntax G1 <axis point> [F Command] [E Command]
Examples G1 X10 Y20 F100

G1 Z100 E50

Use the F command to configure the feedrate of a coordinated linear move that contains dominant axes. Use the E command to configure the feedrate of a coordinated linear move that contains only dependent axes. For more information, see F Command, E Command, and AxisType Parameter.

The G1 command has the same functionality as the MoveLinear() AeroScript function. For more information, refer to Linear Moves.

Coordinated Arc Motion G-code Programming

G2 command: Coordinated Clockwise Arc Motion (First Coordinate System)

Use the G2 command to configure a task to operate in vectorized circular positioning mode in the clockwise direction, using the axes that are specified in the first coordinate system of the task. Use the G16 command to specify the axes in the first coordinate system of the task. Use the G17, G18, and G19 commands to select which axes to use from the first coordinate system of the task.

Syntax G2 <endpoint> <center point> [F Command]
Examples G2 X10 Y0 R5 F100 // R command method

G2 X0 Y0 I0 J10 // IJK method

G2 P108.1 Q-18.3 R1.5 // PQR method

G2 Q-18.3 I.5 J-1.5 // IJK method and Q method

The G2 command has the same functionality as the MoveCw() AeroScript function. For more information, refer to Arc Moves.

G3 command: Coordinated Counterclockwise Arc Motion (First Coordinate System)

Use the G3 command to configure a task to operate in vectorized circular positioning mode in the counterclockwise direction, using the axes that are specified in the first coordinate system of the task. Use the G16 command to specify the axes in the first coordinate system of the task. Use the G17, G18, and G19 commands to select which axes to use from the first coordinate system of the task.

Syntax G3 <endpoint> <center point> [F Command]
Examples G3 X10 Y0 R5 F100 // R command method

G3 X0 Y0 I0 J10 // IJK method

G3 P108.1 Q-18.3 R1.5 // PQR method

G3 Q-18.3 I.5 J-1.5 // IJK method and Q method

The G3 command has the same functionality as the MoveCcw() AeroScript function. For more information, refer to Arc Moves.

G12 command: Coordinated Clockwise Arc Motion (Second Coordinate System)

Use the G12 command to configure a task to operate in vectorized circular positioning mode in the clockwise direction, using the axes that are specified in the second coordinate system of the task. Use the G26 command to specify the axes in the second coordinate system of the task. Use the G27, G28, and G29 commands to select which axes to use from the second coordinate system of the task.

Syntax G12 <endpoint> <center point> [F Command]
Examples G12 X10 Y0 R5 F100 // R command method

G12 X0 Y0 I0 J10 // IJK method

G12 P108.1 Q-18.3 R1.5 // PQR method

G12 Q-18.3 I.5 J-1.5 // IJK method and Q method

The G12 command lets you do two arc motions as part of the same coordinated move. For more information, refer to the Helixes and Dual Circular Motion section of this topic.

G13 command: Coordinated Counterclockwise Arc Motion (Second Coordinate System)

Use the G13 command to configure a task to operate in vectorized circular positioning mode in the counterclockwise direction, using the axes that are specified in the second coordinate system of the task. Use the G26 command to specify the axes in the second coordinate system of the task. Use the G27, G28, and G29 commands to select which axes to use from the second coordinate system of the task.

Syntax G13 <endpoint> <center point> [F Command]
Examples G13 X10 Y0 R5 F100 // R command method

G13 X0 Y0 I0 J10 // IJK method

G13 P108.1 Q-18.3 R1.5 // PQR method

G13 Q-18.3 I.5 J-1.5 // IJK method and Q method

The G13 command lets you do two arc motions as part of the same coordinated move. For more information, refer to the Helixes and Dual Circular Motion section of this topic.

G118 command: Specify Circular Center Points in Absolute Coordinates

When it executes G2, G3, G12, or G13 circular arc motion commands, the controller treats I, J, or K offsets that you specified as relative offsets from the locations of the axes when the move starts. Use the G118 command to cause the controller to interpret any I, J, or K offsets in absolute user units. This command is not modal and must be specified on each G2, G3, G12, or G13 motion line.

Syntax G118 <G-code command arc motion>
Examples G118 G3 X2 Y-2 I.5 J-1.5

G118 G2 X2 Y2 I0.5 J1.5

Helixes and Dual Circular Motion

To create a helix move, specify G2 or G3 command motion on the same line as G1 command motion. You can also create a helix move by specifying G12 or G13 command motion on the same line as G1 command motion.

G2 X10 Y0 R5 G1 A10

If you want to do dual circular motion with four axes at the same time, specify G2 or G3 command motion on the same line as G12 or G13 command motion. You can also do dual circular motion with a helix by specifying G2 or G3 command motion, G12 or G13 command motion, and G1 command motion on the same program line.

G2 X10 Y10 P135 Q45 R5 G13 U10 A0 R5 G1 C10

Specifying the Center Point of Circular Arc Motion

You can specify the center point of a circular arc move (G2, G3, G12, or G13 commands) with the R command method or with the IJK method.

Use the R command method to specify the center point of a circular arc move by specifying a radius. If the radius that you specify to the R command is positive, then the controller generates a shorter arc that is always 180° or less. If the radius that you specify to the R command is negative, then the controller generates a longer arc that is always between 180° and 360°. You cannot create a full 360° circle with the R command method. To create a full 360° circle, you must use the IJK method.

Use the IJK method to specify the center of an arc as an incremental offset from the starting position of the axes. Or, use the G118 command on the same line as a G2 move to specify the center of an arc as absolute user units. The example that follows shows how to create a full 360° circle with the IJK method.

// Configure the first coordinate system to have X, Y, and Z axes
// Then select axes X and Y from the first coordinate system
G16 X Y Z
G17
// Create a full circle that starts and ends at X=0, Y=0
// The center point of the circle is at X=1, Y=0
G2 X0 Y0 I1 J0

Methods for Specifying the Circular End Point

To specify the endpoint of a circular arc move (G2, G3, G12, or G13 commands) by declaring the endpoint positions and using the R command method, you can use the PQR method or the Q command method.

You can declare the end point of a circular arc move when you use the R command method to specify the center point of the circular arc motion.

G2 X10 Y0 P135 Q45 R5

You can use the PQR method to specify the absolute starting angle and absolute ending angle of the circular arc move. Use the P command to specify, in degrees, the absolute starting angle. Use the Q command to specify, in degrees, the absolute ending angle. The two absolute angles are measured counterclockwise from a line that is drawn through the center point of the circular arc, and is parallel to the X axis. If the starting and ending angles are the same, then the controller generates a full 360° circle. Use the R command to specify the radius of the circular arc move.

G2 X10 Y0 R5

You can use the Q command method to specify the absolute ending angle of the circular arc move. Use the Q command to specify, in degrees, the absolute ending angle. The absolute ending angle is measured counterclockwise from a line that is drawn through the center point of the circular arc, and is parallel to the X axis. When you use the Q command method, you cannot use the R command to specify the radius of the circular arc move. You must use the IJK method to specify the center point of the circular arc move.

G2 X10 Y0 I5 J0 Q45

Cutter Radius Compensation G-codes

Cutter radius compensation compensates for the size of a cutting tool by causing the controller to maintain a constant offset that is perpendicular to the programmed path in a two-dimensional plane. You can use this feature to compensate for the radius of a cutting tool or the width of a laser. Use the G40, G41, G42, G43, and G44 modal and non-modal G-code commands to configure cutter radius compensation. For more information, refer to Cutter Radius Compensation.

Cutter Offset Compensation G-codes

Cutter offset compensation compensates for the offset of a cutting tool by causing the controller to maintain a constant offset that is perpendicular to the programmed path in a three-dimensional plane. You can use this feature to compensate for the x-offsets, y-offsets, and cutter length of a cutting tool. Use the G44, G143, G144, and G149 modal and non-modal G-codes to configure cutter offset compensation. For more information, refer to Cutter Offset Compensation.

Configuring Motion

You can use the G-codes and G-code commands that follow to configure different configuration modes for motion on the task.

F Command

Use the F command to specify the feedrate of dominant axes for coordinated motion.

Syntax F <coordinated speed>
Examples F100

F$rglobal[3]

The specified feedrate is modal and stays active until you specify a new feedrate with the F command.

The F command has the same functionality as the SetupCoordinatedSpeed() AeroScript function. For more information, refer to the SetupCoordinatedSpeed() function in Coordinated Speeds. For information about dominant and dependent axes, see AxisType Parameter and E Command in the section that follows.

E Command

Use the E command to specify the feedrate of dependent axes for coordinated motion.

Syntax E <coordinated speed>
Examples E100

E$rglobal[3]

The specified feedrate is modal and stays active until you specify a new feedrate with the E command. If a coordinated move contains dominant and dependent axes, the feedrate for dominant axes (the F command) is used for the move instead of the feedrate for dependent axes (the E command). For information about dominant and dependent axes, see AxisType Parameter and the F Command section of this topic.

The E command has the same functionality as the SetupDependentCoordinatedSpeed() AeroScript function. For more information, refer to Coordinated Speeds.

S Command

Use the S command to specify the speed of the spindle, in user units, that is configured for the task.

Syntax S <spindle speed>
Examples S50

S$rglobal[1]

The value that you specify to the S command has an effect on the operation of the G95, G96, and G97 G-codes. For more information about configuring a spindle axis for a task, refer to SpindleAxis Parameter. The S command has the same functionality as the TaskMso() AeroScript function. For more information, refer to MSO.

G16 G-code: Configure Circular Axes in the First Coordinate System

Use the G16 G-code to configure I, J, and K axes of the first coordinate system for the G2 and G3 circular arc motion G-codes.

Syntax G16 <I axis> <J axis> <K axis>
Examples G16 X Y Z

The first axis that you specify to the G16 G-code is assigned to I, which is the X axis when specified with a G2 or G3 G-code. The second axis that you specify to the G16 G-code is assigned to J, which is the Y axis when specified with a G2 or G3 G-code. The third axis that you specify to the G16 G-code is assigned to K, which is the Z axis when specified with a G2 or G3 G-code.

G26 G-code: Configure Circular Axes in the Second Coordinate System

Use the G26 G-code to configure I, J, and K axes of the second coordinate system for the G12 and G13 circular arc motion G-codes.

Syntax G26 <I axis> <J axis> <K axis>
Examples G26 X Y Z

The first axis that you specify to the G26 G-code is assigned to I, which is the X axis when specified with a G12 or G13 G-code. The second axis that you specify to the G26 G-code is assigned to J, which is the Y axis when specified with a G12 or G13 G-code. The third axis that you specify to the G26 G-code is assigned to K, which is the Z axis when specified with a G12 or G13 G-code.

Coordinated Motion Acceleration and Deceleration Configuration

Use the G60, G61, G63, G64, G65, G66, G66, G67, G68, G69, G165, and G166 G-codes to configure different settings for acceleration and deceleration for coordinated motion.

G60 G-code: Configure Coordinated Acceleration Time

Use the G60 G-code to configure coordinated motion to use the specified amount of time to accelerate. This G-code has an effect only if the task is operating in time-based mode. For more information, refer to the G67 G-code or the SetupCoordinatedRampValue() function in Coordinated Ramping Mode, Rate, and Time.

Syntax G60 P<duration>
Examples G60 P0.5

G63, G64, and G69 G-codes: Configure Coordinated Acceleration and Deceleration Type

Use the G63, G64, and G69 G-codes to configure the type of acceleration that the controller uses to perform coordinated motion.

Syntax G63

G64

G69

Examples G63

G64

G69

Use the G63 G-code to configure coordinated motion to use sinusoidal acceleration and deceleration. Use the G64 G-code to configure coordinated motion to use linear acceleration and deceleration. Use the G69 G-code to configure coordinated motion to use S-curve acceleration and deceleration. Sinusoidal (G63) acceleration and deceleration is typically better than linear acceleration and deceleration (G64) because it results in less disturbance to the servo system. However, it requires π/2 times more current than linear acceleration and deceleration. Refer to Acceleration and Deceleration Ramping.

G65 and G66 G-codes: Configure Dominant Coordinated Acceleration and Deceleration Rate

Use the G65 G-code to configure the coordinated motion to use the specified rate to accelerate dominant axes. Use the G66 G-code to configure the coordinated motion to use the specified value to decelerate dominant axes.

Syntax G65 P<acceleration rate>

G66 P<deceleration rate>

Examples G65 P100

G66 P250

The G65 and G66 G-codes have an effect only if the task is operating in rate-based mode. For more information, refer to the G68 G-code or the SetupCoordinatedRampValue() function in Coordinated Ramping Mode, Rate, and Time. For more information about dominant and dependent axes, refer to AxisType Parameter.

G165 and G166 G-codes: Configure Dependent Coordinated Acceleration and Deceleration Rate

Use the G165 G-code to configure the coordinated motion to use the specified value to accelerate dependent axes. Use the G166 G-code to configure the coordinated motion to use the specified value to decelerate dependent axes.

Syntax G165 P<acceleration rate>

G166 P<deceleration rate>

Examples G165 P100

G166 P250

The G165 and G166 G-codes have an effect only if the task is operating in rate-based mode. For more information, refer to the G68 G-code or the SetupCoordinatedRampValue() function in Coordinated Ramping Mode, Rate, and Time. For more information about dominant and dependent axes, refer to AxisType Parameter.

Distance Units Configuration

G70 and G71 G-codes: Configure Units Mode

You can configure tasks to operate in metric or English user units mode. In metric units mode, the controller interprets the positions and distances that you specify as metric units. In English units mode, the controller interprets the positions and distances that you specify as English units. Use the G70 and G71 G-codes with the PrimaryUnitsMapping Parameter to configure the task to operate in metric or English user units mode.

Syntax G70

G71

Examples G70

G71

If you set the PrimaryUnitsMapping Parameter to metric, which is the default setting, the G71 G-code configures the task to operate in metric units mode, and the G70 G-code configures the task to operate in English units mode. If you set the PrimaryUnitsMapping Parameter to English, then the G71 G-code configures the task to operate in English units mode, and the G70 G-code configures the task to operate in metric units mode.

AeroScript does not have functions to set English (G70) and Metric (G71) units. As an alternative in an AeroScript program, set the units mode to primary units or secondary units by using the SetupTaskDistanceUnits() function. For more information, refer to the SecondaryUnitsScaleFactor Parameter.

Time Units Configuration

Use the G75 and G76 G-codes to configure the time units of the task.

Syntax G75

G76

Examples G75 // Set time units to minutes

G76 // Set time units to seconds

G75 G-code: Specify Feedrates in Distance Units per Minute

Use the G75 G-code to specify that feedrates are specified as distance units per minute. In this mode, the controller sets the Minutes bit of the TaskMode task status item to 1.

G76 G-code: Specify Feedrates in Distance Units per Second

Use the G76 G-code to specify that feedrates are specified in distance units per second. In this mode, the controller sets the Minutes bit of the TaskMode task status item to 0.

To configure the default time units of the task, set the DefaultTaskTimeUnits Parameter. The G75 and G76 G-codes have the same functionality as the SetupTaskTimeUnits() AeroScript function. For more information, refer to Velocity and Acceleration Units.

Target Mode Configuration

Use the G90 and G91 G-codes to configure the target mode of the task.

Syntax G90

G91

Examples G90 // Set the target mode to absolute positioning mode

G91 // Set the target mode to incremental positioning mode

G90 G-code: Configure Absolute Positioning Target Mode

Use the G90 G-code to configure the task to operate in absolute positioning target mode. In this mode, the controller interprets move target positions as being absolute compared to a zero location established by homing or the program position offsets that you specified to the G92 G-code. In this mode, the controller sets the Absolute bit of the TaskMode task status item to 1.

G91 G-code: Configure Incremental Positioning Target Mode

Use the G91 G-code to configure the task to operate in incremental positioning target mode. In this mode, the controller interprets move target positions as being relative to the positions of the axes when the move is started. In this mode, the controller sets the Absolute bit of the TaskMode task status item to 0.

To configure the default target mode of the task, set the DefaultTaskTargetMode Parameter. The G90 and G91 G-codes have the same functionality as the SetupTaskTargetMode() AeroScript function. For more information, refer to Absolute and Incremental Move Targets.

Wait Mode Configuration

Use the G359, G360, and G361 G-codes to configure the wait mode of the task. The wait mode determines how the controller waits for G0, G1, G2, G3, G12, and G13 motion to complete.

Syntax G359

G360

G361

Examples G359 // Set the wait mode to wait mode aut

G360 // Set the wait mode to wait for motion done

G361 // Set the wait mode to wait for axes to be in-position

The G359, G360, and G361 G-codes have the same functionality as the SetupTaskWaitMode() AeroScript function. For more information, refer to Wait Modes.

G359 G-code: Configure Automatic Wait Mode

Use the G359 G-code to configure the task to operate in the automatic wait mode. In this mode, the controller does not wait for the axes that are a part of commanded moves to be in position before program execution continues to the next program line. Use this mode to reduce the cycle time of your program. In this mode, the controller sets the Wait Auto bit of the TaskMode task status item to 1 and sets the Wait For InPos bit of the TaskMode task status item to 0. The G359 G-code operates the same as specifying the WaitMode.Auto enumerator value to the SetupTaskWaitMode() function.

G360 G-code: Configure Move Done Wait Mode

Use the G360 G-code to configure the task to operate in the move done wait mode. In this mode, the controller does not wait for axes that are a part of command moves to be in position before program execution continues to the next program line. However, the controller will wait for the final velocities for all axes that you command to be zero before continuing execution of your program. In this mode, the controller sets the Wait Auto bit of the TaskMode task status item to 0 and sets the Wait For InPos bit of the TaskMode task status item to 0. The G360 G-code operates the same as specifying the WaitMode.MotionDoneAuto enumerator value to the SetupTaskWaitMode() function.

G359 G-code: Configure In-Position Wait Mode

Use the G361 G-code to configure the task to operate in the in-position wait mode. In this mode, the controller will wait for the final velocities for all axes that you command to be zero. This mode will also wait for axes that are a part of command moves to be in position before program execution continues to the next program line. In this mode, the controller sets the Wait Auto bit of the TaskMode task status item to 0 and sets the Wait For InPos bit of the TaskMode task status item to 1. The G361 G-code operates the same as specifying the WaitMode.InPosition enumerator value to the SetupTaskWaitMode() function.

Feedrate Settings

G93 G-code: Configure F Command For Coordinated Moves

Use the G93 G-code to configure the task to operate in a mode where the controller interprets the F command value as the inverse of the duration that is necessary to perform a coordinated move.

Syntax G93
Examples

G93

In this mode, the E command is ignored, and the F command value is used for both dominant and dependent axes. If you enable the G93 mode, then the G96 and G95 modes become disabled. In this mode, the controller sets the Program Feedrate Inverse Time bit of the TaskMode task status item to 1 and sets the Program Feedrate Units Per Spindle Rev bit of the TaskMode task status item to 0.

The AeroScript example program that follows uses the G93 G-code.

// Configure the task to interpret the F command in inverse time units.
G93
// Configure the task to use seconds as the time units.
G76
// Perform a coordinated linear move in two seconds.
G1 X100 F(1.0/2.0)

G94 G-code: Configure F Command in Distance Units per Time Unit

Use the G94 G-code to configure the task to operate in a mode where the controller interprets the F command value as distance units per time unit. This is the default mode.

Syntax G94
Examples G94

If you enable the G94 mode, then the G93 and G95 modes become disabled. In this mode, the controller sets the Program Feedrate Inverse Time bit of the TaskMode task status item to 0 and sets the Program Feedrate Units Per Spindle Rev bit of the TaskMode task status item to 0.

G95 G-code: Configure F Command and E Command in Units per Spindle Revolution

Use the G95 G-code to configure the task to operate in a mode where the controller interprets both the F command value and the E command value in units per spindle revolution. This causes the axes to move at a speed proportional to the absolute value of the programmed spindle speed that you specified with the S command.

Syntax G95
Examples

G95

Variations in the actual speed of the spindle are not tracked and do not have an effect on the speed of the coordinated motion. If you enable the G95 mode, then the G93 and G94 modes become disabled. In this mode, the controller sets the Program Feedrate Inverse Time bit of the TaskMode task status item to 0 and sets the Program Feedrate Units Per Spindle Rev bit of the TaskMode task status item to 1.

Use the G70 and G71 G-codes to configure distance units for the task. The G70 and G71 G-codes have the same functionality as the SetupTaskDistanceUnits() AeroScript function. For more information, refer to Distance Units.

Use the G75 and G76 G-codes to configure time units for the task. The G75 and G76 G-codes have the same functionality as the SetupTaskTimeUnits() AeroScript function. For more information, refer to Velocity and Acceleration Units.

Spindle Feedrate Configuration

Use the G96 and G97 G-codes to configure the method that the controller uses to determine the speed of a spindle axis.

Syntax G96 <axis>

G97

Examples G96 Y

G97

G96 G-code: Configure Tangential Speed as a Constant Value

Use the G96 G-code to configure the tangential speed (the speed on the surface) of the spindle axis to be a constant value. If you enable G96 mode, then G97 mode becomes disabled. The value of the S command and the position command of the radial axis that you specify to the G96 G-code are used to calculate the spindle speed based on the equation that follows.

Where:

is the speed of the spindle in revolutions per minute (RPM).

s is the wanted tangential speed of the spindle, specified by the S command.

R is the programmed position command of the specified radial axis in distance units.

Use the MaxSpeedClamp Parameter to limit the speed of the spindle axis in G96 mode because as the specified radial axis approaches the center of rotation of the spindle, the spindle axis can be commanded to excessive speeds, which can cause axis faults.

G97 G-code: Configure Spindle Speed in Velocity Units

Use the G97 G-code to configure the speed of the spindle to operate in velocity units. If you enable G97 mode, then the G96 mode becomes disabled. The velocity units that you specify to the S command are determined by the values of the CountsPerUnit Parameter and DependentSpeedScaleFactor Parameter of the spindle axis. This mode is the default.

Inverse Dominance Mode

G98 G-code: Enable Inverse Dominance Mode

Use the G98 G-code to enable inverse dominance mode.

Syntax G98
Examples

G98

In this mode, the controller reverses the behavior of axis dominance. Thus, the dominant axes act as dependent axes, and dependent axes act as dominant axes. In this mode, the controller sets the Inverse Dominance bit of the TaskMode task status item to 1. For more information about axis dominance, refer to the AxisType Parameter.

G98 G-code: Disable Inverse Dominance Mode

Use the G99 G-code to disable the inverse dominance mode that was enabled with the G98 G-code. This mode is the default.

Syntax G99
Examples

G99

In this mode, the controller sets the Inverse Dominance bit of the TaskMode task status item to 0.

Spindle Shutdown Mode

G101 G-code: Enable Spindle Shutdown Mode

Use the G101 G-code to enable spindle shutdown mode. In the spindle shutdown mode, the spindle axis reacts to the feedhold state of the task, aborts, and task errors, in the same manner that any other axis reacts to these actions. However, in this mode, if the feedhold state of the task is enabled and subsequently disabled, the spindle axis will not accelerate to its commanded speed. In this mode, the controller sets the Spindle Stop On Program Halt bit of the TaskMode task status item to 1.

G100 G-code: Disable Spindle Shutdown Mode

Use the G100 G-code to disable the spindle shutdown mode that you enabled with the G101 G-code on the task. When you disable the spindle shutdown mode, the spindle axis acts independently of other motion, and is not affected by the feedhold state of the task, aborts, or task errors. This is the default mode. In this mode, the controller sets the Spindle Stop On Program Halt bit of the TaskMode task status item to 0.

Syntax G101

G100

Examples G101

G100

Velocity Profiling G-codes

Use the G108 and G109 G-codes to activate or deactivate the velocity profiling mode of the task.

Syntax G108

G109

Examples G108

G109

The G108 and G109 G-codes have the same functionality as the VelocityBlendingOn() and VelocityBlendingOff() AeroScript functions. For more information, refer to Velocity Blending Functions.

G108 G-code: Enable Velocity Blending Mode

Use the G108 G-code to enable velocity blending mode. In this mode, the controller will blend multiple coordinated motion commands into one continuous motion path. The controller does not decelerate to zero velocity between coordinated moves, but instead uses the coordinated speed to maintain a consistent speed between moves. In this mode, the controller sets the Motion Continuous bit of the TaskMode task status item to 1. Refer to the F Command and the E Command for more information.

G109 G-code: Disable Velocity Blending Mode

Use the G109 G-code to disable the velocity blending mode that you enabled with the G108 G-code. This mode is the default. In this mode, the controller sets the Motion Continuous bit of the TaskMode task status item to 0.

Optional Pause Mode

Use the G114 and G115 G-codes to activate or deactivate the optional pause mode of the task. Refer to the M1 M-code for more information.

Syntax G114

G115

Examples G114

G115

G114 G-code: Enable Optional Pause Mode

Use the G114 G-code to enable optional pause mode for the task. In this mode, the controller will pause the task if an M1 M-code is executed. In this mode, the controller sets the Optional Pause bit of the TaskMode task status item to 1.

G115 G-code: Disable Optional Pause Mode

Use the G115 G-code to disable the optional pause mode for the task that you enabled with the G114 G-code. In this mode, the controller will not perform any operation when executing M1 M-codes, and will continue to execute the program. This is the default mode. In this mode, the controller sets the Optional Pause bit of the TaskMode task status item to 0.

Configuring the Response of Asynchronous Motion to MFO and Feedhold

Use the G120 and G121 G-codes to configure whether the controller applies the manual feedrate override and feedhold state to asynchronous motion. Refer to the Move Functions topic for more information about asynchronous motion.

Syntax G120

G121

Examples G120

G121

G120 G-code: Disable the Effects of MFO and Feedhold on Asynchronous Motion

Use the G120 G-code to disable the effect of manual feedrate override (MFO) and the feedhold state on asynchronous motion that you enabled with the G121 G-code. This is the default mode. In this mode, the controller sets the Mfo Active On Jog bit of the TaskMode task status item to 0.

G121 G-code: Enable the Effects of MFO and Feedhold on Asynchronous Motion

Use the G121 G-code to enable the effects of manual feedrate override (MFO) and the feedhold state on asynchronous motion. In this mode, the controller sets the Mfo Active On Jog bit of the TaskMode task status item to 1.

Part Scaling

G151 G-code: Enable Part Scaling

Use the G151 G-code to enable part scaling mode on the task for the specified axes. When you use the G151 G-code, you must specify one or more pairs that each consist of an axis and a scale factor.

Syntax G151 <axis point>
Examples
// Scale the part by 2 in the direction of the X axis.
// Scale the part by 4 in the direction of the Y axis.
G151 X2 Y4

When part scaling mode is active for any axes on the task, the controller sets the Scaling Active bit of the TaskStatus2 task status item to 1. The part scaling mode scales the programmed position targets of MoveRapid() (G0), MoveLinear() (G1), MoveCw (G2), MoveCcw() (G3), MoveIncremental() and MoveAbsolute() motion. When you issue the G151 G-code, the controller makes a scale center at the current position. Then it scales, by the specified scale factor, all absolute motion positions that you supply. The controller scales these positions around the scale center. Refer to the equation that follows to see how the controller determines the value of each position after part scaling is applied.

G150 G-code: Disable Part Scaling

Use the G150 G-code to disable part scaling mode on the task for the specified axes that you enabled with the G151 G-code. If you do not specify any axes to the G150 G-code, then part scaling mode is disabled on the task for all axes.

Syntax G150

G150 <axes>

Examples
G150      // Disable part scaling for all axes
G150 Y Z  // Disable part scaling for axes Y and Z

When part scaling mode is no longer active for any axes on the task, the controller sets the Scaling Active bit of the TaskStatus2 task status item to 0.

Program Position Offsets

Use the G92 and G82 G-codes to configure program position offsets for a task. The G92 and G82 G-codes have the same functionality as the PositionOffsetSet() and PositionOffsetClear() AeroScript functions. For more information, refer to Position Offsets.

G92 G-code: Configure Program Position Offsets

Use the G92 G-code to set the program position offsets of the specified axes to the specified values. Setting the program position offsets of axes defines a new coordinate system and does not cause the axes to move.

Syntax G92 <axis point>
Examples G92 X10.5 Y$rglobal[3]

G82 G-code: Clear Program Position Offsets

Use the G82 G-code to clear the program position offsets of the specified axes, restoring the offsets to the values that were active before you specified the G92 G-code with the specified axes.

Syntax G82

G82 <axes>

Examples G82 // Clear offsets on all axes

G82 X Z // Clear offsets on axes X and Z

The AeroScript example program that follows uses the G92 and G82 G-codes.


// Move axes X and Y to (3, 3).
G90 G1 X3 Y3
// Axes X and Y remain at absolute position (3, 3).
// The axes report as being at a programmed position of (0, 0).
G92 X0 Y0
// Move axes to a programmed position of (5, 5).
// The axes will move to an absolute position of (8, 8) because of the
// offset positions specified to the G92 command. G1 X5 Y5 // Restore the program position offsets to (0, 0). // This causes the axes to report a programmed position of (8, 8). G82

Work Offsets

Use work offsets to program move targets that are relative to a fixed point in space when you do not know the absolute coordinates of those move targets. Use the G53, G54, G55, G56, G57, G58, and G59 G-codes to use work offsets. Refer to the Work Offsets section on the Motion Functions page for more information.

G54, G55, G56, G57, G58, and G59 G-codes: Enable work offsets

Use the G54, G55, G56, G57, G58, and G59 G-codes to enable work offsets 1 through 6. Work offsets must first be configured by issuing the WorkOffsetConfigureOffset()  AeroScript function. If you do not specify axes, the work offset is enabled for all configured axes.

Syntax

G54
G54 <axes>

G55
G55 <axes>

G56
G56 <axes>

G57
G57 <axes>

G58
G58 <axes>

G59
G59 <axes>

Examples G54 // Enable work offset 1 on all configured axes

G58 X Y // Enable work offset 5 on axes X and Y

G53 G-code: Disable work offsets

Use the G53 G-code to disable work offsets on the specified axes. If you do not specify axes, work offsets are disabled for all axes.

Syntax

G53
G53 <axes>

Examples G53 // Disable work offsets on all axes

G53 X Y // Disable work offsets 5 on axes X and Y

G153 G-code: Suppress work offsets

Use the G153 G-code to disable work offsets only for the G-code motion that you specify on the same program line. When you use G153, program position offsets stay active.

Syntax

G153 <G-code move>

Examples

G153 G1 X10 // Work offsets are not applied for any axes used in this motion

Miscellaneous G-codes

G4 G-code: Motion Dwell

Use the G4 G-code to pause program and motion execution by the specified amount of time, in seconds.

Syntax G4 P<duration>
Examples

G4 P0.002 // Dwell for 2 milliseconds

The duration that you specify has a resolution of 1 millisecond.

The G4 G-code has the same functionality as the Dwell() AeroScript function. For more information, refer to Dwell.

G8 G-code: Instant Acceleration

Use the G8 G-code to force the G-code motion specified on the same line to immediately accelerate to the maximum feedrate, if possible.

Syntax G8 <G-code move>
Examples G8 G1 X10 F50

G9 G-code: Forced Deceleration

Use the G9 G-code to force the G-code motion specified on the same line to decelerate to zero velocity, even when the task is configured to use velocity profiling mode.

Syntax G9 <G-code move>
Examples G9 G2 X10 Y0 R5 F100

When velocity profiling mode is active (G108), you can also force a coordinated G-code move to decelerate to zero velocity if you specify a G4 G-code (motion dwell) on the next program line. When velocity profiling mode is not active (G109), then the controller decelerates all coordinated G-code moves to zero velocity before executing the next move.

G108
G1 X10 F30
G1 X40 F25
G4 P0       // This causes the previous move to decelerate to zero velocity
G1 X50 F27

For more information about velocity profiling mode, refer to the G108 and G109 G-codes in this topic. The G4 G-code has the same functionality as the Dwell() AeroScript function. For more information, refer to Dwell.

M-codes

M-codes consist of the letter M followed by an integer literal, such as M0 or M2. M-codes can be specified on their own line in an AeroScript program or library source file, or they can be specified with some G-codes on the same line. Only one M-code can be specified on a line. The table that follows shows a list of all of the supported M-codes.

Table: Supported M-codes

M-code Description
M0 Pauses the current task.
M1 Pauses the current task if the optional pause mode is active on the task, or does nothing if optional pause mode is not active.
M2 Stops the execution of the program on the current task.
M3 Starts motion in the clockwise direction on the spindle axis that is configured for the task. The command is complete after the spindle accelerates to the commanded speed.
M4 Starts motion in the counterclockwise direction on the spindle axis that is configured for the task. The command is complete after the spindle accelerates to the commanded speed.
M5 Causes the spindle axis that is configured for the task to decelerate to zero speed.
M30 Resets the execution of the AeroScript to the first executable line.
M47 Resets the execution of the AeroScript to the first executable line. Then it causes the controller to start execution of the program.
M48 Disables the use of manual feedrate override (MFO) controls.
M49 Enables the use of manual feedrate override (MFO) controls.
M50 Disables the use of manual spindle override (MSO) controls.
M51 Enables the use of manual spindle override (MSO) controls.
M103 Starts motion on the spindle axis that is configured for the task in the clockwise direction. The command does not wait for the spindle to accelerate to the commanded speed.
M104 Starts motion on the spindle axis that is configured for the task in the counterclockwise direction. The command does not wait for the spindle to accelerate to the commanded speed.

M0 M-code: Pause the AeroScript Program

Use the M0 M-code to pause the execution of the AeroScript program.

Syntax M0
Examples M0

The M0 M-code has the same functionality as the ProgramPause() AeroScript function. For more information, refer to Program Control.

M1 M-code: Optionally Pause the AeroScript Program

Use the M1 M-code to optionally pause the execution of the AeroScript program.

Syntax M1
Examples M1

If the controller executes the M1 M-code when optional pause mode (G114 mode) is active, then the program will pause. Otherwise, if optional pause mode is not active (G115 mode), then the controller will ignore the M1 M-code. Refer to the M0 M-code for more information.

M2 M-code: Stop the AeroScript Program

Use the M2 M-code to end the execution of the AeroScript program.

Syntax M2
Examples M2

The M2 M-code has the same functionality as the ProgramExit() AeroScript function. For more information, refer to Program Control.

M30 M-code: Reset the AeroScript Program

Use the M30 M-code to reset the AeroScript program to its first executable line and pause the program.

Syntax M30
Examples M30

The M30 M-code has the same functionality as the ProgramReset() AeroScript function. For more information, refer to Program Control.

M47 M-code: Restart the AeroScript Program

Use the M47 M-code to reset the AeroScript program to its first executable line and then immediately start running the program.

Syntax M47
Examples M47

This M-code has the same behavior as if you executed the M30 M-code followed by the ProgramStart() function or by pressing the Run button in Automation1 Studio. The M47 M-code has the same functionality as the ProgramRestart() AeroScript function. For more information, refer to Program Control.

Spindle Configuration and Spindle Motion M-Codes

You can use the M3, M4, M5, M50, M51, M103, and M104 M-codes to configure the motion of the spindle that is configured for the task. For more information about configuring a spindle axis for a task, refer to the SpindleAxis Parameter.

For more information about configuring the speed of the spindle axis, refer to the S Command section of this topic.

Enabling Spindle Motion

You can use the M3, M4, M103, or M104 M-codes to enable spindle motion.

M3 M-code: Start Spindle Motion in the Clockwise Direction Synchronously

Use the M3 M-code to cause the spindle axis that is configured for the task to start rotating in the clockwise direction.

Syntax M3
Examples M3

The acceleration behavior of the spindle axis depends on the DefaultAxisRampMode Parameter and the DefaultAxisRampType Parameter. This M-code operates synchronously, so the program line that the M3 M-code is specified on will execute until the spindle axis accelerates to the commanded spindle speed.

M4 M-code: Start Spindle Motion in the Counterclockwise Direction Synchronously

Use the M4 M-code to cause the spindle axis that is configured for the task to start rotating in the counterclockwise direction.

Syntax M4
Examples M4

The acceleration behavior of the spindle axis depends on the DefaultAxisRampMode Parameter and the DefaultAxisRampType Parameter. This M-code operates synchronously, so the program line that the M4 M-code is specified on will execute until the spindle axis has accelerated to the commanded spindle speed.

M103 M-code: Start Spindle Motion in the Clockwise Direction Asynchronously

Use the M103 M-code to cause the spindle axis that is configured for the task to start rotating in the clockwise direction.

Syntax M103
Examples M103

The acceleration behavior of the spindle axis depends on the DefaultAxisRampMode Parameter and the DefaultAxisRampType Parameter. This M-code operates asynchronously, so the program will continue executing more lines after a line containing the M103 M-code without waiting for the spindle axis to reach its full speed.

M104 M-code: Start Spindle Motion in the Counterclockwise Direction Asynchronously

Use the M104 M-code to cause the spindle axis that is configured for the task to start rotating in the counterclockwise direction.

Syntax M104
Examples M104

The acceleration behavior of the spindle axis depends on the DefaultAxisRampMode Parameter and the DefaultAxisRampType Parameter. This M-code operates asynchronously, so the program will continue executing more lines after a line containing the M104 M-code without waiting for the spindle axis to reach its full speed.

M5 M-code: Disable Spindle Motion

Use the M5 M-code to disable spindle motion.

Syntax M5
Examples M5

The M5 M-code will cause the spindle axis to decelerate to zero velocity, using the DefaultAxisRampMode Parameter and the DefaultAxisRampType Parameter to configure the operation of the deceleration. After the spindle axis reaches a speed of zero, the controller will disable the axis.

Manual Spindle Override (MSO) Configuration

Use the M50 and M51 M-codes to configure the behavior of manual spindle override (MSO).

Syntax M50

M51

Examples M50

M51

The M50 and M51 M-codes determine if MSO has an effect on the spindle. For more information about setting MSO, refer to the TaskMso() function in MSO.

M50 M-code: Disable Manual Spindle Override

Use the M50 M-code to disable the usage of the manual spindle override (MSO) mode for the spindle axis that is configured for the task. This mode causes the controller to disable the M51 mode and set the Mso Lock bit of the TaskMode task status item.

M51 M-code: Enable Manual Spindle Override

Use the M51 M-code to enable the usage of manual spindle override (MSO) mode for the spindle axis that is configured for this task. This mode is the default. This mode causes the controller to disable the M50 mode and clear the Mso Lock bit of the TaskMode task status item.

Manual Feedrate Override (MFO) Configuration

Use the M48 and M49 M-codes to configure the behavior of manual feedrate override (MFO).

Syntax M48

M49

Examples M48

M49

The M48 and M49 M-codes determine if MFO has an effect on motion. For more information about setting MFO, refer to TaskMfo() function in MFO.

M48 M-code: Disable Manual Feedrate Override

Use the M48 M-code to disable the use of manual feedrate override. This mode causes the controller to disable the M49 mode and set the Mfo Lock bit of the TaskMode task status item.

M49 M-code: Enable Manual Feedrate Override

Use the M49 M-code to enable the use of manual feedrate override (MFO), that you disabled with the M48 M-code, on the task. This mode causes the controller to clear the Mfo Lock bit of the TaskMode task status item. This is the default mode.

Custom G-codes and M-codes

You can add custom G-codes and M-codes to the G-codes and M-codes in the Aerotech G-code dialect. With custom G-codes and M-codes, you can use G-code syntax to execute a custom AeroScript routine.

Defining Custom G-codes and M-codes

Use the syntax that follows to define a custom G-code or M-code.

gcode G<integer>
    <body>
end
gcode G<integer>.<integer>
    <body>
end
gcode M<integer>
    <body>
end
gcode M<integer>.<integer>
    <body>
end

If you define a custom G-code or M-code by using the G<integer> or M<integer> syntax, the integer value that you specify must be in the range of 0 to 4,294,967,295. If you define a custom G-code or M-code by using the G<integer>.<integer> or M<integer>.<integer> syntax, the two integer values that you specify must be in the range of 0 to 65,535.

The body of the custom G-code or M-code must include the set of AeroScript instructions that the controller will execute when the custom G-code or M-code is invoked. The example that follows shows the definitions of custom G-codes and custom M-codes.

gcode G300
    MoveLinear(X, 10)
end

gcode G300.1 
    MoveLinear(X, -10)
end
						
gcode M450
    Enable([A, B, C])
    Home([A, B, C])
end

gcode M2.1
    Abort(X)
    WaitForMotionDone(X)
    Disable(X)
    ProgramExit()
end

The G-code or M-code that you specify with the gcode keyword cannot be the same as a G-code or M-code in the Aerotech G-code dialect or a custom G-code or M-code that is defined in your program. You can use the #define preprocessor directive to redefine a G-code or M-code in the Aerotech G-code dialect or a custom G-code or M-code that is defined in your program. The example that follows shows the definitions of custom G-codes and custom M-codes that redefine G-codes and M-codes in the Aerotech G-code dialect.

// Redefine G4 to dwell for the number of milliseconds specified by the P argument.
// For example, the G4 P1.0 command will dwell for 1 millisecond instead of 1 second.
#define G4 G1004
gcode G1004
    Dwell(argument(P) / 1000.0)
end

// Redefine M2 to stop the program on the task specified by the P argument.
// For example, the M2 P2 command will stop the program running on Task 2.
#define M2 M1002
gcode M1002
    ProgramStop(argument(P))
end

Custom G-codes and M-codes can also be added to libraries. These are created the same way as library functions. See Libraries for more information. The example that follows shows how to add a custom G-code to a library.

library gcode G500
    Enable([X, Y])
    Home([X, Y])
    MoveLinear([X, Y], [10, 10])
end

Invoking Custom G-codes and M-codes

To invoke custom G-codes and M-codes in an AeroScript program, specify the G-codes and M-codes on a program line. The example that follows shows how to invoke the AeroScript procedure defined by the custom M450 M-code from the previous example.

M450

You must specify custom G-codes and M-codes first on a program line. If you specify a custom G-code or M-code on a program line, then you cannot specify a different G-code or M-code on the same line.

Passing Arguments to Custom G-codes and M-code

You can pass one or more arguments when you use a custom G-code or M-code. Each argument that you specify must be a pair that consists of a name and a real value. The name can be the name of an axis or one of these letters: E, F, I, J, K, P, Q, R, S, T. The example that follows invokes a custom M412 M-code with arguments.

M412 P10.5 Q21.3 R46.2

The AeroScript code in the body of a custom G-code or M-code can access the arguments that were passed to that G-code or M-code when it is used.

argument() Function

Use the built-in argument() function to get the real value from the argument that has a given name.

gcode M500
    $rglobal[0] = argument(X)
end

// Sets $rglobal[0] to 15.5
M500 X15.5

A task error will occur if you call the argument() function with a name that does not match any of the arguments that were specified with the G-code or M-code.

gcode M600
    $rglobal[0] = argument(X)
end

// M600 expects an argument named X, so a task error will occur
M600

defined() Function

Use the built-in defined() function to see if the argument that has a given name was specified with the G-code or M-code. You can use this function to prevent the task error that occurs if you call the argument() function with a name that does not match the name of one of the specified arguments.

gcode M200
    if defined(F)
        $rglobal[5] = argument(F)
    else
        // Argument F was not specified
    end
end

Custom T-Codes

In addition to custom G-codes and M-codes, you can add custom T-codes to the Aerotech G-code dialect. You can use custom T-codes to create a custom AeroScript routine that you can execute by using the T command. You can also use custom T-codes to make an implementation of a tool selection routine together with a custom tool table definition. For an example of how to use custom T-codes, see the Tool Table Example Program.

IMPORTANT: If you want to use T commands in the Aerotech G-code dialect, you must define one custom T-code in an AeroScript program or library. If no custom T-code is defined or two or more custom T-codes are defined, a compiler error will occur.

Defining Custom T-Codes

To define a custom T-code, use the syntax that follows:

gcode T
    <body>
end

The body of the custom T-code must include the set of AeroScript instructions that the controller will execute when the custom T-code is invoked. The example that follows shows you how to define a custom T-code body:

gcode T
    Home(X)
    Disable(X)
end

You can also add custom T-codes to libraries. These are created with the same method as library functions. See Libraries for more information. The example that follows shows you how to add a custom T-code to a library:

library gcode T
    Home(X)
    Disable(X)
end

If a custom T-code is currently defined in your program or in an imported library, you cannot define more custom T-codes. Thus, you can have only one custom T-code in scope at a time in any AeroScript program. Because of this, you must be careful when you define a T-code in an auto-import library. When you do this, it causes the T-code to become accessible to all of the AeroScript programs on the controller. It also prevents you from defining more custom T-codes in any of the AeroScript programs on the controller.

IMPORTANT: Use Program Automation to load only one compiled library that defines a custom T-code onto the controller. If you try to load two or more compiled libraries that have a custom T-code, it will cause an error to occur when you try to reset the controller. To stop this error from occurring, you must remove the compiled libraries from Program Automation.

Invoking Custom T-Codes

To invoke custom T-codes in an AeroScript program, you must specify a G-code T-letter and an integer argument on a program line. The example that follows shows you how to invoke the AeroScript procedure that is defined by the custom T-code in the previous example:

T10

It is not necessary for the specified integer argument to be an integer literal. The argument can be any integer expression. The example that follows shows more ways that you can invoke a custom T-code:

T(5+5)
T=10
T$iglobal[0]

If you want to cause different AeroScript code to be invoked when you specify an argument, use the #define preprocessor directive to redefine the T command for that argument. The example that follows shows you how to redefine T20 so that it does not invoke a custom a custom T-code:

#define T20 Enable(Y)

gcode T
    // ...
end

// T20 will invoke Enable(Y).
T20
// T10 will invoke the custom T-code body.
T10

You can specify custom T-codes in any order that is relative to other G-code commands on a program line.

IMPORTANT: Do not specify T-codes on the same line as:

  • Custom G-codes or M-codes
  • Other T-codes
  • G-codes that must be specified on their own program line

If you do this, a compiler error will occur.

For more information about the execution order of two or more G-code commands on a program line, see G-Code (RS-274) Support.

Accessing Integer Arguments Passed to Custom T-Codes

As mentioned previously, you must invoke custom T-codes with only one integer argument. In order to access the integer argument, use the built-in argument() function with the special G-code letter T syntax.

gcode T
    var $toolNum as integer = argument(T)

    if $toolNum <= 10
        $iglobal[0] = $toolNum
    elseif $toolNum <= 50
        $iglobal[1] = $toolNum
    else
        $iglobal[2] = $toolNum
    end
end

// $iglobal[0] will be equal to 10 after this program line.
T10
// $iglobal[1] will be equal to 25 after this program line.
T25
// $iglobal[2] will be equal to 99 after this program line.
T99

When you use a custom T-code body, it must include a call to the argument() function with the G-code letter T. You must use this call with T because it is the only method you can use to access the required integer argument.

IMPORTANT: If a custom T-code body has a call to the argument() function that uses a G-code letter that is not T, a compiler error will occur. If a custom T-code body does not contain a call to the argument() function with T, a compiler warning will occur.

To see if the integer argument is currently defined, use the defined() function in a custom T-code body. This function gives you more information for custom G-codes and M-codes than it does for custom T-codes. This occurs because custom T-codes must be invoked with the integer argument. If you invoke a T-code without an integer argument that follows, then a compiler error will occur. If the body of the custom T-code was invoked, the integer argument will be defined.

If you use a custom T-code body with a call to the defined() function, it must use the G-code letter T.

IMPORTANT: If a custom T-code body has a call to the defined() function that uses a G-code letter that is not T, a compiler error will occur.

Related Topics 

Acceleration and Deceleration Ramping

G-Code (RS-274) Support

G-Code Example Program

Tool Table Example Program