diff --git a/.gitignore b/.gitignore index 3b261560ecb84427e3c4197a8f551f6a0715b77d..01104a706829187c4bfa8b034cb6e49b739111be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .ipynb_checkpoints -.DS_Store \ No newline at end of file +.DS_Store +dice_firmware \ No newline at end of file diff --git a/01_Code/physical_computing_interface/assembly/app.js b/01_Code/physical_computing_interface/assembly/app.js index e692e8e90a205cf27e8c87fdd6b3127ea183020e..770e61eff034e478753895303b189630022f050b 100644 --- a/01_Code/physical_computing_interface/assembly/app.js +++ b/01_Code/physical_computing_interface/assembly/app.js @@ -27,87 +27,105 @@ assembler.run(); //////////////////////////////python-urx////////////////// - -var ur10Setup={ - 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 +var integratedSetup={ + ur10Setup:{ + parameters:{ + 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 + }, + 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, + + }, - edgeRelativeDistance:{ - x: 0, - y: 0, - z: 0.04, - rx:0, - ry:0, - rz:0 + nodes:[ //relative to the pickup + ], + edges:[ //relative to the pickup + ], + }, + DEMSetup:{ + parameters: { + run:false, + make:false, + delta_t: 1e-4, + cutoff: 0.1, + spring_constant: 1000.0, + num_particles_per_node:3, + region_pitch:1.0, + save_every:20, //visualize every how much frames + save_max:200, //max num of files saved }, - v:0.5, - a:0.5, - v1:0.05, - a1:0.05, - sleep:0.2, - sleep1:0.1, - + particles:[], + } +} - }, - nodes:[ //relative to the pickup - ], - edges:[ //relative to the pickup - ], -}; -GLOBALS.selectedjson=ur10Setup.globals; +GLOBALS.selectedjson=integratedSetup; GLOBALS.editor.set(GLOBALS.selectedjson); document.addEventListener('runNode', function (e) { - startAssembler(ur10Setup); + startAssembler(integratedSetup); }, false); document.addEventListener('addNode', function (e) { - assembleNode(e,ur10Setup); + assembleNode(e,integratedSetup); }, false); -function assembleNode(e,ur10Setup){ +function assembleNode(e,integratedSetup){ + + var ur10Setup=integratedSetup.ur10Setup; var x=e.detail.x; var y=e.detail.y; var z=e.detail.z; @@ -133,7 +151,7 @@ function assembleNode(e,ur10Setup){ ur10Setup.edges.push({ y: (x+0.5*(j1-y)), x: (GLOBALS.gridSize-y-1+0.5*(i1-x)), - z: z*ur10Setup.globals.latticePitch.z, + z: z*ur10Setup.parameters.latticePitch.z, rx:0, ry:0, rz:((j1-y)==0)? 0:Math.PI/2.0, @@ -200,12 +218,27 @@ function assembleNode(e,ur10Setup){ } + ///////////////////////////////////////////////// + //add particles to the DEM simulator + for(var i=0;i<integratedSetup.DEMSetup.parameters.num_particles_per_node;i++){ + integratedSetup.DEMSetup.particles.push({ + position:[ + (Math.random()+(GLOBALS.gridSize-y-1))*integratedSetup.DEMSetup.parameters.region_pitch , + (Math.random()+(x))*integratedSetup.DEMSetup.parameters.region_pitch + ], + velocity:[ + Math.random()*2.0-1.0 , Math.random()*2.0-1.0 + ] + }); + } } -function startAssembler(ur10Setup){ +function startAssembler(integratedSetup){ + var ur10Setup=integratedSetup.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) { + $.post("/", { data : { setup : JSON.stringify(integratedSetup) } }, function(temp) { }); //todo change that to message down diff --git a/01_Code/physical_computing_interface/assembly/python-urx/setup.json b/01_Code/physical_computing_interface/assembly/python-urx/setup.json index f37b76ac6cc9f171870c2d36a86b60d38793a3d3..46e67bcff2c84824311a440e6031a4165ef3c13a 100644 --- a/01_Code/physical_computing_interface/assembly/python-urx/setup.json +++ b/01_Code/physical_computing_interface/assembly/python-urx/setup.json @@ -1,6 +1,6 @@ { "setup": { - "globals": { + "parameters": { "run": true, "pythonFileName": "ur10test", "ipNode": "192.168.1.52", @@ -58,14 +58,6 @@ "sleep1": 0.1 }, "nodes": [ - { - "y": 0, - "x": 1, - "z": 0, - "rx": 0, - "ry": 0, - "rz": 0 - }, { "y": 0, "x": 0, @@ -78,44 +70,20 @@ "edges": [ { "y": 0, - "x": 1.5, + "x": 0.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.5, - "x": 1, + "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, - "x": 0.5, - "z": 0, - "rx": 0, - "ry": 0, - "rz": 0 - }, { "y": 0, "x": -0.5, diff --git a/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py b/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py index c31fa7e0a4f6f46f03a8204999f312c14f9003b0..8f0241d25140a4dbe0813770c183288d83d6b944 100644 --- a/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py +++ b/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py @@ -11,7 +11,7 @@ import json print("") print("") -print('Hello from python!') +print('Hello from ur10test.py!') print("") @@ -22,7 +22,7 @@ with open('../assembly/python-urx/setup.json') as f: # set values setup=data["setup"] -globalSetup=data["setup"]["globals"] +globalSetup=data["setup"]["parameters"] reference_roy=globalSetup["nodePickupRobotHome"] reference_siegfried=globalSetup["edgePickupRobotHome"] latticePitch=globalSetup["latticePitch"] diff --git a/01_Code/physical_computing_interface/json/json.js b/01_Code/physical_computing_interface/json/json.js index 4a4034aa8d504b1e89b87c218f29099f92fd2310..e79d856255fb892bcf21c87f2433b6fbfd7464c0 100644 --- a/01_Code/physical_computing_interface/json/json.js +++ b/01_Code/physical_computing_interface/json/json.js @@ -203,13 +203,12 @@ function initEditor(){ if(json.ipNode === undefined){ GLOBALS.updateNode(json); }else{ - ur10Setup.globals=json; //todo remove from here + integratedSetup=json; //todo remove from here } } }; GLOBALS.editor = new JSONEditor(container, options); - GLOBALS.editor.set({bla:"hi"}); document.addEventListener('selectNode', function (e) { GLOBALS.editor.set(GLOBALS.selectedjson); diff --git a/01_Code/physical_computing_interface/setup/serve.js b/01_Code/physical_computing_interface/setup/serve.js index 7f08b54b1fc9dbae9b123d9d7b8ca603eba5836e..77e2d63a0eaab6a92624dbbed424457f0890fcee 100644 --- a/01_Code/physical_computing_interface/setup/serve.js +++ b/01_Code/physical_computing_interface/setup/serve.js @@ -19,7 +19,6 @@ app.use(express.urlencoded({limit: '50mb', extended: true})); //serve the html 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; @@ -28,8 +27,6 @@ app.post("/", function(req, res) { console.log("run python_urx!"); runPython_urx(setup); - - res.send("I am done"); }); @@ -46,20 +43,46 @@ function runPython_urx(setup){ var root="../assembly/python-urx/"; let outputFile = editJsonFile(`${__dirname}/`+root+`setup.json`); - outputFile.set("setup", setup); + outputFile.set("setup", setup.ur10Setup); outputFile.save(); - console.log("saved the setup in ../assembly/python-urx/setup.json"); + console.log("saved the UR10 setup in ../assembly/python-urx/setup.json"); console.log(); - if(setup.globals.run){ + if(setup.ur10Setup.parameters.run){ console.log("Call python script:") var commands=[]; - commands.push("python " + root+setup.globals.pythonFileName +".py"); + commands.push("python " + root+setup.ur10Setup.parameters.pythonFileName +".py"); runListCommand(commands,0); }else{ console.log("didn't run the UR10"); } + + if(integratedSetup.DEMSetup.parameters.run){ + var root="../simulation/dice_firmware/build/x86/src/sim/vis/"; + let outputFile = editJsonFile(`${__dirname}/`+root+`sim_config.json`); + outputFile.set("setup", setup.DEMSetup); + outputFile.save(); + console.log("saved the DEM setup in ../simulation/dice_firmware/build/x86/src/sim/vis/"); + console.log(); + console.log("Compile and run the DEM simulator:") + var commands=[]; + if(integratedSetup.DEMSetup.parameters.make){ + //make first + commands.push("cd " + "../simulation/dice_firmware/build/x86"); + commands.push("make"); + commands.push("cd " + "src/sim/vis/"); + + }else{ + commands.push("cd " + root); + } + + commands.push("./sim_vis_executable"); + runListCommand(commands,0); + + }else{ + console.log("didn't run DEM simulation"); + } } function runListCommand(commands,index){ diff --git a/02_Presentation/assembly/json.png b/02_Presentation/assembly/json.png new file mode 100644 index 0000000000000000000000000000000000000000..346ebdb252b7f0859c9eaa7a8cd1b6b22051d057 Binary files /dev/null and b/02_Presentation/assembly/json.png differ diff --git a/02_Presentation/assembly/ur10.md b/02_Presentation/assembly/ur10.md index 9033f5aa93b4ae94b5536ee2107d805d6b932211..136597ed589da8d446242b1c8954f2274672e6ee 100644 --- a/02_Presentation/assembly/ur10.md +++ b/02_Presentation/assembly/ur10.md @@ -13,7 +13,8 @@ 5. Now you can run the node.js server by running - `node server.js` 6. this will show you instructions to navigate to `http://localhost:8080/demos/indexUR10.html` on your browser -7. There you can **first** change the settings in the json editor in the bottom right, these are the global settings: +7. There you can **first** change the settings in the json editor in the bottom right, these are under ur10Setup parameters settings: + -  ```javascript { run:true, // if true it will call the python script to move the UR10s, if false it will just save the setup ../assembly/python-urx/setup.json @@ -75,7 +76,7 @@ ``` 8. If the settings are correct you can place the nodes in the assembly 3d grid, for now place them in the bottom right corner -  -9. You can run after placing one node or after placing both nodes by pressing right click while the cursor is on the node; then the radial menu will appear, you can then press play. +9. You can run after placing one node or after placing both nodes by pressing right click while the cursor is on the node; then the radial menu will appear, you can then press play. -  -10. This will save the current setup to `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/setup.json` and if `run:true` it will run the python file that is in `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/` for example `ur10test.py` -11. `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py` uses `python-urx` library to communicate with the UR10s and it uses the settings in `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/setup.json`, you can debug this independently. \ No newline at end of file +11. This will save the current setup to `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/setup.json` and if `run:true` it will run the python file that is in `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/` for example `ur10test.py` +12. `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/ur10test.py` uses `python-urx` library to communicate with the UR10s and it uses the settings in `./physical-computing-design-tools/01_Code/physical_computing_interface/assembly/python-urx/setup.json`, you can debug this independently. \ No newline at end of file