Browse Source

initial stuff

John 7 months ago
parent
commit
bafa44dae8
5 changed files with 249 additions and 0 deletions
  1. 26 0
      cylinder.jsnc
  2. 34 0
      examples/smiles.jsnc
  3. 95 0
      gcode.json
  4. 25 0
      index.html
  5. 69 0
      index.js

+ 26 - 0
cylinder.jsnc

@@ -0,0 +1,26 @@
+let safe = 3;
+let depthOfCut = 1;
+let plungeRate = 100;
+let feedRate = 200;
+let rapidRate = 1300;
+let toolDiameter = 3;
+let radius = 12-(toolDiameter/2);
+let depth = 6;
+
+G21
+
+M3 S800
+
+for(let d=depthOfCut; d<=depth; d+=depthOfCut){
+  gcode.push("; layer");
+  G0 Z$safe F$rapidRate
+  G0 X0 Y0
+  G1 Z${-1*d} F$plungeRate;
+  for(let i=depthOfCut; i<=radius; i+=depthOfCut){
+    G1 X$i F$feedRate
+    G2 X$i Y0 I${-1*i} J0 F$feedRate
+  }
+}
+
+M5 S0
+M2

+ 34 - 0
examples/smiles.jsnc

@@ -0,0 +1,34 @@
+//a program to draw smileson a paper with a pen
+let radius = 10;
+let safe = 1;
+let feed = 1300;
+
+G21
+G0 Z$safe F$feed
+G0 X0 Y0 
+G1 F$feed
+
+function smile(){
+  //outside
+  G0 X${-1*radius}
+  G1 Z0
+  G2 X${-1*radius} Y0 I$radius J0 F$feed
+  //mouth
+  G0 Z$safe
+  G0 X${radius/-2.5} Y${radius/-2.5}
+  G1 Z0
+  G3 X${radius/2.5} Y${radius/-2.5} I${radius/2.5} J0
+  //left eye
+  G0 Z$safe
+  G0 X${radius/-2.5 - 1} Y-0.5
+  G1 Z0
+  G2 X${radius/-2.5 - 1.5} I1.5
+  //right eye
+  G0 Z$safe
+  G0 X${radius/2.5 - 1.5} Y-0.5
+  G1 Z0
+  G2 X${radius/2.5 - 1.5} I1.5
+
+}
+
+smile();

+ 95 - 0
gcode.json

@@ -0,0 +1,95 @@
+{
+  "G0": "rapid linear",
+  "G1": "cut linear",
+  "G2": "cut clockwise arc",
+  "G3": "cut anticlockwise arc",
+  "G4": "dwell",
+  "G5": "",
+  "G9": "",
+  "G10": "",
+  "G15": "Turn OFF Polar Coords",
+  "G16": "Turn ON Polar Coords",
+  "G17": "X-Y Plane",
+  "G18": "X-Z Plane",
+  "G19": "Y-Z Plane",
+  "G20": "inch mode",
+  "G21": "metric mode",
+  "G27": "",
+  "G28": "",
+  "G29": "",
+  "G30": "",
+  "G32": "",
+  "G40": "tool cutter compensation off",
+  "G41": "",
+  "G42": "",
+  "G43": "",
+  "G43.1": "Dynamic Tool Length Offset",
+  "G44": "",
+  "G49": "tool length compensation cancel",
+  "G50": "",
+  "G51": "",
+  "G52": "",
+  "G53": "",
+  "G54": "",
+  "G55": "",
+  "G56": "",
+  "G57": "",
+  "G58": "",
+  "G59": "",
+  "G61": "",
+  "G62": "",
+  "G63": "",
+  "G64": "",
+  "G65": "",
+  "G68": "",
+  "G69": "",
+  "G73": "",
+  "G74": "",
+  "G76": "",
+  "G80": "",
+  "G81": "",
+  "G82": "",
+  "G83": "",
+  "G84": "",
+  "G85": "",
+  "G86": "",
+  "G87": "",
+  "G88": "",
+  "G89": "",
+  "G90": "Absolute programming of XYZ",
+  "G90.1": "Absolute programming of IJK",
+  "G91": "",
+  "G91.1": "",
+  "G92": "",
+  "G92.1": "",
+  "G92.2": "",
+  "G92.3": "",
+  "G94": "",
+  "G95": "",
+  "G96": "",
+  "G97": "",
+  "G98": "",
+  "G99": "",
+
+  "M0": "Program Stop (non-optional)",
+  "M1": "Optional Stop",
+  "M2": "End of Program",
+  "M3": "Spindle ON Clockwise",
+  "M4": "Spindle ON Anticlockwise",
+  "M4": "Spindle OFF",
+  "M6": "Tool Change",
+  "M7": "Mist Coolant ON",
+  "M8": "Flood Coolant OFF",
+  "M9": "Coolant OFF",
+  "M17": "",
+  "M29": "",
+  "M30": "",
+  "M97": "",
+  "M98": "",
+  "M99": "",
+
+  "F": {
+    "pattern": "F[0-9]+",
+    "description": "feedrate"
+  }
+}

