Skip to content

Commit

Permalink
Streamlined Validation G Code
Browse files Browse the repository at this point in the history
  • Loading branch information
will1742 committed Jun 18, 2021
1 parent c070d39 commit eb82fe1
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions Haas_Next_Generation/haas vf2.cps
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,11 @@ function onSection() {
writeRetract(Z);
}
}

// 6/18/21 | Gavin Williams | will1742
// Terminate any media that may have been active at beginning of section
// Issue 001: Input and validation
cancelMedia();

if (insertToolCall || operationNeedsSafeStart) {
Expand Down Expand Up @@ -2343,6 +2348,7 @@ function onSection() {
}
}

writeComment("BEGIN VALIDATION SECTION")
// Added 06/15/21 | Gavin Williams | will1742
// Verifies tool-stock distance. Post fails if tool fails clearance standards
var toolDistance = initialPosition.z - stockTopZ;
Expand All @@ -2353,42 +2359,59 @@ function onSection() {
if (toolDistance == Infinity) {
throw "Error: invalid tool distance. Contact a TA.";
}
// asks user if height is accurate
var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['Y', 'N']);

// if correct, carry on
writeln("N" + gotoRef[0][1] + " GOTO" + sequenceNumber);
// Prompt user to check stock-tool distance
displayMedia("Net Share/checkDistance.png");

// Allow door to be opened
linePrint("M0" + " (Halt program)");
displayMedia("Net Share/arrowDown.png");

// asks user if measured height is accurate to displayed
var gotoRef = takeInput(("Is the tool " + toolDistance.toPrecision(3) + "in from the stock? [Y/N]"), ['N', 'Y']);

// Create GOTO cases for Y/N selection, halt if N
getTA("getTAWarning.png", gotoRef[0][1], onSecGotoRef);

writeComment("END VALIDATION SECTION")

// initialize spindle and engage coolant if heights are correct
writeln("N" + gotoRef[1][1] + " M" + (tool.clockwise ? 3 : 4) + " (Restart spindle)");

// if incorrect stop program and call for TA
getTA(gotoRef[1][1], onSecGotoRef);
// Modified 06/09/21 | Gavin Williams | will1742
// Issue 000 Init coolant after positioning
setCoolant(tool.coolant);


// define subprogram
subprogramDefine(initialPosition, abc, retracted, zIsOutput);
}

// print with sequence number
function linePrint(message) {
writeln("N" + sequenceNumber + " " + message);
sequenceNumber += getProperty("sequenceNumberIncrement");
}

// Added 6/14/21 | Gavin Williams | will1742
// Issue 001 Input and Validation
// Displays a file: MP4, MOV, PNG, JPEG. 1920x1080
// Input: Absolute path to file
function displayMedia(file) {
writeln("N" + sequenceNumber + " M130 (" + file + ")");
sequenceNumber += getProperty("sequenceNumberIncrement");
linePrint("M130 (" + file + ")");
}

// Ends displayed media
function cancelMedia() {
writeln("N" + sequenceNumber + " M131 (End Media)");
sequenceNumber += getProperty("sequenceNumberIncrement");
linePrint("M131" + " (End multimedia)");
}

// Added 6/14/21 | Gavin Williams | will1742
// Issue 001 Input and Validation
// Takes input from the user
// Input: string prompt, will be displayed to users
// char array options, capital letters accepted as input
// int opSeqNum, optional arg to init prompt at specific value
// Output: 2D array [Letter, Coorresponding GOTO]
// EX: [Y, 56][N, 57]
var macroNumber = 500;
Expand All @@ -2397,17 +2420,16 @@ function takeInput(prompt, options) {
// Cycle through macro variables, reset at end of general purpose vars
if (macroNumber > 549) macroNumber = 500;
// init var to 0
writeln("#" + macroNumber + "=0");
// init macro var to 0
writeln("#" + macroNumber + "=0" + " (Initialize macro variable)");
// disply prompt and save response
writeln("N" + sequenceNumber + " M109 " + "P" + macroNumber + " (" + prompt + ")");
var gotoRef = sequenceNumber;
// wait for input
writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + gotoRef)
writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + gotoRef + " (NULL)");
// TODO: Line number and GOTO optimization
// print if's and goto's
var gotoMap =[];
var gotoInc = 1;
Expand All @@ -2417,12 +2439,13 @@ function takeInput(prompt, options) {
gotoInc += 1;
});

// adjust sequence number if needed
for (i = 5; i < gotoInc; i+=5) {
sequenceNumber += getProperty("sequenceNumberIncrement");
}

// return to input until valid option is entered
writeln("GOTO" + gotoRef)
writeln("GOTO" + gotoRef + " (INVALID INPUT)")

// increase var number, iterate sequence number
macroNumber += 1;
Expand All @@ -2433,10 +2456,11 @@ function takeInput(prompt, options) {
// Added 06/15/21 | Gavin Williamas | will1742
// Issue 001 Input and validation
// Halts program until TA arrives. Returns to beginning of onSection
function getTA(seqNum, gotoRef) {
writeln("N" + seqNum + " G53 G0 Z0.");
var conRef = takeInput("GET A TA", ['X'])
writeln("N" + conRef[0][1] + " GOTO" + gotoRef + " (Return to beginning of operation)");
function getTA(file, seqNum, gotoRef) {
writeln("N" + seqNum + " G53 G0 Z0." + " (Retract spindle)");
writeln("M130 (" + file + ")");
writeln("M0" + " (Halt program)");
writeln("GOTO" + gotoRef + " (Return to beginning of operation)");
}

function onDwell(seconds) {
Expand Down

0 comments on commit eb82fe1

Please sign in to comment.