Advertisement
Guest User

Untitled

a guest
Jan 11th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.29 KB | None | 0 0
  1. /**
  2. Copyright (C) 2007-2012 by HSMWorks ApS
  3. All rights reserved.
  4.  
  5. Enhanced Machine Controller (EMC) post processor configuration.
  6.  
  7. $Revision: 31982 $
  8. $Date: 2012-08-15 17:18:40 +0200 (on, 15 aug 2012) $
  9.  
  10. FORKID {52A5C3D6-1533-413e-B493-7B93D9E48B30}
  11. */
  12.  
  13. description = "Generic Enhanced Machine Controller (EMC)";
  14. vendor = "HSMWorks ApS";
  15. vendorUrl = "http://www.hsmworks.com";
  16. legal = "Copyright (C) 2007-2012 HSMWorks ApS";
  17. certificationLevel = 2;
  18. minimumRevision = 24000;
  19.  
  20. extension = "ngc";
  21. setCodePage("ascii");
  22.  
  23. tolerance = spatial(0.002, MM);
  24.  
  25. minimumChordLength = spatial(0.01, MM);
  26. minimumCircularRadius = spatial(0.01, MM);
  27. maximumCircularRadius = spatial(1000, MM);
  28. minimumCircularSweep = toRad(0.01);
  29. maximumCircularSweep = toRad(180);
  30. allowHelicalMoves = true;
  31. allowedCircularPlanes = undefined; // allow any circular motion
  32.  
  33.  
  34.  
  35. // user-defined properties
  36. properties = {
  37. writeMachine: true, // write machine
  38. writeTools: true, // writes the tools
  39. preloadTool: true, // preloads next tool on tool change if any
  40. showSequenceNumbers: true, // show sequence numbers
  41. sequenceNumberStart: 10, // first sequence number
  42. sequenceNumberIncrement: 5, // increment for sequence numbers
  43. optionalStop: true, // optional stop
  44. separateWordsWithSpace: true, // specifies that the words should be separated with a white space
  45. useRadius: false, // specifies that arcs should be output using the radius (R word) instead of the I, J, and K words.
  46. useParametricFeed: false, // specifies that feed should be output using Q values
  47. showNotes: false // specifies that operation notes should be output.
  48. };
  49.  
  50.  
  51.  
  52. var permittedCommentChars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,=_-";
  53.  
  54. var mapCoolantTable = new Table(
  55. [9, 8, 7],
  56. {initial:COOLANT_OFF, force:true},
  57. "Invalid coolant mode"
  58. );
  59.  
  60. var gFormat = createFormat({prefix:"G", decimals:1});
  61. var mFormat = createFormat({prefix:"M", decimals:1});
  62. var hFormat = createFormat({prefix:"H", decimals:1});
  63. var dFormat = createFormat({prefix:"D", decimals:1});
  64.  
  65. var xyzFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
  66. var rFormat = xyzFormat; // radius
  67. var abcFormat = createFormat({decimals:3, forceDecimal:true, scale:DEG});
  68. var feedFormat = createFormat({decimals:(unit == MM ? 2 : 3), forceDecimal:true});
  69. var pitchFormat = createFormat({decimals:(unit == MM ? 3 : 4), forceDecimal:true});
  70. var toolFormat = createFormat({decimals:0});
  71. var rpmFormat = createFormat({decimals:0});
  72. var secFormat = createFormat({decimals:3, forceDecimal:true}); // seconds - range 0.001-99999.999
  73. var taperFormat = createFormat({decimals:1, scale:DEG});
  74.  
  75. var xOutput = createVariable({prefix:"X"}, xyzFormat);
  76. var yOutput = createVariable({prefix:"Y"}, xyzFormat);
  77. var zOutput = createVariable({prefix:"Z"}, xyzFormat);
  78. var aOutput = createVariable({prefix:"A"}, abcFormat);
  79. var bOutput = createVariable({prefix:"B"}, abcFormat);
  80. var cOutput = createVariable({prefix:"C"}, abcFormat);
  81. var feedOutput = createVariable({prefix:"F"}, feedFormat);
  82. var sOutput = createVariable({prefix:"S", force:true}, rpmFormat);
  83. var dOutput = createVariable({}, dFormat);
  84.  
  85. // circular output
  86. var iOutput = createReferenceVariable({prefix:"I", force:true}, xyzFormat);
  87. var jOutput = createReferenceVariable({prefix:"J", force:true}, xyzFormat);
  88. var kOutput = createReferenceVariable({prefix:"K", force:true}, xyzFormat);
  89.  
  90. var gMotionModal = createModal({}, gFormat); // modal group 1 // G0-G3, ...
  91. var gPlaneModal = createModal({onchange:function () {gMotionModal.reset();}}, gFormat); // modal group 2 // G17-19
  92. var gAbsIncModal = createModal({}, gFormat); // modal group 3 // G90-91
  93. var gFeedModeModal = createModal({}, gFormat); // modal group 5 // G93-94
  94. var gUnitModal = createModal({}, gFormat); // modal group 6 // G20-21
  95. var gCycleModal = createModal({}, gFormat); // modal group 9 // G81, ...
  96. var gRetractModal = createModal({}, gFormat); // modal group 10 // G98-99
  97.  
  98. // fixed settings
  99. var firstFeedParameter = 100;
  100.  
  101. var WARNING_WORK_OFFSET = 0;
  102.  
  103. // collected state
  104. var sequenceNumber;
  105. var currentWorkOffset;
  106. var forceSpindleSpeed = false;
  107. var activeMovements; // do not use by default
  108. var currentFeedId;
  109.  
  110.  
  111.  
  112. /**
  113. Writes the specified block.
  114. */
  115. function writeBlock() {
  116. if (properties.showSequenceNumbers) {
  117. writeWords2("N" + sequenceNumber, arguments);
  118. sequenceNumber += properties.sequenceNumberIncrement;
  119. if (sequenceNumber > 99999) {
  120. sequenceNumber = properties.sequenceNumberStart;
  121. }
  122. } else {
  123. writeWords(arguments);
  124. }
  125. }
  126.  
  127. /**
  128. Writes the specified optional block.
  129. */
  130. function writeOptionalBlock() {
  131. if (properties.showSequenceNumbers) {
  132. var words = formatWords(arguments);
  133. if (words) {
  134. writeWords("/", "N" + sequenceNumber, words);
  135. sequenceNumber += properties.sequenceNumberIncrement;
  136. if (sequenceNumber > 99999) {
  137. sequenceNumber = properties.sequenceNumberStart;
  138. }
  139. }
  140. } else {
  141. writeWords("/", arguments);
  142. }
  143. }
  144.  
  145. function formatComment(text) {
  146. return "(" + filterText(String(text).toUpperCase(), permittedCommentChars) + ")";
  147. }
  148.  
  149. /**
  150. Output a comment.
  151. */
  152. function writeComment(text) {
  153. writeln(formatComment(text));
  154. }
  155.  
  156. function onOpen() {
  157.  
  158. if (false) { // note: setup your machine here
  159. var aAxis = createAxis({coordinate:0, table:false, axis:[1, 0, 0], range:[-360,360], preference:1});
  160. var cAxis = createAxis({coordinate:2, table:false, axis:[0, 0, 1], range:[-360,360], preference:1});
  161. machineConfiguration = new MachineConfiguration(aAxis, cAxis);
  162.  
  163. setMachineConfiguration(machineConfiguration);
  164. optimizeMachineAngles2(0); // TCP mode
  165. }
  166.  
  167. if (!machineConfiguration.isMachineCoordinate(0)) {
  168. aOutput.disable();
  169. }
  170. if (!machineConfiguration.isMachineCoordinate(1)) {
  171. bOutput.disable();
  172. }
  173. if (!machineConfiguration.isMachineCoordinate(2)) {
  174. cOutput.disable();
  175. }
  176.  
  177. if (!properties.separateWordsWithSpace) {
  178. setWordSeparator("");
  179. }
  180.  
  181. sequenceNumber = properties.sequenceNumberStart;
  182. writeln("%");
  183.  
  184. if (programName) {
  185. writeComment(programName);
  186. }
  187. if (programComment) {
  188. writeComment(programComment);
  189. }
  190.  
  191. // dump machine configuration
  192. var vendor = machineConfiguration.getVendor();
  193. var model = machineConfiguration.getModel();
  194. var description = machineConfiguration.getDescription();
  195.  
  196. if (properties.writeMachine && (vendor || model || description)) {
  197. writeComment(localize("Machine"));
  198. if (vendor) {
  199. writeComment(" " + localize("vendor") + ": " + vendor);
  200. }
  201. if (model) {
  202. writeComment(" " + localize("model") + ": " + model);
  203. }
  204. if (description) {
  205. writeComment(" " + localize("description") + ": " + description);
  206. }
  207. }
  208.  
  209. // dump tool information
  210. if (properties.writeTools) {
  211. var zRanges = {};
  212. if (is3D()) {
  213. var numberOfSections = getNumberOfSections();
  214. for (var i = 0; i < numberOfSections; ++i) {
  215. var section = getSection(i);
  216. var zRange = section.getGlobalZRange();
  217. var tool = section.getTool();
  218. if (zRanges[tool.number]) {
  219. zRanges[tool.number].expandToRange(zRange);
  220. } else {
  221. zRanges[tool.number] = zRange;
  222. }
  223. }
  224. }
  225.  
  226. var tools = getToolTable();
  227. if (tools.getNumberOfTools() > 0) {
  228. for (var i = 0; i < tools.getNumberOfTools(); ++i) {
  229. var tool = tools.getTool(i);
  230. var comment = "T" + toolFormat.format(tool.number) + " " +
  231. "D=" + xyzFormat.format(tool.diameter) + " " +
  232. localize("CR") + "=" + xyzFormat.format(tool.cornerRadius);
  233. if ((tool.taperAngle > 0) && (tool.taperAngle < Math.PI)) {
  234. comment += " " + localize("TAPER") + "=" + taperFormat.format(tool.taperAngle) + localize("deg");
  235. }
  236. if (zRanges[tool.number]) {
  237. comment += " - " + localize("ZMIN") + "=" + xyzFormat.format(zRanges[tool.number].getMinimum());
  238. }
  239. comment += " - " + getToolTypeName(tool.type);
  240. writeComment(comment);
  241. }
  242. }
  243. }
  244.  
  245. if (false) {
  246. // check for duplicate tool number
  247. for (var i = 0; i < getNumberOfSections(); ++i) {
  248. var sectioni = getSection(i);
  249. var tooli = sectioni.getTool();
  250. for (var j = i + 1; j < getNumberOfSections(); ++j) {
  251. var sectionj = getSection(j);
  252. var toolj = sectionj.getTool();
  253. if (tooli.number == toolj.number) {
  254. if (xyzFormat.areDifferent(tooli.diameter, toolj.diameter) ||
  255. xyzFormat.areDifferent(tooli.cornerRadius, toolj.cornerRadius) ||
  256. abcFormat.areDifferent(tooli.taperAngle, toolj.taperAngle) ||
  257. (tooli.numberOfFlutes != toolj.numberOfFlutes)) {
  258. error(
  259. subst(
  260. localize("Using the same tool number for different cutter geometry for operation '%1' and '%2'."),
  261. sectioni.hasParameter("operation-comment") ? sectioni.getParameter("operation-comment") : ("#" + (i + 1)),
  262. sectionj.hasParameter("operation-comment") ? sectionj.getParameter("operation-comment") : ("#" + (j + 1))
  263. )
  264. );
  265. return;
  266. }
  267. }
  268. }
  269. }
  270. }
  271.  
  272. // absolute coordinates, feed per min, and incremental arc center mode
  273. writeBlock(gAbsIncModal.format(90), gFeedModeModal.format(94), gPlaneModal.format(17), gFormat.format(91.1));
  274.  
  275. switch (unit) {
  276. case IN:
  277. writeBlock(gUnitModal.format(20));
  278. break;
  279. case MM:
  280. writeBlock(gUnitModal.format(21));
  281. break;
  282. }
  283. }
  284.  
  285. function onComment(message) {
  286. writeComment(message);
  287. }
  288.  
  289. /** Force output of X, Y, and Z. */
  290. function forceXYZ() {
  291. xOutput.reset();
  292. yOutput.reset();
  293. zOutput.reset();
  294. }
  295.  
  296. /** Force output of A, B, and C. */
  297. function forceABC() {
  298. aOutput.reset();
  299. bOutput.reset();
  300. cOutput.reset();
  301. }
  302.  
  303. /** Force output of X, Y, Z, A, B, C, and F on next output. */
  304. function forceAny() {
  305. forceXYZ();
  306. forceABC();
  307. feedOutput.reset();
  308. }
  309.  
  310. function FeedContext(id, description, feed) {
  311. this.id = id;
  312. this.description = description;
  313. this.feed = feed;
  314. }
  315.  
  316. function getFeed(f) {
  317. if (activeMovements) {
  318. var feedContext = activeMovements[movement];
  319. if (feedContext != undefined) {
  320. if (!feedFormat.areDifferent(feedContext.feed, f)) {
  321. if (feedContext.id == currentFeedId) {
  322. return ""; // nothing has changed
  323. }
  324. currentFeedId = feedContext.id;
  325. feedOutput.reset();
  326. return "F#" + (firstFeedParameter + feedContext.id);
  327. }
  328. }
  329. currentFeedId = undefined; // force Q feed next time
  330. }
  331. return feedOutput.format(f); // use feed value
  332. }
  333.  
  334. function initializeActiveFeeds() {
  335. activeMovements = new Array();
  336. var movements = currentSection.getMovements();
  337.  
  338. var id = 0;
  339. var activeFeeds = new Array();
  340. if (hasParameter("operation:tool_feedCutting")) {
  341. if (movements & (1 << MOVEMENT_CUTTING) | (1 << MOVEMENT_LINK_TRANSITION) | (1 << MOVEMENT_EXTENDED)) {
  342. var feedContext = new FeedContext(id, localize("Cutting"), getParameter("operation:tool_feedCutting"));
  343. activeFeeds.push(feedContext);
  344. activeMovements[MOVEMENT_CUTTING] = feedContext;
  345. activeMovements[MOVEMENT_LINK_TRANSITION] = feedContext;
  346. activeMovements[MOVEMENT_EXTENDED] = feedContext;
  347. }
  348. ++id;
  349. if (movements & (1 << MOVEMENT_PREDRILL)) {
  350. feedContext = new FeedContext(id, localize("Predrilling"), getParameter("operation:tool_feedCutting"));
  351. activeMovements[MOVEMENT_PREDRILL] = feedContext;
  352. activeFeeds.push(feedContext);
  353. }
  354. ++id;
  355. }
  356.  
  357. if (hasParameter("operation:finishFeedrate")) {
  358. if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
  359. var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:finishFeedrate"));
  360. activeFeeds.push(feedContext);
  361. activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
  362. }
  363. ++id;
  364. } else if (hasParameter("operation:tool_feedCutting")) {
  365. if (movements & (1 << MOVEMENT_FINISH_CUTTING)) {
  366. var feedContext = new FeedContext(id, localize("Finish"), getParameter("operation:tool_feedCutting"));
  367. activeFeeds.push(feedContext);
  368. activeMovements[MOVEMENT_FINISH_CUTTING] = feedContext;
  369. }
  370. ++id;
  371. }
  372.  
  373. if (hasParameter("operation:tool_feedEntry")) {
  374. if (movements & (1 << MOVEMENT_LEAD_IN)) {
  375. var feedContext = new FeedContext(id, localize("Entry"), getParameter("operation:tool_feedEntry"));
  376. activeFeeds.push(feedContext);
  377. activeMovements[MOVEMENT_LEAD_IN] = feedContext;
  378. }
  379. ++id;
  380. }
  381.  
  382. if (hasParameter("operation:tool_feedExit")) {
  383. if (movements & (1 << MOVEMENT_LEAD_OUT)) {
  384. var feedContext = new FeedContext(id, localize("Exit"), getParameter("operation:tool_feedExit"));
  385. activeFeeds.push(feedContext);
  386. activeMovements[MOVEMENT_LEAD_OUT] = feedContext;
  387. }
  388. ++id;
  389. }
  390.  
  391. if (hasParameter("operation:noEngagementFeedrate")) {
  392. if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
  393. var feedContext = new FeedContext(id, localize("Direct"), getParameter("operation:noEngagementFeedrate"));
  394. activeFeeds.push(feedContext);
  395. activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
  396. }
  397. ++id;
  398. } else if (hasParameter("operation:tool_feedCutting") &&
  399. hasParameter("operation:tool_feedEntry") &&
  400. hasParameter("operation:tool_feedExit")) {
  401. if (movements & (1 << MOVEMENT_LINK_DIRECT)) {
  402. var feedContext = new FeedContext(id, localize("Direct"), Math.max(getParameter("operation:tool_feedCutting"), getParameter("operation:tool_feedEntry"), getParameter("operation:tool_feedExit")));
  403. activeFeeds.push(feedContext);
  404. activeMovements[MOVEMENT_LINK_DIRECT] = feedContext;
  405. }
  406. ++id;
  407. }
  408.  
  409. /*
  410. if (hasParameter("operation:reducedFeedrate")) {
  411. if (movements & (1 << MOVEMENT_REDUCED)) {
  412. var feedContext = new FeedContext(id, localize("Reduced"), getParameter("operation:reducedFeedrate"));
  413. activeFeeds.push(feedContext);
  414. activeMovements[MOVEMENT_REDUCED] = feedContext;
  415. }
  416. ++id;
  417. }
  418. */
  419.  
  420. if (hasParameter("operation:tool_feedRamp")) {
  421. if (movements & (1 << MOVEMENT_RAMP) | (1 << MOVEMENT_RAMP_HELIX) | (1 << MOVEMENT_RAMP_PROFILE) | (1 << MOVEMENT_RAMP_ZIG_ZAG)) {
  422. var feedContext = new FeedContext(id, localize("Ramping"), getParameter("operation:tool_feedRamp"));
  423. activeFeeds.push(feedContext);
  424. activeMovements[MOVEMENT_RAMP] = feedContext;
  425. activeMovements[MOVEMENT_RAMP_HELIX] = feedContext;
  426. activeMovements[MOVEMENT_RAMP_PROFILE] = feedContext;
  427. activeMovements[MOVEMENT_RAMP_ZIG_ZAG] = feedContext;
  428. }
  429. ++id;
  430. }
  431. if (hasParameter("operation:tool_feedPlunge")) {
  432. if (movements & (1 << MOVEMENT_PLUNGE)) {
  433. var feedContext = new FeedContext(id, localize("Plunge"), getParameter("operation:tool_feedPlunge"));
  434. activeFeeds.push(feedContext);
  435. activeMovements[MOVEMENT_PLUNGE] = feedContext;
  436. }
  437. ++id;
  438. }
  439. if (true) { // high feed
  440. if (movements & (1 << MOVEMENT_HIGH_FEED)) {
  441. var feedContext = new FeedContext(id, localize("High Feed"), this.highFeedrate);
  442. activeFeeds.push(feedContext);
  443. activeMovements[MOVEMENT_HIGH_FEED] = feedContext;
  444. }
  445. ++id;
  446. }
  447.  
  448. for (var i = 0; i < activeFeeds.length; ++i) {
  449. var feedContext = activeFeeds[i];
  450. writeBlock("#" + (firstFeedParameter + feedContext.id) + "=" + feedFormat.format(feedContext.feed), formatComment(feedContext.description));
  451. }
  452. }
  453.  
  454. var currentWorkPlaneABC = undefined;
  455.  
  456. function forceWorkPlane() {
  457. currentWorkPlaneABC = undefined;
  458. }
  459.  
  460. function setWorkPlane(abc) {
  461. if (!machineConfiguration.isMultiAxisConfiguration()) {
  462. return; // ignore
  463. }
  464.  
  465. if (!((currentWorkPlaneABC == undefined) ||
  466. abcFormat.areDifferent(abc.x, currentWorkPlaneABC.x) ||
  467. abcFormat.areDifferent(abc.y, currentWorkPlaneABC.y) ||
  468. abcFormat.areDifferent(abc.z, currentWorkPlaneABC.z))) {
  469. return; // no change
  470. }
  471.  
  472. onCommand(COMMAND_UNLOCK_MULTI_AXIS);
  473.  
  474. // NOTE: add retract here
  475.  
  476. writeBlock(
  477. gMotionModal.format(0),
  478. conditional(machineConfiguration.isMachineCoordinate(0), "A" + abcFormat.format(abc.x)),
  479. conditional(machineConfiguration.isMachineCoordinate(1), "B" + abcFormat.format(abc.y)),
  480. conditional(machineConfiguration.isMachineCoordinate(2), "C" + abcFormat.format(abc.z))
  481. );
  482.  
  483. onCommand(COMMAND_LOCK_MULTI_AXIS);
  484.  
  485. currentWorkPlaneABC = abc;
  486. }
  487.  
  488. var closestABC = false; // choose closest machine angles
  489. var currentMachineABC;
  490.  
  491. function getWorkPlaneMachineABC(workPlane) {
  492. var W = workPlane; // map to global frame
  493.  
  494. var abc = machineConfiguration.getABC(W);
  495. if (closestABC) {
  496. if (currentMachineABC) {
  497. abc = machineConfiguration.remapToABC(abc, currentMachineABC);
  498. } else {
  499. abc = machineConfiguration.getPreferredABC(abc);
  500. }
  501. } else {
  502. abc = machineConfiguration.getPreferredABC(abc);
  503. }
  504.  
  505. try {
  506. abc = machineConfiguration.remapABC(abc);
  507. currentMachineABC = abc;
  508. } catch (e) {
  509. error(
  510. localize("Machine angles not supported") + ":"
  511. + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
  512. + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
  513. + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
  514. );
  515. }
  516.  
  517. var direction = machineConfiguration.getDirection(abc);
  518. if (!isSameDirection(direction, W.forward)) {
  519. error(localize("Orientation not supported."));
  520. }
  521.  
  522. if (!machineConfiguration.isABCSupported(abc)) {
  523. error(
  524. localize("Work plane is not supported") + ":"
  525. + conditional(machineConfiguration.isMachineCoordinate(0), " A" + abcFormat.format(abc.x))
  526. + conditional(machineConfiguration.isMachineCoordinate(1), " B" + abcFormat.format(abc.y))
  527. + conditional(machineConfiguration.isMachineCoordinate(2), " C" + abcFormat.format(abc.z))
  528. );
  529. }
  530.  
  531. var tcp = true;
  532. if (tcp) {
  533. setRotation(W); // TCP mode
  534. } else {
  535. var O = machineConfiguration.getOrientation(abc);
  536. var R = machineConfiguration.getRemainingOrientation(abc, W);
  537. setRotation(R);
  538. }
  539.  
  540. return abc;
  541. }
  542.  
  543. function onSection() {
  544. var insertToolCall = isFirstSection() ||
  545. currentSection.getForceToolChange && currentSection.getForceToolChange() ||
  546. (tool.number != getPreviousSection().getTool().number);
  547.  
  548. var retracted = false; // specifies that the tool has been retracted to the safe plane
  549. var newWorkOffset = isFirstSection() ||
  550. (getPreviousSection().workOffset != currentSection.workOffset); // work offset changes
  551. var newWorkPlane = isFirstSection() ||
  552. !isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis());
  553. if (insertToolCall || newWorkOffset || newWorkPlane) {
  554.  
  555. // stop spindle before retract during tool change
  556. if (insertToolCall && !isFirstSection()) {
  557. onCommand(COMMAND_STOP_SPINDLE);
  558. }
  559.  
  560. // retract to safe plane
  561. retracted = true;
  562. writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract
  563. writeBlock(gAbsIncModal.format(90));
  564. zOutput.reset();
  565. }
  566.  
  567. if (hasParameter("operation-comment")) {
  568. var comment = getParameter("operation-comment");
  569. if (comment) {
  570. writeComment(comment);
  571. }
  572. }
  573.  
  574. if (properties.showNotes && hasParameter("notes")) {
  575. var notes = getParameter("notes");
  576. if (notes) {
  577. var lines = String(notes).split("\n");
  578. var r1 = new RegExp("^[\\s]+", "g");
  579. var r2 = new RegExp("[\\s]+$", "g");
  580. for (line in lines) {
  581. var comment = lines[line].replace(r1, "").replace(r2, "");
  582. if (comment) {
  583. writeComment(comment);
  584. }
  585. }
  586. }
  587. }
  588.  
  589. if (insertToolCall) {
  590. forceWorkPlane();
  591.  
  592. retracted = true;
  593. onCommand(COMMAND_COOLANT_OFF);
  594.  
  595. if (!isFirstSection() && properties.optionalStop) {
  596. onCommand(COMMAND_OPTIONAL_STOP);
  597. }
  598.  
  599. if (tool.number > 99) {
  600. warning(localize("Tool number exceeds maximum value."));
  601. }
  602.  
  603. writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
  604. if (tool.comment) {
  605. writeComment(tool.comment);
  606. }
  607. var showToolZMin = false;
  608. if (showToolZMin) {
  609. if (is3D()) {
  610. var numberOfSections = getNumberOfSections();
  611. var zRange = currentSection.getGlobalZRange();
  612. var number = tool.number;
  613. for (var i = currentSection.getId() + 1; i < numberOfSections; ++i) {
  614. var section = getSection(i);
  615. if (section.getTool().number != number) {
  616. break;
  617. }
  618. zRange.expandToRange(section.getGlobalZRange());
  619. }
  620. writeComment(localize("ZMIN") + "=" + zRange.getMinimum());
  621. }
  622. }
  623.  
  624. if (properties.preloadTool) {
  625. var nextTool = getNextTool(tool.number);
  626. if (nextTool) {
  627. writeBlock("T" + toolFormat.format(nextTool.number));
  628. } else {
  629. // preload first tool
  630. var section = getSection(0);
  631. var firstToolNumber = section.getTool().number;
  632. if (tool.number != firstToolNumber) {
  633. writeBlock("T" + toolFormat.format(firstToolNumber));
  634. }
  635. }
  636. }
  637. }
  638.  
  639. if (insertToolCall ||
  640. forceSpindleSpeed ||
  641. isFirstSection() ||
  642. (rpmFormat.areDifferent(tool.spindleRPM, sOutput.getCurrent())) ||
  643. (tool.clockwise != getPreviousSection().getTool().clockwise)) {
  644. forceSpindleSpeed = false;
  645.  
  646. if (tool.spindleRPM < 1) {
  647. error(localize("Spindle speed out of range."));
  648. return;
  649. }
  650. if (tool.spindleRPM > 99999) {
  651. warning(localize("Spindle speed exceeds maximum value."));
  652. }
  653. writeBlock(
  654. sOutput.format(tool.spindleRPM), mFormat.format(tool.clockwise ? 3 : 4)
  655. );
  656. }
  657.  
  658. // wcs
  659. var workOffset = currentSection.workOffset;
  660. if (workOffset == 0) {
  661. warningOnce(localize("Work offset has not been specified. Using G54 as WCS."), WARNING_WORK_OFFSET);
  662. workOffset = 1;
  663. }
  664. if (workOffset > 0) {
  665. if (workOffset > 6) {
  666. var p = workOffset - 6; // 1->...
  667. if (p > 3) {
  668. error(localize("Work offset out of range."));
  669. return;
  670. } else {
  671. if (workOffset != currentWorkOffset) {
  672. writeBlock(gFormat.format(59.1), "P" + p); // G59.1P
  673. currentWorkOffset = workOffset;
  674. }
  675. }
  676. } else {
  677. if (workOffset != currentWorkOffset) {
  678. writeBlock(gFormat.format(53 + workOffset)); // G54->G59
  679. currentWorkOffset = workOffset;
  680. }
  681. }
  682. }
  683.  
  684. forceXYZ();
  685.  
  686. if (machineConfiguration.isMultiAxisConfiguration()) { // use 5-axis indexing for multi-axis mode
  687. // set working plane after datum shift
  688.  
  689. var abc = new Vector(0, 0, 0);
  690. if (currentSection.isMultiAxis()) {
  691. forceWorkPlane();
  692. cancelTransformation();
  693. } else {
  694. abc = getWorkPlaneMachineABC(currentSection.workPlane);
  695. }
  696. setWorkPlane(abc);
  697. } else { // pure 3D
  698. var remaining = currentSection.workPlane;
  699. if (!isSameDirection(remaining.forward, new Vector(0, 0, 1))) {
  700. error(localize("Tool orientation is not supported."));
  701. return;
  702. }
  703. setRotation(remaining);
  704. }
  705.  
  706. // set coolant after we have positioned at Z
  707. {
  708. var c = mapCoolantTable.lookup(tool.coolant);
  709. if (c) {
  710. writeBlock(mFormat.format(c));
  711. } else {
  712. warning(localize("Coolant not supported."));
  713. }
  714. }
  715.  
  716. forceAny();
  717. gMotionModal.reset();
  718.  
  719. var initialPosition = getFramePosition(currentSection.getInitialPosition());
  720. if (!retracted) {
  721. if (getCurrentPosition().z < initialPosition.z) {
  722. writeBlock(gMotionModal.format(0), zOutput.format(initialPosition.z));
  723. }
  724. }
  725.  
  726. if (insertToolCall || retracted) {
  727. var lengthOffset = tool.lengthOffset;
  728. if (lengthOffset > 99) {
  729. error(localize("Length offset out of range."));
  730. return;
  731. }
  732.  
  733. gMotionModal.reset();
  734. writeBlock(gPlaneModal.format(17));
  735.  
  736. if (!machineConfiguration.isHeadConfiguration()) {
  737. writeBlock(
  738. gAbsIncModal.format(90),
  739. gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y)
  740. );
  741. writeBlock(gMotionModal.format(0), gFormat.format(43), zOutput.format(initialPosition.z), hFormat.format(lengthOffset));
  742. } else {
  743. writeBlock(
  744. gAbsIncModal.format(90),
  745. gMotionModal.format(0),
  746. gFormat.format(43), xOutput.format(initialPosition.x),
  747. yOutput.format(initialPosition.y),
  748. zOutput.format(initialPosition.z), hFormat.format(lengthOffset)
  749. );
  750. }
  751.  
  752. gMotionModal.reset();
  753. } else {
  754. writeBlock(
  755. gAbsIncModal.format(90),
  756. gMotionModal.format(0),
  757. xOutput.format(initialPosition.x),
  758. yOutput.format(initialPosition.y)
  759. );
  760. }
  761.  
  762.  
  763. if (properties.useParametricFeed &&
  764. hasParameter("operation-strategy") &&
  765. (getParameter("operation-strategy") != "drill")) {
  766. if (!insertToolCall &&
  767. activeMovements &&
  768. (getCurrentSectionId() > 0) &&
  769. (getPreviousSection().getPatternId() == currentSection.getPatternId())) {
  770. // use the current feeds
  771. } else {
  772. initializeActiveFeeds();
  773. }
  774. } else {
  775. activeMovements = undefined;
  776. }
  777. }
  778.  
  779. function onDwell(seconds) {
  780. if (seconds > 99999.999) {
  781. warning(localize("Dwelling time is out of range."));
  782. }
  783. writeBlock(gFeedModeModal.format(94), gFormat.format(4), "P" + secFormat.format(seconds));
  784. }
  785.  
  786. function onSpindleSpeed(spindleSpeed) {
  787. writeBlock(sOutput.format(spindleSpeed));
  788. }
  789.  
  790. function onCycle() {
  791. writeBlock(gPlaneModal.format(17));
  792. }
  793.  
  794. function getCommonCycle(x, y, z, r) {
  795. forceXYZ(); // force xyz on first drill hole of any cycle
  796. return [xOutput.format(x), yOutput.format(y),
  797. zOutput.format(z),
  798. "R" + xyzFormat.format(r)];
  799. }
  800.  
  801. function onCyclePoint(x, y, z) {
  802. switch (cycleType) {
  803. case "tapping":
  804. case "left-tapping":
  805. case "right-tapping":
  806. cycleExpanded = true;
  807. repositionToCycleClearance(cycle, x, y, z);
  808. writeBlock(
  809. gAbsIncModal.format(90), gMotionModal.format(0),
  810. conditional(gPlaneModal.getCurrent() == 17, zOutput.format(cycle.retract)),
  811. conditional(gPlaneModal.getCurrent() == 18, yOutput.format(cycle.retract)),
  812. conditional(gPlaneModal.getCurrent() == 19, xOutput.format(cycle.retract))
  813. );
  814. writeBlock(
  815. gAbsIncModal.format(90), gFormat.format(33.1),
  816. conditional(gPlaneModal.getCurrent() == 17, zOutput.format(z)),
  817. conditional(gPlaneModal.getCurrent() == 18, yOutput.format(y)),
  818. conditional(gPlaneModal.getCurrent() == 19, xOutput.format(x)),
  819. "K" + pitchFormat.format(tool.threadPitch)
  820. );
  821. writeBlock(
  822. gAbsIncModal.format(90), gMotionModal.format(0),
  823. conditional(gPlaneModal.getCurrent() == 17, zOutput.format(cycle.clearance)),
  824. conditional(gPlaneModal.getCurrent() == 18, yOutput.format(cycle.clearance)),
  825. conditional(gPlaneModal.getCurrent() == 19, xOutput.format(cycle.clearance))
  826. );
  827. return;
  828. /*
  829. case "tapping-with-chip-breaking":
  830. case "left-tapping-with-chip-breaking":
  831. case "right-tapping-with-chip-breaking":
  832. */
  833. }
  834.  
  835. if (isFirstCyclePoint()) {
  836. repositionToCycleClearance(cycle, x, y, z);
  837.  
  838. // return to initial Z which is clearance plane and set absolute mode
  839.  
  840. var F = cycle.feedrate;
  841. var P = (cycle.dwell == 0) ? 0 : clamp(0.001, cycle.dwell, 99999999); // in seconds
  842.  
  843. switch (cycleType) {
  844. case "drilling":
  845. writeBlock(
  846. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81),
  847. getCommonCycle(x, y, z, cycle.retract),
  848. feedOutput.format(F)
  849. );
  850. break;
  851. case "counter-boring":
  852. if (P > 0) {
  853. writeBlock(
  854. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(82),
  855. getCommonCycle(x, y, z, cycle.retract),
  856. "P" + secFormat.format(P),
  857. feedOutput.format(F)
  858. );
  859. } else {
  860. writeBlock(
  861. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(81),
  862. getCommonCycle(x, y, z, cycle.retract),
  863. feedOutput.format(F)
  864. );
  865. }
  866. break;
  867. case "chip-breaking":
  868. expandCyclePoint(x, y, z);
  869. break;
  870. case "deep-drilling":
  871. if (P > 0) {
  872. expandCyclePoint(x, y, z);
  873. } else {
  874. writeBlock(
  875. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(83),
  876. getCommonCycle(x, y, z, cycle.retract),
  877. "Q" + xyzFormat.format(cycle.incrementalDepth),
  878. // conditional(P > 0, "P" + secFormat.format(P)),
  879. feedOutput.format(F)
  880. );
  881. }
  882. break;
  883. case "fine-boring":
  884. expandCyclePoint(x, y, z);
  885. break;
  886. /* // not supported
  887. case "back-boring":
  888. var dx = (gPlaneModal.getCurrent() == 19) ? cycle.backBoreDistance : 0;
  889. var dy = (gPlaneModal.getCurrent() == 18) ? cycle.backBoreDistance : 0;
  890. var dz = (gPlaneModal.getCurrent() == 17) ? cycle.backBoreDistance : 0;
  891. writeBlock(
  892. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(87),
  893. getCommonCycle(x - dx, y - dy, z - dz, cycle.bottom),
  894. "Q" + xyzFormat.format(cycle.shift),
  895. "P" + secFormat.format(P), // not optional
  896. feedOutput.format(F)
  897. );
  898. break;
  899. */
  900. case "reaming":
  901. if (P > 0) {
  902. writeBlock(
  903. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89),
  904. getCommonCycle(x, y, z, cycle.retract),
  905. "P" + secFormat.format(P),
  906. feedOutput.format(F)
  907. );
  908. } else {
  909. writeBlock(
  910. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85),
  911. getCommonCycle(x, y, z, cycle.retract),
  912. feedOutput.format(F)
  913. );
  914. }
  915. break;
  916. case "stop-boring":
  917. writeBlock(
  918. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(86),
  919. getCommonCycle(x, y, z, cycle.retract),
  920. conditional(P > 0, "P" + secFormat.format(P)),
  921. feedOutput.format(F)
  922. );
  923. break;
  924. case "manual-boring":
  925. writeBlock(
  926. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(88),
  927. getCommonCycle(x, y, z, cycle.retract),
  928. "P" + secFormat.format(P), // not optional
  929. feedOutput.format(F)
  930. );
  931. break;
  932. case "boring":
  933. if (P > 0) {
  934. writeBlock(
  935. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(89),
  936. getCommonCycle(x, y, z, cycle.retract),
  937. "P" + secFormat.format(P), // not optional
  938. feedOutput.format(F)
  939. );
  940. } else {
  941. writeBlock(
  942. gRetractModal.format(98), gAbsIncModal.format(90), gCycleModal.format(85),
  943. getCommonCycle(x, y, z, cycle.retract),
  944. feedOutput.format(F)
  945. );
  946. }
  947. break;
  948. default:
  949. expandCyclePoint(x, y, z);
  950. }
  951. } else {
  952. if (cycleExpanded) {
  953. expandCyclePoint(x, y, z);
  954. } else {
  955. var _x = xOutput.format(x);
  956. var _y = yOutput.format(y);
  957. var _z = zOutput.format(z);
  958. if (!_x && !_y && !_z) {
  959. switch (gPlaneModal.getCurrent()) {
  960. case 17: // XY
  961. xOutput.reset(); // at least one axis is required
  962. _x = xOutput.format(x);
  963. break;
  964. case 18: // ZX
  965. zOutput.reset(); // at least one axis is required
  966. _z = zOutput.format(z);
  967. break;
  968. case 19: // YZ
  969. yOutput.reset(); // at least one axis is required
  970. _y = yOutput.format(y);
  971. break;
  972. }
  973. }
  974. writeBlock(_x, _y, _z);
  975. }
  976. }
  977. }
  978.  
  979. function onCycleEnd() {
  980. if (!cycleExpanded) {
  981. writeBlock(gCycleModal.format(80));
  982. }
  983. }
  984.  
  985. var pendingRadiusCompensation = -1;
  986.  
  987. function onRadiusCompensation() {
  988. pendingRadiusCompensation = radiusCompensation;
  989. }
  990.  
  991. function onRapid(_x, _y, _z) {
  992. var x = xOutput.format(_x);
  993. var y = yOutput.format(_y);
  994. var z = zOutput.format(_z);
  995. if (x || y || z) {
  996. if (pendingRadiusCompensation >= 0) {
  997. error(localize("Radius compensation mode cannot be changed at rapid traversal."));
  998. return;
  999. }
  1000. writeBlock(gMotionModal.format(0), x, y, z);
  1001. feedOutput.reset();
  1002. }
  1003. }
  1004.  
  1005. function onLinear(_x, _y, _z, feed) {
  1006. var x = xOutput.format(_x);
  1007. var y = yOutput.format(_y);
  1008. var z = zOutput.format(_z);
  1009. var f = getFeed(feed);
  1010. if (x || y || z) {
  1011. if (pendingRadiusCompensation >= 0) {
  1012. pendingRadiusCompensation = -1;
  1013. var d = tool.diameterOffset;
  1014. if (d > 99) {
  1015. warning(localize("The diameter offset exceeds the maximum value."));
  1016. }
  1017. writeBlock(gPlaneModal.format(17));
  1018. switch (radiusCompensation) {
  1019. case RADIUS_COMPENSATION_LEFT:
  1020. dOutput.reset();
  1021. writeBlock(gMotionModal.format(1), gFormat.format(41), x, y, z, dOutput.format(d), f);
  1022. break;
  1023. case RADIUS_COMPENSATION_RIGHT:
  1024. dOutput.reset();
  1025. writeBlock(gMotionModal.format(1), gFormat.format(42), x, y, z, dOutput.format(d), f);
  1026. break;
  1027. default:
  1028. writeBlock(gMotionModal.format(1), gFormat.format(40), x, y, z, f);
  1029. }
  1030. } else {
  1031. writeBlock(gMotionModal.format(1), x, y, z, f);
  1032. }
  1033. } else if (f) {
  1034. if (getNextRecord().isMotion()) { // try not to output feed without motion
  1035. feedOutput.reset(); // force feed on next line
  1036. } else {
  1037. writeBlock(gMotionModal.format(1), f);
  1038. }
  1039. }
  1040. }
  1041.  
  1042. function onRapid5D(_x, _y, _z, _a, _b, _c) {
  1043. if (pendingRadiusCompensation >= 0) {
  1044. error(localize("Radius compensation mode cannot be changed at rapid traversal."));
  1045. return;
  1046. }
  1047. var x = xOutput.format(_x);
  1048. var y = yOutput.format(_y);
  1049. var z = zOutput.format(_z);
  1050. var a = aOutput.format(_a);
  1051. var b = bOutput.format(_b);
  1052. var c = cOutput.format(_c);
  1053. writeBlock(gMotionModal.format(0), x, y, z, a, b, c);
  1054. feedOutput.reset();
  1055. }
  1056.  
  1057. function onLinear5D(_x, _y, _z, _a, _b, _c, feed) {
  1058. if (pendingRadiusCompensation >= 0) {
  1059. error(localize("Radius compensation cannot be activated/deactivated for 5-axis move."));
  1060. return;
  1061. }
  1062. var x = xOutput.format(_x);
  1063. var y = yOutput.format(_y);
  1064. var z = zOutput.format(_z);
  1065. var a = aOutput.format(_a);
  1066. var b = bOutput.format(_b);
  1067. var c = cOutput.format(_c);
  1068. var f = getFeed(feed);
  1069. if (x || y || z || a || b || c) {
  1070. writeBlock(gMotionModal.format(1), x, y, z, a, b, c, f);
  1071. } else if (f) {
  1072. if (getNextRecord().isMotion()) { // try not to output feed without motion
  1073. feedOutput.reset(); // force feed on next line
  1074. } else {
  1075. writeBlock(gMotionModal.format(1), f);
  1076. }
  1077. }
  1078. }
  1079.  
  1080. function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
  1081. if (pendingRadiusCompensation >= 0) {
  1082. error(localize("Radius compensation cannot be activated/deactivated for a circular move."));
  1083. return;
  1084. }
  1085.  
  1086. var start = getCurrentPosition();
  1087.  
  1088. if (isFullCircle()) {
  1089. if (properties.useRadius || isHelical()) { // radius mode does not support full arcs
  1090. linearize(tolerance);
  1091. return;
  1092. }
  1093. switch (getCircularPlane()) {
  1094. case PLANE_XY:
  1095. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), jOutput.format(cy - start.y, 0), getFeed(feed));
  1096. break;
  1097. case PLANE_ZX:
  1098. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
  1099. break;
  1100. case PLANE_YZ:
  1101. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
  1102. break;
  1103. default:
  1104. linearize(tolerance);
  1105. }
  1106. } else if (!properties.useRadius) {
  1107. switch (getCircularPlane()) {
  1108. case PLANE_XY:
  1109. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(17), 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), getFeed(feed));
  1110. break;
  1111. case PLANE_ZX:
  1112. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), iOutput.format(cx - start.x, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
  1113. break;
  1114. case PLANE_YZ:
  1115. writeBlock(gAbsIncModal.format(90), gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), jOutput.format(cy - start.y, 0), kOutput.format(cz - start.z, 0), getFeed(feed));
  1116. break;
  1117. default:
  1118. linearize(tolerance);
  1119. }
  1120. } else { // use radius mode
  1121. var r = getCircularRadius();
  1122. if (toDeg(getCircularSweep()) > 180) {
  1123. r = -r; // allow up to <360 deg arcs
  1124. }
  1125. switch (getCircularPlane()) {
  1126. case PLANE_XY:
  1127. writeBlock(gPlaneModal.format(17), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
  1128. break;
  1129. case PLANE_ZX:
  1130. writeBlock(gPlaneModal.format(18), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
  1131. break;
  1132. case PLANE_YZ:
  1133. writeBlock(gPlaneModal.format(19), gMotionModal.format(clockwise ? 2 : 3), xOutput.format(x), yOutput.format(y), zOutput.format(z), "R" + rFormat.format(r), getFeed(feed));
  1134. break;
  1135. default:
  1136. linearize(tolerance);
  1137. }
  1138. }
  1139. }
  1140.  
  1141. var mapCommand = {
  1142. COMMAND_STOP:0,
  1143. COMMAND_OPTIONAL_STOP:1,
  1144. COMMAND_END:2,
  1145. COMMAND_SPINDLE_CLOCKWISE:3,
  1146. COMMAND_SPINDLE_COUNTERCLOCKWISE:4,
  1147. COMMAND_STOP_SPINDLE:5,
  1148. COMMAND_ORIENTATE_SPINDLE:19,
  1149. COMMAND_LOAD_TOOL:6,
  1150. COMMAND_COOLANT_ON:8,
  1151. COMMAND_COOLANT_OFF:9
  1152. };
  1153.  
  1154. function onCommand(command) {
  1155. switch (command) {
  1156. case COMMAND_STOP:
  1157. writeBlock(mFormat.format(0));
  1158. forceSpindleSpeed = true;
  1159. return;
  1160. case COMMAND_START_SPINDLE:
  1161. onCommand(tool.clockwise ? COMMAND_SPINDLE_CLOCKWISE : COMMAND_SPINDLE_COUNTERCLOCKWISE);
  1162. return;
  1163. case COMMAND_LOCK_MULTI_AXIS:
  1164. return;
  1165. case COMMAND_UNLOCK_MULTI_AXIS:
  1166. return;
  1167. case COMMAND_BREAK_CONTROL:
  1168. return;
  1169. case COMMAND_TOOL_MEASURE:
  1170. return;
  1171. }
  1172.  
  1173. var stringId = getCommandStringId(command);
  1174. var mcode = mapCommand[stringId];
  1175. if (mcode != undefined) {
  1176. writeBlock(mFormat.format(mcode));
  1177. } else {
  1178. onUnsupportedCommand(command);
  1179. }
  1180. }
  1181.  
  1182. function onSectionEnd() {
  1183. if (currentSection.isMultiAxis()) {
  1184. writeBlock(gMotionModal.format(49));
  1185. }
  1186. writeBlock(gPlaneModal.format(17));
  1187.  
  1188. if (((getCurrentSectionId() + 1) >= getNumberOfSections()) ||
  1189. (tool.number != getNextSection().getTool().number)) {
  1190. onCommand(COMMAND_BREAK_CONTROL);
  1191. }
  1192.  
  1193. forceAny();
  1194. }
  1195.  
  1196. function onClose() {
  1197. onCommand(COMMAND_COOLANT_OFF);
  1198.  
  1199. writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0)); // retract
  1200. zOutput.reset();
  1201.  
  1202. setWorkPlane(new Vector(0, 0, 0)); // reset working plane
  1203.  
  1204. if (!machineConfiguration.hasHomePositionX() && !machineConfiguration.hasHomePositionY()) {
  1205. // 90/91 mode is don't care
  1206. writeBlock(gFormat.format(28), gAbsIncModal.format(91), "X" + xyzFormat.format(0), "Y" + xyzFormat.format(0)); // return to home
  1207. } else {
  1208. var homeX;
  1209. if (machineConfiguration.hasHomePositionX()) {
  1210. homeX = "X" + xyzFormat.format(machineConfiguration.getHomePositionX());
  1211. }
  1212. var homeY;
  1213. if (machineConfiguration.hasHomePositionY()) {
  1214. homeY = "Y" + xyzFormat.format(machineConfiguration.getHomePositionY());
  1215. }
  1216. writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), homeX, homeY);
  1217. }
  1218.  
  1219. onImpliedCommand(COMMAND_END);
  1220. onImpliedCommand(COMMAND_STOP_SPINDLE);
  1221. writeBlock(mFormat.format(30)); // stop program, spindle stop, coolant off
  1222. writeln("%");
  1223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement