Commit 26bbd9bf authored by Jake Read's avatar Jake Read

ready for sww, some improvements to go

parent b08b0c28
......@@ -6,7 +6,6 @@ const Programs = require('./programs.js')
// the program object: real simple, just has a description, and a 'modules'
var program = Programs.new('new program')
var canvas = Programs.loadModuleFromSource(program, './modules/ui/threeCanvas.js')
Programs.setUI(canvas, 200, 200)
......
// business
const Reps = require('./reps.js')
const Programs = require('./programs.js')
// the program object: real simple, just has a description, and a 'modules'
var program = Programs.new('new program')
/* ok
- new plotter
- ack four
- go to pos block
- neil:mm adjust
- git push
- add y axis network wait ?
*/
// das link
var link = Programs.loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
link.startUp()
link.state.log = true
let steps = 10
// x motor
var xm = Programs.loadModuleFromSource(program, './modules/hardware/atkstepper.js')
xm.route.route = '0,0'
xm.state.route = '0,0'
xm.state.spu = steps
xm.state.axis = 'X'
// y left and right
var ylm = Programs.loadModuleFromSource(program, './modules/hardware/atkstepper.js')
ylm.route.route = '0,1'
ylm.state.route = '0,1'
ylm.state.spu = steps
ylm.state.axis = 'Y'
var ylr = Programs.loadModuleFromSource(program, './modules/hardware/atkstepper.js')
ylr.route.route = '0,2'
ylr.state.route = '0,2'
ylr.state.spu = -steps
ylr.state.axis = 'Y'
// z motor
var zm = Programs.loadModuleFromSource(program, './modules/hardware/atkstepper.js')
zm.route.route = '0,3'
zm.state.route = '0,3'
zm.state.spu = -steps
zm.state.axis = 'Z'
var planner = Programs.loadModuleFromSource(program, './modules/motion/simplanner.js')
planner.state.minSpeed = 1
planner.state.accel = 300
planner.netWindow = 1
/*
var simplanner = Programs.loadModuelFromSource(program, './modules/motion/simplanner.js')
let ahMove = {
axes: ['X', 'Y', 'Z'],
p1: [10, 10, 10],
p2: [20, 20, 20],
vector: [10, 10, 10],
cruise: 100,
entry: 10,
exit: 10,
accel: 100
}
*/
// what doth planner output ?
/*
var newMove = {
axes: axes,
p1: p1,
p2: p2,
cruise: move.speed,
entry: 0,
exit: 0,
accel: state.accel
}
*/
// can we write something that just steps through moves one by one ?
// HOOKUP
planner.outputs.moves.attach(xm.inputs.trapezoid)
planner.outputs.moves.attach(ylm.inputs.trapezoid)
planner.outputs.moves.attach(ylr.inputs.trapezoid)
planner.outputs.moves.attach(zm.inputs.trapezoid)
xm.outputs.ack.attach(planner.inputs.acks)
ylm.outputs.ack.attach(planner.inputs.acks)
zm.outputs.ack.attach(planner.inputs.acks)
let moveToPlanner = {
position: {
X: 20,
Y: 10,
Z: 5
},
speed: 150
}
link.onOpen = function(){
// planner.inputs.instruction.fn(moveToPlanner)
//xm.inputs.trapezoid.fn(ahMove)
}
// ws input
var sockit = Programs.loadModuleFromSource(program, './modules/pipes/websocket.js')
var np = Programs.loadModuleFromSource(program, './modules/motion/neilparse.js')
sockit.outputs.data.attach(np.inputs.array)
np.outputs.move.attach(planner.inputs.instruction)
planner.outputs.moveComplete.attach(np.inputs.shift)
// UI HOOKUP
Programs.setView(program, {
scale: 0.5,
translate: [-160, -30],
origin: [200, 120]
})
let top = 100
let motorbar = 1200
let motorspace = 400
Programs.setUI(sockit, top, top)
Programs.setUI(np, 600, top)
Programs.setUI(link, 1800, top)
Programs.setUI(xm, motorbar, top)
Programs.setUI(ylm, motorbar, top + motorspace)
Programs.setUI(ylr, motorbar, top + 2 * motorspace)
Programs.setUI(zm, motorbar, top + 3 * motorspace)
Programs.setUI(planner, 600, 450)
// UI
const View = require('./views.js')
View.startHttp()
View.startWs()
Programs.assignSocket(View.uiSocket)
View.assignProgram(program)
\ No newline at end of file
......@@ -94,6 +94,7 @@ function ATKSerialLink() {
//state.portStatus = 'opening'
serialport.on('open', function() {
state.portStatus = 'open'
atkSerialLink.onOpen()
})
serialport.on('error', function(err) {
state.portStatus = err.message
......@@ -103,6 +104,10 @@ function ATKSerialLink() {
}
}
atkSerialLink.onOpen = function() {
// null 4 now ...
}
/*
------------------------------------------------------
PACKETS TO HARDWARE
......
......@@ -47,7 +47,7 @@ function Stepper() {
})
state.axis = 'X'
state.spu = 200 // steps per unit
state.spu = 80 // steps per unit
state.rawMove = -10
var ui = stepper.ui
......@@ -191,7 +191,7 @@ function Stepper() {
console.log(dMove)
}
if(verbose) console.log('------------------- DMOVE', state.axis, dMove.steps)
if(true) console.log('------------------- DMOVE', state.axis, dMove)
var packet = new Array()
// step blocks are #131
......
// boilerplate atkapi header
const JSUnit = require('../../src/jsunit.js')
let Input = JSUnit.Input
let Output = JSUnit.Output
let State = JSUnit.State
// unit to convert neil's mods-output arrays into human readable move objects
// probably do flow control here also ?
function NeilParser() {
var neilParser = {
description: {
name: 'neilParser Parser',
alt: 'line of neilParser -> points'
}
}
// log more
var verbose = false
let npList = null
// one caveat here is that we can't dynamically add objects to this,
// or they don't get getter / settered when we do
neilParser.state = State()
var state = neilParser.state
state.lift = 50
state.moveSpeed = 200
state.plungeSpeed = 50
state.jogSpeed = 600
state.listLength = 0
neilParser.inputs = {
array: Input('array', (arr) => {
let list = writeMoveObjects(arr)
console.log('have list', list)
npList = list
state.listLength = npList.length
// throw it out
neilParser.outputs.newList.emit(1)
onShift()
}),
shift: Input('event', (arg) => {
onShift()
})
}
neilParser.outputs = {
move: Output('move'),
newList: Output('event')
}
function writeMoveObjects(arr) {
// arr[i] are segments,
// between arr[i] instances, we put a z-lift and then
// a z-drop
if (Array.isArray(arr)) {
let flat = new Array()
for (var i = 0; i < arr.length; i++) {
flat.push(arr[i][0])
flat.push('z down move')
flat = flat.concat(arr[i].slice(1))
flat.push('z up move')
}
// console.log('FLATTENED TO', flat)
// add header
flat.splice(0, 0, 'z up move')
// and return home
flat.push([0, 0])
// make a list of objs
let list = new Array()
// this is actually stateful ... jogging or not
let upState = false
for (var j = 0; j < flat.length; j++) {
if (Array.isArray(flat[j])) {
let move = {
position: {
X: flat[j][0],
Y: flat[j][1]
}
}
if (upState) {
move.speed = state.jogSpeed
} else {
move.speed = state.moveSpeed
}
list.push(move)
} else if (flat[j] === 'z up move') {
upState = true
list.push({
position: {
Z: state.lift
},
speed: state.plungeSpeed
})
} else if (flat[j] === 'z down move') {
upState = false
list.push({
position: {
Z: 0
},
speed: state.plungeSpeed
})
}
}
return list
} else {
console.log('NEIL PARSE: err: not an array')
}
}
function onShift() {
if (npList != null && npList.length > 0) {
neilParser.outputs.move.emit(npList.shift())
state.listLength = npList.length
} else {
console.log('NP Completes Moves')
}
}
return neilParser
}
// export the module
module.exports = NeilParser
\ No newline at end of file
This diff is collapsed.
// boilerplate atkapi header
const JSUnit = require('../../src/jsunit.js')
let Input = JSUnit.Input
let Output = JSUnit.Output
let State = JSUnit.State
// websocket, to share program representations with the client (and back)
const ws = require('ws')
function WebSocket() {
var webSocket = {
description: {
name: 'webSocket',
alt: 'webseket'
}
}
// log more
var verbose = false
let sckt = null
// one caveat here is that we can't dynamically add objects to this,
// or they don't get getter / settered when we do
webSocket.state = State()
var state = webSocket.state
state.address = '127.0.0.1'
state.port = 1234
state.status = 'closed'
webSocket.inputs = {
in: Input('any', (thing) => {
// some fn
})
}
webSocket.outputs = {
data: Output('any')
}
function openSocket(){
const wss = new ws.Server({port: state.port})
wss.on('connection', (pipe) => {
sckt = pipe
console.log('WebSocket Opened')
sckt.on('message', (msg) => {
webSocket.outputs.data.emit(JSON.parse(msg))
})
})
}
openSocket()
return webSocket
}
// export the module
module.exports = WebSocket
\ No newline at end of file
......@@ -29,9 +29,9 @@ const Reps = require('./reps.js')
const Programs = require('./programs.js')
// the program object: real simple, just has a description, and a 'modules'
// var program = Programs.new('new program')
var program = Programs.new('new program')
var program = Programs.open('./programs/temp.json')
//var program = Programs.open('./programs/temp.json')
/*
var stest = Programs.loadModuleFromSource(program, './modules/ui/stest.js')
......
......@@ -39,6 +39,7 @@ function Hardware() {
argument: 'reset hardware'
})
})
ui.resetButton.subscribe('onclick', onReset)
ui.addElement('testButton', 'ui/uiButton.js')
ui.testButton.subscribe('onload', function(msg) {
......@@ -47,8 +48,10 @@ function Hardware() {
argument: 'test network'
})
})
ui.testButton.subscribe('onclick', onNetworkTest)
state.onUiChange('route', function() {
console.log('logging state / route change')
hardware.route.route = state.route
})
......
......@@ -141,7 +141,7 @@ function socketSend(type, data) {
//console.log('SEND', msg)
sckt.send(JSON.stringify(msg))
} else {
console.log('on socketSend, ws not ready')
// console.log('on socketSend, ws not ready')
}
}
......@@ -306,7 +306,7 @@ function uiRequestUiChange(data){
}
function uiRequestMdlPositionChange(data) {
if(verbose) console.log('UI REQUEST ADD / CHANGE UI INFO TO MODULE', data)
if(true) console.log('UI REQUEST ADD / CHANGE UI INFO TO MODULE', data)
var mod = program.modules[data.description.id]
mod.description.position = data.description.position
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment