Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jake Read
rndmc
Commits
d6dab2ac
Commit
d6dab2ac
authored
Dec 09, 2018
by
Jake Read
Browse files
new basic for soma
parent
25547096
Changes
8
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
d6dab2ac
...
...
@@ -267,6 +267,8 @@ View.assignProgram(program)
## Immediately
-
saved program doesn't save state booleans
-
ui objects ... refresh ... use state model ?
-
ui objects client drop below inputs / outputs
...
...
client/client.js
View file @
d6dab2ac
...
...
@@ -32,6 +32,7 @@ var wrapper = {}
var
nav
=
{}
var
verbose
=
false
var
verboseComs
=
false
/*
...
...
@@ -97,7 +98,7 @@ function socketSend(type, data) {
type
:
type
,
data
:
data
}
console
.
log
(
'
SEND
'
,
msg
)
if
(
verboseComs
)
console
.
log
(
'
SEND
'
,
msg
)
sckt
.
send
(
JSON
.
stringify
(
msg
))
}
...
...
@@ -105,7 +106,7 @@ function socketRecv(evt) {
var
recv
=
JSON
.
parse
(
evt
.
data
)
var
type
=
recv
.
type
var
data
=
recv
.
data
console
.
log
(
'
RECV
'
,
recv
)
if
(
verboseComs
)
console
.
log
(
'
RECV
'
,
recv
)
// tree banger
switch
(
type
)
{
case
'
console
'
:
...
...
@@ -233,7 +234,7 @@ function heapSendsStateChange(data) {
}
function
heapSendsUiChange
(
data
)
{
if
(
tru
e
)
console
.
log
(
'
HEAP SENDS MSG TO UI ELEMENT IN MDL
'
,
data
)
if
(
verbos
e
)
console
.
log
(
'
HEAP SENDS MSG TO UI ELEMENT IN MDL
'
,
data
)
program
.
modules
[
data
.
id
].
ui
[
data
.
key
].
lump
.
onMessage
(
data
.
msg
)
}
...
...
client/ui/threeCanvas.js
View file @
d6dab2ac
...
...
@@ -8,21 +8,23 @@
var
container
=
document
.
createElement
(
'
div
'
)
var
scene
=
new
THREE
.
Scene
()
scene
.
background
=
new
THREE
.
Color
(
0xd6d6d6
)
var
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
1
,
1
,
1000
)
var
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
1
,
0.
1
,
1000
)
camera
.
up
.
set
(
0
,
0
,
1
)
var
renderer
=
new
THREE
.
WebGLRenderer
()
renderer
.
setSize
(
396
,
396
)
container
.
appendChild
(
renderer
.
domElement
)
// axes
var
axesHelper
=
new
THREE
.
AxesHelper
(
1
)
var
axesHelper
=
new
THREE
.
AxesHelper
(
0.
1
)
scene
.
add
(
axesHelper
)
// grid
/*
var gridHelper = new THREE.GridHelper(10, 100)
gridHelper.translateOnAxis(new THREE.Vector3(0, 0, 1), -0.01)
gridHelper.rotateX(-Math.PI / 2)
scene.add(gridHelper)
*/
// one line
var
material
=
new
THREE
.
LineBasicMaterial
({
color
:
0x00ffff
})
...
...
modules/hardware/atkmrobot.js
View file @
d6dab2ac
...
...
@@ -47,6 +47,8 @@ function ATKMathRobot() {
state
.
message
=
'
no packet yet
'
state
.
enc_cnt
=
16384
state
.
enc_offset
=
0
state
.
enc_reverse
=
false
state
.
pc_t
=
2048
state
.
onUiChange
(
'
pc_t
'
,
onPositionTargetUserChange
)
...
...
@@ -92,6 +94,11 @@ function ATKMathRobot() {
atkmr
.
route
.
subscribe
(
145
,
function
(
msg
){
var
pos
=
PCKT
.
unPack32
(
msg
.
slice
(
1
))
if
(
state
.
enc_reverse
){
pos
=
state
.
enc_cnt
-
pos
}
pos
+=
state
.
enc_offset
pos
%=
state
.
enc_cnt
var
rads
=
2
*
Math
.
PI
*
(
pos
/
state
.
enc_cnt
)
atkmr
.
outputs
.
pos
.
emit
(
rads
)
})
...
...
modules/robot/forwardTransform.js
View file @
d6dab2ac
...
...
@@ -9,8 +9,6 @@ let State = JSUnit.State
function
forwardTransform
()
{
var
theta1
=
0
var
theta2
=
0
var
l1
=
0
var
l2
=
0
var
forwardTransform
=
{
description
:
{
...
...
@@ -25,9 +23,9 @@ function forwardTransform() {
// one caveat here is that we can't dynamically add objects to this,
// or they don't get getter / settered when we do
forwardTransform
.
state
=
State
()
//
forwardTransform.state
.mode = 'G0'
// forwardTransform.
state.
G0
=
1200
// forwardTransform.
state.
G1
=
400
var
state
=
forwardTransform
.
state
state
.
l1
=
0.4
state
.
l2
=
0.2
forwardTransform
.
inputs
=
{
theta1
:
Input
(
'
any
'
,
intakeTheta1
),
...
...
@@ -37,11 +35,9 @@ function forwardTransform() {
}
forwardTransform
.
outputs
=
{
originpt
:
Output
(
'
tuple?
'
),
jointpt
:
Output
(
'
tuple?
'
),
touchpt
:
Output
(
'
tuple?
'
)
// instructionOut: Output('move instruction'),
// modeChange: Output('string')
originpt
:
Output
(
'
array
'
),
jointpt
:
Output
(
'
array
'
),
touchpt
:
Output
(
'
array
'
)
}
function
intakeTheta1
(
num
){
...
...
@@ -63,97 +59,37 @@ function forwardTransform() {
}
function
intakeL1
(
num
){
l1
=
num
state
.
l1
=
num
var
points
=
parseforwardTransform
()
forwardTransform
.
outputs
.
originpt
.
emit
(
points
.
originpt
)
forwardTransform
.
outputs
.
jointpt
.
emit
(
points
.
jointpt
)
forwardTransform
.
outputs
.
touchpt
.
emit
(
points
.
touchpt
)
//console.log('l1 input')
//console.log('
state.
l1 input')
}
function
intakeL2
(
num
){
l2
=
num
state
.
l2
=
num
var
points
=
parseforwardTransform
()
forwardTransform
.
outputs
.
originpt
.
emit
(
points
.
originpt
)
forwardTransform
.
outputs
.
jointpt
.
emit
(
points
.
jointpt
)
forwardTransform
.
outputs
.
touchpt
.
emit
(
points
.
touchpt
)
//console.log('l2 input')
//console.log('
state.
l2 input')
}
// input functions
/*
function onLineIn(str){
var instruction = parseforwardTransform(str)
if (instruction.hasMove) {
if(verbose) console.log('forwardTransform:', instruction)
forwardTransform.outputs.instructionOut.emit(instruction)
} else {
if(verbose) console.log('forwardTransform:', forwardTransform.state.mode)
forwardTransform.outputs.modeChange.emit(forwardTransform.state.mode)
}
}
*/
/*
// local functions
function getKeyValues(str) {
var kv = {}
for (var i = 0; i < str.length; i++) {
if (str[i].match('[A-Za-z]')) { // regex to match upper case letters
var lastIndex = str.indexOf(' ', i)
if (lastIndex < 0) {
lastIndex = str.length
}
var key = str[i].toUpperCase()
kv[key] = parseFloat(str.slice(i + 1, lastIndex))
}
}
return kv
}
*/
// TODO: test, can we link global vars to ui objects ...
// forwardTransform.ui.mode.value = var ? no bc set / get etc
// more like var = forwardTransform.ui.mode.value ? is this referential?
function
parseforwardTransform
()
{
var
points
=
{
originpt
:
(
0
,
0
)
,
jointpt
:
(
0
,
0
)
,
touchpt
:
(
0
,
0
)
originpt
:
[
0
,
0
]
,
jointpt
:
[
0
,
0
]
,
touchpt
:
[
0
,
0
]
}
points
.
jointpt
=
(
l1
*
Math
.
cos
(
theta1
),
l1
*
Math
.
sin
(
theta1
))
points
.
touchpt
=
(
l1
*
Math
.
cos
(
theta1
)
+
l2
*
Math
.
cos
(
theta2
),
l1
*
Math
.
sin
(
theta1
)
+
l2
*
Math
.
sin
(
theta2
))
/* var instruction = {
position: {},
hasMove: false,
speed: 0
}
kv = getKeyValues(str)
// track modality
if (kv.G == 0 | kv.G == 1) {
forwardTransform.state.mode = 'G' + kv.G.toString()
} else if (kv.G != null) {
// no arcs pls
console.log('unfriendly forwardTransform mode!', kv)
}
for (key in kv) {
if (key.match('[A-EX-Z]')) {
instruction.position[key] = kv[key]
instruction.hasMove = true
} else if (key.match('[F]')) {
// tricky / ugly: sets using the mode state string as object key
forwardTransform.state[forwardTransform.state.mode] = kv.F
}
}
points
.
jointpt
=
[
state
.
l1
*
Math
.
cos
(
theta1
),
state
.
l1
*
Math
.
sin
(
theta1
)]
points
.
touchpt
=
[
state
.
l1
*
Math
.
cos
(
theta1
)
+
state
.
l2
*
Math
.
cos
(
theta2
),
state
.
l1
*
Math
.
sin
(
theta1
)
+
state
.
l2
*
Math
.
sin
(
theta2
)]
instruction.speed = forwardTransform.state[forwardTransform.state.mode]
// and this for help later?
instruction.kv = kv
*/
return
points
}
...
...
modules/ui/threeCanvas.js
View file @
d6dab2ac
...
...
@@ -45,7 +45,7 @@ function PointOnCanvas() {
}
function
onNewXY2
(
array
){
ui
.
threeCanvas
.
updateXY2
f
([
array
[
0
],
0
,
array
[
1
]])
ui
.
threeCanvas
.
updateXY2
([
array
[
0
],
0
,
array
[
1
]])
}
function
onUICallback
(
msg
)
{
...
...
programs/temp.json
View file @
d6dab2ac
{
"description"
:
{
"name"
:
"new program"
,
"counter"
:
1
4
"counter"
:
1
6
},
"modules"
:
{
"SerialportATKLink-0"
:
{
...
...
@@ -20,9 +20,9 @@
"inputs"
:
{},
"outputs"
:
{},
"state"
:
{
"portName"
:
"
---
"
,
"portStatus"
:
"
closed
"
,
"log"
:
tru
e
"portName"
:
"
COM18
"
,
"portStatus"
:
"
open
"
,
"log"
:
fals
e
},
"ui"
:
{
"kickButton"
:
{
...
...
@@ -69,6 +69,10 @@
{
"parentId"
:
"gateCounter-9"
,
"key"
:
"thru"
},
{
"parentId"
:
"forwardTransform Parser-15"
,
"key"
:
"theta1"
}
]
}
...
...
@@ -77,6 +81,8 @@
"message"
:
"no packet yet"
,
"route"
:
"0,0"
,
"enc_cnt"
:
16384
,
"enc_offset"
:
-6000
,
"enc_reverse"
:
false
,
"pc_t"
:
2048
,
"pKp"
:
4.5
,
"pKi"
:
0
,
...
...
@@ -100,8 +106,8 @@
"id"
:
"atk-math-robot-joint-2"
,
"path"
:
"./modules/hardware/atkmrobot.js"
,
"position"
:
{
"left"
:
60
0
,
"top"
:
4
50
"left"
:
60
4
,
"top"
:
4
92
}
},
"inputs"
:
{
...
...
@@ -130,6 +136,10 @@
{
"parentId"
:
"logger-14"
,
"key"
:
"thru"
},
{
"parentId"
:
"forwardTransform Parser-15"
,
"key"
:
"theta2"
}
]
}
...
...
@@ -138,6 +148,8 @@
"message"
:
"no packet yet"
,
"route"
:
"0,1"
,
"enc_cnt"
:
16384
,
"enc_offset"
:
550
,
"enc_reverse"
:
true
,
"pc_t"
:
2048
,
"pKp"
:
4.5
,
"pKi"
:
0
,
...
...
@@ -289,7 +301,7 @@
},
"state"
:
{
"prefix"
:
"JTN1:"
,
"message"
:
"
---
"
"message"
:
"
2.9398741799828314
"
},
"ui"
:
{}
},
...
...
@@ -300,8 +312,8 @@
"id"
:
"ThreeJS-Canvas-7"
,
"path"
:
"./modules/ui/threeCanvas.js"
,
"position"
:
{
"left"
:
2263
,
"top"
:
326
"left"
:
1312
,
"top"
:
133
}
},
"inputs"
:
{
...
...
@@ -329,8 +341,8 @@
"id"
:
"collector-8"
,
"path"
:
"./modules/util/collector.js"
,
"position"
:
{
"left"
:
1
728
,
"top"
:
1
0
57
"left"
:
1
649
,
"top"
:
1
1
57
}
},
"inputs"
:
{
...
...
@@ -408,8 +420,8 @@
"id"
:
"parallelContencator-11"
,
"path"
:
"./modules/util/parallelContencator.js"
,
"position"
:
{
"left"
:
1
232
,
"top"
:
1
053
"left"
:
1
193
,
"top"
:
1
147
}
},
"inputs"
:
{
...
...
@@ -556,7 +568,107 @@
},
"state"
:
{
"prefix"
:
"JTN2:"
,
"message"
:
"---"
"message"
:
"5.845233792238235"
},
"ui"
:
{}
},
"forwardTransform Parser-15"
:
{
"description"
:
{
"name"
:
"forwardTransform Parser"
,
"alt"
:
"line of forwardTransform -> points"
,
"id"
:
"forwardTransform Parser-15"
,
"path"
:
"./modules/robot/forwardTransform.js"
,
"position"
:
{
"left"
:
1323
,
"top"
:
718
}
},
"inputs"
:
{
"theta1"
:
{
"accepts"
:
"any"
},
"theta2"
:
{
"accepts"
:
"any"
},
"l1"
:
{
"accepts"
:
"any"
},
"l2"
:
{
"accepts"
:
"any"
}
},
"outputs"
:
{
"originpt"
:
{
"emits"
:
"array"
,
"calls"
:
[]
},
"jointpt"
:
{
"emits"
:
"array"
,
"calls"
:
[
{
"parentId"
:
"ThreeJS-Canvas-7"
,
"key"
:
"xy1"
}
]
},
"touchpt"
:
{
"emits"
:
"array"
,
"calls"
:
[
{
"parentId"
:
"ThreeJS-Canvas-7"
,
"key"
:
"xy2"
}
]
}
},
"state"
:
{
"l1"
:
0.4
,
"l2"
:
0.2
},
"ui"
:
{}
},
"leastSquares Parser-16"
:
{
"description"
:
{
"name"
:
"leastSquares Parser"
,
"alt"
:
"line of leastSquares -> l1 and l2 values"
,
"id"
:
"leastSquares Parser-16"
,
"path"
:
"./modules/robot/leastSquares.js"
,
"position"
:
{
"left"
:
1823
,
"top"
:
991
}
},
"inputs"
:
{
"theta1s"
:
{
"accepts"
:
"any"
},
"theta2s"
:
{
"accepts"
:
"any"
}
},
"outputs"
:
{
"l1"
:
{
"emits"
:
"num"
,
"calls"
:
[
{
"parentId"
:
"forwardTransform Parser-15"
,
"key"
:
"l1"
}
]
},
"l2"
:
{
"emits"
:
"num"
,
"calls"
:
[
{
"parentId"
:
"forwardTransform Parser-15"
,
"key"
:
"l2"
}
]
}
},
"state"
:
{
"c"
:
1
,
"d"
:
-2
},
"ui"
:
{}
}
...
...
src/jsunit.js
View file @
d6dab2ac
// event system to include type-checking etc
// dataflow types for javascript objects ...
var
verbose
=
false
function
Input
(
type
,
fn
)
{
var
input
=
{
accepts
:
type
,
...
...
@@ -58,7 +60,7 @@ function Output(type) {
output
.
emit
=
function
(
data
)
{
if
(
this
.
calls
.
length
==
0
)
{
console
.
log
(
'
no inputs bound to this output
'
)
if
(
verbose
)
console
.
log
(
'
no inputs bound to this output
'
)
}
else
{
for
(
index
in
this
.
calls
)
{
this
.
calls
[
index
].
fn
(
JSON
.
parse
(
JSON
.
stringify
(
data
)))
...
...
Write
Preview
Markdown
is supported
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