diff --git a/README.md b/README.md index 3823dfec65e14e59de1720fa00b7d52096cc446b..90a1fe5fcee3a8b98b44c5187d17c1fd933dd7ea 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ aka project consistent-sandbox ## oy - - wait return -> planner + - cooler demo + - jog option + - port flushing ? - want a test / reset set - really, should be built into bridge (or hardware default objs) diff --git a/load/ico.gcode b/load/ico.gcode new file mode 100644 index 0000000000000000000000000000000000000000..1cd1d2b93c35e699afc26ad467bc50f851e5247e --- /dev/null +++ b/load/ico.gcode @@ -0,0 +1,234 @@ +G0 Z5.0000 F100 +G0 X87.7230Y8.0230 +G1 Z0.0000 F50 +G1 X0.9540Y126.8930 +G0 Z5.0000 +G0 X0.9540Y126.8930 +G1 Z0.0000 +G1 X29.2600Y54.1250 +G1 X87.6220Y8.0230 +G1 X87.7230Y8.0230 +G0 Z5.0000 +G0 X87.7230Y8.0230 +G1 Z0.0000 +G1 X87.7320Y8.0230 +G1 X91.6956Y21.1580 +G0 Z5.0000 +G0 X91.6956Y21.1580 +G1 Z0.0000 +G1 X123.4990Y126.5520 +G1 X123.4990Y126.5606 +G0 Z5.0000 +G0 X123.4990Y126.5606 +G1 Z0.0000 +G1 X91.6956Y21.1580 +G0 Z5.0000 +G0 X91.6956Y21.1580 +G1 Z0.0000 +G1 X87.7323Y8.0228 +G0 Z5.0000 +G0 X87.7323Y8.0228 +G1 Z0.0000 +G1 X169.6749Y9.3584 +G1 X227.8618Y53.8484 +G0 Z5.0000 +G0 X227.8618Y53.8484 +G1 Z0.0000 +G1 X87.7323Y8.0228 +G0 Z5.0000 +G0 X123.4990Y126.5606 +G1 Z0.0000 +G1 X123.4997Y126.5611 +G0 Z5.0000 +G0 X123.4997Y126.5611 +G1 Z0.0000 +G1 X123.5012Y126.5600 +G0 Z5.0000 +G0 X123.5012Y126.5600 +G1 Z0.0000 +G1 X123.5000Y126.5600 +G1 X123.4997Y126.5611 +G0 Z5.0000 +G0 X123.4997Y126.5611 +G1 Z0.0000 +G1 X93.7777Y223.2278 +G0 Z5.0000 +G0 X93.7777Y223.2278 +G1 Z0.0000 +G1 X86.5717Y246.6659 +G0 Z5.0000 +G0 X86.5717Y246.6659 +G1 Z0.0000 +G1 X86.5713Y246.6656 +G0 Z5.0000 +G0 X86.5713Y246.6656 +G1 Z0.0000 +G1 X86.4979Y246.6105 +G0 Z5.0000 +G0 X86.4979Y246.6105 +G1 Z0.0000 +G1 X0.9907Y127.1050 +G0 Z5.0000 +G0 X0.9907Y127.1050 +G1 Z0.0000 +G1 X0.9906Y127.1048 +G0 Z5.0000 +G0 X0.9906Y127.1048 +G1 Z0.0000 +G1 X86.4979Y246.6105 +G0 Z5.0000 +G0 X86.4979Y246.6105 +G1 Z0.0000 +G1 X28.2465Y201.8719 +G1 X0.9907Y127.1050 +G0 Z5.0000 +G0 X0.9907Y127.1050 +G1 Z0.0000 +G1 X0.9630Y127.0220 +G1 X7.7722Y126.9995 +G0 Z5.0000 +G0 X7.7722Y126.9995 +G1 Z0.0000 +G1 X0.9630Y127.0220 +G1 X0.9350Y126.9390 +G1 X0.9540Y126.8930 +G0 Z5.0000 +G0 X7.7722Y126.9995 +G1 Z0.0000 +G1 X123.4807Y126.6170 +G0 Z5.0000 +G0 X123.4807Y126.6170 +G1 Z0.0000 +G1 X7.7722Y126.9995 +G0 Z5.0000 +G0 X123.4807Y126.6170 +G1 Z0.0000 +G1 X123.4810Y126.6170 +G0 Z5.0000 +G0 X123.4810Y126.6170 +G1 Z0.0000 +G1 X123.4990Y126.5606 +G0 Z5.0000 +G0 X123.5012Y126.5600 +G1 Z0.0000 +G1 X205.3440Y69.7019 +G0 Z5.0000 +G0 X205.3440Y69.7019 +G1 Z0.0000 +G1 X123.5100Y126.5600 +G0 Z5.0000 +G0 X123.5100Y126.5600 +G1 Z0.0000 +G1 X227.0000Y201.4800 +G0 Z5.0000 +G0 X227.0000Y201.4800 +G1 Z0.0000 +G1 X226.9900Y201.5000 +G1 X226.9018Y201.5686 +G0 Z5.0000 +G0 X226.9018Y201.5686 +G1 Z0.0000 +G1 X201.5364Y209.7327 +G0 Z5.0000 +G0 X201.5364Y209.7327 +G1 Z0.0000 +G1 X226.9000Y201.5700 +G1 X226.9018Y201.5686 +G0 Z5.0000 +G0 X226.9018Y201.5686 +G1 Z0.0000 +G1 X226.9039Y201.5680 +G1 X168.2011Y247.8725 +G0 Z5.0000 +G0 X168.2011Y247.8725 +G1 Z0.0000 +G1 X86.6730Y246.7027 +G1 X201.5364Y209.7327 +G0 Z5.0000 +G0 X201.5364Y209.7327 +G1 Z0.0000 +G1 X86.6700Y246.7000 +G1 X86.6300Y246.7000 +G1 X86.5700Y246.6700 +G0 Z5.0000 +G0 X86.5700Y246.6700 +G1 Z0.0000 +G1 X86.5713Y246.6656 +G0 Z5.0000 +G0 X86.5713Y246.6656 +G1 Z0.0000 +G1 X93.7777Y223.2278 +G0 Z5.0000 +G0 X93.7777Y223.2278 +G1 Z0.0000 +G1 X123.4807Y126.6170 +G0 Z5.0000 +G0 X123.5012Y126.5600 +G1 Z0.0000 +G1 X123.5100Y126.5600 +G0 Z5.0000 +G0 X205.3440Y69.7019 +G1 Z0.0000 +G1 X227.8979Y54.0315 +G0 Z5.0000 +G0 X227.8979Y54.0315 +G1 Z0.0000 +G1 X227.8982Y53.9686 +G0 Z5.0000 +G0 X227.8982Y53.9686 +G1 Z0.0000 +G1 X227.8982Y53.8944 +G1 X227.8892Y53.8670 +G1 X227.8618Y53.8484 +G0 Z5.0000 +G0 X227.8982Y53.9686 +G1 Z0.0000 +G1 X227.8987Y53.8944 +G1 X255.3111Y129.1221 +G1 X227.0236Y201.4114 +G0 Z5.0000 +G0 X227.0236Y201.4114 +G1 Z0.0000 +G1 X227.5750Y108.4543 +G0 Z5.0000 +G0 X227.5750Y108.4543 +G1 Z0.0000 +G1 X227.8979Y54.0332 +G0 Z5.0000 +G0 X227.8979Y54.0332 +G1 Z0.0000 +G1 X227.8979Y54.0315 +G0 Z5.0000 +G0 X227.8979Y54.0315 +G1 Z0.0000 +G1 X227.8982Y54.0312 +G0 Z5.0000 +G0 X227.8982Y54.0312 +G1 Z0.0000 +G1 X227.8982Y53.9686 +G0 Z5.0000 +G0 X227.8982Y54.0312 +G1 Z0.0000 +G1 X227.9000Y54.0300 +G1 X227.5750Y108.4543 +G0 Z5.0000 +G0 X227.5750Y108.4543 +G1 Z0.0000 +G1 X227.0200Y201.4100 +G1 X227.0000Y201.4800 +G0 Z5.0000 +G0 X205.3440Y69.7019 +G1 Z0.0000 +G1 X227.8979Y54.0332 +G0 Z5.0000 +G0 X227.8979Y54.0332 +G1 Z0.0000 +G1 X227.8987Y54.0326 +G0 Z5.0000 +G0 X227.8987Y54.0326 +G1 Z0.0000 +G1 X227.8982Y54.0312 +G0 Z5.0000 +G0 Z5.0000 +G0 X0Y0 +M05 diff --git a/server.js b/server.js index 82f084b95288cdb1529fa1aeca6fcc9f32ca1986..e9bea40b2b1309fe04c95a0e08fd20f57c82fca1 100644 --- a/server.js +++ b/server.js @@ -116,7 +116,7 @@ var term = addModule('./src/ui/terminal.js') var multiline = addModule('./src/ui/multiline.js') var button = addModule('./src/ui/button.js') var numOut = addModule('./src/ui/number.js') -var delay = addModule('./src/util/delay.js') +var delay = addModule('./src/util/delay.js') var gcode = addModule('./src/parsing/gcode.js') var planner = addModule('./src/motion/planner.js') @@ -157,8 +157,11 @@ planner.outputs.moves.attach(ymb.inputs.move) planner.outputs.moves.attach(zm.inputs.move) zm.outputs.ack.attach(planner.inputs.acks) +planner.outputs.moveComplete.attach(multiline.inputs.req) + // same motors / bridge xm.state.axis = 'X' +xm.state.spu = 100 xm.outputs.packet.attach(bridge.inputs.A) bridge.outputs.A.attach(xm.inputs.packet) bridge.state.rA = '0,3' @@ -166,7 +169,7 @@ t1.outputs.packet.attach(bridge.inputs.A) bridge.outputs.A.attach(t1.inputs.packet) yma.state.axis = 'Y' -yma.state.spu = -200 +yma.state.spu = -100 yma.outputs.packet.attach(bridge.inputs.B) bridge.outputs.B.attach(yma.inputs.packet) bridge.state.rB = '0,0' @@ -175,7 +178,7 @@ bridge.outputs.B.attach(t2.inputs.packet) ymb.state.axis = 'Y' // should have to reverse this but did it with wires :| -ymb.state.spu = -200 +ymb.state.spu = -100 ymb.outputs.packet.attach(bridge.inputs.C) bridge.outputs.C.attach(ymb.inputs.packet) bridge.state.rC = '0,5' @@ -183,7 +186,7 @@ t3.outputs.packet.attach(bridge.inputs.C) bridge.outputs.C.attach(t3.inputs.packet) zm.state.axis = 'Z' -zm.state.spu = -200 +zm.state.spu = -100 zm.outputs.packet.attach(bridge.inputs.D) bridge.outputs.D.attach(zm.inputs.packet) bridge.state.rD = '0,1' diff --git a/src/hardware/bridge.js b/src/hardware/bridge.js index f355ec73944005997344806ea213f667578bd05e..ff3af69fe7e904395236ddf560b2e45770af8672 100644 --- a/src/hardware/bridge.js +++ b/src/hardware/bridge.js @@ -80,7 +80,15 @@ function ATKBridge() { function sendToHardware(pckt) { if (port != null && port.writable) { - port.write(pckt) + if(port.write(pckt)){ + return true + } else { + console.log('------------------ !ACHTUNG! -------------------') + console.log('------------------ !ACHTUNG! -------------------') + console.log('---------- port.write(pckt) false --------------') + // https://nodejs.org/api/stream.html#stream_event_drain + // https://serialport.io/docs/api-stream + } return true } else { return false @@ -196,7 +204,7 @@ function ATKBridge() { function onPortData(data) { // we'll make sure it's what we think it will be - console.log("PORT DATA") + // console.log("PORT DATA") var dtArray = new Array() if (Buffer.isBuffer(data)) { for (var i = 0; i < data.length; i++) { @@ -249,7 +257,7 @@ function ATKBridge() { var outKey = key.toString().charAt(1) match = outKey var headless = pckt.slice(pckt.indexOf(255) + 1) - console.log('headless', headless) + //console.log('headless', headless) bridge.outputs[outKey].emit(headless) return true } diff --git a/src/hardware/stepper.js b/src/hardware/stepper.js index 1a2f78cbb5afecf33bdb9f377f37f2e55ba1741b..7e9f1e8177fc670023e4ec9a7f0cce3f53de60ce 100644 --- a/src/hardware/stepper.js +++ b/src/hardware/stepper.js @@ -50,7 +50,6 @@ function Stepper() { } function onHardwareIn(pckt) { - console.log("PCKT TO STEP", pckt) var debug = false if (debug) console.log('PCKT into stepper', pckt) var key = pckt[0] @@ -90,7 +89,7 @@ function Stepper() { } function onRawMove() { - console.log('raw move for', state.rawMove) + console.log('TEST move for', state.rawMove) // finds type of ramp, calculates entry and exit ramp lengths var len = Math.abs(state.rawMove) var delta = state.rawMove @@ -117,7 +116,7 @@ function Stepper() { } else { // have to watch out for zero-lengths on this axis, also var delta = move.vector[axisIndex] - console.log('DELTA', delta) + //console.log('DELTA', delta) if (Math.abs(delta) <= 0) { // find a DOF w/o zlv var fnd = false diff --git a/src/hardware/test.js b/src/hardware/test.js index 139c94b0cad0c8dbe68a4ab340e2059452e80ee5..7be7a80842f87ac2224753971687b0382df01f5b 100644 --- a/src/hardware/test.js +++ b/src/hardware/test.js @@ -40,7 +40,6 @@ function Test() { } function onPacketReturn(evt) { - console.log("EVT", evt) if (evt[0] == '127') { state.message = 'packet return OK' } else { diff --git a/src/motion/planner.js b/src/motion/planner.js index fecba5d4a58ff7aaa9efcdc6199d43b2f225daff..7d6115af8dbed5e7eb2b0239e68d433bb211f540 100644 --- a/src/motion/planner.js +++ b/src/motion/planner.js @@ -26,9 +26,9 @@ function Planner() { state.reset = Button('reset planner') state.onChange('reset', onPlannerReset) - state.accel = 50 // units/s/s - state.jd = 1 // units to arc about - state.minSpeed = 5 // units/s + state.accel = 100 // units/s/s + state.jd = 0.5 // units to arc about + state.minSpeed = 10 // units/s state.startStop = Button('start / stop planner') state.onChange('startStop', onStartStop) @@ -60,7 +60,7 @@ function Planner() { */ function onAck(msg) { - console.log("Planner onAck:", msg) + //console.log("Planner onAck:", msg) // update position, net states, run netCheck var axes = state.axisIDs.split(',') var match = axes.indexOf(msg.axis) @@ -135,18 +135,18 @@ function Planner() { // check equality while (ns[i] == ns[i + 1]) { i++ - console.log('EQUALITY LOOP') + // console.log('EQUALITY LOOP') if (i > ns.length - 1) { break } } if (i == ns.length - 1) { while (ns[i] < state.netWindow) { - console.log('loop 2') + // console.log('loop 2') sendMoveToNetwork() - if(mq.length <= 0){ + if (mq.length <= 0) { planner.isRunning = 0 - break + break } } } @@ -162,6 +162,7 @@ function Planner() { var move = JSON.parse(JSON.stringify(mq.shift())) console.log("MOVE FROM PLANNER", move) planner.outputs.moves.emit(move) + planner.outputs.moveComplete.emit(1) } else { planner.isRunning = 0 } @@ -176,6 +177,8 @@ function Planner() { // the move que, of which it is nice to have shorthand var mq = new Array() + var zlcounter = 0 + function onNewInstruction(move) { // our axis var axes = state.axisIDs.split(',') @@ -205,7 +208,13 @@ function Planner() { } // check for zero-length vector if (MJS.distance(p1, p2) == 0) { + console.log('------------------ !ACHTUNG! -------------------') + console.log('------------------ !ACHTUNG! -------------------') console.log('planner throwing zero length vector') + zlcounter ++ + console.log(zlcounter) + // this means we need another one from the queue + planner.outputs.moveComplete.emit(1) } else { // starting with basics var newMove = { @@ -307,6 +316,8 @@ function Planner() { for (var i = 0; i < mq.length; i++) { calcTrap(mq[i], accel, false) if (moveTime(mq[i]) < 0.1) { + console.log('------------------ !ACHTUNG! -------------------') + console.log('------------------ !ACHTUNG! -------------------') console.log("WARN! move time here", moveTime(mq[i])) } console.log(moveTime(mq[i])) diff --git a/src/ui/multiline.js b/src/ui/multiline.js index 2ab55f43c4f161db40ad52d843f62770b7405ec9..f430342fc050bd0eb7675853bef403d1f6592047 100644 --- a/src/ui/multiline.js +++ b/src/ui/multiline.js @@ -7,6 +7,8 @@ let State = InOut.State let MultiLine = InOut.MultiLine let Button = InOut.Button +const fs = require('fs') + // a constructor, a fn, a javascript mess function MultiLineIn() { @@ -21,13 +23,18 @@ function MultiLineIn() { multilinein.state = State() // alias ! var state = multilinein.state - + state.load = Button('LOAD') + state.onChange('load', onLoadFile) state.thru = Button('WHAM') state.previously = MultiLine('lines complete', 11) // = Multiline(rows) state.now = MultiLine('line just out', 1) state.onChange('thru', lineThru) + state.incoming = MultiLine('future lines', 36) - state.incoming.value = "G0 F50 X10\nG0 Y10\nG0 X0\nG0 Z5\nG0 X10Y10\nG0 X0Y20\nG0 X0Y0Z0" + state.incoming.value = "G0 Z5.0000 F100\nG0 X87.7230Y8.0230\nG1 Z0.0000 F50\nG1 X0.9540Y126.8930\nG0 Z5.0000\nG0 X0.9540Y126.8930\nG1 Z0.0000\nG1 X29.2600Y54.1250\nG1 X87.6220Y8.0230\nG1 X87.7230Y8.0230\nG0 Z5.0000\nG0 X87.7230Y8.0230\nG1 Z0.0000\nG1 X87.7320Y8.0230\nG1 X91.6956Y21.1580\nG0 Z5.0000\nG0 X91.6956Y21.1580\nG1 Z0.0000\nG1 X123.4990Y126.5606\nG0 Z5.0000\n" + /* + G0 F50 X100\nG0 Y100\nG0 X0\nG0 Z5\nG0 X10Y10\nG0 X0Y20\nG0 X0Y0Z0" + */ multilinein.inputs = { req: Input('number', onLineRequest), @@ -57,7 +64,7 @@ function MultiLineIn() { state.previously.value = outBox.join('\n') state.incoming.value = inBox.join('\n') // HERE is another hack for busted state-passing system - state.now = state.now + state.now = state.now if (inBox.length < 1 && box == '') { console.log("END OF MULTILINE") @@ -68,18 +75,24 @@ function MultiLineIn() { } function onLineRequest(num) { - console.log('ON LINE REQ', num) + console.log('-------------------------- ON LINE REQ', num) for (var i = 0; i < num; i++) { lineThru() } } - function onExternalLine(str) { - // push new str to bottom of queue + function onLoadFile() { + console.log('!!!!!!') + fs.readFile('load/ico.gcode', 'utf8', (err, data) => { + if (err) throw err; + console.log(data); + state.incoming.value = data + state.incoming = state.incoming + }) } - function onLoadFile(path) { - // reset, git big string from file + function onExternalLine(str) { + // push new str to bottom of queue } return multilinein