Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jake Read
rndmc
Commits
56973ba3
Commit
56973ba3
authored
Feb 09, 2019
by
Jake Read
Browse files
sww demo is go
parent
26bbd9bf
Changes
7
Hide whitespace changes
Inline
Side-by-side
client/client.js
View file @
56973ba3
...
...
@@ -60,7 +60,7 @@ window.onload = function() {
nav
=
document
.
getElementById
(
'
nav
'
)
const
socket
=
new
WebSocket
(
'
ws://localhost:808
1
'
)
const
socket
=
new
WebSocket
(
'
ws://localhost:808
2
'
)
socket
.
onopen
=
function
(
evt
)
{
// pass to global ref
...
...
littlerascal.js
View file @
56973ba3
...
...
@@ -6,20 +6,19 @@ const Programs = require('./programs.js')
var
program
=
Programs
.
new
(
'
new program
'
)
/* ok
-
new plotter
-
ack four
-
go to pos block
-
neil:mm adjust
-
video
-
cut: red
-
mountain: green
-
valley: blue
- git push
- add y axis network wait ?
*/
// das link
var
link
=
Programs
.
loadModuleFromSource
(
program
,
'
./modules/hardware/atkseriallink.js
'
)
link
.
startUp
()
link
.
state
.
log
=
tru
e
link
.
state
.
log
=
fals
e
let
steps
=
1
0
let
steps
=
8
0
// x motor
var
xm
=
Programs
.
loadModuleFromSource
(
program
,
'
./modules/hardware/atkstepper.js
'
)
...
...
@@ -49,9 +48,11 @@ 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
planner
.
state
.
minSpeed
=
0.1
planner
.
state
.
accel
=
20
var
outButton
=
Programs
.
loadModuleFromSource
(
program
,
'
./modules/motion/usermove.js
'
)
outButton
.
state
.
moveSpeed
=
200
/*
...
...
@@ -90,9 +91,16 @@ 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
)
xm
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
positions
)
ylm
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
acks
)
ylm
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
positions
)
ylr
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
acks
)
zm
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
acks
)
zm
.
outputs
.
ack
.
attach
(
planner
.
inputs
.
positions
)
let
moveToPlanner
=
{
position
:
{
...
...
@@ -109,6 +117,7 @@ link.onOpen = function(){
}
// ws input
// fusion runs on socket 1234 ...
var
sockit
=
Programs
.
loadModuleFromSource
(
program
,
'
./modules/pipes/websocket.js
'
)
var
np
=
Programs
.
loadModuleFromSource
(
program
,
'
./modules/motion/neilparse.js
'
)
...
...
@@ -117,6 +126,8 @@ sockit.outputs.data.attach(np.inputs.array)
np
.
outputs
.
move
.
attach
(
planner
.
inputs
.
instruction
)
planner
.
outputs
.
moveComplete
.
attach
(
np
.
inputs
.
shift
)
outButton
.
outputs
.
move
.
attach
(
planner
.
inputs
.
instruction
)
// UI HOOKUP
Programs
.
setView
(
program
,
{
...
...
@@ -131,6 +142,7 @@ let motorspace = 400
Programs
.
setUI
(
sockit
,
top
,
top
)
Programs
.
setUI
(
np
,
600
,
top
)
Programs
.
setUI
(
outButton
,
top
,
300
)
Programs
.
setUI
(
link
,
1800
,
top
)
Programs
.
setUI
(
xm
,
motorbar
,
top
)
...
...
modules/hardware/atkstepper.js
View file @
56973ba3
...
...
@@ -191,7 +191,7 @@ function Stepper() {
console
.
log
(
dMove
)
}
if
(
true
)
console
.
log
(
'
------------------- DMOVE
'
,
state
.
axis
,
dMove
)
if
(
true
)
console
.
log
(
'
------------------- DMOVE
'
,
state
.
axis
,
dMove
.
steps
)
var
packet
=
new
Array
()
// step blocks are #131
...
...
modules/motion/neilparse.js
View file @
56973ba3
...
...
@@ -25,10 +25,11 @@ function NeilParser() {
// 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
.
unitsPerMM
=
8
state
.
lift
=
5
state
.
moveSpeed
=
100
state
.
plungeSpeed
=
20
state
.
jogSpeed
=
200
state
.
listLength
=
0
neilParser
.
inputs
=
{
...
...
@@ -78,8 +79,8 @@ function NeilParser() {
if
(
Array
.
isArray
(
flat
[
j
]))
{
let
move
=
{
position
:
{
X
:
flat
[
j
][
0
],
Y
:
flat
[
j
][
1
]
X
:
flat
[
j
][
0
]
/
state
.
unitsPerMM
,
Y
:
flat
[
j
][
1
]
/
state
.
unitsPerMM
}
}
if
(
upState
)
{
...
...
modules/motion/simplanner.js
View file @
56973ba3
...
...
@@ -30,36 +30,24 @@ function Planner() {
var
state
=
planner
.
state
// reference pass attempt?
state
.
axisIDs
=
'
X,Y,Z
'
state
.
onUiChange
(
'
axisIDs
'
,
axisIDUpdate
)
state
.
accel
=
200
// units/s/s
state
.
minSpeed
=
1
// units/s
state
.
position
=
[
0
,
0
,
0
]
// should be grn / red button ...
state
.
isRunning
=
1
state
.
onUiChange
(
'
isRunning
'
,
netStateRefresh
)
state
.
netWindow
=
1
state
.
netState
=
[
0
,
0
,
0
]
state
.
netState
=
0
planner
.
ui
=
UI
()
var
ui
=
planner
.
ui
ui
.
addElement
(
'
startStopButton
'
,
'
ui/uiButton.js
'
)
ui
.
startStopButton
.
subscribe
(
'
onload
'
,
function
(
msg
)
{
ui
.
startStopButton
.
send
({
calls
:
'
setText
'
,
argument
:
'
start / stop planner
'
})
})
ui
.
startStopButton
.
subscribe
(
'
onclick
'
,
onStartStop
)
planner
.
inputs
=
{
instruction
:
Input
(
'
move instruction
'
,
onNewInstruction
),
acks
:
Input
(
'
move acknowledgement
'
,
onAck
),
run
:
Input
(
'
boolean
'
,
onRunInstruc
tion
)
positions
:
Input
(
'
new positions
'
,
onPosi
tion
s
)
}
planner
.
outputs
=
{
...
...
@@ -67,23 +55,16 @@ function Planner() {
moveComplete
:
Output
(
'
number
'
)
}
// we'll use one of these to assert / do things
// after the module is loaded, and state is copied etc
// i.e. one thing we can do is assert a starting value
planner
.
init
=
function
()
{
state
.
isRunning
=
0
state
.
netState
=
[
0
,
0
,
0
]
}
/*
------------------------------------------------------
UPDATING / SETUP
------------------------------------------------------
*/
function
on
Ack
(
msg
)
{
function
on
Positions
(
msg
){
//console.log("Planner onAck:", msg)
// update position, net states, run netCheck
// positions ...
var
axes
=
state
.
axisIDs
.
split
(
'
,
'
)
var
match
=
axes
.
indexOf
(
msg
.
axis
)
if
(
match
!==
-
1
)
{
...
...
@@ -91,82 +72,23 @@ function Planner() {
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
if
(
verbose
)
console
.
log
(
'
NEW NET STATE
'
,
newNetState
)
}
else
{
console
.
log
(
'
ERR in PLANNER: missed axis on ack from stepper
'
)
}
netStateRefresh
()
}
function
netStateRefresh
()
{
// check if received all four,
// send a packet
var
ns
=
state
.
netState
var
i
=
0
// check equality
while
(
ns
[
i
]
==
ns
[
i
+
1
])
{
i
++
// console.log('EQUALITY LOOP')
if
(
i
>
ns
.
length
-
1
)
{
break
}
}
if
(
i
==
ns
.
length
-
1
)
{
function
onAck
(
msg
)
{
// just count to four
state
.
netState
++
if
(
state
.
netState
>=
4
){
console
.
log
(
'
Planner confirms Move Complete
'
)
state
.
netState
=
0
planner
.
outputs
.
moveComplete
.
emit
(
1
)
}
}
function
onRunInstruction
(
boolean
)
{
if
(
boolean
)
{
if
(
state
.
isRunning
)
{
// already running, do nothing
}
else
{
state
.
isRunning
=
1
netStateRefresh
()
}
}
else
{
if
(
state
.
isRunning
)
{
state
.
isRunning
=
0
}
else
{
// oy
}
}
}
function
axisIDUpdate
()
{
var
axes
=
state
.
axisIDs
.
split
(
'
,
'
)
var
position
=
new
Array
(
axes
.
length
)
position
.
fill
(
0
)
var
packetState
=
new
Array
(
axes
.
length
)
for
(
i
in
axes
)
{
position
.
push
(
0
)
packetState
.
push
(
0
)
// could do
//planner.outputs[axes[i]] = Output('move instruction')
}
state
.
position
=
position
state
.
packetState
=
packetState
console
.
log
(
planner
)
}
function
onStartStop
()
{
if
(
state
.
isRunning
)
{
state
.
isRunning
=
0
}
else
{
state
.
isRunning
=
1
netStateRefresh
()
}
}
function
sendMoveToNetwork
(
move
)
{
for
(
i
in
state
.
netState
)
{
state
.
netState
[
i
]
++
}
state
.
netState
=
state
.
netState
planner
.
outputs
.
moves
.
emit
(
move
)
}
...
...
@@ -203,8 +125,6 @@ function Planner() {
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
{
...
...
modules/motion/usermove.js
0 → 100644
View file @
56973ba3
// boilerplate atkapi header
const
JSUnit
=
require
(
'
../../src/jsunit.js
'
)
let
Input
=
JSUnit
.
Input
let
Output
=
JSUnit
.
Output
let
State
=
JSUnit
.
State
// interface elements
const
JSUI
=
require
(
'
../../src/jsui.js
'
)
let
UI
=
JSUI
.
UI
// unit to convert neil's mods-output arrays into human readable move objects
// probably do flow control here also ?
function
UserMove
()
{
var
userMove
=
{
description
:
{
name
:
'
userMove gen
'
,
alt
:
'
line of userMove -> points
'
}
}
// one caveat here is that we can't dynamically add objects to this,
// or they don't get getter / settered when we do
userMove
.
state
=
State
()
var
state
=
userMove
.
state
state
.
moveTo
=
'
100,100,10
'
state
.
moveSpeed
=
100
userMove
.
inputs
=
{
go
:
Input
(
'
event
'
,
(
evt
)
=>
{
sendMove
()
})
}
userMove
.
outputs
=
{
move
:
Output
(
'
move
'
)
}
userMove
.
ui
=
UI
()
var
ui
=
userMove
.
ui
ui
.
addElement
(
'
goButton
'
,
'
ui/uiButton.js
'
)
ui
.
goButton
.
subscribe
(
'
onload
'
,
function
(
msg
)
{
ui
.
goButton
.
send
({
calls
:
'
setText
'
,
argument
:
'
click to send move
'
})
})
ui
.
goButton
.
subscribe
(
'
onclick
'
,
(
evt
)
=>
{
sendMove
()
})
function
sendMove
()
{
var
axes
=
state
.
moveTo
.
split
(
'
,
'
)
if
(
axes
.
length
==
3
)
{
let
move
=
{
position
:
{
X
:
parseFloat
(
axes
[
0
]),
Y
:
parseFloat
(
axes
[
1
]),
Z
:
parseFloat
(
axes
[
2
]),
},
speed
:
state
.
moveSpeed
}
console
.
log
(
'
User Move is
'
,
move
)
userMove
.
outputs
.
move
.
emit
(
move
)
}
else
{
console
.
log
(
"
len for moves must be three
"
)
}
}
return
userMove
}
// export the module
module
.
exports
=
UserMove
\ No newline at end of file
views.js
View file @
56973ba3
...
...
@@ -44,22 +44,22 @@ function startHttp() {
})
// through this window
http
.
listen
(
808
0
,
()
=>
{
console
.
log
(
'
RNDMC is listening on localhost:808
0
'
)
http
.
listen
(
808
1
,
()
=>
{
console
.
log
(
'
RNDMC is listening on localhost:808
1
'
)
})
}
function
startWs
()
{
// and listening for requests here
const
wss
=
new
WebSocket
.
Server
({
port
:
808
1
})
const
wss
=
new
WebSocket
.
Server
({
port
:
808
2
})
wss
.
on
(
'
connection
'
,
(
ws
)
=>
{
sckt
=
ws
// say hello
socketSend
(
'
console
'
,
'
hello client
'
)
// send current config as list of all modules
console
.
log
(
'
socket open on 808
1
'
)
console
.
log
(
'
socket open on 808
2
'
)
ws
.
on
(
'
message
'
,
(
evt
)
=>
{
socketRecv
(
evt
)
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment