gcmc - G-Code Meta Compiler

Library functions


canned_drill.inc.gcmc

undef canned_drill ( vectorlist:holelist, scalar:retractz, scalar:dw, scalar:oldz )
holelist vectorlist [distance] Vectors pointing to the holes to drill
retractz scalar [distance] Z-axis retract level (R-plane)
dw scalar [none] Dwell time at bottom of hole if ≥0. No dwell is performed if <0
oldz scalar [none] Boolean to indicate if retract should return to original Z
Perform a canned drilling cycle with optional dwelling at the bottom of the hole. The position of the holes are set by the holelist argument where holelist[0] must include a Z-coordinate to set the drilling depth. Each vector in holelist may include X-, Y- or both XY-coordinates to set the position of each drill-hole. An optional Z-coordinate for each vector in holelist may set a new drilling depth for the following hole(s).

The retractz argument sets the R-plane. The R-plane defines the Z-level at which further down-movement is performed at the current feedrate. The actual retraction point depends on oldz, where true means full retraction to the Z-level before the canned_drill() function was called. Setting oldz to false retracts to the R-plane after each drilling sequence. The retractz level is used instead of the original Z-level if the original Z-level was below the R-plane.

The canned_drill() function calls pathmode(1) to set exact path mode before attempting any movement.

undef canned_drill_peck ( vectorlist:holelist, scalar:retractz, scalar:incr, scalar:oldz )
holelist vectorlist [distance] Vectors pointing to the holes to drill
retractz scalar [distance] Z-axis retract level (R-plane)
incr scalar [distance] Incremental drilling depth; must be >0
oldz scalar [none] Boolean to indicate if retract should return to original Z
Perform a canned peck-drilling cycle with incr denoting the incremental down-move distance before clearing the hole. The position of the holes are set by the holelist argument where holelist[0] must include a Z-coordinate to set the drilling depth. Each vector in holelist may include X-, Y- or both XY-coordinates to set the position of each drill-hole. An optional Z-coordinate for each vector in holelist may set a new drilling depth for the following hole(s).

The retractz argument sets the R-plane. The R-plane defines the Z-level to reach to clear the hole. The final retraction point depends on oldz, where true means full retraction to the Z-level before the canned_drill_peck() function was called. Setting oldz to false retracts to the R-plane after each drilling sequence. The retractz level is used instead of the original Z-level if the original Z-level was below the R-plane.

The canned_drill_peck() function calls pathmode(1) to set exact path mode before attempting any movement.

Canned drilling examples

See also the distribution's example file example/canned.gcmc.
include("canned_drill.inc.gcmc");

homepos = [0mm, 0mm, 0mm];
initpos = [-1mm, -1mm, 10mm];	/* Somewhere to start */

retract = 5.0mm;		/* R-plane level */
incr = 2.2mm;			/* Peck increment */

feedrate(100);

goto(homepos);
move(homepos);	/* Just to let LinuxCNC show a line in the preview */

/* A set of holes */
holes = {
	[10mm, 0mm, -5mm],	/* First hole at 10,0 depth -1 */
	[15mm],			/* Second hole at X=15 same Y and depth */
	[20mm],
	[25mm],
	[-, 5mm],		/* Move only in Y */
	[20mm],
	[15mm, -, -6mm],	/* Set new drilling depth */
	[10mm]
};

goto(initpos);
canned_drill(holes, retract, -1, 0);	/* Drill a set of holes */

/* Set a new set of holes with explicit coordinates */
holes = {
	[10mm, 20mm, -5mm],
	[15mm, 20mm],
	[20mm, 20mm],
	[25mm, 20mm],
	[25mm, 25mm],	
	[20mm, 25mm],
	[15mm, 25mm, -6mm],
	[10mm, 25mm]
};

goto(initpos + [-, 20]);
canned_drill_peck(holes, retract, incr, 1);	/* Peck-drilling */

goto(head(homepos, 2));
goto(homepos);

tracepath.inc.gcmc