+ 25 - 0
index.html

@@ -0,0 +1,25 @@
+<html>
+  <head>
+<style>
+  #holder{
+    display: flex;
+    flex-direction: row;
+
+    height: 100%;
+  }
+  .put{
+    width:50%;
+    height: 100%;
+    resize: none;
+  }
+</style>
+  </head>
+  <body>
+    <div id="holder">
+      <textarea class="put" id="input"></textarea>
+      <textarea class="put" id="output"></textarea>
+    </div>
+
+    <script src="index.js"></script>
+  </body>
+</html>

+ 69 - 0
index.js

@@ -0,0 +1,69 @@
+let input = document.getElementById("input");
+let output = document.getElementById("output");
+input.addEventListener("keyup",() => { convert(input.value) });
+
+document.addEventListener("keydown", (e) => {
+  if(e.ctrlKey && e.key == 's'){
+    convert(input.value);
+    download(output.innerHTML,"out.nc","text/plain");
+    e.preventDefault();
+  }
+  else if(e.ctrlKey && e.key == 'q'){
+    download(input.value,"in.jsnc","text/plain");
+    e.preventDefault();
+  }
+  //else if(e.key == "Tab"){
+  //  let cp = input.selectionStart;
+  //  input.value = input.value.substring(0,cp)  + "  " + input.value.substring(cp);
+  //  input.selectionStart = cp + 2;
+  //  input.selectionEnd = cp + 2;
+  //  e.preventDefault();
+  //}
+});
+
+//(([GMFSXYZIJKF]((-?[0-9]+(\.[0-9]+)?)|(\$\{[^\}]+\})|(\$[a-zA-Z0-9]+))) ?)+/g
+const prepro = {
+  //reComment: {
+  //  regex: /^([^\n;]*)(;[^;\n]*)$/gm,
+  //  replace: "$1;gcode.push('$2');"
+  //},
+  bareInterpolables:{
+    regex: /\$([a-zA-Z0-9_]+)/g,
+    replace: "$${$1}"
+  },
+  push:{
+    regex: /(([GMFSXYZIJKF]((-?[0-9]+(\.[0-9]+)?)|(\$\{[^\}]+\}))) ?)+/g,
+    replace: "gcode.push(`$&`);"
+  }
+}
+
+function convert(data){
+  for(let pname in prepro){
+    let pass = prepro[pname];
+    data = data.replace(pass.regex, pass.replace);
+  }
+
+  gcode = [];
+  eval(data);
+  let o = gcode.join("\n");
+  output.innerHTML = o;
+}
+
+// Function to download data to a file
+function download(data, filename, type) {
+    var file = new Blob([data], {type: type});
+    if (window.navigator.msSaveOrOpenBlob) // IE10+
+        window.navigator.msSaveOrOpenBlob(file, filename);
+    else { // Others
+        var a = document.createElement("a"),
+                url = URL.createObjectURL(file);
+        a.href = url;
+        a.download = filename;
+        document.body.appendChild(a);
+        a.click();
+        setTimeout(function() {
+            document.body.removeChild(a);
+            window.URL.revokeObjectURL(url);  
+        }, 0); 
+    }
+}