diff --git a/hunks/adhoc/saturn.js b/hunks/adhoc/saturn.js index 4f6615b59b0d62f594c368a3692a8be5ae89772a..2fb0562e0cabc12fff70cc6eb1aec897ea9adee1 100644 --- a/hunks/adhoc/saturn.js +++ b/hunks/adhoc/saturn.js @@ -56,26 +56,25 @@ export default function Saturn() { return (!outx.io() && !outy.io() && !outz.io()) } - // our positions (and num segs to plan over) - let positionsBufferSize = 64 - let positions = [ - [0, 0, 0] - ] // should always have p[0] (current) and p[1] (one target) when running, at standstill have p[0] only - // settings, let deviation = 0.1 // virtual radius to junction about let accel = 980 // units/s/s (9.8m/s/s, 9800mm/s/s is 1G) let minSpeed = 0.01 // conspicuous, to debug for tails (indexing) let period = 0.050 // his.state('number', 'period', 50) // in ms, - // current states, let cruise = 200 // target, (units/s) + // the metal (do here, or elsewhere?) + let spmm = 200 + + // our positions (and num segs to plan over) + let positionsBufferSize = 32 + let positions = [ + [0, 0, 0] + ] // should always have p[0] (current) and p[1] (one target) when running, at standstill have p[0] only + let ramps = [] let speed = minSpeed // currently let posUpdated = false - // we nasty, - let spmm = 200 - // OK: *i think* the move might be to do this *first* and then never increase moves let periodPass = (speeds, debug) => { for (let i = positions.length - 2; i > 0; i--) { @@ -214,6 +213,7 @@ export default function Saturn() { let rampPass = (speeds, debug) => { let ramps = [] for (let i = 0; i < positions.length - 2; i++) { + let numRampsBefore = ramps.length if (debug) console.log(`ramp pass for ${i}`) let pi = positions[i] let pf = positions[i + 1] @@ -270,11 +270,11 @@ export default function Saturn() { // here we will handle triangles '/\' and 'full trapezoids' '/--\' let dcDist = (Math.pow(cruise, 2) - Math.pow(vf, 2)) / (2 * accel) let acDist = (Math.pow(cruise, 2) - Math.pow(vi, 2)) / (2 * accel) - if (dcDist + dcDist > d) { + if (dcDist + dcDist >= d) { if (debug) console.log('/\\') writeTriangle(ramps, vi, vf, pi, pf) } else { // BEGIN TRAP SELECTIONS - if (debug) console.log('/--\\') + if (true) console.log('/--\\') let pa = math.add(pi, vScalar(vUnitBetween(pi, pf), acDist)) let pb = math.add(pf, vScalar(vUnitBetween(pf, pi), dcDist)) // ok, @@ -285,7 +285,7 @@ export default function Saturn() { if (tSeg2 < period) { // for this case, contencating into a triangle is fine... it will be within ~ 50ms of extra accel time: not much if (debug) console.log('/\\') - writeTriangle() + writeTriangle(ramps, vi, vf, pi, pf) } else if (tSeg1 < period && tSeg3 < period) { // contencate into one ramp writeSeg(ramps, vi, vf, pi, pf) @@ -299,9 +299,15 @@ export default function Saturn() { // write first, then contencate second, third into one writeSeg(ramps, vi, cruise, pi, pa) writeSeg(ramps, cruise, vf, pa, pf) + } else { + // forgot the genuine full cruiser, here it is + writeSeg(ramps, vi, cruise, pi, pa) + writeSeg(ramps, cruise, cruise, pa, pb) + writeSeg(ramps, cruise, vf, pb, pf) } } // end TRAP SELECTIONS } // end BIGSWITCH + if(ramps.length === numRampsBefore) console.warn('zero ramps written for', pi, pf, vi, vf) } // end for-over-positions return ramps } @@ -318,109 +324,132 @@ export default function Saturn() { } let rampCheck = (ramps) => { - for(let r of ramps){ + for (let i = 0; i < ramps.length; i ++) { + let r = ramps[i] let d = vDist(r.pi, r.pf) let t = 2 * d / (r.vi + r.vf) - if(t < (period - 0.001)) console.warning('troublesome ramp, small time', r) - if(r.vi > (cruise + 1) || r.vf > (cruise + 1)) console.warning('troublesome ramp, high speed', r) + if (t < (period - 0.001)) console.warn('troublesome ramp, small time', r) + // more than 10% over speed is probably not cool, + let cruiseAbsMax = cruise + 0.15 * cruise + if (r.vi > cruiseAbsMax || r.vf > cruiseAbsMax) console.warn('troublesome ramp, high speed', r) + // check that ramps are continuous + if(i < ramps.length - 2){ + let sep = vDist(r.pf, ramps[i + 1].pi) + if(sep > 0.001) console.warn('troublesome ramp junction', r, ramps[i + 1]) + } } } - let blockOnce = true - let blocks = [] - let posNow = [] + let blockOnce = false this.loop = () => { - // loading new points, - if (positions.length < positionsBufferSize && inpts.io()) { - let np = inpts.get() - // reject the baddies - try { - if (vLen(math.subtract(np, positions[positions.length - 1])) === 0) { - // dunk on 'em - console.warn('zero length appendage rejected by planner') - } else { - positions.push(np) // end of queue - //console.log('new pt\t', positions.length, np) - } - } catch (err) { - console.warn('error caught at saturn input', err) - } - } - //if (allClear() && positions.length > 32) { - // first we get all move final v's by jd: - // we jd, - if (positions.length > positionsBufferSize - 1 && blockOnce) { - blockOnce = false - // ok, here's the lookahead routine: - console.time('lookahead') - // positions[] is global, speeds is generated now - // speed[0], matching positions[0], are our current situations - let speeds = new Array(positions.length) - speeds[0] = speed - speeds[speeds.length - 1] = minSpeed - // first, set speeds such that moves can be made within single periods, - periodPass(speeds) - console.timeLog('lookahead') - // jd runs an algorithm that calculates maximum allowable - // instantaneous accelerations at corners - jd(speeds) // at ~ 38ms, this is the beef of it - console.timeLog('lookahead') - // revpass to link by max. accel: - reversePass(speeds) - forwardPass(speeds) - // rough check speeds after initial passes, - // TODO: if we find these throwing errs, interrupt control when we - // hit some geometry we can't deal with? - positionsCheck(speeds) - console.timeLog('lookahead') - // ok, ramps: - let ramps = rampPass(speeds) - // and a check, - rampCheck(ramps) - console.timeLog('lookahead') - // NEXT - /* - console.timeLog('lookahead') - for (let i = 0; i < positions.length - 1; i++) { - console.log(`${i} of ${positions.length} has speed ${speeds[i].toFixed(3)} dist ${vDist(positions[i], positions[i+1]).toFixed(3)}`) - } - // now ready to segment - //... - let ramps = rampPass(speeds, true) - // hmm... - console.log(`have ${ramps.length} ramps`) - /* - for(let r of ramps){ - console.log(r.t) - } - */ - // re-hash from here - // what is a block to a motor? - // if we want to preserve times, perhaps blocks are: - // (uint) timebase (period size) - // (int) rate start - // (int) rate rate - // (uint) rate count - } - - if (blocks.length > 0 && allClear()) { - let bl = blocks.shift() - //console.log('block', bl) - let dist = vDist(bl[0], bl[1]) - console.log(dist.toFixed(4)) - // to gate, + // 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) - // output in steps-space... - posNow = vScalar(bl[0], spmm) + // our 'current position, from the end of the + // last ramp we shipped, is rpo.pf posUpdated = true + // 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]) + // if we're within 10^-3 of the units, clear it out + console.log(`at evt, dtp is ${dtp.toFixed(6)}`) + if (dtp < 0.001) { + console.log(`> complete position, had ${positions.length}`) + for(let i = 0; i < 10; i ++){ + console.log(`> position[${i}] ${positions[i][0].toFixed(3)}, ${positions[i][1].toFixed(3)}, ${positions[i][2].toFixed(3)}`) + } + for(let i = 0; i < 10; i ++){ + console.log(`> ramps[${i}].pi ${ramps[i].pi[0].toFixed(3)},${ramps[i].pi[1].toFixed(3)},${ramps[i].pi[2].toFixed(3)}`) + console.log(`> ramps[${i}].pf ${ramps[i].pf[0].toFixed(3)},${ramps[i].pf[1].toFixed(3)},${ramps[i].pf[2].toFixed(3)}`) + } + positions.shift() + ramps.shift() + console.log(`> now position, have ${positions.length}`) + // have to recalculate blocks now I think? + } else { + console.log(`updating p[0]`) + positions[0] = ramps[0].pf + ramps.shift() + } + console.log(`${ramps.length} ramps, ${positions.length} positions`) } if (!outp.io() && posUpdated) { - outp.put(posNow) + outp.put(positions[0]) posUpdated = false } + + let logTimes = false + + // load new pts into the array, + if (positions.length < positionsBufferSize && inpts.io()) { + // get the new pt, adding it if it is of any appreciable distance + if(!blockOnce){ + let np = inpts.get() + try { + if (vDist(np, positions[positions.length - 1]) < 0.001) { + // dunk on 'em + console.warn('zero length appendage rejected by planner') + } else { + positions.push(np) // end of queue + console.log(`puts new position for ${positions.length}`) + // THE BUSINESS: + // ok, here's the lookahead routine: + } + } catch (err) { + console.warn('error caught at saturn input', err) + } + } + + if (positions.length > positionsBufferSize - 2 && !blockOnce) { + blockOnce = true + console.log('lookahead') + // LOOKAHEAD BEGIN + if (logTimes) console.time('lookahead') + // positions[] is global, speeds is generated now + // speed[0], matching positions[0], are our current situations + let speeds = new Array(positions.length) + speeds[0] = speed + speeds[speeds.length - 1] = minSpeed + // first, set speeds such that moves can be made within single periods, + periodPass(speeds) + if (logTimes) console.timeLog('lookahead') + // jd runs an algorithm that calculates maximum allowable + // instantaneous accelerations at corners + jd(speeds) // at ~ 38ms, this is the beef of it + if (logTimes) console.timeLog('lookahead') + // revpass to link by max. accel: + reversePass(speeds) + forwardPass(speeds) + // rough check speeds after initial passes, + // TODO: if we find these throwing errs, interrupt control when we + // hit some geometry we can't deal with? + positionsCheck(speeds) + if (logTimes) console.timeLog('lookahead') + // ok, ramps: + ramps.length = 0 + ramps = rampPass(speeds) + // is this still conn. to our head? + if (ramps.length > 0) console.log('new ramps', vDist(ramps[0].pi, positions[0]).toFixed(5)) + // and a check, + rampCheck(ramps) + if (logTimes) console.timeLog('lookahead') + if (logTimes) console.timeEnd('lookahead') + for(let i = 0; i < 20; i ++){ + console.log(positions[i]) + } + console.log(ramps[0].pi) + for(let i = 0; i < 30; i ++){ + console.log(ramps[i].pf) + } + throw new Error('once') + //console.log('new pt\t', positions.length, np) + // LOOKAHEAD END + } + } } } diff --git a/hunks/adhoc/tpath.js b/hunks/adhoc/tpath.js index 651d610de479c813eb1056210466434a343cd24b..92d00b29dd36073159483b068871370348c82f39 100644 --- a/hunks/adhoc/tpath.js +++ b/hunks/adhoc/tpath.js @@ -14,7 +14,7 @@ import { // example-path-long.js also exists... // example-path-small.js ... // example-path-sl2.js -import * as expath from '../../test_files/example-path-sl2.js' +import * as expath from '../../test_files/example-path-small.js'//example-path-sl2.js' import { vScalar } from '../../libs/smallvectors.js' let dpi = 72 diff --git a/save/contexts/cuttlefish/dbg-25ms-bare.json b/save/contexts/cuttlefish/dbg-25ms-bare.json new file mode 100644 index 0000000000000000000000000000000000000000..103ba5cb0493d9c1d82072209ad1cd462a140301 --- /dev/null +++ b/save/contexts/cuttlefish/dbg-25ms-bare.json @@ -0,0 +1,124 @@ +{ + "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/tpath", + "name": "adhoc/tpath_2", + "outputs": [ + { + "name": "position", + "type": "array", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "reset", + "type": "boolean", + "value": "false" + } + ] + }, + { + "type": "adhoc/saturn", + "name": "adhoc/saturn_3", + "inputs": [ + { + "name": "posn", + "type": "array" + } + ], + "outputs": [ + { + "name": "posn", + "type": "array" + }, + { + "name": "outx", + "type": "number", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + }, + { + "name": "outy", + "type": "number" + }, + { + "name": "outz", + "type": "number" + } + ] + }, + { + "type": "adhoc/consumer", + "name": "adhoc/consumer_5", + "inputs": [ + { + "name": "takes", + "type": "number" + } + ], + "states": [ + { + "name": "period", + "type": "number", + "value": "25" + } + ] + } + ] +} \ No newline at end of file diff --git a/save/contexts/cuttlefish/dbg-50ms-bare.json b/save/contexts/cuttlefish/dbg-50ms-bare.json new file mode 100644 index 0000000000000000000000000000000000000000..13b3cf1ca21b7d23a9260c73d2b5fdfa88b98d66 --- /dev/null +++ b/save/contexts/cuttlefish/dbg-50ms-bare.json @@ -0,0 +1,124 @@ +{ + "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/tpath", + "name": "adhoc/tpath_2", + "outputs": [ + { + "name": "position", + "type": "array", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "reset", + "type": "boolean", + "value": "false" + } + ] + }, + { + "type": "adhoc/saturn", + "name": "adhoc/saturn_3", + "inputs": [ + { + "name": "posn", + "type": "array" + } + ], + "outputs": [ + { + "name": "posn", + "type": "array" + }, + { + "name": "outx", + "type": "number", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + }, + { + "name": "outy", + "type": "number" + }, + { + "name": "outz", + "type": "number" + } + ] + }, + { + "type": "adhoc/consumer", + "name": "adhoc/consumer_5", + "inputs": [ + { + "name": "takes", + "type": "number" + } + ], + "states": [ + { + "name": "period", + "type": "number", + "value": "50" + } + ] + } + ] +} \ No newline at end of file diff --git a/save/contexts/cuttlefish/dbg-50ms-log.json b/save/contexts/cuttlefish/dbg-50ms-log.json new file mode 100644 index 0000000000000000000000000000000000000000..12bb4ab6d1bb49167dd7c713101d79234f8ca360 --- /dev/null +++ b/save/contexts/cuttlefish/dbg-50ms-log.json @@ -0,0 +1,152 @@ +{ + "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/tpath", + "name": "adhoc/tpath_2", + "outputs": [ + { + "name": "position", + "type": "array", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "reset", + "type": "boolean", + "value": "false" + } + ] + }, + { + "type": "adhoc/saturn", + "name": "adhoc/saturn_3", + "inputs": [ + { + "name": "posn", + "type": "array" + } + ], + "outputs": [ + { + "name": "posn", + "type": "array", + "connections": [ + { + "inHunkIndex": "5", + "inHunkInput": "0" + } + ] + }, + { + "name": "outx", + "type": "number", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + }, + { + "name": "outy", + "type": "number" + }, + { + "name": "outz", + "type": "number" + } + ] + }, + { + "type": "adhoc/consumer", + "name": "adhoc/consumer_5", + "inputs": [ + { + "name": "takes", + "type": "number" + } + ], + "states": [ + { + "name": "period", + "type": "number", + "value": "50" + } + ] + }, + { + "type": "data/log_objects", + "name": "data/log_objects_5", + "inputs": [ + { + "name": "tolog", + "type": "reference" + } + ], + "states": [ + { + "name": "prefix", + "type": "string", + "value": "LOG:" + }, + { + "name": "console", + "type": "boolean", + "value": "false" + } + ] + } + ] +} \ No newline at end of file diff --git a/save/contexts/cuttlefish/dbg-50ms.json b/save/contexts/cuttlefish/dbg-50ms.json new file mode 100644 index 0000000000000000000000000000000000000000..a40117e04a56b9eebe91ebf16d71f1348f62d18b --- /dev/null +++ b/save/contexts/cuttlefish/dbg-50ms.json @@ -0,0 +1,140 @@ +{ + "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/tpath", + "name": "adhoc/tpath_2", + "outputs": [ + { + "name": "position", + "type": "array", + "connections": [ + { + "inHunkIndex": "3", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "reset", + "type": "boolean", + "value": "false" + } + ] + }, + { + "type": "adhoc/saturn", + "name": "adhoc/saturn_3", + "inputs": [ + { + "name": "posn", + "type": "array" + } + ], + "outputs": [ + { + "name": "posn", + "type": "array", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + }, + { + "name": "outx", + "type": "number", + "connections": [ + { + "inHunkIndex": "5", + "inHunkInput": "0" + } + ] + }, + { + "name": "outy", + "type": "number" + }, + { + "name": "outz", + "type": "number" + } + ] + }, + { + "type": "interface/threejs_ghost", + "name": "interface/threejs_ghost_4", + "inputs": [ + { + "name": "point", + "type": "array" + } + ] + }, + { + "type": "adhoc/consumer", + "name": "adhoc/consumer_5", + "inputs": [ + { + "name": "takes", + "type": "number" + } + ], + "states": [ + { + "name": "period", + "type": "number", + "value": "50" + } + ] + } + ] +} \ No newline at end of file