PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

OrientationVisualiser.pde 4.1KB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import processing.serial.*;
  2. Serial myPort;
  3. float yaw = 0.0;
  4. float pitch = 0.0;
  5. float roll = 0.0;
  6. void setup()
  7. {
  8. size(600, 500, P3D);
  9. // if you have only ONE serial port active
  10. //myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active
  11. // if you know the serial port name
  12. //myPort = new Serial(this, "COM5:", 9600); // Windows "COM#:"
  13. //myPort = new Serial(this, "\\\\.\\COM41", 9600); // Windows, COM10 or higher
  14. myPort = new Serial(this, "/dev/ttyACM0", 9600); // Linux "/dev/ttyACM#"
  15. //myPort = new Serial(this, "/dev/cu.usbmodem1217321", 9600); // Mac "/dev/cu.usbmodem######"
  16. textSize(16); // set text size
  17. textMode(SHAPE); // set text mode to shape
  18. }
  19. void draw()
  20. {
  21. serialEvent(); // read and parse incoming serial message
  22. background(255); // set background to white
  23. lights();
  24. translate(width/2, height/2); // set position to centre
  25. pushMatrix(); // begin object
  26. float c1 = cos(radians(roll));
  27. float s1 = sin(radians(roll));
  28. float c2 = cos(radians(-pitch));
  29. float s2 = sin(radians(-pitch));
  30. float c3 = cos(radians(yaw));
  31. float s3 = sin(radians(yaw));
  32. applyMatrix( c2*c3, s1*s3+c1*c3*s2, c3*s1*s2-c1*s3, 0,
  33. -s2, c1*c2, c2*s1, 0,
  34. c2*s3, c1*s2*s3-c3*s1, c1*c3+s1*s2*s3, 0,
  35. 0, 0, 0, 1);
  36. drawPropShield();
  37. //drawArduino();
  38. popMatrix(); // end of object
  39. // Print values to console
  40. print(roll);
  41. print("\t");
  42. print(-pitch);
  43. print("\t");
  44. print(yaw);
  45. println();
  46. }
  47. void serialEvent()
  48. {
  49. int newLine = 13; // new line character in ASCII
  50. String message;
  51. do {
  52. message = myPort.readStringUntil(newLine); // read from port until new line
  53. if (message != null) {
  54. String[] list = split(trim(message), " ");
  55. if (list.length >= 4 && list[0].equals("Orientation:")) {
  56. yaw = float(list[1]); // convert to float yaw
  57. pitch = float(list[2]); // convert to float pitch
  58. roll = float(list[3]); // convert to float roll
  59. }
  60. }
  61. } while (message != null);
  62. }
  63. void drawArduino()
  64. {
  65. /* function contains shape(s) that are rotated with the IMU */
  66. stroke(0, 90, 90); // set outline colour to darker teal
  67. fill(0, 130, 130); // set fill colour to lighter teal
  68. box(300, 10, 200); // draw Arduino board base shape
  69. stroke(0); // set outline colour to black
  70. fill(80); // set fill colour to dark grey
  71. translate(60, -10, 90); // set position to edge of Arduino box
  72. box(170, 20, 10); // draw pin header as box
  73. translate(-20, 0, -180); // set position to other edge of Arduino box
  74. box(210, 20, 10); // draw other pin header as box
  75. }
  76. void drawPropShield()
  77. {
  78. // 3D art by Benjamin Rheinland
  79. stroke(0); // black outline
  80. fill(0, 128, 0); // fill color PCB green
  81. box(190, 6, 70); // PCB base shape
  82. fill(255, 215, 0); // gold color
  83. noStroke();
  84. //draw 14 contacts on Y- side
  85. translate(65, 0, 30);
  86. for (int i=0; i<14; i++) {
  87. sphere(4.5); // draw gold contacts
  88. translate(-10, 0, 0); // set new position
  89. }
  90. //draw 14 contacts on Y+ side
  91. translate(10, 0, -60);
  92. for (int i=0; i<14; i++) {
  93. sphere(4.5); // draw gold contacts
  94. translate(10, 0, 0); // set position
  95. }
  96. //draw 5 contacts on X+ side (DAC, 3v3, gnd)
  97. translate(-10,0,10);
  98. for (int i=0; i<5; i++) {
  99. sphere(4.5);
  100. translate(0,0,10);
  101. }
  102. //draw 4 contacts on X+ side (G C D 5)
  103. translate(25,0,-15);
  104. for (int i=0; i<4; i++) {
  105. sphere(4.5);
  106. translate(0,0,-10);
  107. }
  108. //draw 4 contacts on X- side (5V - + GND)
  109. translate(-180,0,10);
  110. for (int i=0; i<4; i++) {
  111. sphere(4.5);
  112. translate(0,0,10);
  113. }
  114. //draw audio amp IC
  115. stroke(128);
  116. fill(24); //Epoxy color
  117. translate(30,-6,-25);
  118. box(13,6,13);
  119. //draw pressure sensor IC
  120. stroke(64);
  121. translate(32,0,0);
  122. fill(192);
  123. box(10,6,18);
  124. //draw gyroscope IC
  125. stroke(128);
  126. translate(27,0,0);
  127. fill(24);
  128. box(16,6,16);
  129. //draw flash memory IC
  130. translate(40,0,-15);
  131. box(20,6,20);
  132. //draw accelerometer/magnetometer IC
  133. translate(-5,0,25);
  134. box(12,6,12);
  135. //draw 5V level shifter ICs
  136. translate(42.5,2,0);
  137. box(6,4,8);
  138. translate(0,0,-20);
  139. box(6,4,8);
  140. }