{"id":720,"date":"2011-03-14T21:28:42","date_gmt":"2011-03-14T21:28:42","guid":{"rendered":"http:\/\/blog.ensci.com\/fablab\/?p=720"},"modified":"2011-03-16T22:33:33","modified_gmt":"2011-03-16T22:33:33","slug":"codes-processing","status":"publish","type":"post","link":"http:\/\/blog.ensci.com\/fablab\/2011\/03\/14\/codes-processing\/","title":{"rendered":"Codes Processing"},"content":{"rendered":"<p style=\"text-align: center\"><a href=\"http:\/\/4.bp.blogspot.com\/_52TrOJpuoZ4\/TTwgf3zaN2I\/AAAAAAAAErY\/nbD64tsnSGY\/s1600\/planche%2BCode2-01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"margin-top: 0px;margin-bottom: 10px;width: 400px;height: 300px\" src=\"http:\/\/4.bp.blogspot.com\/_52TrOJpuoZ4\/TTwgf3zaN2I\/AAAAAAAAErY\/nbD64tsnSGY\/s400\/planche%2BCode2-01.jpg\" border=\"0\" alt=\"\" width=\"400\" height=\"300\" \/><\/a><span style=\"font-family: arial;font-size: 12px;line-height: 18px\">Version des codes Alpha (encore pas mal de bugs)<\/span><\/p>\n<p style=\"text-align: center\">&nbsp;<\/p>\n<p>import processing.serial.*;<\/p>\n<p>&nbsp;<\/p>\n<p>Serial myPort;<\/p>\n<p>String numScanner = \u00ab\u00a0\u00a0\u00bb;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/ plateau<\/p>\n<p>final int numberOfSteps = 40;<\/p>\n<p>final int maxStepArduinoPlateau = 2270;<\/p>\n<p>final int stepToSendPlateau = maxStepArduinoPlateau\/numberOfSteps;<\/p>\n<p>final int maxValueToTouchZero = 240;<\/p>\n<p>int currentStep = 0;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/ head<\/p>\n<p>&nbsp;<\/p>\n<p>final int numberOfHeightMeasures = 40;<\/p>\n<p>final int maxStepArduinoHead = 4460;<\/p>\n<p>final int stepToSendHead = maxStepArduinoHead\/numberOfHeightMeasures;<\/p>\n<p>int currentHeightStep = 0;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>boolean stateLeftToRght = true;<\/p>\n<p>&nbsp;<\/p>\n<p>boolean go = false;<\/p>\n<p>boolean goPlateauTurn = false;<\/p>\n<p>boolean goAndBack = true;<\/p>\n<p>boolean finishHim = false;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/ x,y,z<\/p>\n<p>float measuresXYZ[][][] = new float[numberOfSteps][numberOfHeightMeasures][3];<\/p>\n<p>&nbsp;<\/p>\n<p>void setup() {<\/p>\n<p>&nbsp;<\/p>\n<p>size(800,800,P3D);<\/p>\n<p>\/\/ List all the available serial ports:<\/p>\n<p>println(Serial.list());<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ I know that the first port in the serial list on my mac<\/p>\n<p>\/\/ is always my \u00a0Keyspan adaptor, so I open Serial.list()[0].<\/p>\n<p>\/\/ Open whatever port is the one you&rsquo;re using.<\/p>\n<p>myPort = new Serial(this, Serial.list()[0], 9600);<\/p>\n<p>\/\/ prepareLists();<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>void draw() {<\/p>\n<p>int input = 0;<\/p>\n<p>if (finishHim!=true) {<\/p>\n<p>String myString = \u00ab\u00a0\u00a0\u00bb;<\/p>\n<p>while (myPort.available() &gt; 0) {<\/p>\n<p>myString = myPort.readStringUntil(10);<\/p>\n<p>if (myString != null) {<\/p>\n<p>String[] a = splitTokens(myString);<\/p>\n<p>input = int(a[0]);<\/p>\n<p>if (input&gt;0) go = true;<\/p>\n<p>\/\/ println(input);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>background(30);<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/iterate scanner<\/p>\n<p>noStroke();<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>if (go) {<\/p>\n<p>&nbsp;<\/p>\n<p>if (goAndBack) {<\/p>\n<p>&nbsp;<\/p>\n<p>if (currentHeightStep&lt;numberOfHeightMeasures-1) {<\/p>\n<p>currentHeightStep++;<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>goPlateauTurn = true;<\/p>\n<p>goAndBack = false;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>if (currentHeightStep&gt;0) {<\/p>\n<p>currentHeightStep&#8211;;<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>goPlateauTurn = true;<\/p>\n<p>goAndBack = !goAndBack;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>if ((currentStep&lt;numberOfSteps-1) &amp;&amp; (goPlateauTurn==true)) {<\/p>\n<p>currentStep++;<\/p>\n<p>goPlateauTurn = false;<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>if (currentStep==numberOfSteps-1)<\/p>\n<p>finishHim = true;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ give info<\/p>\n<p>&nbsp;<\/p>\n<p>String xStr = str(currentHeightStep*stepToSendHead) + \u00ab\u00a0x\u00a0\u00bb;<\/p>\n<p>String yStr = str(currentStep*stepToSendPlateau) + \u00ab\u00a0y\u00a0\u00bb;<\/p>\n<p>\/\/ \u00a0 println(xStr + \u00a0\u00bb \u00a0\u00bb + yStr);<\/p>\n<p>&nbsp;<\/p>\n<p>myPort.write(xStr);<\/p>\n<p>myPort.write(yStr);<\/p>\n<p>println(currentStep + \u00ab\u00a0plateau \u00a0\u00a0\u00bb + currentHeightStep + \u00a0\u00bb head\u00a0\u00bb);<\/p>\n<p>\/\/println(input);<\/p>\n<p>\/\/calculate angles<\/p>\n<p>float currentStepAngle = (TWO_PI\/numberOfSteps) * float(currentStep); \/\/plateau<\/p>\n<p>float currentHeightAngle = (PI\/numberOfHeightMeasures) * float(currentHeightStep); \/\/\/head<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ get coordinates<\/p>\n<p>&nbsp;<\/p>\n<p>float z = calculateZ(input, currentHeightAngle);<\/p>\n<p>float x = calculateDistanceFromCenter(input, currentHeightAngle);<\/p>\n<p>float y = 0.0;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ rotate coordinates in to the good angle, Z is constant<\/p>\n<p>float xp = sin(currentStepAngle)*x;<\/p>\n<p>float yp = cos(currentStepAngle)*x;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ put values into the memory<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][0] = xp;<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][1] = yp;<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][2] = z;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>go = false;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/\/ RENDER<\/p>\n<p>\/\/\/ view transformations<\/p>\n<p>rotateX(0.8);<\/p>\n<p>translate(width\/2,0,-height\/2);<\/p>\n<p>&nbsp;<\/p>\n<p>fill(255);<\/p>\n<p>for (int i = 0; i&lt;numberOfSteps; i++) {<\/p>\n<p>for (int j = 0; j&lt;numberOfHeightMeasures; j++) {<\/p>\n<p>pushMatrix();<\/p>\n<p>&nbsp;<\/p>\n<p>translate(measuresXYZ[i][j][0], measuresXYZ[i][j][1], measuresXYZ[i][j][2]);<\/p>\n<p>&nbsp;<\/p>\n<p>ellipse(0,0, 5,5);<\/p>\n<p>&nbsp;<\/p>\n<p>popMatrix();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>float calculateZ(int in, float angle) {<\/p>\n<p>int c = maxValueToTouchZero-in;<\/p>\n<p>return float(c)*sin(angle);<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>float calculateDistanceFromCenter(int in, float angle) {<\/p>\n<p>int c = in-maxValueToTouchZero;<\/p>\n<p>return float(c)*cos(angle);<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>void prepareLists() {<\/p>\n<p>for (currentStep = 0; currentStep&lt;numberOfSteps; currentStep++) {<\/p>\n<p>for (currentHeightStep = 0; currentHeightStep&lt;numberOfHeightMeasures; currentHeightStep++) {<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/calculate angles<\/p>\n<p>float currentStepAngle = (TWO_PI\/numberOfSteps) * float(currentStep); \/\/plateau<\/p>\n<p>float currentHeightAngle = (PI\/numberOfHeightMeasures) * float(currentHeightStep); \/\/\/head<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ get coordinates<\/p>\n<p>&nbsp;<\/p>\n<p>float z = calculateZ(100, currentHeightAngle);<\/p>\n<p>float x = calculateDistanceFromCenter(100, currentHeightAngle);<\/p>\n<p>float y = 0.0;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ rotate coordinates in to the good angle, Z is constant<\/p>\n<p>&nbsp;<\/p>\n<p>float xp = sin(currentStepAngle)*x;<\/p>\n<p>float yp = cos(currentStepAngle)*x;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ put values into the memory<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][0] = xp;<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][1] = yp;<\/p>\n<p>measuresXYZ[currentStep][currentHeightStep][2] = z;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p style=\"text-align: center\"><span style=\"font-family: arial;font-size: 12px;line-height: 18px\"><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Version des codes Alpha (encore pas mal de bugs) &nbsp; import processing.serial.*; &nbsp; Serial myPort; String numScanner = \u00ab\u00a0\u00a0\u00bb; &nbsp; \/\/\/ plateau final int numberOfSteps = 40; final int maxStepArduinoPlateau = 2270; final int stepToSendPlateau = maxStepArduinoPlateau\/numberOfSteps; final int maxValueToTouchZero = 240; int currentStep = 0; &nbsp; \/\/\/ head &nbsp; final int numberOfHeightMeasures = 40; [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[75,68],"tags":[],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-fabrication","category-scanner3d"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/comments?post=720"}],"version-history":[{"count":1,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/posts\/720\/revisions"}],"predecessor-version":[{"id":721,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/posts\/720\/revisions\/721"}],"wp:attachment":[{"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/media?parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/categories?post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ensci.com\/fablab\/wp-json\/wp\/v2\/tags?post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}