Skip to content

Commit

Permalink
Formatting and code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
will1742 committed Jun 22, 2021
1 parent 3034bbb commit 7bfeb3f
Showing 1 changed file with 60 additions and 70 deletions.
130 changes: 60 additions & 70 deletions Haas_Next_Generation/haas vf2.cps
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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});
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2088,7 +2085,6 @@ function onSection() {
forceAny();

// Added 06/15/21 | Gavin Williams | Will1742
//
var onSecGotoRef = sequenceNumber;

if (operationNeedsSafeStart) {
Expand Down Expand Up @@ -2411,38 +2407,32 @@ 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";
}

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");

// 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("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);
}
Expand All @@ -2455,16 +2445,14 @@ 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
// 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]
// Output: 2D dict {Letter, Coorresponding GOTO}
// EX: [Y, 56][N, 57]
var macroNumber = 500;
function takeInput(prompt, options) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 7bfeb3f

Please sign in to comment.