|
- import processing.serial.*;
- Serial myPort;
-
- float yaw = 0.0;
- float pitch = 0.0;
- float roll = 0.0;
-
- void setup()
- {
- size(600, 500, P3D);
-
-
-
-
-
-
-
- myPort = new Serial(this, "/dev/ttyACM0", 9600);
-
-
- textSize(16);
- textMode(SHAPE);
- }
-
- void draw()
- {
- serialEvent();
- background(255);
- lights();
-
- translate(width/2, height/2);
-
- pushMatrix();
-
- float c1 = cos(radians(roll));
- float s1 = sin(radians(roll));
- float c2 = cos(radians(-pitch));
- float s2 = sin(radians(-pitch));
- float c3 = cos(radians(yaw));
- float s3 = sin(radians(yaw));
- applyMatrix( c2*c3, s1*s3+c1*c3*s2, c3*s1*s2-c1*s3, 0,
- -s2, c1*c2, c2*s1, 0,
- c2*s3, c1*s2*s3-c3*s1, c1*c3+s1*s2*s3, 0,
- 0, 0, 0, 1);
-
- drawPropShield();
-
-
- popMatrix();
-
-
- print(roll);
- print("\t");
- print(-pitch);
- print("\t");
- print(yaw);
- println();
- }
-
- void serialEvent()
- {
- int newLine = 13;
- String message;
- do {
- message = myPort.readStringUntil(newLine);
- if (message != null) {
- String[] list = split(trim(message), " ");
- if (list.length >= 4 && list[0].equals("Orientation:")) {
- yaw = float(list[1]);
- pitch = float(list[2]);
- roll = float(list[3]);
- }
- }
- } while (message != null);
- }
-
- void drawArduino()
- {
-
- stroke(0, 90, 90);
- fill(0, 130, 130);
- box(300, 10, 200);
-
- stroke(0);
- fill(80);
-
- translate(60, -10, 90);
- box(170, 20, 10);
-
- translate(-20, 0, -180);
- box(210, 20, 10);
- }
-
- void drawPropShield()
- {
-
- stroke(0);
- fill(0, 128, 0);
- box(190, 6, 70);
-
- fill(255, 215, 0);
- noStroke();
-
-
- translate(65, 0, 30);
- for (int i=0; i<14; i++) {
- sphere(4.5);
- translate(-10, 0, 0);
- }
-
-
- translate(10, 0, -60);
- for (int i=0; i<14; i++) {
- sphere(4.5);
- translate(10, 0, 0);
- }
-
-
- translate(-10,0,10);
- for (int i=0; i<5; i++) {
- sphere(4.5);
- translate(0,0,10);
- }
-
-
- translate(25,0,-15);
- for (int i=0; i<4; i++) {
- sphere(4.5);
- translate(0,0,-10);
- }
-
-
- translate(-180,0,10);
- for (int i=0; i<4; i++) {
- sphere(4.5);
- translate(0,0,10);
- }
-
-
- stroke(128);
- fill(24);
- translate(30,-6,-25);
- box(13,6,13);
-
-
- stroke(64);
- translate(32,0,0);
- fill(192);
- box(10,6,18);
-
-
- stroke(128);
- translate(27,0,0);
- fill(24);
- box(16,6,16);
-
-
- translate(40,0,-15);
- box(20,6,20);
-
-
- translate(-5,0,25);
- box(12,6,12);
-
-
- translate(42.5,2,0);
- box(6,4,8);
- translate(0,0,-20);
- box(6,4,8);
- }
|