Advertisement
Guest User

Config

a guest
Aug 20th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.90 KB | None | 0 0
  1. /**
  2. Copyright (C) 2012-2017 by Autodesk, Inc.
  3. All rights reserved.
  4.  
  5. UCCNC post processor configuration.
  6.  
  7. $Revision: 41369 65a1f6cb57e3c7389dc895ea10958fc2f7947b0d $
  8. $Date: 2017-03-20 14:12:44 $
  9.  
  10. FORKID {9076F4FE-2652-48D2-9DAD-1A22C240A8B8}
  11. */
  12.  
  13. description = "STEPCRAFT UCCNC";
  14. vendor = "UCCNC";
  15. vendorUrl = "http://www.cncdrive.com/";
  16. legal = "Copyright (C) 2012-2017 by Autodesk, Inc.";
  17. certificationLevel = 2;
  18. minimumRevision = 24000;
  19.  
  20. longDescription = "Generic post for STEPCRAFT machines using UCCNC control software. If you are using a fourth axis, make sure to enable either the property 'fourthAxisAroundX' or 'fourthAxisAroundY'. If you have an automatic tool changer, enable the property 'useToolChanger'.";
  21.  
  22. extension = "nc";
  23. setCodePage("ascii");
  24.  
  25. capabilities = CAPABILITY_MILLING;
  26. tolerance = spatial(0.002, MM);
  27.  
  28. minimumChordLength = spatial(0.01, MM);
  29. minimumCircularRadius = spatial(0.01, MM);
  30. maximumCircularRadius = spatial(1000, MM);
  31. minimumCircularSweep = toRad(0.01);
  32. maximumCircularSweep = toRad(90);
  33. allowHelicalMoves = true;
  34. allowedCircularPlanes = 1 << PLANE_XY; // allow only XY circular motion
  35.  
  36.  
  37. // user-defined properties
  38. properties = {
  39. writeMachine: true, // write machine
  40. writeTools: true, // writes the tools
  41. showSequenceNumbers: false, // show sequence numbers
  42. sequenceNumberStart: 10, // first sequence number
  43. sequenceNumberIncrement: 1, // increment for sequence numbers
  44. separateWordsWithSpace: true, // specifies that the words should be separated with a white space
  45. useToolChanger: false, // specifies that a tool changer is available
  46. toolChangePositionX: 0, // specifies the tool change position for X
  47. toolChangePositionY: 0, // specifies the tool change position for Y
  48. fourthAxisAroundX: false, // specifies that a fourth axis is mounted along X
  49. fourthAxisAroundY: false, // specifies that a fourth axis is mounted along Y
  50. useSmoothing: true // specifies to use constant velocity mode
  51. /*referenceRun: true*/ // move to reference point first at the beginning of the program
  52. };
  53.  
  54. var gFormat = createFormat({prefix:"G", decimals:1});
  55. var mFormat = createFormat({prefix:"M", decimals:0});
  56. var hFormat = createFormat({prefix:"H", decimals:0});
  57.  
  58. var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
  59. var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG});
  60. var feedFormat = createFormat({decimals:(unit == MM ? 1 : 2)});
  61. var toolFormat = createFormat({decimals:0});
  62. var rpmFormat = createFormat({decimals:0});
  63. var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-1000
  64. var milliFormat = createFormat({decimals:0}); // milliseconds - range 1-?
  65. var taperFormat = createFormat({decimals:1, scale:DEG});
  66. var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
  67.  
  68. var xOutput = createVariable({prefix:"X"}, xyzFormat);
  69. var yOutput = createVariable({prefix:"Y"}, xyzFormat);
  70. var zOutput = createVariable({prefix:"Z"}, xyzFormat);
  71. var aOutput = createVariable({prefix:"A"}, abcFormat);
  72. var bOutput = createVariable({prefix:"B"}, abcFormat);
  73. var cOutput = createVariable({prefix:"C"}, abcFormat);
  74. var feedOutput = createVariable({prefix:"F"}, feedFormat);
  75. var sOutput = createVariable({prefix:"S", force:true}, rpmFormat);
  76. var pitchOutput = createVariable({prefix:"K", force:true}, pitchFormat);
  77.  
  78. // circular output
  79. var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat);
  80. var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat);
  81. var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat);
  82.  
  83. var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
  84. // var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19
  85. var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
  86. var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94
  87. var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-22
  88. var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ...
  89.  
  90. var WARNING_WORK_OFFSET = 0;
  91.  
  92. // collected state
  93. var sequenceNumber;
  94. var currentWorkOffset;
  95.  
  96. /**
  97. Writes the specified block.
  98. */
  99. function writeBlock() {
  100. if (properties.showSequenceNumbers) {
  101. writeWords2("N" + sequenceNumber, arguments);
  102. sequenceNumber += properties.sequenceNumberIncrement;
  103. } else {
  104. writeWords(arguments);
  105. }
  106. }
  107.  
  108. function formatComment(text) {
  109. return "(" + String(text).replace(/[\[\]]/g, "") + ")";
  110. }
  111.  
  112. /**
  113. Output a comment.
  114. */
  115. function writeComment(text) {
  116. writeln(formatComment(text));
  117. }
  118.  
  119. function onOpen() {
  120.  
  121. if (properties.fourthAxisAroundX && properties.fourthAxisAroundY) {
  122. error(localize("Both fourthAxisAroundX and fourthAxisAroundY are enabled. Please select only one of these properties."));
  123. return;
  124. }
  125.  
  126. if (properties.fourthAxisAroundX || properties.fourthAxisAroundY) {
  127. var aAxis = createAxis({coordinate:0, table:true, axis:[(properties.fourthAxisAroundX ? 1 : 0), (properties.fourthAxisAroundY ? 1 : 0), 0], cyclic:true, preference:0});
  128. machineConfiguration = new MachineConfiguration(aAxis);
  129.  
  130. setMachineConfiguration(machineConfiguration);
  131. optimizeMachineAngles2(1); // map tip mode
  132. }
  133.  
  134. if (!machineConfiguration.isMachineCoordinate(0)) {
  135. aOutput.disable();
  136. }
  137. if (!machineConfiguration.isMachineCoordinate(1)) {
  138. bOutput.disable();
  139. }
  140. if (!machineConfiguration.isMachineCoordinate(2)) {
  141. cOutput.disable();
  142. }
  143.  
  144. if (!properties.separateWordsWithSpace) {
  145. setWordSeparator("");
  146. }
  147.  
  148. sequenceNumber = properties.sequenceNumberStart;
  149.  
  150. if (programName) {
  151. writeComment(programName);
  152. }
  153. if (programComment) {
  154. writeComment(programComment);
  155. }
  156.  
  157. // dump machine configuration
  158. var vendor = machineConfiguration.getVendor();
  159. var model = machineConfiguration.getModel();
  160. var description = machineConfiguration.getDescription();
  161.  
  162. if (properties.writeMachine && (vendor || model || description)) {
  163. writeComment(localize("Machine"));
  164. if (vendor) {
  165. writeComment(" " + localize("vendor") + ": " + vendor);
  166. }
  167. if (model) {
  168. writeComment(" " + localize("model") + ": " + model);
  169. }
  170. if (description) {
  171. writeComment(" " + localize("description") + ": " + description);
  172. }
  173. }
  174.  
  175. // dump tool information
  176. if (properties.writeTools) {
  177. var zRanges = {};
  178. if (is3D()) {
  179. var numberOfSections = getNumberOfSections();
  180. for (var i = 0; i < numberOfSections; ++i) {
  181. var section = getSection(i);
  182. var zRange = section.getGlobalZRange();
  183. var tool = section.getTool();
  184. if (zRanges[tool.number]) {
  185. zRanges[tool.number].expandToRange(zRange);
  186. } else {
  187. zRanges[tool.number] = zRange;
  188. }
  189. }
  190. }
  191.  
  192. var tools = getToolTable();
  193. if (tools.getNumberOfTools() > 0) {
  194. for (var i = 0; i < tools.getNumberOfTools(); ++i) {
  195. var tool = tools.getTool(i);
  196. var comment = "T" + toolFormat.format(tool.number) + " " +
  197. "D=" + xyzFormat.format(tool.diameter) + " " +
  198. localize("CR") + "=" + xyzFormat.format(tool.cornerRadius);
  199. if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) {
  200. comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg");
  201. }
  202. if (zRanges[tool.number]) {
  203. comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum());
  204. }
  205. comment += " - " + getToolTypeName(tool.type);
  206. writeComment(comment);
  207. }
  208. }
  209. }
  210.  
  211. if ((getNumberOfSections() > 0) && (getSection(0).workOffset == 0)) {
  212. for (var i = 0; i < getNumberOfSections(); ++i) {
  213. if (getSection(i).workOffset > 0) {
  214. error(localize("Using multiple work offsets is not possible if the initial work offset is 0."));
  215. return;
  216. }
  217. }
  218. }
  219.  
  220. // absolute coordinates and feed per min
  221. writeBlock(gAbsIncModal.format(90));
  222.  
  223. /*
  224. if (properties.referenceRun) {
  225. writeBlock(gFormat.format(28.1));
  226. }
  227. */
  228.  
  229. /* not supported on UCCNC
  230. switch (unit) {
  231. case IN:
  232. writeBlock(gUnitModal.format(20));
  233. break;
  234. case MM:
  235. writeBlock(gUnitModal.format(22)); // G21 is cm
  236. break;
  237. }
  238. */
  239. }
  240.  
  241. function onComment(message) {
  242. writeComment(message);
  243. }
  244.  
  245. /** Force output of X, Y, and Z. */
  246. function forceXYZ() {
  247. xOutput.reset();
  248. yOutput.reset();
  249. zOutput.reset();
  250. }
  251.  
  252. /** Force output of A, B, and C. */
  253. function forceABC() {
  254. aOutput.reset();
  255. bOutput.reset();
  256. cOutput.reset();
  257. }
  258.  
  259. /** Force output of X, Y, Z, A, B, C, and F on next output. */
  260. function forceAny() {
  261. forceXYZ();
  262. forceABC();
  263. forceFeed();
  264. }
  265.  
  266. function forceFeed() {
  267. currentFeedId = undefined;
  268. feedOutput.reset();
  269. }
  270.  
  271. function onParameter(name, value) {
  272. }
  273.  
  274. var currentWorkPlaneABC = undefined;
  275.  
  276. function forceWorkPlane() {
  277. currentWorkPlaneABC = undefined;
  278. }
  279.  
  280. function setWorkPlane(abc) {
  281. if (!machineConfiguration.isMultiAxisConfiguration()) {
  282. return; // ignore
  283. }
  284.  
  285. if (!((currentWorkPlaneABC == undefined) ||
  286. abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) ||
  287. abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) ||
  288. abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) {
  289. return; // no change
  290. }
  291.  
  292. onCommand(COMMAND_UNLOCK_MULTI_AXIS);
  293.  
  294. // NOTE: add retract here
  295. gMotionModal.reset();
  296. writeBlock(
  297. gMotionModal.format(0),
  298. conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)),
  299. conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)),
  300. conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z))
  301. );
  302.  
  303. onCommand(COMMAND_LOCK_MULTI_AXIS);
  304.  
  305. currentWorkPlaneABC = abc;
  306. }
  307.  
  308. var closestABC = false; // choose closest machine angles
  309. var currentMachineABC;
  310.  
  311. function getWorkPlaneMachineABC(workPlane) {
  312. var W = workPlane; // map to global frame
  313.  
  314. var abc = machineConfiguration.getABC(W);
  315. if (closestABC) {
  316. if (currentMachineABC) {
  317. abc = machineConfiguration.remapToABC(abc, currentMachineABC);
  318. } else {
  319. abc = machineConfiguration.getPreferredABC(abc);
  320. }
  321. } else {
  322. abc = machineConfiguration.getPreferredABC(abc);
  323. }
  324.  
  325. try {
  326. abc = machineConfiguration.remapABC(abc);
  327. currentMachineABC = abc;
  328. } catch (e) {
  329. error(
  330. localize("Machine angles not supported") + ":"
  331. + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
  332. + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
  333. + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
  334. );
  335. }
  336.  
  337. var direction = machineConfiguration.getDirection(abc);
  338. if (!isSameDirection(direction, W.forward)) {
  339. error(localize("Orientation not supported."));
  340. return new Vector();
  341. }
  342.  
  343. if (!machineConfiguration.isABCSupported(abc)) {
  344. error(
  345. localize("Work plane is not supported") + ":"
  346. + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
  347. + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
  348. + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
  349. );
  350. }
  351.  
  352. var tcp = false;
  353. if (tcp) {
  354. setRotation(W); // TCP mode
  355. } else {
  356. var O = machineConfiguration.getOrientation(abc);
  357. var R = machineConfiguration.getRemainingOrientation(abc, W);
  358. setRotation(R);
  359. }
  360.  
  361. return abc;
  362. }
  363.  
  364. function onSection() {
  365. var insertToolCall = isFirstSection() ||
  366. currentSection.getForceToolChange && currentSection.getForceToolChange() ||
  367. (tool.number != getPreviousSection().getTool().number);
  368.  
  369. var retracted = false; // specifies that the tool has been retracted to the safe plane
  370. var newWorkOffset = isFirstSection() ||
  371. (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes
  372. var newWorkPlane = isFirstSection() ||
  373. !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis());
  374. if (insertToolCall || newWorkOffset || newWorkPlane) {
  375.  
  376. // retract to safe plane
  377. retracted = true;
  378. writeBlock(gMotionModal.format(0), gFormat.format(53), "Z" + xyzFormat.format(0));
  379. zOutput.reset();
  380. }
  381.  
  382. writeln("");
  383.  
  384. if (hasParameter("operation-comment")) {
  385. var comment = getParameter("operation-comment");
  386. if (comment) {
  387. writeComment(comment);
  388. }
  389. }
  390.  
  391. if (insertToolCall) {
  392. forceWorkPlane();
  393.  
  394. retracted = true;
  395. if (!isFirstSection()) {
  396. onCommand(COMMAND_COOLANT_OFF);
  397. }
  398.  
  399. if (properties.useToolChanger) {
  400. writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
  401. } else {
  402. if (!isFirstSection()) {
  403. onCommand(COMMAND_STOP_SPINDLE);
  404. writeComment(localize("Move to tool change position"));
  405. writeBlock(gMotionModal.format(0), gFormat.format(53), "X" + xyzFormat.format(properties.toolChangePositionX), "Y" + xyzFormat.format(properties.toolChangePositionY));
  406. writeBlock(mFormat.format(0), formatComment(localize("Pause program for tool change")));
  407. }
  408. writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6) + " (" + getToolTypeName(tool.type) + " D=" + xyzFormat.format(tool.diameter) + (tool.description ? " " + tool.description : "") + ")");
  409. }
  410. if (tool.comment) {
  411. writeComment(tool.comment);
  412. }
  413. var showToolZMin = false;
  414. if (showToolZMin) {
  415. if (is3D()) {
  416. var numberOfSections = getNumberOfSections();
  417. var zRange = currentSection.getGlobalZRange();
  418. var number = tool.number;
  419. for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) {
  420. var section = getSection(i);
  421. if (section.getTool().number != number) {
  422. break;
  423. }
  424. zRange.expandToRange(section.getGlobalZRange());
  425. }
  426. writeComment(localize("ZMIN") + "=" + zRange.getMinimum());
  427. }
  428. }
  429. }
  430.  
  431. if (insertToolCall ||
  432. isFirstSection() ||
  433. (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) ||
  434. (tool.clockwise != getPreviousSection().getTool().clockwise)) {
  435. if (tool.spindleRPM < 1) {
  436. error(localize("Spindle speed out of range."));
  437. return;
  438. }
  439. if (tool.spindleRPM > 99999) {
  440. warning(localize("Spindle speed exceeds maximum value."));
  441. }
  442. writeBlock(sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4));
  443. }
  444.  
  445. if (properties.useSmoothing) {
  446. if (hasParameter("operation-strategy") && (getParameter("operation-strategy") == "drill")) {
  447. writeBlock(gFormat.format(61));
  448. } else {
  449. writeBlock(gFormat.format(64));
  450. }
  451. }
  452.  
  453. // wcs
  454. if (insertToolCall) { // force work offset when changing tool
  455. currentWorkOffset = undefined;
  456. }
  457. var workOffset = currentSection.workOffset;
  458. if (workOffset == 0) {
  459. warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET);
  460. workOffset = 1;
  461. }
  462. if (workOffset > 0) {
  463. if (workOffset > 6) {
  464. error(localize("Work offset out of range."));
  465. return;
  466. } else {
  467. if (workOffset != currentWorkOffset) {
  468. writeBlock(gFormat.format(53 + workOffset)); // G54->G59
  469. currentWorkOffset = workOffset;
  470. }
  471. }
  472. }
  473.  
  474. forceXYZ();
  475.  
  476. if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode
  477. // set working plane after datum shift
  478.  
  479. var abc = new Vector(0, 0, 0);
  480. if (currentSection.isMultiAxis()) {
  481. forceWorkPlane();
  482. cancelTransformation();
  483. abc = currentSection.getInitialToolAxisABC();
  484. } else {
  485. abc = getWorkPlaneMachineABC(currentSection.workPlane);
  486. }
  487. setWorkPlane(abc);
  488. } else { // pure 3D
  489. var remaining = currentSection.workPlane;
  490. if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) {
  491. error(localize("Tool orientation is not supported."));
  492. return;
  493. }
  494. setRotation(remaining);
  495. }
  496.  
  497.  
  498. // set coolant after we have positioned at Z
  499. setCoolant(tool.coolant);
  500.  
  501. forceAny();
  502.  
  503. var initialPosition = getFramePosition(currentSection.getInitialPosition());
  504. if (!retracted) {
  505. if (getCurrentPosition().z < initialPosition.z) {
  506. writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z));
  507. }
  508. }
  509.  
  510. if (insertToolCall || retracted) {
  511. var lengthOffset = tool.lengthOffset;
  512. if (lengthOffset > 99) {
  513. error(localize("Length offset out of range."));
  514. return;
  515. }
  516.  
  517. gMotionModal.reset();
  518. if (!machineConfiguration.isHeadConfiguration()) {
  519. writeBlock(gFormat.format(43), hFormat.format(lengthOffset));
  520. writeBlock(
  521. gAbsIncModal.format(90),
  522. gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y)
  523. );
  524. writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z));
  525. } else {
  526. writeBlock(gFormat.format(43), hFormat.format(lengthOffset));
  527. writeBlock(
  528. gAbsIncModal.format(90),
  529. gMotionModal.format(0),
  530. xOutput.format(initialPosition.x),
  531. yOutput.format(initialPosition.y),
  532. zOutput.format(initialPosition.z)
  533. );
  534. }
  535. } else {
  536. writeBlock(
  537. gAbsIncModal.format(90),
  538. gMotionModal.format(0),
  539. xOutput.format(initialPosition.x),
  540. yOutput.format(initialPosition.y)
  541. );
  542. }
  543. }
  544.  
  545. var currentCoolantMode = COOLANT_OFF;
  546.  
  547. function setCoolant(coolant) {
  548. if (coolant == currentCoolantMode) {
  549. return; // coolant is already active
  550. }
  551.  
  552. if (coolant == COOLANT_OFF) {
  553. writeBlock(mFormat.format(9));
  554. currentCoolantMode = COOLANT_OFF;
  555. return;
  556. }
  557.  
  558. var m;
  559. switch (coolant) {
  560. case COOLANT_FLOOD:
  561. m = 8;
  562. break;
  563. case COOLANT_MIST:
  564. m = 7;
  565. break;
  566. default:
  567. onUnsupportedCoolant(coolant);
  568. m = 9;
  569. }
  570.  
  571. if (m) {
  572. writeBlock(mFormat.format(m));
  573. currentCoolantMode = coolant;
  574. }
  575. }
  576.  
  577. function onDwell(seconds) {
  578. if (seconds > 99999.999) {
  579. warning(localize("Dwelling time is out of range."));
  580. }
  581. seconds = clamp(0.001, seconds, 99999.999);
  582. writeBlock(gFormat.format(4), "P" + milliFormat.format(seconds * 1000));
  583. }
  584.  
  585. function onSpindleSpeed(spindleSpeed) {
  586. writeBlock(sOutput.format(spindleSpeed));
  587. }
  588.  
  589. function onCycle() {
  590. }
  591.  
  592. function getCommonCycle(x, y, z, r) {
  593. forceXYZ();
  594. return [xOutput.format(x), yOutput.format(y),
  595. zOutput.format(z),
  596. (r !== undefined) ? "R" + xyzFormat.format(r) : ""];
  597. }
  598.  
  599. function onCyclePoint(x, y, z) {
  600. var forceCycle = false;
  601. switch (cycleType) {
  602. case "tapping":
  603. case "left-tapping":
  604. case "right-tapping":
  605. if (!isFirstCyclePoint()) {
  606. onCommand(COMMAND_STOP_SPINDLE);
  607. }
  608. forceCycle = true;
  609. }
  610.  
  611. if (forceCycle || isFirstCyclePoint()) {
  612. repositionToCycleClearance(cycle, x, y, z);
  613.  
  614. // return to initial Z which is clearance plane and set absolute mode
  615.  
  616. var F = cycle.feedrate;
  617. var P = (cycle.dwell == 0) ? 0 : clamp(1, cycle.dwell * 1000, 99999999); // in milliseconds
  618.  
  619. switch (cycleType) {
  620. case "drilling":
  621. writeBlock(
  622. gAbsIncModal.format(90), gCycleModal.format(81),
  623. getCommonCycle(x, y, z, cycle.retract),
  624. feedOutput.format(F)
  625. );
  626. break;
  627. case "counter-boring":
  628. if (P > 0) {
  629. writeBlock(
  630. gAbsIncModal.format(90), gCycleModal.format(82),
  631. getCommonCycle(x, y, z, cycle.retract),
  632. "P" + milliFormat.format(P),
  633. feedOutput.format(F)
  634. );
  635. } else {
  636. writeBlock(
  637. gAbsIncModal.format(90), gCycleModal.format(81),
  638. getCommonCycle(x, y, z, cycle.retract),
  639. feedOutput.format(F)
  640. );
  641. }
  642. break;
  643. case "chip-breaking":
  644. if (P > 0) {
  645. expandCyclePoint(x, y, z);
  646. } else {
  647. writeBlock(
  648. gAbsIncModal.format(90), gCycleModal.format(73),
  649. getCommonCycle(x, y, z, cycle.retract),
  650. "Q" + xyzFormat.format(cycle.incrementalDepth),
  651. feedOutput.format(F)
  652. );
  653. }
  654. break;
  655. case "deep-drilling":
  656. if (P > 0) {
  657. expandCyclePoint(x, y, z);
  658. } else {
  659. writeBlock(
  660. gAbsIncModal.format(90), gCycleModal.format(83),
  661. getCommonCycle(x, y, z, cycle.retract),
  662. "Q" + xyzFormat.format(cycle.incrementalDepth),
  663. feedOutput.format(F)
  664. );
  665. }
  666. break;
  667. case "tapping":
  668. if (P > 0) {
  669. expandCyclePoint(x, y, z);
  670. } else {
  671. if (!isFirstCyclePoint()) {
  672. writeBlock(sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4));
  673. }
  674. writeBlock(
  675. gAbsIncModal.format(90), gCycleModal.format((tool.type == TOOL_TAP_LEFT_HAND) ? 33.2 : 33.1),
  676. zOutput.format(z),
  677. pitchOutput.format(tool.threadPitch)
  678. );
  679. gCycleModal.reset();
  680. }
  681. break;
  682. case "left-tapping":
  683. if (P > 0) {
  684. expandCyclePoint(x, y, z);
  685. } else {
  686. if (!isFirstCyclePoint()) {
  687. writeBlock(sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4));
  688. }
  689. writeBlock(
  690. gAbsIncModal.format(90), gCycleModal.format(33.2),
  691. zOutput.format(z),
  692. pitchOutput.format(tool.threadPitch)
  693. );
  694. gCycleModal.reset();
  695. }
  696. break;
  697. case "right-tapping":
  698. if (P > 0) {
  699. expandCyclePoint(x, y, z);
  700. } else {
  701. if (!isFirstCyclePoint()) {
  702. writeBlock(sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4));
  703. }
  704. writeBlock(
  705. gAbsIncModal.format(90), gCycleModal.format(33.1),
  706. zOutput.format(z),
  707. pitchOutput.format(tool.threadPitch)
  708. );
  709. gCycleModal.reset();
  710. }
  711. break;
  712. case "tapping-with-chip-breaking":
  713. case "left-tapping-with-chip-breaking":
  714. case "right-tapping-with-chip-breaking":
  715. error(localize("Tapping with chip breaking is not supported."));
  716. return;
  717. default:
  718. expandCyclePoint(x, y, z);
  719. }
  720. } else {
  721. if (cycleExpanded) {
  722. expandCyclePoint(x, y, z);
  723. } else {
  724. var _x = xOutput.format(x);
  725. var _y = yOutput.format(y);
  726. if (!_x && !_y) {
  727. xOutput.reset(); // at least one axis is required
  728. _x = xOutput.format(x);
  729. }
  730. writeBlock(_x, _y);
  731. }
  732. }
  733. if (forceCycle) {
  734. sOutput.reset();
  735. }
  736. }
  737.  
  738. function onCycleEnd() {
  739. if (!cycleExpanded) {
  740. writeBlock(gCycleModal.format(80));
  741. zOutput.reset();
  742. }
  743. }
  744.  
  745. var pendingRadiusCompensation = -1;
  746.  
  747. function onRadiusCompensation() {
  748. pendingRadiusCompensation = radiusCompensation;
  749. error(localize("Radius compensation is not supported for UCCNC. Please change the compensation type to 'in computer' for the toolpath."));
  750. return;
  751. }
  752.  
  753. function onRapid(_x, _y, _z) {
  754. var x = xOutput.format(_x);
  755. var y = yOutput.format(_y);
  756. var z = zOutput.format(_z);
  757. if (x || y || z) {
  758. if (pendingRadiusCompensation >= 0) {
  759. error(localize("Radius compensation mode cannot be changed at rapid traversal."));
  760. return;
  761. }
  762. writeBlock(gMotionModal.format(0), x, y, z);
  763. feedOutput.reset();
  764. }
  765. }
  766.  
  767. function onLinear(_x, _y, _z, feed) {
  768. // at least one axis is required
  769. if (pendingRadiusCompensation >= 0) {
  770. // ensure that we end at desired position when compensation is turned off
  771. xOutput.reset();
  772. yOutput.reset();
  773. }
  774. var x = xOutput.format(_x);
  775. var y = yOutput.format(_y);
  776. var z = zOutput.format(_z);
  777. var f = feedOutput.format(feed);
  778. if (x || y || z) {
  779. if (pendingRadiusCompensation >= 0) {
  780. pendingRadiusCompensation = -1;
  781. var d = tool.diameterOffset;
  782. switch (radiusCompensation) {
  783. case RADIUS_COMPENSATION_LEFT:
  784. writeBlock(
  785. gMotionModal.format(1), gFormat.format(41), x, y, z,
  786. conditional(properties.useToolChanger, "O" + xyzFormat.format(tool.diameter/2)), f
  787. );
  788. break;
  789. case RADIUS_COMPENSATION_RIGHT:
  790. writeBlock(
  791. gMotionModal.format(1), gFormat.format(42), x, y, z,
  792. conditional(properties.useToolChanger, "O" + xyzFormat.format(tool.diameter/2)), f
  793. );
  794. break;
  795. default:
  796. writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f);
  797. }
  798. } else {
  799. writeBlock(gMotionModal.format(1), x, y, z, f);
  800. }
  801. } else if (f) {
  802. if (getNextRecord().isMotion()) { // try not to output feed without motion
  803. feedOutput.reset(); // force feed on next line
  804. } else {
  805. writeBlock(gMotionModal.format(1), f);
  806. }
  807. }
  808. }
  809.  
  810. function onRapid5D(_x, _y, _z, _a, _b, _c) {
  811. if (!currentSection.isOptimizedForMachine()) {
  812. error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath."));
  813. return;
  814. }
  815. if (pendingRadiusCompensation >= 0) {
  816. error(localize("Radius compensation mode cannot be changed at rapid traversal."));
  817. return;
  818. }
  819. var x = xOutput.format(_x);
  820. var y = yOutput.format(_y);
  821. var z = zOutput.format(_z);
  822. var a = aOutput.format(_a);
  823. var b = bOutput.format(_b);
  824. var c = cOutput.format(_c);
  825. writeBlock(gMotionModal.format(0), x, y, z, a, b, c);
  826. feedOutput.reset();
  827. }
  828.  
  829. function onLinear5D(_x, _y, _z, _a, _b, _c, feed) {
  830. if (!currentSection.isOptimizedForMachine()) {
  831. error(localize("This post configuration has not been customized for 5-axis simultaneous toolpath."));
  832. return;
  833. }
  834. // at least one axis is required
  835. if (pendingRadiusCompensation >= 0) {
  836. error(localize("Radius compensation cannot be activated/deactivated for 5-axis move."));
  837. return;
  838. }
  839. var x = xOutput.format(_x);
  840. var y = yOutput.format(_y);
  841. var z = zOutput.format(_z);
  842. var a = aOutput.format(_a);
  843. var b = bOutput.format(_b);
  844. var c = cOutput.format(_c);
  845. var f = feedOutput.format(feed);
  846. if (x || y || z || a || b || c) {
  847. writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f);
  848. } else if (f) {
  849. if (getNextRecord().isMotion()) { // try not to output feed without motion
  850. feedOutput.reset(); // force feed on next line
  851. } else {
  852. writeBlock(gMotionModal.format(1), f);
  853. }
  854. }
  855. }
  856.  
  857. function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
  858. if (pendingRadiusCompensation >= 0) {
  859. error(localize("Radius compensation cannot be activated/deactivated for a circular move."));
  860. return;
  861. }
  862.  
  863. var start = getCurrentPosition();
  864.  
  865. if (isFullCircle()) {
  866. if (isHelical()) {
  867. linearize(tolerance);
  868. return;
  869. }
  870. switch (getCircularPlane()) {
  871. case PLANE_XY:
  872. writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed));
  873. break;
  874. default:
  875. linearize(tolerance);
  876. }
  877. } else {
  878. switch (getCircularPlane()) {
  879. case PLANE_XY:
  880. writeBlock(gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), feedOutput.format(feed));
  881. break;
  882. default:
  883. linearize(tolerance);
  884. }
  885. }
  886. }
  887.  
  888. var mapCommand = {
  889. };
  890.  
  891. function onCommand(command) {
  892. switch (command) {
  893. case COMMAND_STOP:
  894. writeBlock(mFormat.format(2));
  895. return;
  896. case COMMAND_COOLANT_OFF:
  897. setCoolant(COOLANT_OFF);
  898. return;
  899. case COMMAND_START_SPINDLE:
  900. onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE);
  901. return;
  902. case COMMAND_SPINDLE_CLOCKWISE:
  903. writeBlock(mFormat.format(3));
  904. return;
  905. case COMMAND_SPINDLE_COUNTERCLOCKWISE:
  906. writeBlock(mFormat.format(4));
  907. return;
  908. case COMMAND_STOP_SPINDLE:
  909. writeBlock(mFormat.format(5));
  910. return;
  911. case COMMAND_ORIENTATE_SPINDLE:
  912. return;
  913. case COMMAND_LOCK_MULTI_AXIS:
  914. return;
  915. case COMMAND_UNLOCK_MULTI_AXIS:
  916. return;
  917. case COMMAND_BREAK_CONTROL:
  918. return;
  919. case COMMAND_TOOL_MEASURE:
  920. return;
  921. }
  922.  
  923. var stringId = getCommandStringId(command);
  924. var mcode = mapCommand[stringId];
  925. if (mcode != undefined) {
  926. writeBlock(mFormat.format(mcode));
  927. } else {
  928. onUnsupportedCommand(command);
  929. }
  930. }
  931.  
  932. function onSectionEnd() {
  933. forceAny();
  934. }
  935.  
  936. function onClose() {
  937. onCommand(COMMAND_COOLANT_OFF);
  938. onCommand(COMMAND_STOP_SPINDLE);
  939.  
  940. writeBlock(gMotionModal.format(0), gFormat.format(53), "Z" + xyzFormat.format(0));
  941.  
  942. setWorkPlane(new Vector(0, 0, 0)); // reset working plane
  943. // writeBlock(gFormat.format(28)); // retract
  944. writeBlock(mFormat.format(30));
  945. zOutput.reset();
  946. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement