From 7bfeb3fa450fe0faa72f1a2a4a5341a7498c6701 Mon Sep 17 00:00:00 2001 From: will1742 Date: Tue, 22 Jun 2021 12:21:07 -0400 Subject: [PATCH] Formatting and code cleaning --- Haas_Next_Generation/haas vf2.cps | 130 ++++++++++++++---------------- 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/Haas_Next_Generation/haas vf2.cps b/Haas_Next_Generation/haas vf2.cps index 507b1c1..9cfd763 100644 --- a/Haas_Next_Generation/haas vf2.cps +++ b/Haas_Next_Generation/haas vf2.cps @@ -400,6 +400,46 @@ properties = { } }; */ +staticProperties = { + machineModel: "none", + safePositionMethod: "G53", + hasAAxis: "false", + hasBAxis: "false", + hasCAxis: "false", + useDPMFeeds: false, + useTCPC: true, + useDWO: true, + safeStartAllOperations: true, + preloadTool: true, + chipTransport: true, + optionalStop: true, + separateWordsWithSpace: true, + useRadius: false, + useParametricFeed: true, + useG0: true, + useG187: false, + homePositionCenter: false, + optionallyCycleToolsAtStart: false, + measureToolsAtStart: true, + forceHomeOnIndexing: true, + toolBreakageTolerance: 0.1, + fastToolChange: false, + useG95forTapping: false, + safeRetractDistance: 0, + useSubroutines: "allOperations", //allOperations + writeMachine: false, + writeTools: true, + writeVersion: false, + showSequenceNumbers: true, + sequenceNumberStart: 10, + sequenceNumberIncrement: 5, + sequenceNumberOnlyOnToolChange: false, + showNotes: true, + useM130PartImages: false, + useM130ToolImages: false, + coolantPressure: "", + singleResultsFile: true + }; var singleLineCoolant = false; // specifies to output multiple coolant codes in one line rather than in separate lines // samples: @@ -417,48 +457,6 @@ var coolants = [ {id: COOLANT_OFF, off: 9} ]; -staticProperties = { -// TODO convert to single var - machineModel: "none", - safePositionMethod: "G53", - hasAAxis: "false", - hasBAxis: "false", - hasCAxis: "false", - useDPMFeeds: false, - useTCPC: true, - useDWO: true, - safeStartAllOperations: true, - preloadTool: true, - chipTransport: true, - optionalStop: true, - separateWordsWithSpace: true, - u1eRadius: false, - useParametricFeed: true, - useG0: true, - useG187: false, - homePositionCenter: false, - optionallyCycleToolsAtStart: false, - measureToolsAtStart: true, - forceHomeOnIndexing: true, - toolBreakageTolerance: 0.1, - fastToolChange: false, - useG95forTapping: false, - safeRetractDistance: 0, - useSubroutines: "allOperations", //allOperations - writeMachine: false, - writeTools: true, - writeVersion: false, - showSequenceNumbers: true, - sequenceNumberStart: 10, - sequenceNumberIncrement: 5, - sequenceNumberOnlyOnToolChange: false, - showNotes: true, - useM130PartImages: false, - useM130ToolImages: false, - coolantPressure: "", - singleResultsFile: true -}; - // old machines only support 4 digits var oFormat = createFormat({width:5, zeropad:true, decimals:0}); var nFormat = createFormat({decimals:0}); @@ -561,7 +559,7 @@ var hasB = false; var hasC = false; var measureTool = false; var cycleReverse = false; -probeMultipleFeatures = true; +var probeMultipleFeatures = true; var maximumSpindleRPM = 15000; var homePositionCenter = false; @@ -1150,7 +1148,6 @@ function onOpen() { if (staticProperties.measureToolsAtStart) { writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6)); //Changes Tool writeBlock(mFormat.format(0), formatComment("Load Tool")); //Pause until operator loads tool - //writeToolMeasureOPT(tool); writeToolMeasureBlock(tool, true); } else { writeToolCycleBlock(tool); @@ -2088,7 +2085,6 @@ function onSection() { forceAny(); // Added 06/15/21 | Gavin Williams | Will1742 - // var onSecGotoRef = sequenceNumber; if (operationNeedsSafeStart) { @@ -2411,7 +2407,6 @@ 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; if (toolDistance < 1) { throw "Error: Clearance height must be greater than 1 inch from stock"; } @@ -2419,11 +2414,10 @@ function onSection() { if (toolDistance == Infinity) { throw "Error: invalid tool distance. Contact a TA."; } + var toolDistance = initialPosition.z - stockTopZ; // Prompt user to check stock-tool distance displayMedia("Net Share/Media/checkDistance.png"); - - // Allow door to be opened writeBlock(mFormat.format(0), formatComment("Open door")); displayMedia("Net Share/Media/arrowDown.png"); @@ -2431,18 +2425,14 @@ function onSection() { 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("Net Share/Media/TAWarning.png", gotoRef[0][1], onSecGotoRef); - + getTA("Net Share/Media/TAWarning.png", gotoRef['N'], onSecGotoRef); + writeWords("N" + nFormat.format(gotoRef['Y']), mFormat.format(131), formatComment("End Multimedia")); writeComment("END VALIDATION SECTION") + // initialize spindle and engage coolant if heights are correct - writeln("N" + nFormat.format(gotoRef[1][1]) + " " + mFormat.format(131) + " " + formatComment("End Multimedia")); writeBlock(mFormat.format((tool.clockwise ? 3 : 4)), formatComment("Restart spindle")); - - // Modified 06/09/21 | Gavin Williams | will1742 - // Issue 000 Init coolant after positioning setCoolant(tool.coolant); - // define subprogram subprogramDefine(initialPosition, abc, retracted, zIsOutput); } @@ -2455,8 +2445,6 @@ function displayMedia(file) { writeBlock(mFormat.format(130), formatComment(file)); } -// Ends displayed media - // TODO: switch to map for gotoref // Added 6/14/21 | Gavin Williams | will1742 // Issue 001 Input and Validation @@ -2464,7 +2452,7 @@ function displayMedia(file) { // 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] +// Output: 2D dict {Letter, Coorresponding GOTO} // EX: [Y, 56][N, 57] var macroNumber = 500; function takeInput(prompt, options) { @@ -2473,31 +2461,33 @@ function takeInput(prompt, options) { if (macroNumber > 549) macroNumber = 500; // init macro var to 0 - writeln("#" + macroNumber + "=0" + " " + formatComment("Initialize macro variable")); + writeWords("#" + macroNumber + "=0", formatComment("Initialize macro variable")); // disply prompt and save response writeBlock(mFormat.format(109), "P" + nFormat.format(macroNumber), formatComment(prompt)); - var gotoRef = sequenceNumber - staticProperties.sequenceNumberIncrement; + sequenceNumber -= staticProperties.sequenceNumberIncrement; + var gotoRef = sequenceNumber; // wait for input writeln("IF[#" + macroNumber + " EQ 0.] GOTO" + nFormat.format(gotoRef) + " " + formatComment("NULL")); // print if's and goto's - var gotoMap =[]; + var gotoMap = {}; var gotoInc = 1; options.forEach(function (element) { - writeln("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc) + " (" + element + ")"); - gotoMap.push([element, (sequenceNumber + gotoInc)]); + writeWords("IF[#" + macroNumber + " EQ " + element.charCodeAt(0) + ".] GOTO" + nFormat.format(sequenceNumber + gotoInc), formatComment(element)); + gotoMap[element] = (sequenceNumber + gotoInc); gotoInc += 1; }); + var incNum = staticProperties.sequenceNumberIncrement; // adjust sequence number if needed - for (i = 5; i < gotoInc; i+=5) { + for (i = incNum; i < gotoInc; i+=incNum) { sequenceNumber += staticProperties.sequenceNumberIncrement; } // return to input until valid option is entered - writeln("GOTO" + nFormat.format(gotoRef) + " " + formatComment("INVALID INPUT")) + writeWords("GOTO" + nFormat.format(gotoRef), formatComment("INVALID INPUT")) // increase var number, iterate sequence number macroNumber += 1; @@ -2509,12 +2499,12 @@ function takeInput(prompt, options) { // Issue 001 Input and validation // Halts program until TA arrives. Returns to beginning of onSection function getTA(file, seqNum, gotoRef) { - writeln("N" + nFormat.format(seqNum) + " " + - gFormat.format(53) + " " + gFormat.format(0) + " " + zOutput.format(0.) + " " + + writeWords("N" + nFormat.format(seqNum), + gFormat.format(53), gFormat.format(0), zOutput.format(0.), formatComment("Retract spindle")); - writeln(mFormat.format(130) + " " + formatComment(file)); - writeln(mFormat.format(0) + " " + formatComment("Halt Program")); - writeln("GOTO" + nFormat.format(gotoRef) + " " + formatComment("Return to beginning of operation")); + writeWords(mFormat.format(130), formatComment(file)); + writeWords(mFormat.format(0), formatComment("Halt Program")); + writeWords("GOTO" + nFormat.format(gotoRef), formatComment("Return to beginning of operation")); } function onDwell(seconds) {