diff --git a/hunks/calibrations/lsq.js b/hunks/calibrations/lsq.js index 5bc58ac405062f2d4cad3592c4fa5341ef5fa2c2..4c6a94966f432986d6392edca8b0835f8593e6e6 100644 --- a/hunks/calibrations/lsq.js +++ b/hunks/calibrations/lsq.js @@ -2,7 +2,7 @@ input previous system measurements as state (lists) make predictions for y based on input at x, with lsq. from old data -to expand: accept arrays as inputs, from automatic measurements ? +to expand: accept arrays as inputs, from automatic measurements ? */ @@ -15,7 +15,7 @@ import { import smallmath from '../../libs/smallmath.js' -export default function LoadcellCalibration() { +export default function LeastSquares() { Hunkify(this) let loadCellInput = new Input('number', 'reading', this) diff --git a/hunks/flowcontrol/pressure.js b/hunks/flowcontrol/pressure.js deleted file mode 100644 index 6ea8e7e8495b6c095f61598de98042d313b92a51..0000000000000000000000000000000000000000 --- a/hunks/flowcontrol/pressure.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - -always on - -*/ - -import { - Hunkify, - Input, - Output, - State -} from '../hunks.js' - -// at the moment, just boolean, but really want a way (probably just 'type' setting...) -// to pass through any-type event -// or maybe a series of 'flowcontroller' hunks that *just* operate on flows ? -// w/ abstract non-operable pipes ?? hurm - -function Pressure() { - Hunkify(this) - - let evtIn = new Input('boolean', 'thru', this) - let runStateIn = new Input('boolean', 'run', this) - this.inputs.push(evtIn, runStateIn) - - let evtOut = new Output('boolean', 'thru', this) - this.outputs.push(evtOut) - - // the hack is that boolean states are often just used as buttons ... - let runState = new State('boolean', 'run', false) - this.states.push(runState) - - // don't need to init, thx - let internal = false - - this.loop = () => { - if(evtIn.io()){ - internal = evtIn.get() - } - if(!evtOut.io() && runState.value){ - evtOut.put(internal) - } - } -} - -export default Pressure diff --git a/hunks/flowcontrol/syncpressure.js b/hunks/flowcontrol/syncpressure.js new file mode 100644 index 0000000000000000000000000000000000000000..101a540f833c8a174bd50dc09f50de032974c892 --- /dev/null +++ b/hunks/flowcontrol/syncpressure.js @@ -0,0 +1,106 @@ +/* + +always on + +*/ + +import { + Hunkify, + Input, + Output, + State +} from '../hunks.js' + +import { + TSET, + findPhy +} from '../../typeset.js' + +// synchronous pressure .. polymorphic + +export default function Pressure() { + Hunkify(this) + + // the hack is that boolean states are often just used as buttons ... + let runState = new State('boolean', 'run', false) + this.states.push(runState) + // and setup: + let status = new State('string', 'types', '') + let pTypes = new State('string', 'types', 'boolean, number') + let pVals = new State('string', 'values', 'true, 12') + this.states.push(status, pTypes, pVals) + + let values = [] + let setup = (init) => { + let pt = pTypes.value.split(',') + let pv = pVals.value.split(',') + // tough, we want to check that all types exist, and can convert from some string to whatever else we put in here... + if (pt.length == pv.length) { + let count = 0 + let candOutputs = [] + let candValues = [] + for (let t in pt) { + // take leading spaces out, + if (pt[t].indexOf(' ') > -1) pt[t] = pt[t].substring(pt[t].indexOf(' ') + 1) + if (findPhy(pt[t])) { + candOutputs.push(new Output(pt[t], pt[t], this)) + } + } + if (candOutputs.length != pv.length){ + status.set('missing some outputs...') + return + } + for (let v in pv) { + // let's use the string copy f'ns for this + let strphy = findPhy('string') + // a method to write values from strings exists? + if(strphy.copy[pt[v]]){ + candValues.push(strphy.copy[pt[v]](pv[v])) + } else { + console.log(`no string-to-${pt[v]} exists`) + } + } + if(candValues.length != pv.length){ + status.set('missing some values...') + } + status.set('type, value sets OK') + this.outputs = candOutputs + values = candValues + // if we call this during init the system becomes confused + if(!init) this.mgr.evaluateHunk(this) + } else { + status.set('mistmatched lists...') + // mismatched lists, probably ... + // here's a case where it would be great to repl- with an error... + } + } + + pTypes.onChange = (value) => { + pTypes.set(value) + setup() + } + + pVals.onChange = (value) => { + pVals.set(value) + setup() + } + + this.init = () => { + setup(true) + } + + this.loop = () => { + if (runState.value) { + let clear = 0 + for (let op of this.outputs) { + if (!op.io()) clear++ + } + if (clear && clear >= this.outputs.length) { + // contact! + for (let o in this.outputs) { + this.outputs[o].put(values[o]) + } + } + } + } +} diff --git a/hunks/hunks.js b/hunks/hunks.js index b63e59a0175799146acc3d59aa68150fa32bdd45..b8f2e099a53ac6d63633090bb7102d16f81d943c 100644 --- a/hunks/hunks.js +++ b/hunks/hunks.js @@ -73,7 +73,6 @@ function Output(type, name, parent, linktype) { // yonder put call, transport call // copy-in (chances are that after .put call the referenced object changes, before it is copied out) // and copy-out (same on the other side, we are potentially passing to many downstream, need a different copy for each) - this.put = this.phy.put // typing ... odd ? this.put = (data) => { if(!this.io()){ diff --git a/save/systems/dive-l1-a.json b/save/systems/dive-l1-a.json new file mode 100644 index 0000000000000000000000000000000000000000..6ed13c33807b6ef283cb8be3642a5e29844ac888 --- /dev/null +++ b/save/systems/dive-l1-a.json @@ -0,0 +1,561 @@ +{ + "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": "pipes/vfptc", + "name": "pipes/vfptc_2", + "inputs": [ + { + "name": "data", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "pipe status", + "type": "string", + "value": "open" + }, + { + "name": "websocket port", + "type": "string", + "value": "2042" + }, + { + "name": "usb product id", + "type": "string", + "value": "8022" + }, + { + "name": "pipe reset", + "type": "boolean", + "value": "false" + }, + { + "name": "serialport status", + "type": "string", + "value": "open" + } + ] + }, + { + "type": "link", + "name": "link_3", + "inputs": [ + { + "name": "data", + "type": "byteArray" + }, + { + "name": "mgrMsgs", + "type": "byteArray" + }, + { + "name": "auto_54_2", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "2", + "inHunkInput": "0" + } + ] + }, + { + "name": "mgrMsgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + }, + { + "name": "auto_92_3", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "5", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "isActive", + "type": "boolean", + "value": "true" + }, + { + "name": "otherLink", + "type": "uint16", + "value": "1" + }, + { + "name": "inputList", + "type": "string", + "value": "mgrMsgs (byteArray), auto_54_2 (byteArray)" + }, + { + "name": "outputList", + "type": "string", + "value": "mgrMsgs (byteArray), auto_92_3 (byteArray)" + } + ], + "contains": { + "interpreterName": "ponyo", + "interpreterVersion": "v0.1", + "hunks": [ + { + "type": "manager", + "name": "ponyo_one", + "inputs": [ + { + "name": "mgrMsgs_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "mgrMsgs_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "1" + } + ] + } + ] + }, + { + "type": "link", + "name": "link_1", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + }, + { + "name": "mgrMsgs_1024", + "type": "byteArray" + }, + { + "name": "auto_117_3_512", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "2", + "inHunkInput": "0" + } + ] + }, + { + "name": "mgrMsgs_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "0", + "inHunkInput": "0" + } + ] + }, + { + "name": "auto_120_2_512", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "1" + } + ] + } + ], + "states": [ + { + "name": "isActive", + "type": "boolean", + "value": "true" + }, + { + "name": "otherLink", + "type": "uint16", + "value": "3" + }, + { + "name": "inputList", + "type": "string", + "value": "mgrMsgs (byteArray), auto_117_3 (byteArray)" + }, + { + "name": "outputList", + "type": "string", + "value": "mgrMsgs (byteArray), auto_120_2 (byteArray)" + } + ] + }, + { + "type": "comm/COBSerialUSB", + "name": "comm/COBSerialUSB_2", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "comm/COBSerialRJ45_A", + "name": "comm/COBSerialRJ45_A_3", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "link", + "name": "link_4", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + }, + { + "name": "mgrMsgs_512", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + }, + { + "name": "mgrMsgs_512", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "2" + } + ] + } + ], + "states": [ + { + "name": "isActive", + "type": "boolean", + "value": "true" + }, + { + "name": "otherLink", + "type": "uint16", + "value": "1" + }, + { + "name": "inputList", + "type": "string", + "value": "mgrMsgs (byteArray)" + }, + { + "name": "outputList", + "type": "string", + "value": "mgrMsgs (byteArray)" + } + ], + "contains": { + "interpreterName": "ponyo", + "interpreterVersion": "v0.1", + "hunks": [ + { + "type": "manager", + "name": "ponyo_one", + "inputs": [ + { + "name": "mgrMsgs_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "mgrMsgs_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "1" + } + ] + } + ] + }, + { + "type": "link", + "name": "link_1", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + }, + { + "name": "mgrMsgs_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "2", + "inHunkInput": "0" + } + ] + }, + { + "name": "mgrMsgs_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "0", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "isActive", + "type": "boolean", + "value": "true" + }, + { + "name": "otherLink", + "type": "uint16", + "value": "4" + }, + { + "name": "inputList", + "type": "string", + "value": "mgrMsgs (byteArray)" + }, + { + "name": "outputList", + "type": "string", + "value": "mgrMsgs (byteArray)" + } + ] + }, + { + "type": "comm/COBSerialRJ45_A", + "name": "comm/COBSerialRJ45_A_2", + "inputs": [ + { + "name": "data_1024", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "data_1024", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "stepper", + "name": "step_driver", + "inputs": [ + { + "name": "increment", + "type": "int32" + }, + { + "name": "enable", + "type": "boolean" + } + ], + "outputs": [ + { + "name": "increment", + "type": "int32" + }, + { + "name": "stallGuard", + "type": "uint32" + } + ], + "states": [ + { + "name": "current (6-24)", + "type": "uint16", + "value": "16" + }, + { + "name": "enable", + "type": "boolean", + "value": "true" + } + ] + } + ] + } + } + ] + } + }, + { + "type": "view", + "name": "view_4", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "1" + } + ] + } + ] + }, + { + "type": "view", + "name": "view_5", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "2" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/typeset.js b/typeset.js index c1c9201f3975819f024bffd85bf4ca243486e1b6..29aff84e9241358797820328406e68f9c12f22d8 100644 --- a/typeset.js +++ b/typeset.js @@ -49,6 +49,7 @@ const findPhy = (type) => { return cand.name === type }) if (phy === undefined) + // try this... catch err elsewhere throw new Error(`could not find phy for datatype: ${type}`) return phy } @@ -79,6 +80,10 @@ copy: move about within js, we are still not really type-checking on calls to .put(), and should be... there is probably a slick, clean way to do this also: would really like to work with typedarrays where they are appropriate + +.. *could* imagine some hairbrain walk through these things: if we have, i.e., conversion +from string -> number written, and from number -> uint8, we should be able to +compose a tree of these on the fly ... */ const TSET = [ @@ -204,6 +209,16 @@ const TSET = [ copy: { string: function(str) { return str + }, + number: function(str) { + return parseFloat(str) + }, + boolean: function(str){ + if(str == true){ + return true + } else { + return false + } } } }, { @@ -384,7 +399,7 @@ const TSET = [ return bounds(int32, -2147483647, 2147483647) }, number: function(int32){ - return int32 + return int32 } } },