diff --git a/01_Code/physical_computing_interface/assembly/app.js b/01_Code/physical_computing_interface/assembly/app.js index 11b959505cc14e14a776a218efcc7f4f78e255e2..e692e8e90a205cf27e8c87fdd6b3127ea183020e 100644 --- a/01_Code/physical_computing_interface/assembly/app.js +++ b/01_Code/physical_computing_interface/assembly/app.js @@ -20,43 +20,198 @@ initEditor();// todo enclose into class /////////////assmebly//////////////////// -var assembler= new Assembler(three,GLOBALS,1,50,[new THREE.Vector3(0,0,0)],[new THREE.Vector3(GLOBALS.gridSize/2.0*GLOBALS.voxelSpacing,0,0)]); +var assembler= new Assembler(three,GLOBALS,1,50,[new THREE.Vector3(10,10,10)],[new THREE.Vector3(GLOBALS.gridSize/2.0*GLOBALS.voxelSpacing,0,0)]); assembler.run(); //////////////////////////////python-urx////////////////// + + + var ur10Setup={ - run:true, - pythonFileName: "script2", //in ./assembly/python-urx/ - ip: "192.168.1.52", - pickup:{ - x: 0.043008387088775635, - y: -1.296274487172262, - z: 2.373403787612915, - rx:-1.3105805555926722, - ry:0.04273087903857231, - rz:-1.3469165007220667 - }, - locations:[ - { - x: 0.02622373215854168, - y: -1.2583287397967737, - z: 2.196824550628662, - rx:-1.2858575026141565, - ry:0.026594867929816246, - rz:-1.2329323927508753, + globals:{ + run:true, + pythonFileName: "ur10test", //in ./assembly/python-urx/ + ipNode: "192.168.1.52", + ipEdge: "192.168.1.53", + latticePitch:{ + x:0.031, + y:0.031, + z:0.006, + }, + nodePickupRobotHome:{ + x: -1.5394771734820765, + y: -1.6685369650470179, + z: -2.495819155369894, + rx:-2.1159094015704554, + ry:-1.5422142187701624, + rz:-1.5874159971820276, + }, + edgePickupRobotHome:{ + x: -0.21965343156923467, + y: -1.5261443297015589, + z: 2.5553131103515625, + rx:-1.0277064482318323, + ry:1.3498035669326782, + rz:-1.5769990126239222, + }, + programmingRelativeDistance:{ + x: -0.203, + y: 0.0127, + z: 0.013, + rx:0, + ry:0, + rz:0, + }, + nodeRelativeDistance:{ + x: -0.4417, + y: 0.005, + z: 0.04, + rx:0, + ry:0, + rz:0 }, - { - x:0.02478637360036373, - y:-1.2227914969073694, - z:2.1424121856689453, - rx:-1.2808602491961878, - ry:0.02525300905108452, - rz:-1.218954865132467, + edgeRelativeDistance:{ + x: 0, + y: 0, + z: 0.04, + rx:0, + ry:0, + rz:0 }, + v:0.5, + a:0.5, + v1:0.05, + a1:0.05, + sleep:0.2, + sleep1:0.1, + + + }, + nodes:[ //relative to the pickup + ], + edges:[ //relative to the pickup ], }; -$.post("/", { data : { foo : JSON.stringify(ur10Setup) } }, function(temp) { - // temp === "I am done"; -}); \ No newline at end of file + +GLOBALS.selectedjson=ur10Setup.globals; +GLOBALS.editor.set(GLOBALS.selectedjson); + +document.addEventListener('runNode', function (e) { + startAssembler(ur10Setup); +}, false); + +document.addEventListener('addNode', function (e) { + assembleNode(e,ur10Setup); +}, false); + + +function assembleNode(e,ur10Setup){ + var x=e.detail.x; + var y=e.detail.y; + var z=e.detail.z; + // + ur10Setup.nodes.push({ + y: x, + x: (GLOBALS.gridSize-y-1), + z: z, + rx:0, + ry:0, + rz:0, + + }); + //add edges + console.log("x:"+x+", y:"+y+", z:"+z) + var list=utils.getNeighborsList(GLOBALS.grid,x,y,z); + console.log(list) + + for(var i=0;i<list.length;i++){ + var i1,j1,k1; + [i1,j1,k1]=list[i]; + if ( !GLOBALS.occupancy[i1][j1][k1] && k1==z ) { + ur10Setup.edges.push({ + y: (x+0.5*(j1-y)), + x: (GLOBALS.gridSize-y-1+0.5*(i1-x)), + z: z*ur10Setup.globals.latticePitch.z, + rx:0, + ry:0, + rz:((j1-y)==0)? 0:Math.PI/2.0, + + }); + } + } + + //add boundary + var i=x-1; + if ( i<0 ){ + //build + ur10Setup.edges.push({ + y: (x), + x: (GLOBALS.gridSize-y-1-0.5), + z: z, + rx:0, + ry:0, + rz:0, + + }); + } + + var i=x+1; + if ( i==GLOBALS.gridSize ){ + //build + ur10Setup.edges.push({ + y: (x), + x: (GLOBALS.gridSize-y-1+0.5), + z: z, + rx:0, + ry:0, + rz:0, + + }); + } + + var j=y-1; + if ( j<0 ){ + //build + ur10Setup.edges.push({ + y: (x-0.5), + x: (GLOBALS.gridSize-y-1), + z: z, + rx:0, + ry:0, + rz:Math.PI/2.0, + + }); + } + + var j=y+1; + if ( j==GLOBALS.gridSize ){ + //build + ur10Setup.edges.push({ + y: (x+0.5), + x: (GLOBALS.gridSize-y-1), + z: z, + rx:0, + ry:0, + rz:Math.PI/2.0, + + }); + } + + +} + +function startAssembler(ur10Setup){ + console.log("Run Assembler to assemble "+ur10Setup.nodes.length+ " node(s) and "+ur10Setup.edges.length+ " edge(s)!"); + console.log(ur10Setup.edges) + $.post("/", { data : { setup : JSON.stringify(ur10Setup) } }, function(temp) { + }); + //todo change that to message down + + //delete list of nodes in setup + ur10Setup.nodes=[]; + ur10Setup.edges=[]; + +} + diff --git a/01_Code/physical_computing_interface/assembly/assembly.js b/01_Code/physical_computing_interface/assembly/assembly.js index 2130a44342a6e872f6f60a862f213184e0ab487d..0337e2d4cd67dfe97f67060ef9c020f47ffb1be7 100644 --- a/01_Code/physical_computing_interface/assembly/assembly.js +++ b/01_Code/physical_computing_interface/assembly/assembly.js @@ -164,6 +164,7 @@ Assembler.prototype.declareGlobals=function(){ this.IK.push([]); } + // //starting positions and pickup stations // if(numberOfRobots>1){ // robotState[1].leg1Pos=new THREE.Vector3((GLOBALS.gridSize-1),(GLOBALS.gridSize-2),0); diff --git a/01_Code/physical_computing_interface/assembly/python-urx/script1.py b/01_Code/physical_computing_interface/assembly/python-urx/script1.py index 13cc681c5b43b2815e4be28fb470ab54b6243927..62a7689547993a3906ccf7043dfd5da411b57c70 100644 --- a/01_Code/physical_computing_interface/assembly/python-urx/script1.py +++ b/01_Code/physical_computing_interface/assembly/python-urx/script1.py @@ -1 +1,14 @@ -print('Hello from python') \ No newline at end of file +print('Hello from python') + +import json + +# import os + +# path = os.getcwd() + +# print(path) + + +with open('../assembly/python-urx/setup.json') as f: + data = json.load(f) +print(data["setup"]["globals"]["ipNode"]) \ No newline at end of file diff --git a/01_Code/physical_computing_interface/assembly/python-urx/setup.json b/01_Code/physical_computing_interface/assembly/python-urx/setup.json new file mode 100644 index 0000000000000000000000000000000000000000..f775e0769d4c6b83b3d31f4b5ca9c33661827d7d --- /dev/null +++ b/01_Code/physical_computing_interface/assembly/python-urx/setup.json @@ -0,0 +1,137 @@ +{ + "setup": { + "globals": { + "run": true, + "pythonFileName": "ur10test", + "ipNode": "192.168.1.52", + "ipEdge": "192.168.1.53", + "latticePitch": { + "x": 0.031, + "y": 0.031, + "z": 0.006 + }, + "nodePickupRobotHome": { + "x": -1.5394771734820765, + "y": -1.6685369650470179, + "z": -2.495819155369894, + "rx": -2.1159094015704554, + "ry": -1.5422142187701624, + "rz": -1.5874159971820276 + }, + "edgePickupRobotHome": { + "x": -0.21965343156923467, + "y": -1.5261443297015589, + "z": 2.5553131103515625, + "rx": -1.0277064482318323, + "ry": 1.3498035669326782, + "rz": -1.5769990126239222 + }, + "programmingRelativeDistance": { + "x": -0.203, + "y": 0.0127, + "z": 0.013, + "rx": 0, + "ry": 0, + "rz": 0 + }, + "nodeRelativeDistance": { + "x": -0.4417, + "y": 0.005, + "z": 0.04, + "rx": 0, + "ry": 0, + "rz": 0 + }, + "edgeRelativeDistance": { + "x": 0, + "y": 0, + "z": 0.04, + "rx": 0, + "ry": 0, + "rz": 0 + }, + "v": 0.5, + "a": 0.5, + "v1": 0.05, + "a1": 0.05, + "sleep": 0.2, + "sleep1": 0.1 + }, + "nodes": [ + { + "y": 0, + "x": 0, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + }, + { + "y": 0, + "x": 1, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + } + ], + "edges": [ + { + "y": 0, + "x": 0.5, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + }, + { + "y": -0.5, + "x": 0, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 1.5707963267948966 + }, + { + "y": 0, + "x": -0.5, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + }, + { + "y": 0.5, + "x": 0, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 1.5707963267948966 + }, + { + "y": 0, + "x": 1.5, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + }, + { + "y": -0.5, + "x": 1, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 1.5707963267948966 + }, + { + "y": 0, + "x": 0.5, + "z": 0, + "rx": 0, + "ry": 0, + "rz": 0 + } + ] + } +} \ No newline at end of file diff --git a/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py b/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py new file mode 100644 index 0000000000000000000000000000000000000000..c31fa7e0a4f6f46f03a8204999f312c14f9003b0 --- /dev/null +++ b/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py @@ -0,0 +1,136 @@ +import sys +import urx +from urx.robotiq_two_finger_gripper import Robotiq_Two_Finger_Gripper +import time +import math3d as m3d +import json + + +# roy = nodes +# siegfried = struts + +print("") +print("") +print('Hello from python!') +print("") + + +with open('../assembly/python-urx/setup.json') as f: + data = json.load(f) +# print(data) + + +# set values +setup=data["setup"] +globalSetup=data["setup"]["globals"] +reference_roy=globalSetup["nodePickupRobotHome"] +reference_siegfried=globalSetup["edgePickupRobotHome"] +latticePitch=globalSetup["latticePitch"] +sleepTime=globalSetup["sleep"] +sleepTime1=globalSetup["sleep1"] + + +# # reference locations are 40 mm above pickup points +# reference_roy_j = (reference_roy["x"], reference_roy["y"], reference_roy["z"], reference_roy["rx"], reference_roy["ry"], reference_roy["rz"]) +# reference_siegfried_j = (reference_siegfried["x"], reference_siegfried["y"], reference_siegfried["z"], reference_siegfried["rx"], reference_siegfried["ry"], reference_siegfried["rz"]) + +# roy = urx.Robot(globalSetup["ipNode"]) +# roy.set_tcp((0, 0, 0.1, 0, 0, 0)) +# roy.set_payload(2, (0, 0, 0.1)) +# time.sleep(sleepTime) #leave some time to robot to process the setup commands + + +# siegfried = urx.Robot(globalSetup["ipEdge"]) +# siegfried.set_tcp((0, 0, 0.1, 0, 0, 0)) +# siegfried.set_payload(2, (0, 0, 0.1)) +# time.sleep(sleepTime) #leave some time to robot to process the setup commands + + + +# placement location reference (top view) +# [S1] [S2] +# +#[S3] [N1] [S4] [N2] [S5] +# +# [S6] [S7] + + +for node in setup["nodes"]: + print("Build Node:") + print(node) + + # v = globalSetup["v"] + # a = globalSetup["a"] + + # # move to reference locations and get current transformation matrices + # roy.movej(reference_roy_j, acc = a, vel = v) + # roy_trans = roy.get_pose() + # time.sleep(sleepTime) + + # v = globalSetup["v1"] + # a = globalSetup["a1"] + + # # move to pickup locations from reference + # roy_trans.pos.z += globalSetup["nodeRelativeDistance"]["z"] + # roy.set_pose(roy_trans, acc = a, vel = v) + # time.sleep(sleepTime) + + + # # close and open grippers + # roy.send_program('set_tool_digital_out(0, True)') #close node tool + # time.sleep(sleepTime1) + # roy.send_program('set_tool_digital_out(0, False)') #open node tool + # time.sleep(sleepTime1) + + # # move roy (nodes) to programming location from reference, drops to program, then lifts to reference height + # roy_trans.pos.x += globalSetup["programmingRelativeDistance"]["x"] + # roy_trans.pos.y += globalSetup["programmingRelativeDistance"]["y"] + # roy.set_pose(roy_trans, acc = a, vel = v) + # roy_trans.pos.z -= globalSetup["programmingRelativeDistance"]["z"] + # roy.set_pose(roy_trans, acc = a, vel = v) + # time.sleep(1) # programming time! + # roy_trans.pos.z += globalSetup["programmingRelativeDistance"]["z"] + # roy.set_pose(roy_trans, acc = a, vel = v) + + # # move roy (nodes) to node from reference location + # roy_trans.pos.x += ((globalSetup["nodeRelativeDistance"]["x"])+node["x"]*latticePitch["x"]) + # roy_trans.pos.y += ((globalSetup["nodeRelativeDistance"]["y"])+node["y"]*latticePitch["y"]) + # roy.set_pose(roy_trans, acc = a, vel = v) + # roy_trans.pos.z -= (globalSetup["nodeRelativeDistance"]["z"]-node["z"]*latticePitch["z"]) + # roy.set_pose(roy_trans, acc = a, vel = v) + # roy_trans.pos.z += (globalSetup["nodeRelativeDistance"]["z"]-node["z"]*latticePitch["z"]) + # time.sleep(sleepTime) + + + +print("") + + +for edge in setup["edges"]: + + print("Build Edge:") + print(edge) + + # v = globalSetup["v"] + # a = globalSetup["a"] + + # # move to reference locations and get current transformation matrices + # siegfried.movej(reference_siegfried_j, acc = a, vel = v) + # siegfried_trans = siegfried.get_pose() + # time.sleep(sleepTime) + + # # move to pickup locations from reference + # siegfried_trans.pos.z += globalSetup["edgeRelativeDistance"]["z"] + # siegfried.set_pose(siegfried_trans, acc = a, vel = v) + # time.sleep(sleepTime) + + # # close and open grippers + # siegfried.send_program('set_tool_digital_out(0, True)') #close strut tool + # time.sleep(sleepTime1) + # siegfried.send_program('set_tool_digital_out(0, False)') #open strut tool + # time.sleep(sleepTime1) + + + +# print ("roy's current pose: ", roy.getj()) +# print ("siegfried's current pose: ", siegfried.getj()) diff --git a/01_Code/physical_computing_interface/json/json.js b/01_Code/physical_computing_interface/json/json.js index 207e6cd0aef7f8ae5ae84f79dae7afaa0695fead..4a4034aa8d504b1e89b87c218f29099f92fd2310 100644 --- a/01_Code/physical_computing_interface/json/json.js +++ b/01_Code/physical_computing_interface/json/json.js @@ -200,37 +200,42 @@ function initEditor(){ // console.log(jsonString); // const json = editor.get(); var json=JSON.parse(jsonString); - GLOBALS.updateNode(json); + if(json.ipNode === undefined){ + GLOBALS.updateNode(json); + }else{ + ur10Setup.globals=json; //todo remove from here + } + } }; - var editor = new JSONEditor(container, options); - + GLOBALS.editor = new JSONEditor(container, options); + GLOBALS.editor.set({bla:"hi"}); document.addEventListener('selectNode', function (e) { - editor.set(GLOBALS.selectedjson); + GLOBALS.editor.set(GLOBALS.selectedjson); }, false); document.addEventListener('selectEdge', function (e) { - editor.set(GLOBALS.selectedjson); + GLOBALS.editor.set(GLOBALS.selectedjson); }, false); // get json //set info // document.getElementById('getJSON').onclick = function () { - // var json = editor.get(); + // var json = GLOBALS.editor.get(); // // alert(JSON.stringify(json, null, 2)); // GLOBALS.updateNode(json); // }; - // editor.on('onChangeJson',function() { + // GLOBALS.editor.on('onChangeJson',function() { // console.log("hiii"); // }); - // editor.onChangeJson= function(json){ + // GLOBALS.editor.onChangeJson= function(json){ // // console.log(json); // console.log("hiii"); // }; - // document.addEventListener('onChangeJson', function (e) { + // GLOBALS.document.addEventListener('onChangeJson', function (e) { // console.log("hissssii"); // }, false); diff --git a/01_Code/physical_computing_interface/setup/globals.js b/01_Code/physical_computing_interface/setup/globals.js index 449727bbeb577273f8b2579395389905dfbb49de..4a425114bcafaeeb2aa8764cdccc4a40e91e7fd7 100644 --- a/01_Code/physical_computing_interface/setup/globals.js +++ b/01_Code/physical_computing_interface/setup/globals.js @@ -280,6 +280,7 @@ function globals(utils){ this.totalTimeSteps=0; this.timeline=[]; this.selectedjson; + this.editor; } diff --git a/01_Code/physical_computing_interface/setup/package-lock.json b/01_Code/physical_computing_interface/setup/package-lock.json index 85651edbada6fc06c119ef5fd4578467b92bfa2d..932e96a53aad315e56578f451f560954de7d2a7c 100644 --- a/01_Code/physical_computing_interface/setup/package-lock.json +++ b/01_Code/physical_computing_interface/setup/package-lock.json @@ -79,6 +79,18 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "edit-json-file": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/edit-json-file/-/edit-json-file-1.4.1.tgz", + "integrity": "sha512-YqnKYc2+F+j4Y0qGVKY36Qzb7zusQnQU3JFyqDAZU+vVdtPPqrFtVytsTsCC2kMej5I0BkUCCfPMQq6w5j+cBg==", + "requires": { + "find-value": "^1.0.3", + "iterate-object": "^1.3.2", + "r-json": "^1.2.5", + "set-value": "^3.0.1", + "w-json": "^1.3.5" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -150,6 +162,11 @@ "unpipe": "~1.0.0" } }, + "find-value": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/find-value/-/find-value-1.0.12.tgz", + "integrity": "sha512-OCpo8LTk8eZ2sdDCwbU2Lc3ivYsdM6yod6jP2jHcNEFcjPhkgH0+POzTIol7xx1LZgtbI5rkO5jqxsG5MWtPjQ==" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -190,6 +207,24 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, + "is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "requires": { + "isobject": "^3.0.1" + } + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=" + }, + "iterate-object": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/iterate-object/-/iterate-object-1.3.4.tgz", + "integrity": "sha512-4dG1D1x/7g8PwHS9aK6QV5V94+ZvyP4+d19qDv43EzImmrndysIl4prmJ1hWWIGCqrZHyaHBm6BSEWHOLnpoNw==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -265,6 +300,11 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" }, + "r-json": { + "version": "1.2.10", + "resolved": "https://registry.npmjs.org/r-json/-/r-json-1.2.10.tgz", + "integrity": "sha512-hu9vyLjSlHXT62NAS7DjI9WazDlvjN0lgp3n431dCVnirVcLkZIpzSwA3orhZEKzdDD2jqNYI+w0yG0aFf4kpA==" + }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -329,6 +369,14 @@ "send": "0.17.1" } }, + "set-value": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-3.0.2.tgz", + "integrity": "sha512-npjkVoz+ank0zjlV9F47Fdbjfj/PfXyVhZvGALWsyIYU/qrMzpi6avjKW3/7KeSU2Df3I46BrN1xOI1+6vW0hA==", + "requires": { + "is-plain-object": "^2.0.4" + } + }, "setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", @@ -367,6 +415,11 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + }, + "w-json": { + "version": "1.3.10", + "resolved": "https://registry.npmjs.org/w-json/-/w-json-1.3.10.tgz", + "integrity": "sha512-XadVyw0xE+oZ5FGApXsdswv96rOhStzKqL53uSe5UaTadABGkWIg1+DTx8kiZ/VqTZTBneoL0l65RcPe4W3ecw==" } } } diff --git a/01_Code/physical_computing_interface/setup/package.json b/01_Code/physical_computing_interface/setup/package.json index e2b3129ab4c8cae36451d2e66d4c61775fedc30e..d8106c81c434d0991f2795b1878c8d9d8e2b0ff0 100644 --- a/01_Code/physical_computing_interface/setup/package.json +++ b/01_Code/physical_computing_interface/setup/package.json @@ -218,18 +218,7 @@ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "version": "1.0.3" }, - "edit-json-file": { - "integrity": "sha512-0I7+oa195vpuiO/pOvO0F+ngoFLyU5dn0Zbr56D9lER1lwxq0ZM1jhCtTUqs4lvEPBUopnK9CHszRkfnqNi2Rg==", - "requires": { - "find-value": "^1.0.3", - "iterate-object": "^1.3.2", - "r-json": "^1.2.5", - "set-value": "^3.0.1", - "w-json": "^1.3.5" - }, - "resolved": "https://registry.npmjs.org/edit-json-file/-/edit-json-file-1.3.2.tgz", - "version": "1.3.2" - }, + "edit-json-file": "^1.4.1", "ee-first": { "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/01_Code/physical_computing_interface/setup/serve.js b/01_Code/physical_computing_interface/setup/serve.js index 9af3904f9c328236b2ad2081ceec866d89036786..01a20a616396528fe345bb4dd4cda2131d088030 100644 --- a/01_Code/physical_computing_interface/setup/serve.js +++ b/01_Code/physical_computing_interface/setup/serve.js @@ -11,6 +11,9 @@ var fs = require('fs'); var app = express(); var path = require('path'); +var fs = require('fs'); +const editJsonFile = require("edit-json-file"); + var setup; // will parse incoming JSON data and convert it into an object literal for you @@ -24,15 +27,12 @@ app.use(express.static(__dirname + '/../')); // exposes index.html, per below app.post("/", function(req, res) { // each key in req.body will match the keys in the data object that you passed in var myObject = req.body.data; - setup=JSON.parse(myObject.foo); - console.log(setup.ip) + setup=JSON.parse(myObject.setup); + + console.log("run python_urx!"); + runPython_urx(setup); + - if(setup.run){ - console.log("run python_urx!"); - runPython_urx(setup.pythonFileName); - }else{ - console.log("reading data"); - } res.send("I am done"); }); @@ -42,55 +42,28 @@ port = 8080; app.listen(port); console.log(`Open http://localhost:${port}/demos/indexUR10.html in your browser`); - - -function runPython_urx(fileName){ - console.log("here") +function runPython_urx(setup){ // var dataToSend; // const python = exec('python', ['./assembly/python-urx/script1.py']); // const exec = spawn(‘python’, [‘script2.py’,’node.js’,’python’]); var root="../assembly/python-urx/"; - var commands=[]; - commands.push("python " + root+fileName +".py"+ " hi"+ " hello"); - commands.push("python " + root+"script1" +".py") - - runListCommand(commands,0); - - - // var command= "python " + root+fileName +".py"+ " hi"+ " hello"; - // // var command= "ls"; - - // const python =exec(command, (error, stdout, stderr) => { - // if (error) { - // console.log(`error: ${error.message}`); - // return; - // } - // if (stderr) { - // console.log(`stderr: ${stderr}`); - // return; - // } - // console.log(`stdout: ${stdout}`); - // }); - - - // var command= "python " + root+"script1" +".py"; - - - - // python.stdout.on('data', function (data) { - // console.log('Pipe data from python script ...'); - // dataToSend = data.toString(); - // console.log(dataToSend) - // }); - // // in close event we are sure that stream from child process is closed - // python.on('close', (code) => { - // console.log(`child process close all stdio with code ${code}`); - // // send data to browser - // res.send(dataToSend) - // }); - + let outputFile = editJsonFile(`${__dirname}/`+root+`setup.json`); + outputFile.set("setup", setup); + outputFile.save(); + console.log("saved the setup in ../assembly/python-urx/setup.json"); + console.log(); + + if(setup.globals.run){ + console.log("Call python script:") + var commands=[]; + commands.push("python " + root+setup.globals.pythonFileName +".py"); + runListCommand(commands,0); + + }else{ + console.log("didn't run the UR10"); + } } function runListCommand(commands,index){ @@ -105,7 +78,8 @@ function runListCommand(commands,index){ console.log(`stderr: ${stderr}`); return; } - console.log(`stdout: ${stdout}`); + console.log(`stdout:`); + console.log(`${stdout}`); runListCommand(commands,index+1); }); }