a DSL to do numerical control for CNC machines

gwen 3690b6ed6f spooling пре 3 година
examples bafa44dae8 initial stuff пре 4 година
.gitignore 9eec99b9d9 gitignore пре 4 година
LICENSE d4fe8a89a8 Initial commit пре 4 година
README.md 3690b6ed6f spooling пре 3 година
cylinder.jsnc f6566e0fb0 lots of stuff пре 4 година
gcode.json bafa44dae8 initial stuff пре 4 година
index.html bafa44dae8 initial stuff пре 4 година
index.js 26c7ee709e delete the old code when we emit пре 4 година
jsconfig.json 89aa3c3e31 a bunch of stuff but mostly adding letters пре 4 година
stdPaths.jsnc 33b9cf456a added newline, tweaked spacing пре 4 година

README.md

JSNC (javascript numerical control)

JSNC is a small DSL and library for generating gcode for CNC machines. It allows you to use all the power of a scripting language to create otherwise difficult toolpaths. It is inspired in part by OpenSCAD.

Features

  • all of javascript! JSNC is basically just a handful of preprocess steps that convert your jsnc code into vanila javascript which gets (gasp) eval'd. So any neato feature in JS is yours for the taking
  • A small (but growing) standard library of shapes/paths and functions.
  • It's own font! I've designed a font so you can write your heart out. Currently only supports A-Z period space and newlines.
  • Emiting gcode is super clean. any time a gcode is hit in the flow of your program it's pushed onto the stack of gcodes to be emitted into the final output
  • auto-cleans excessive G90 and G91 codes
    • these codes are used to switch between absolute and relative mode
    • When one is found it is checked against the last known state so that extra calls aren't emitted into the final gcode

"Instalation"

For the moment the "installation" is just cloning the repo and running an http server in the folder.

Code Sample

Here is a snippet that generates a Lorentz Attractor. goodluck modeling THAT in autocad :P

let x = 0.01;
let y = 0.01;
let z = 0.01;

let o = 10;
let p = 28;
let B = 8 / 3;
let dt = 0.001;
let scale = 2;

G21
G90
G0 Z0 F1300

for (let i = 0; i < 100000; i++) {
  const dx = o * (y - x);
  const dy = x * (p - z) - y;
  const dz = x * y - B * z;

  x += dx * dt;
  y += dy * dt;
  z += dz * dt;

  G0 X${trnc(x)*scale} Y${trnc(y)*scale}
}

function trnc(v){
  return Math.round(v*1000)/1000
}

G0 Z1
M5