diff --git a/hunks/adhoc/saturn.js b/hunks/adhoc/saturn.js index c5cc8b766ae76d327a0d19bbcaf5b2e76e29844a..b3ca26135cc3fcc3d91262f52d379d161362d90e 100644 --- a/hunks/adhoc/saturn.js +++ b/hunks/adhoc/saturn.js @@ -16,7 +16,7 @@ import { vSum } from '../../libs/smallvectors.js' -export default function Saturn(){ +export default function Saturn() { Hunkify(this) let inpts = this.input('array', 'posn') @@ -37,75 +37,59 @@ export default function Saturn(){ // current states, let feed = 10 // (units/s) let lt = [] // last transform (since we know time, this is our speed data) - let position = [0,0,0] // we track position... + let position = [0, 0, 0] // we track position... let posUpdated = false let calculateNextIncrement = () => { // for now, straightforward: current position w/r/t path, // increment is this posn -> next target, at rate ... // for simplicity, we can assume that we're always going from where we're at to the [1]th point in the path, - let vect = [0,0,0] + let vect = [0, 0, 0] let dist = vDist(position, path[0]) vect.forEach((axis, i) => { vect[i] = (path[0][i] - position[i]) / dist }) // easy increment is just this vector * rate / period - let timeSeg = [0,0,0] + let timeSeg = [0, 0, 0] timeSeg.forEach((axis, i) => { timeSeg[i] = vect[i] * (feed / period) }) // now, is this a step-over ? some fast-slow-math for this: let np = vSum(position, timeSeg) - if(vDist(np, position) > vDist(position, path[0])){ + if (vDist(np, position) > vDist(position, path[0])) { // ts is just to get us exactly to it .. timeSeg.forEach((axis, i) => { timeSeg[i] = path[0][i] - position[i] }) - console.log('passing') path.shift() } return timeSeg } this.loop = () => { - if(path.length < pathBufferSize && inpts.io()){ - path.push(inpts.get()) + if (path.length < pathBufferSize && inpts.io()) { + let np = inpts.get() + console.log('new pt\t', path.length, np) + path.push(np) } - if(allclear()){ + if (allclear() && path.length > 0) { // this is our major timestep, and should happen only once-every-segment - if(path.length > 0){ - // we have items in the path, - // we should calculate an ideal trajectory from our current position and speed - // probably recalculating the whole thing, and then send that out... - let ts = calculateNextIncrement() - console.log('time seg', ts) - position = vSum(position, ts) - posUpdated = true - /* - console.log('nt', nt) - // update internal state, - position.forEach((axis, i) => { - position[i] += nt[i] - }) - console.log('position', position) - */ - // have to do this so that flowcontrol happens, gating us - outx.put(0) - outy.put(0) - outz.put(0) - /* - let np = op.shift() // actually, calc next transform based on last posn' and the increment we want now - cp = np - posUpdated = true - */ - // actually like: - /* - lt = np - cp += lt - */ - } + // path length reads @ 26, but NaN ?? + // do check ... if anything is NaN, print all path, OK. maybe reference problem? + console.log(path.length) + // we have items in the path, + // we should calculate an ideal trajectory from our current position and speed + // probably recalculating the whole thing, and then send that out... + let ts = calculateNextIncrement() + console.log('time seg\t', ts) + position = vSum(position, ts) + posUpdated = true + // send 'em + outx.put(ts[0]) + outy.put(ts[1]) + outz.put(ts[2]) } - if(!outp.io() && posUpdated){ + if (!outp.io() && posUpdated) { outp.put(position) posUpdated = false } diff --git a/hunks/adhoc/tpath.js b/hunks/adhoc/tpath.js index 21614da51e36c933f5de5545ed2857746f46a371..7ee984701ce1a74fba385a8bfcf3380ebdf7dd21 100644 --- a/hunks/adhoc/tpath.js +++ b/hunks/adhoc/tpath.js @@ -11,7 +11,8 @@ import { State } from '../hunks.js' -import * as expath from '../../test_files/example-path.js' +// example-path-long.js also exists... +import * as expath from '../../test_files/example-path-small.js' export default function TPFCOUT(){ Hunkify(this) @@ -19,7 +20,7 @@ export default function TPFCOUT(){ // copy this in au manuel let ogpath = expath.default.arr let path = [] - let go = true + let go = true let outPosn = this.output('array', 'position') let outReset = this.state('boolean', 'reset', false) @@ -35,7 +36,7 @@ export default function TPFCOUT(){ // copies out, one at a time, fc pressure this.loop = () => { - if(path.length && go){ + if(path.length > 0 && go){ if(!outPosn.io()){ outPosn.put(path.shift()) } diff --git a/test_files/example-path.js b/test_files/example-path-long.js similarity index 100% rename from test_files/example-path.js rename to test_files/example-path-long.js diff --git a/test_files/example-path-small.js b/test_files/example-path-small.js new file mode 100644 index 0000000000000000000000000000000000000000..8e6ce802b608497ab0e4ebe98552d950997743fa --- /dev/null +++ b/test_files/example-path-small.js @@ -0,0 +1,1149 @@ +export default { + arr: [ + [ + 63, + 63, + 50 + ], + [ + 63, + 63, + -5 + ], + [ + 1791, + 63, + -5 + ], + [ + 1791, + 1854, + -5 + ], + [ + 63, + 1854, + -5 + ], + [ + 63, + 63, + -5 + ], + [ + 63, + 63, + 50 + ], + [ + 172, + 135, + 50 + ], + [ + 172, + 135, + -5 + ], + [ + 172, + 195, + -5 + ], + [ + 201, + 195, + -5 + ], + [ + 201, + 249, + -5 + ], + [ + 169, + 249, + -5 + ], + [ + 169, + 335, + -5 + ], + [ + 201, + 335, + -5 + ], + [ + 201, + 405, + -5 + ], + [ + 204, + 405, + -5 + ], + [ + 204, + 411, + -5 + ], + [ + 253, + 411, + -5 + ], + [ + 253, + 382, + -5 + ], + [ + 218, + 382, + -5 + ], + [ + 218, + 335, + -5 + ], + [ + 250, + 335, + -5 + ], + [ + 250, + 249, + -5 + ], + [ + 218, + 249, + -5 + ], + [ + 218, + 195, + -5 + ], + [ + 222, + 195, + -5 + ], + [ + 222, + 135, + -5 + ], + [ + 172, + 135, + -5 + ], + [ + 172, + 135, + 50 + ], + [ + 366, + 97, + 50 + ], + [ + 366, + 97, + -5 + ], + [ + 366, + 135, + -5 + ], + [ + 350, + 135, + -5 + ], + [ + 350, + 195, + -5 + ], + [ + 400, + 195, + -5 + ], + [ + 400, + 135, + -5 + ], + [ + 383, + 135, + -5 + ], + [ + 383, + 114, + -5 + ], + [ + 683, + 114, + -5 + ], + [ + 683, + 182, + -5 + ], + [ + 661, + 182, + -5 + ], + [ + 661, + 308, + -5 + ], + [ + 723, + 308, + -5 + ], + [ + 723, + 182, + -5 + ], + [ + 700, + 182, + -5 + ], + [ + 700, + 114, + -5 + ], + [ + 1329, + 114, + -5 + ], + [ + 1329, + 182, + -5 + ], + [ + 1306, + 182, + -5 + ], + [ + 1306, + 308, + -5 + ], + [ + 1368, + 308, + -5 + ], + [ + 1368, + 182, + -5 + ], + [ + 1346, + 182, + -5 + ], + [ + 1346, + 114, + -5 + ], + [ + 1740, + 114, + -5 + ], + [ + 1740, + 1024, + -5 + ], + [ + 1672, + 1024, + -5 + ], + [ + 1672, + 1001, + -5 + ], + [ + 1546, + 1001, + -5 + ], + [ + 1546, + 1063, + -5 + ], + [ + 1672, + 1063, + -5 + ], + [ + 1672, + 1041, + -5 + ], + [ + 1740, + 1041, + -5 + ], + [ + 1740, + 1791, + -5 + ], + [ + 1033, + 1791, + -5 + ], + [ + 1033, + 1722, + -5 + ], + [ + 1056, + 1722, + -5 + ], + [ + 1056, + 1596, + -5 + ], + [ + 994, + 1596, + -5 + ], + [ + 994, + 1722, + -5 + ], + [ + 1017, + 1722, + -5 + ], + [ + 1017, + 1807, + -5 + ], + [ + 1757, + 1807, + -5 + ], + [ + 1757, + 97, + -5 + ], + [ + 366, + 97, + -5 + ], + [ + 366, + 97, + 50 + ], + [ + 436, + 135, + 50 + ], + [ + 436, + 135, + -5 + ], + [ + 436, + 284, + -5 + ], + [ + 402, + 284, + -5 + ], + [ + 402, + 249, + -5 + ], + [ + 322, + 249, + -5 + ], + [ + 322, + 335, + -5 + ], + [ + 402, + 335, + -5 + ], + [ + 402, + 300, + -5 + ], + [ + 436, + 300, + -5 + ], + [ + 436, + 436, + -5 + ], + [ + 368, + 436, + -5 + ], + [ + 368, + 430, + -5 + ], + [ + 318, + 430, + -5 + ], + [ + 318, + 459, + -5 + ], + [ + 368, + 459, + -5 + ], + [ + 368, + 453, + -5 + ], + [ + 436, + 453, + -5 + ], + [ + 436, + 588, + -5 + ], + [ + 402, + 588, + -5 + ], + [ + 402, + 554, + -5 + ], + [ + 322, + 554, + -5 + ], + [ + 322, + 588, + -5 + ], + [ + 309, + 588, + -5 + ], + [ + 309, + 1096, + -5 + ], + [ + 270, + 1096, + -5 + ], + [ + 270, + 1073, + -5 + ], + [ + 144, + 1073, + -5 + ], + [ + 144, + 1136, + -5 + ], + [ + 270, + 1136, + -5 + ], + [ + 270, + 1113, + -5 + ], + [ + 309, + 1113, + -5 + ], + [ + 309, + 1176, + -5 + ], + [ + 618, + 1176, + -5 + ], + [ + 618, + 1100, + -5 + ], + [ + 704, + 1100, + -5 + ], + [ + 704, + 1084, + -5 + ], + [ + 601, + 1084, + -5 + ], + [ + 601, + 1160, + -5 + ], + [ + 326, + 1160, + -5 + ], + [ + 326, + 639, + -5 + ], + [ + 402, + 639, + -5 + ], + [ + 402, + 605, + -5 + ], + [ + 453, + 605, + -5 + ], + [ + 453, + 152, + -5 + ], + [ + 620, + 152, + -5 + ], + [ + 620, + 364, + -5 + ], + [ + 683, + 364, + -5 + ], + [ + 683, + 454, + -5 + ], + [ + 661, + 454, + -5 + ], + [ + 661, + 580, + -5 + ], + [ + 723, + 580, + -5 + ], + [ + 723, + 454, + -5 + ], + [ + 700, + 454, + -5 + ], + [ + 700, + 364, + -5 + ], + [ + 764, + 364, + -5 + ], + [ + 764, + 152, + -5 + ], + [ + 1265, + 152, + -5 + ], + [ + 1265, + 389, + -5 + ], + [ + 1329, + 389, + -5 + ], + [ + 1329, + 454, + -5 + ], + [ + 1306, + 454, + -5 + ], + [ + 1306, + 580, + -5 + ], + [ + 1368, + 580, + -5 + ], + [ + 1368, + 454, + -5 + ], + [ + 1346, + 454, + -5 + ], + [ + 1346, + 389, + -5 + ], + [ + 1409, + 389, + -5 + ], + [ + 1409, + 152, + -5 + ], + [ + 1702, + 152, + -5 + ], + [ + 1702, + 804, + -5 + ], + [ + 1227, + 804, + -5 + ], + [ + 1227, + 844, + -5 + ], + [ + 1099, + 844, + -5 + ], + [ + 1099, + 861, + -5 + ], + [ + 1244, + 861, + -5 + ], + [ + 1244, + 821, + -5 + ], + [ + 1702, + 821, + -5 + ], + [ + 1702, + 960, + -5 + ], + [ + 1490, + 960, + -5 + ], + [ + 1490, + 1024, + -5 + ], + [ + 1400, + 1024, + -5 + ], + [ + 1400, + 1001, + -5 + ], + [ + 1274, + 1001, + -5 + ], + [ + 1274, + 1063, + -5 + ], + [ + 1400, + 1063, + -5 + ], + [ + 1400, + 1041, + -5 + ], + [ + 1490, + 1041, + -5 + ], + [ + 1490, + 1104, + -5 + ], + [ + 1702, + 1104, + -5 + ], + [ + 1702, + 1623, + -5 + ], + [ + 1579, + 1623, + -5 + ], + [ + 1579, + 1559, + -5 + ], + [ + 1494, + 1559, + -5 + ], + [ + 1494, + 1640, + -5 + ], + [ + 1702, + 1640, + -5 + ], + [ + 1702, + 1752, + -5 + ], + [ + 1097, + 1752, + -5 + ], + [ + 1097, + 1540, + -5 + ], + [ + 1033, + 1540, + -5 + ], + [ + 1033, + 1451, + -5 + ], + [ + 1056, + 1451, + -5 + ], + [ + 1056, + 1325, + -5 + ], + [ + 994, + 1325, + -5 + ], + [ + 994, + 1451, + -5 + ], + [ + 1017, + 1451, + -5 + ], + [ + 1017, + 1540, + -5 + ], + [ + 953, + 1540, + -5 + ], + [ + 953, + 1752, + -5 + ], + [ + 605, + 1752, + -5 + ], + [ + 605, + 1640, + -5 + ], + [ + 640, + 1640, + -5 + ], + [ + 640, + 1559, + -5 + ], + [ + 554, + 1559, + -5 + ], + [ + 554, + 1591, + -5 + ], + [ + 250, + 1591, + -5 + ], + [ + 250, + 1479, + -5 + ], + [ + 279, + 1479, + -5 + ], + [ + 279, + 1378, + -5 + ], + [ + 250, + 1378, + -5 + ], + [ + 250, + 1338, + -5 + ], + [ + 330, + 1338, + -5 + ], + [ + 330, + 1252, + -5 + ], + [ + 249, + 1252, + -5 + ], + [ + 249, + 1287, + -5 + ], + [ + 233, + 1287, + -5 + ], + [ + 233, + 1378, + -5 + ], + [ + 204, + 1378, + -5 + ], + [ + 204, + 1479, + -5 + ], + [ + 233, + 1479, + -5 + ], + [ + 233, + 1608, + -5 + ], + [ + 554, + 1608, + -5 + ], + [ + 554, + 1640, + -5 + ], + [ + 588, + 1640, + -5 + ], + [ + 588, + 1769, + -5 + ], + [ + 970, + 1769, + -5 + ], + [ + 970, + 1557, + -5 + ], + [ + 1080, + 1557, + -5 + ], + [ + 1080, + 1769, + -5 + ], + [ + 1719, + 1769, + -5 + ], + [ + 1719, + 1087, + -5 + ], + [ + 1507, + 1087, + -5 + ], + [ + 1507, + 977, + -5 + ], + [ + 1719, + 977, + -5 + ], + [ + 1719, + 135, + -5 + ], + [ + 1392, + 135, + -5 + ], + [ + 1392, + 372, + -5 + ], + [ + 1282, + 372, + -5 + ], + [ + 1282, + 135, + -5 + ], + [ + 747, + 135, + -5 + ], + [ + 747, + 347, + -5 + ], + [ + 637, + 347, + -5 + ] + ] +}