undef tracepath ( vectorlist:path, scalar:z, scalar:dw )
path vectorlist [distance] Vectors pointing to the XY positions to visit
z scalar [distance] Cutting plane Z-level
dw scalar [none] Dwell time at bottom each point if ≥0. No dwell is performed if <0
Cut a path at depth z following all points as defined by path. The tracepath() function performs a preliminary movement to path[0] at the current Z-level, moves to cutting depth according to the z argument, visits each vector of path and finally retracts to original Z-level.

A dwell of length dw is performed at each point in the path if it is ≥0. Any negative value of dw will suppress dwelling.

Tracepath example

include("tracepath.inc.gcmc");

starpath = {
	[ 1,  1], [ 0,  3],
	[-1,  1], [-3,  0],
	[-1, -1], [ 0, -3],
	[ 1, -1], [ 3,  0]
};

SAFEZ = [0mm, 0mm, 1mm];

feedrate(100);
goto(SAFEZ);

starpath *= 10mm;	/* Scale the star */

tracepath(starpath, -1mm, -1);

goto(SAFEZ);

tracepath_comp.inc.gcmc

undef tracepath_comp ( vectorlist:path, scalar:width, scalar:flags )
path vectorlist [distance] Vectors pointing to the XY positions to visit.
width scalar [distance] Compensation distance
flags scalar [none] Binary flags or'ed together to set the operational mode:
TPC_CLOSEDInterpret path as being closed (path[0] and path[-1] are connected)
TPC_KEEPZDon't move on Z-axis and ignore all Z-coordinates of the path
TPC_OLDZReturn to Z-coordinate where it was before calling the function
TPC_LEFTTrace at left side of path
TPC_RIGHTTrace at right side of path (default)
TPC_ARCINArc in-to the path
TPC_ARCOUTArc out-of the path
TPC_QUIETDon't warn on unreachable inside corners
Cut the path at a tool-compensated distance of width at the left or right side of the path. The right side, set by flag TPC_RIGHT, is seen as being right from a path that moves in positive Y-direction. The left side, set by flag TPC_LEFT, is consequently on the left from a path moving in positive Y-direction.

The cutting depth is set by the Z-coordinate of the first entry at path[0]. Subsequent path entries may contain same or different Z-coordinates. All Z-coordinates will be ignored when flag TPC_KEEPZ is set and no Z-axis movement is performed. The Z-coordinate at function-entry will be restored with a rapid when the TPC_OLDZ flag is set

Entry and exit of the path is controlled by the TPC_ARCIN and TPC_ARCOUT flags. The path is entered with a 90 degree arc to the normal at the first point and exited with a 90 degree arc from the normal at the last point respectively. The arc's radius is equal to width. If the flag is unset, then a linear, perpendicular to the segment, move is performed of length width.

Internal corners which are too small to enter will be deleted from the path and a warning is issued, unless the TPC_QUIET is set. Entering and exiting a closed path on a corner of <180 degrees will result in a warning because the entry and exit positions will cause an inward cut less than width. Co-linear segments are combined into a single segment. A warning is emitted if a Z-axis change is detected on to points with equal X- and Y-coordinates.

Note: Only one point look-ahead is performed on calculations and segments. Therefore, unreachable internal pockets and angles are not detected if hidden beyond one point look-ahead. You should always check the result before accepting it.

Tool-compensated trace example

include("tracepath_comp.inc.gcmc");

starpath = {
	[ 0,  3], [-1,  1],
	[-3,  0], [-1, -1],
	[ 0, -3], [ 1, -1],
	[ 3,  0], [ 1,  1]
};

HOME = [0.0mm, 0.0mm, 1.0mm];

feedrate(100);
goto(HOME);
move(HOME);			// To visualize following rapids

starpath *= 10.0mm;		// Scale the star

// Show original path as rapids
foreach(starpath; v) {
	goto(v);
}

starpath[0][2] = -1.0mm;	// Set the cutting depth
tracepath_comp(starpath, 2.0mm, TPC_OLDZ|TPC_RIGHT|TPC_ARCIN|TPC_ARCOUT|TPC_CLOSED);

goto(HOME);