README.md 1.6 KB

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 herat out. Currently only supports A-Z . space and newlines.
  • Emiting gcode is super clean. any time a gcode is hit in the flow of your program a matching code is push onto the stack of gcodes to be emitted
  • 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 emited in the final gcode

Try it out!

Code Sample

Here is a code 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