Skip to content

Commit

Permalink
Basic Gantry Tool Probing
Browse files Browse the repository at this point in the history
  • Loading branch information
will1742 committed Jul 19, 2021
1 parent b9e19b6 commit 25de4df
Showing 1 changed file with 145 additions and 7 deletions.
152 changes: 145 additions & 7 deletions Haas_Gantry_BIDC/Bechtel SR.cps
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ properties = {
title: "Parametric feed",
description: "Parametric feed values based on movement type are output.",
type: "boolean",
value: false,
value: true,
scope: "post"
},
showNotes: {
Expand All @@ -146,7 +146,7 @@ properties = {
title: "Use G0",
description: "Specifies that G0s should be used for rapid moves when moving along a single axis.",
type: "boolean",
value: false,
value: true,
scope: "post"
},
safePositionMethod: {
Expand All @@ -171,7 +171,7 @@ properties = {
{title: "Cycles", id: "cycles"},
{title: "Patterns", id: "patterns"}
],
value: "none",
value: "allOperations",
scope: "post"
},
useG187: {
Expand Down Expand Up @@ -199,7 +199,7 @@ properties = {
title: "Optionally measure tools at start",
description: "Measure each tool used at the beginning of the program when block delete is turned off.",
type: "boolean",
value: false,
value: true,
scope: "post"
},
toolBreakageTolerance: {
Expand Down Expand Up @@ -278,6 +278,30 @@ var coolants = [
{id: COOLANT_OFF, off: 9}
];

const HAAS_DRILL = 1;
const HAAS_TAP = 2;
const HAAS_SHELL = 3;
const HAAS_END_MILL = 4;
const HAAS_CENTER = 5;
const HAAS_BALL_NOSE = 6;
const HAAS_PROBE = 7;

const NO_PROBING = 0;
const LEN_ROT = 1;
const LEN_NON_ROT = 2;
const LEN_DIA_ROT = 3;

const DEFAULT_HAAS_K_FACTOR = 0.05;
const NULL_HAAS_K_FACTOR = 0;

const CLEARANCE_HEIGHT = 1;
const LENGTH_TOLERANCE = .25;
const DIAM_TOLERANCE = .01;

const TOOL_CHANGE_X = -9.;
const TOOL_CHANGE_Y = -50.;
const G53RETRACT_Z = 3.6;

// old machines only support 4 digits
var oFormat = createFormat({width:5, zeropad:true, decimals:0});
var nFormat = createFormat({decimals:0});
Expand Down Expand Up @@ -442,6 +466,10 @@ function writeComment(text) {
writeln(formatComment(text.substr(0, maximumLineLength - 2)));
}

function displayMedia(file) {
writeBlock(mFormat.format(130), formatComment(file));
}

/**
Returns the matching HAAS tool type for the tool.
*/
Expand Down Expand Up @@ -500,6 +528,79 @@ function getHaasProbingType(toolType, use9023) {
}
}

function getHaasToolTypeBIDC(toolType) {
switch (toolType) {
case TOOL_DRILL:
case TOOL_REAMER:
return HAAS_DRILL; // drill
case TOOL_TAP_RIGHT_HAND:
case TOOL_TAP_LEFT_HAND:
return HAAS_TAP; // tap
case TOOL_MILLING_FACE:
case TOOL_MILLING_SLOT:
case TOOL_BORING_BAR:
return HAAS_SHELL; // shell mill
case TOOL_MILLING_END_FLAT:
case TOOL_MILLING_END_BULLNOSE:
case TOOL_MILLING_TAPERED:
case TOOL_MILLING_DOVETAIL:
case TOOL_MILLING_THREAD:
return HAAS_END_MILL; // end mill
case TOOL_DRILL_SPOT:
case TOOL_MILLING_CHAMFER:
case TOOL_DRILL_CENTER:
case TOOL_COUNTER_SINK:
case TOOL_COUNTER_BORE:
case TOOL_MILLING_FORM:
return HAAS_CENTER; // center drill
case TOOL_MILLING_END_BALL:
case TOOL_MILLING_LOLLIPOP:
case TOOL_MILLING_RADIUS:
return HAAS_BALL_NOSE; // ball nose
case TOOL_PROBE:
return HAAS_PROBE; // probe
default:
error(localize("Invalid HAAS tool type."));
return -1;
}
}

function formatCNumber(probeType, use9023){
if (use9023) {
if (probeType == LEN_NON_ROT || probeType == LEN_DIA_ROT){
return probeType + 10;
}
return 23;
}
return probeType;
}

function getHaasProbingTypeBIDC(tool, use9023) {
switch (getHaasToolTypeBIDC(tool.type)) {
case HAAS_PROBE:
return formatCNumber(NO_PROBING, use9023);
case HAAS_TAP:
case HAAS_DRILL:
return formatCNumber(LEN_NON_ROT, use9023);
case HAAS_CENTER:
if (tool.type == TOOL_MILLING_FORM) {
return formatCNumber(NO_PROBING, use9023);
}
return formatCNumber(LEN_NON_ROT, use9023);
case HAAS_END_MILL:
return formatCNumber((tool.type == TOOL_MILLING_TAPERED ? LEN_ROT : LEN_DIA_ROT), use9023);
case HAAS_BALL_NOSE:
return formatCNumber((tool.type == TOOL_MILLING_RADIUS ? LEN_ROT : LEN_DIA_ROT), use9023);
case HAAS_SHELL:
if ((tool.type == TOOL_MILLING_FACE) && (tool.taperAngle !=0)) {
return formatCNumber(LEN_ROT, use9023);
}
return formatCNumber(LEN_DIA_ROT, use9023);
default:
return -1;
}
}

function writeToolCycleBlock(tool) {
writeOptionalBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); // get tool
writeOptionalBlock(mFormat.format(0)); // wait for operator
Expand All @@ -520,6 +621,21 @@ function prepareForToolCheck() {
}
}

function BIDCWriteToolMeasureBlock(tool, rotating) {
writeBlock(gFormat.format(43), hFormat.format(tool.number), zOutput.format(tool.bodyLength + tool.holderLength));
if (rotating) {
writeBlock(gFormat.format(59), gFormat.format(0), xOutput.format(0), yOutput.format(tool.diameter/2));
writeBlock(sOutput.format(tool.spindleRPM), mFormat.format(!tool.clockwise ? 3 : 4));
} else {
writeBlock(gFormat.format(59), gFormat.format(0), xOutput.format(0), yOutput.format(0));
}
writeBlock(gFormat.format(37), hFormat.format(tool.number), zOutput.format(0), "F10.");
writeBlock(gFormat.format(91), gFormat.format(0), zOutput.format(.1), "F100.");
writeBlock(gFormat.format(37), hFormat.format(tool.number), zOutput.format(0), "F2.");
onCommand(COMMAND_STOP_SPINDLE);
writeRetract(Z);
}

function writeToolMeasureBlock(tool, preMeasure) {
var writeFunction = measureTool ? writeBlock : writeOptionalBlock;
var comment = measureTool ? formatComment("MEASURE TOOL") : "";
Expand Down Expand Up @@ -614,6 +730,8 @@ function onOpen() {
"O" + oFormat.format(programId) +
conditional(programComment, " " + formatComment(programComment.substr(0, maximumLineLength - 2 - ("O" + oFormat.format(programId)).length - 1)))
);
writeWords(writeComment(getGlobalParameter("username") + ": " + getGlobalParameter("document-path")), writeComment(getGlobalParameter("generated-at")));

lastSubprogram = (initialSubprogramNumber - 1);
} else {
error(localize("Program name has not been specified."));
Expand Down Expand Up @@ -673,6 +791,9 @@ function onOpen() {
var tools = getToolTable();
if (tools.getNumberOfTools() > 0) {
for (var i = 0; i < tools.getNumberOfTools(); ++i) {
// if (tool.number == 1 || tool.number == 2) {
// throw "Tool numbers 1 and 2 are not available."
// }
var tool = tools.getTool(i);
var comment = "T" + toolFormat.format(tool.number) + " " +
"D=" + xyzFormat.format(tool.diameter) + " " +
Expand All @@ -695,14 +816,16 @@ function onOpen() {
if (tools.getNumberOfTools() > 0) {
writeln("");
/*
writeOptionalBlock(mFormat.format(0), formatComment(localize("Read note"))); // wait for operator
writeComment(localize("With BLOCK DELETE turned off each tool will cycle through"));
writeComment(localize("the spindle to verify that the correct tool is in the tool magazine"));
if (getProperty("optionallyMeasureToolsAtStart")) {
writeComment(localize("and to automatically measure it"));
}
writeComment(localize("Once the tools are verified turn BLOCK DELETE on to skip verification"));

*/

for (var i = 0; i < tools.getNumberOfTools(); ++i) {
var tool = tools.getTool(i);
if (getProperty("optionallyMeasureToolsAtStart") && (tool.type == TOOL_PROBE)) {
Expand All @@ -715,9 +838,24 @@ function onOpen() {
comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg");
}
comment += " - " + getToolTypeName(tool.type);
writeComment(tool.description);
writeComment(comment);
if (getProperty("optionallyMeasureToolsAtStart")) {
writeToolMeasureBlock(tool, true);
var probeType = getHaasProbingTypeBIDC(tool, false)
if (!retracted) {
writeRetract(Z);
}
writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool
writeBlock(gFormat.format(10), "L" + 10, "P" + tool.number, "R" + (tool.holderLength + tool.bodyLength).toFixed(4));
if (probeType == 3) {
writeBlock(gFormat.format(10), "L" + 12, "P" + tool.number, "R" + (tool.diameter).toFixed(4));
}
writeRetract(Z);
writeBlock(gFormat.format(53), gFormat.format(0), xOutput.format(TOOL_CHANGE_X), yOutput.format(TOOL_CHANGE_Y));
writeBlock(mFormat.format(0), formatComment("Load Tool " + tool.number)); //Pause until operator loads tool
BIDCWriteToolMeasureBlock(tool, probeType != 2);
// writeToolMeasureBlock(tool, true);
writeln("")
} else {
writeToolCycleBlock(tool);
}
Expand Down Expand Up @@ -3389,7 +3527,7 @@ function writeRetract() {
_xHome = machineConfiguration.hasHomePositionX() ? machineConfiguration.getHomePositionX() : toPreciseUnit(0, MM);
}
_yHome = machineConfiguration.hasHomePositionY() ? machineConfiguration.getHomePositionY() : toPreciseUnit(0, MM);
_zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(0, MM);
_zHome = machineConfiguration.getRetractPlane() != 0 ? machineConfiguration.getRetractPlane() : toPreciseUnit(G53RETRACT_Z, IN);
}
for (var i = 0; i < arguments.length; ++i) {
switch (arguments[i]) {
Expand Down

0 comments on commit 25de4df

Please sign in to comment.