From 7c21c261c7a1e591ae703aa4791055b2973f3f03 Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Thu, 31 Oct 2019 14:52:43 -0400 Subject: [PATCH] MDmseg --- hunks/adhoc/saturn.js | 28 ++-- hunks/adhoc/tpath.js | 7 +- save/contexts/cuttlefish/dbg-25ms-ghost.json | 17 ++- save/contexts/cuttlefish/mdmsegtest.json | 136 +++++++++++++++++++ typeset.js | 17 +++ 5 files changed, 187 insertions(+), 18 deletions(-) create mode 100644 save/contexts/cuttlefish/mdmsegtest.json diff --git a/hunks/adhoc/saturn.js b/hunks/adhoc/saturn.js index f13733e..3125fe3 100644 --- a/hunks/adhoc/saturn.js +++ b/hunks/adhoc/saturn.js @@ -48,13 +48,7 @@ export default function Saturn() { let outp = this.output('array', 'posn') - let outx = this.output('number', 'outx') - let outy = this.output('number', 'outy') - let outz = this.output('number', 'outz') - - let allClear = () => { - return (!outx.io() && !outy.io() && !outz.io()) - } + let mdmsegOut = this.output('MDmseg', 'motionSegment') // settings, let deviation = 0.1 // virtual radius to junction about @@ -345,18 +339,24 @@ export default function Saturn() { } } + let writeMDmsegFromRamp = (ramp) => { + return { + p0: ramp.pi, + p1: ramp.pf, + t: ramp.t, + v0: ramp.vi, + a: (ramp.vf - ramp.vi) / ramp.t + } + } + let debugRuntime = false this.loop = () => { // handle output to stepper, if we have any existing blocks to issue: - if (ramps.length > 0 && allClear()) { - //console.log('op ramp', rpo.pf) - outx.put(1) - outy.put(1) - outz.put(1) - // our 'current position, from the end of the - // last ramp we shipped, is rpo.pf + if (ramps.length > 0 && !mdmsegOut.io()) { posUpdated = true + // multi-dimensional mseg, + mdmsegOut.put(writeMDmsegFromRamp(ramps[0])) // this means we are either inside of two old positions, // in which case we update p[0], or at the end of p[0], at p[1] let dtp = vDist(ramps[0].pf, positions[1]) diff --git a/hunks/adhoc/tpath.js b/hunks/adhoc/tpath.js index b0a4628..04f6794 100644 --- a/hunks/adhoc/tpath.js +++ b/hunks/adhoc/tpath.js @@ -19,8 +19,6 @@ import * as smallpath from '../../test_files/example-path-small.js' import * as sl2path from '../../test_files/example-path-sl2.js' import { vScalar } from '../../libs/smallvectors.js' -let dpi = 72 - export default function TPFCOUT(){ Hunkify(this) @@ -28,6 +26,9 @@ export default function TPFCOUT(){ let go = false let outPosn = this.output('array', 'position') + + let mmPerPixel = this.state('number', 'mm/pix', (1/72)*25.4) + let longSet = this.state('boolean', 'longpath', false) longSet.onChange = (value) => { go = true @@ -48,7 +49,7 @@ export default function TPFCOUT(){ this.loop = () => { if(path.length > 0 && go){ if(!outPosn.io()){ - let op = vScalar(path.shift(), (1/dpi)*25.4) + let op = vScalar(path.shift(), mmPerPixel.value) //console.log(op[1]) outPosn.put(op) } diff --git a/save/contexts/cuttlefish/dbg-25ms-ghost.json b/save/contexts/cuttlefish/dbg-25ms-ghost.json index 377bed8..f9ae7ff 100644 --- a/save/contexts/cuttlefish/dbg-25ms-ghost.json +++ b/save/contexts/cuttlefish/dbg-25ms-ghost.json @@ -63,7 +63,22 @@ ], "states": [ { - "name": "reset", + "name": "mm/pix", + "type": "number", + "value": "1" + }, + { + "name": "longpath", + "type": "boolean", + "value": "false" + }, + { + "name": "shortpath", + "type": "boolean", + "value": "false" + }, + { + "name": "sl2path", "type": "boolean", "value": "false" } diff --git a/save/contexts/cuttlefish/mdmsegtest.json b/save/contexts/cuttlefish/mdmsegtest.json new file mode 100644 index 0000000..2cf45e9 --- /dev/null +++ b/save/contexts/cuttlefish/mdmsegtest.json @@ -0,0 +1,136 @@ +{ + "interpreterName": "cuttlefish", + "interpreterVersion": "v0.1", + "hunks": [ + { + "type": "manager", + "name": "nrol", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "view", + "name": "tlview", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "0", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "adhoc/saturn", + "name": "adhoc/saturn_2", + "inputs": [ + { + "name": "posn", + "type": "array" + } + ], + "outputs": [ + { + "name": "posn", + "type": "array" + }, + { + "name": "motionSegment", + "type": "MDmseg", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "data/logger", + "name": "data/logger_3", + "inputs": [ + { + "name": "tolog", + "type": "reference" + } + ], + "states": [ + { + "name": "prefix", + "type": "string", + "value": "LOG:" + }, + { + "name": "console", + "type": "boolean", + "value": "true" + } + ] + }, + { + "type": "adhoc/tpath", + "name": "adhoc/tpath_4", + "outputs": [ + { + "name": "position", + "type": "array", + "connections": [ + { + "inHunkIndex": "2", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "mm/pix", + "type": "number", + "value": "0.35277777777777775" + }, + { + "name": "longpath", + "type": "boolean", + "value": "false" + }, + { + "name": "shortpath", + "type": "boolean", + "value": "false" + }, + { + "name": "sl2path", + "type": "boolean", + "value": "false" + } + ] + } + ] +} \ No newline at end of file diff --git a/typeset.js b/typeset.js index ca65b80..81608e5 100644 --- a/typeset.js +++ b/typeset.js @@ -520,6 +520,23 @@ const TSET = [ return arr } } + }, + { + name: 'MDmseg', + copy: { + MDmseg: (mdmseg) => { + return { + p0: mdmseg.p0, + p1: mdmseg.p1, + t: mdmseg.t, + v0: mdmseg.v0, + a: mdmseg.a + } + }, + reference: (mdmseg) => { + return mdmseg + } + } } // etc ] // end TSET -- GitLab