The G31/G31.X code is a CNC command that is used to perform a probing cycle. A probing cycle is a process of moving the tool or the workpiece until it touches a sensor, such as a touch probe or a tool setter, and then recording the position or the offset of the contact point. Probing cycles are useful for measuring, aligning, calibrating, or inspecting the workpiece or the tool.
Usage Format
The general format of the G31/G31.X code is:
G31 P~ X~ Y~ Z~ F~
or
G31.X P~ X~ Y~ Z~ F~
where:
- G31 or G31.X is the probe function code. The X can be any letter from A to Z, except G, M, N, O, S, and T. The X letter specifies the plane of motion for the probe. For example, G31.Z means the probe will move along the Z-axis only.
- P~ is the parameter number where the probe position will be stored. For example, P100 means the probe position will be stored in parameter #100.
- X~, Y~, Z~ are the coordinates of the target position for the probe. The probe will move towards these coordinates until it touches the sensor or reaches the target position. If the target position is not specified for an axis, the probe will not move along that axis.
- F~ is the feed rate for the probe movement. The feed rate should be set to a low value to avoid damaging the sensor or the workpiece.
Explanation
The G31/G31.X code works as follows:
- The probe function is activated by the G31 or G31.X code.
- The probe moves towards the target position at the specified feed rate.
- If the probe touches the sensor before reaching the target position, the probe function is terminated and the probe position is stored in the specified parameter.
- If the probe reaches the target position without touching the sensor, the probe function is terminated and an alarm is generated.
- The probe function can be canceled by another motion code (such as G00, G01, G02, etc.) or by an M code (such as M00, M01, M02, etc.).
Example
Here is an example of using the G31/G31.X code to measure the diameter of a cylindrical workpiece:
G00 X0 Y0 Z10 ; Move to the center of the workpiece
G31 P100 X50 F100 ; Move the probe along the X-axis until it touches the workpiece and store the position in parameter #100
G00 X0 ; Move back to the center
G31 P101 X-50 F100 ; Move the probe along the negative X-axis until it touches the workpiece and store the position in parameter #101
G00 X0 ; Move back to the center
#102 = #100 - #101 ; Calculate the diameter of the workpiece and store it in parameter #102
#103 = #102 / 2 ; Calculate the radius of the workpiece and store it in parameter #103
G00 Z0 ; Move to the surface of the workpiece
G31 P104 Z-50 F100 ; Move the probe along the negative Z-axis until it touches the workpiece and store the position in parameter #104
G00 Z10 ; Move away from the workpiece
#105 = ABS[#104] ; Calculate the height of the workpiece and store it in parameter #105