Commit 13b2678e authored by Jake Read's avatar Jake Read
Browse files

packet return from stepper

parent 61e7dda0
# Automatakit API
aka project consistent-sandbox
## oy
- buffer return ... OK
- go forth to stepper, then you have this state-double-bouncing issue
- then you have this multiline gcode / start / stop sequencing issue
- then you have this multiline gcode / start / stop sequencing issue
- and with it, scrolling around your messy program
- want jog keys & speed commands w/ those buttons
- really want those LIGHTS
- lead / state double bounce ?
- rolls into proper objects, classes, files ?
- more consistent dereferencing
- callback-via-hookup ... steppers -> network, planner -> steppers both want this
- understand how callbacks work, how often used, etc, cc @ sean
- button / multiline / 3js UI elements / ui handling throughout ?
- big P now is how to hook it all up ?
- same as previous, just to:
- steppers -> packets, packets -> acks
- net checking, events for planner
- gcode terminal is longer,
- planner requests next line from gcode
- sequencing ?
- jog keys
- then want
- smarter hookup for networked parts
- stepper feedback
- accel feedback
- 3js window
- really want to watch accelerometer
- want to measure network speed
- want to show motor torques coming back, set motor torques
## Majors to Address
- states / uis / etc - one off / one-at-a-time for updates
- i.e. all f'n update calls are to single module-global state update
- !
- states / getters / setters not applicable to sub-elements in an object within state
- i.e. array access
- consistent dereferencing ?
## Features we Want
- UI classes
- buttons, w/ colors & reasonable std. events
- multiline input w/ current-line highlighting, terminal-write-in ?
- 3js
- prettier hw/sw representation
- callbacks / duplex links ? handing over an object, basically
- reload-in-place
~ for SFO, we do ~
- machine eats gcode and runs it, and jogs, etc
......
......@@ -8,6 +8,17 @@ function pack32(val) {
return pack;
}
function unPack32(arr){
if(arr.length == 4){
var unPacked = arr[0] << 24 | arr[1] << 16 | arr[2] << 8 | arr[3]
return unPacked
} else {
console.log("ERR: arr > 4 at unPack32")
}
}
module.exports = {
pack32: pack32
pack32: pack32,
unPack32: unPack32
}
\ No newline at end of file
......@@ -131,7 +131,7 @@ xm.outputs.ack.attach(planner.inputs.acks)
planner.outputs.moves.attach(yma.inputs.move)
yma.outputs.ack.attach(planner.inputs.acks)
planner.outputs.moves.attach(ymb.inputs.move)
ymb.outputs.ack.attach(planner.inputs.acks)
//ymb.outputs.ack.attach(planner.inputs.acks)
planner.outputs.moves.attach(zm.inputs.move)
zm.outputs.ack.attach(planner.inputs.acks)
......@@ -150,16 +150,18 @@ zm.state.axis = 'Z'
zm.outputs.packet.attach(bridge.inputs.D)
bridge.outputs.D.attach(zm.inputs.packet)
bridge.init()
// setting data w/r/t the representations they serve
setUiPos(term, 10, 10)
setUiPos(gcode, 50, 100)
setUiPos(planner, 100, 250)
setUiPos(xm, 600, 180)
setUiPos(yma, 600, 380)
setUiPos(ymb, 600, 580)
setUiPos(zm, 600, 780)
setUiPos(xm, 600, 20)
setUiPos(yma, 600, 260)
setUiPos(ymb, 600, 500)
setUiPos(zm, 600, 740)
setUiPos(bridge, 600, 980)
......@@ -311,11 +313,16 @@ function changeState(data) {
if (oldState[key].isButton) {
if (oldState[key].isPressed != newState[key].isPressed) {
console.log('CHANGE STATE', key, 'to', newState[key], 'in', data.id)
// this will trigger some 'onChange' f'ns
// that might change some state
oldState[key] = newState[key]
// to prevent quickly changing it back, we'll exit now (one state change from UI per trx)
return true
}
} else if (oldState[key] !== newState[key]) {
console.log('CHANGE STATE', key, 'to', newState[key], 'in', data.id)
oldState[key] = newState[key]
oldState[key] = newState[key]
return true
}
}
}
......
......@@ -56,6 +56,7 @@ function ATKBridge() {
}
state.onChange('connect', openPort)
bridge.init = openPort
function openPort() {
if (state.portName == '---') {
......@@ -76,6 +77,7 @@ function ATKBridge() {
}
}
function sendToHardware(pckt) {
if (port != null && port.writable) {
port.write(pckt)
......@@ -120,7 +122,7 @@ function ATKBridge() {
})
function parseTerminal(str) {
//
console.log("BRIDGE TERMINAL PARSE NOT YET")
return false
}
......@@ -214,6 +216,7 @@ function ATKBridge() {
}
function onPacket(pckt) {
var debug = false
console.log('PCKT IN <<', pckt.toString())
shiftPacketPointer(pckt)
var incomingRoute = pckt.slice(2, pckt.indexOf(255))
......@@ -224,8 +227,8 @@ function ATKBridge() {
}
var match = null
for (key in bridge.pairs) {
if(returnRoute.toString() === bridge.pairs[key].route.toString()){
console.log("PCKT FOUND", key)
if (returnRoute.toString() === bridge.pairs[key].route.toString()) {
if (debug) console.log("PCKT FOUND", key)
var headless = pckt.slice(pckt.indexOf(255) + 1)
bridge.pairs[key].output.emit(headless)
}
......@@ -248,7 +251,7 @@ function ATKBridge() {
pckt[j] = pckt[j + 1]
}
pckt[end - 1] = 0
console.log('shifted', pckt)
// console.log('shifted', pckt)
}
return bridge
......
......@@ -50,7 +50,36 @@ function Stepper() {
}
function onHardwareIn(pckt) {
console.log('PCKT from stepper', pckt)
var debug = false
if (debug) console.log('PCKT into stepper', pckt)
var key = pckt[0]
pckt.shift()
switch (key) {
case 131:
onHardwareStepsComplete(pckt)
break
case 132:
onHardwareWaitComplete(pckt)
break
default:
console.log("STEP: pckt return w/ no recognized key")
}
}
function onHardwareStepsComplete(pckt){
var stepsMade = PCKT.unPack32(pckt)
state.position += stepsMade
var unitsMade = stepsMade / state.spu
var ack = {
axis: state.axis,
increment: unitsMade
}
stepper.outputs.ack.emit(ack)
}
function onHardwareWaitComplete(pckt){
var msg = PCKT.unPack32(pckt)
console.log("WAITED", msg)
}
function onRawMove() {
......@@ -59,11 +88,11 @@ function Stepper() {
var len = Math.abs(state.rawMove)
var delta = state.rawMove
var testMove = {
delta: len,
entry: 5,
accel: 10,
accelLen: len/2 - len/4,
deccelLen: len/2 + len/4
delta: len,
entry: 5,
accel: 10,
accelLen: len / 2 - len / 4,
deccelLen: len / 2 + len / 4
}
sendToHardware(testMove)
}
......@@ -159,9 +188,9 @@ function Stepper() {
}
function sendToHardware(aMove) {
// steps / unit
var spu = state.spu
var convert = Math.abs(spu)
// steps / unit
var spu = state.spu
var convert = Math.abs(spu)
// 'axis' move and discreet move
var dMove = {}
dMove.steps = watchRounding(aMove.delta * spu)
......@@ -200,7 +229,7 @@ function Stepper() {
if (error > 0.05) {
console.log('WATCH ROUNDING', val, rounded, error)
}
return rounded
return rounded
}
return stepper
......
......@@ -56,7 +56,20 @@ function Planner() {
function onAck(msg) {
console.log("Planner onAck:", msg)
// stepper has moved, ID to position & speed state, count for time to send new move
// update position, net states, run netCheck
var axes = state.axisIDs.split(',')
var match = axes.indexOf(msg.axis)
if(match !== -1){
// HERE is a hack, for our state-updating system doesn't yet accomodate arrays
var newPos = state.position.slice(0)
newPos[match] += msg.increment
state.position = newPos
var newNetState = state.netState.slice(0)
newNetState[match] -= 1
state.netState = newNetState
} else {
console.log('ERR: missed axis on ack from stepper')
}
}
function axisIDUpdate() {
......
Supports Markdown
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