import processing.serial.*; int value_1 = 0; int value_2 = 1; String text_value="Angles"; Serial myPort; PFont fontA; String gg; String filename; byte start=0; int battVal=75; long serialStart=0; float[] nums=new float[42]; int[] values1; int[] values2; int[] values3; int[] values4; int[] valuesOutputX; int[] valuesErrorX; String outputString; String[] outputStringArr; void setup() { filename=sketchPath("")+"CSV/"+nf(year(),4)+nf(month(),2)+nf(day(),2)+"_" +nf(hour(),2)+"."+nf(minute(),2)+"."+nf(second(),2)+".txt"; println("Creating file: "+filename); outputString = "x,y,X,Y,Z,Error X,Error Y,Error Z,Setpoint X,Setpoint Y,Setpoint Z,SW1,Output Right,Output Left,Output Yaw,Output Servo,Kp_X,Ki_X,Kd_X,I Limit_X,Integral_X,Kp_Y,Ki_Y,Kd_Y,I Limit_Y,Integral_Y,Kp_Z,Ki_Z,Kd_Z,I Limit_Z,Integral_Z,Throttle,Period,Battery,PID ON"; outputStringArr = split(outputString,","); saveData(filename,"time "+join(outputStringArr, " "),false); println(Serial.list()); println("Hello there!"); size(1200, 750); smooth(); fontA = loadFont("Arial48.vlw"); textAlign(LEFT); textFont(fontA, 32); background(0); String portName = Serial.list()[1]; myPort = new Serial(this, portName, 38400); myPort.bufferUntil(10); values1 = new int[width]; values2 = new int[width]; values3 = new int[width]; values4 = new int[width]; println("setup end"); } void draw() { if(nums[33]>15) background(0); else if (second()%2==0) background(#FF381d); else background(0); stroke(100); fill(255); textFont(fontA, 20); text(text_value,width-80,225); text("X", width-150, 149); line(0, 150, width, 150); text("Y", width-150, 299); line(0, 300, width, 300); if ((start==1)){ nums = float(split(gg, ',')); if (nums.length < 42) { nums=expand(nums,42); } textFont(fontA, 24); text("Angles:",5,460); text("X:"+nums[0],140,460); text("Y:"+nums[1],270,460); text("Gyro Z:"+nums[4],359,460); text("Errors:",5,490); text("X:"+nums[5],140,490); text("Y:"+nums[6],270,490); text("Z:"+nums[7],418,490); text("Setpoints:",5,520); text("X:"+int(nums[8]),140,520); text("Y:"+int(nums[9]),270,520); text("Z:"+int(nums[10]),418,520); text("Sw#1:"+nums[11],540,520); text("Throtle:"+nums[31],720,520); text("Ouputs:",5,550); text("R:"+int(nums[12]),140,550); text("L:"+int(nums[13]),270,550); text("Y:"+int(nums[14]),418,550); text("Serv:"+int(nums[15]),540,550); noFill(); strokeWeight(3); rect(450,740,740,-140); rect(450,740,740,-105); rect(450,740,740,-70); rect(450,740,740,-35); rect(450,740,620,-140); rect(450,740,490,-140); rect(450,740,375,-140); rect(450,740,250,-140); rect(450,740,130,-140); strokeWeight(1); text("PID",470,625); text("Kp",590,625); text("Ki",710,625); text("Kd",835,625); text("I limit",950,625); text("Integral",1080,625); text("X angle",470,660); text(nums[16],590,660); text(nums[17],710,660); text(nums[18]/10,835,660); text(nums[19],950,660); text(nums[20],1080,660); text("Y angle",470,695); text(nums[21],590,695); text(nums[22],710,695); text(nums[23]/10,835,695); text(nums[24],950,695); text(nums[25],1080,695); text("Z gyro",470,730); text(nums[26],590,730); text(nums[27],710,730); text(nums[28]/10,835,730); text(nums[29],950,730); text(nums[30],1080,730); // Throtle nums[31] text("Period:"+nums[32],5,650); text("Battery:"+ map(round( nums[33] * 100.0f ) / 100.0f, 0, 100, 8.9, 12.4),5,720); text("PID ON:"+nums[34],5,680); for (int i=0; i-181;angle+=-18) line(130*cos(angle*PI/180),130*sin(angle*PI/180),120*cos(angle*PI/180), 120*sin(angle*PI/180)); stroke(#FF381d); strokeWeight(3); line(126*cos(-153*PI/180),126*sin(-153*PI/180),110*cos(- 153*PI/180),110*sin(-153*PI/180)); stroke(255); strokeWeight(1); fill(255); text ("50%", -18, -100); text ("BATTERY", -30, -40); text ("0%", -110, 5); text ("100%", 70, 5); battVal=int(map(nums[33]+50,0,100,0,180)); rotate(radians(battVal)); stroke(#0030FF); fill(#0030FF); triangle(10, 0,-10, 0, 0, 110); triangle(10, 0,-10, 0, 0, -10); fill(0); ellipse (0,0,3,3); fill(255); popMatrix(); } void logo() { noFill(); translate(width-75, 20); fill(#c5681d); roundedRect(140, 30, 3 ); translate(75-width, -20); fill(#eeeeee); textFont(fontA, 18); text("Super_tricopter", width-136, 27); noFill(); translate(115, 20); fill(#c5681d); roundedRect(215, 30, 3 ); translate(-115, -20); fill(#eeeeee); textFont(fontA, 18); text(nf(year(),4)+"/"+nf(month(),2)+"/"+nf(day(),2)+" "+nf(hour(),2)+":"+nf(minute(),2)+":"+nf(second(),2), 20, 27); } void roundedRect(float w, float h, float r) { beginShape(); vertex( w/2 - r, -h/2 ); bezierVertex( w/2 - r , -h/2, w/2, -h/2, w/2 , -h/2 + r); vertex( w/2 , h/2 - r ); bezierVertex( w/2, h/2 , w/2 - r , h/2 , w/2 - r, h/2); vertex( -w/2 + r, h/2 ); bezierVertex( - w/2, h/2, -w/2, h/2 - r, -w/2 , h/2 - r ); vertex( -w/2 , -h/2 + r ); bezierVertex( -w/2, -h/2, -w/2 + r, -h/2, -w/2 + r, -h/2 ); endShape(CLOSE); } void saveData(String fileName, String newData, boolean appendData){ BufferedWriter bw = null; try { FileWriter fw = new FileWriter(fileName, appendData); bw = new BufferedWriter(fw); bw.write(newData + System.getProperty("line.separator")); } catch (IOException e) { } finally { if (bw != null){ try { bw.close(); } catch (IOException e) {} } } }