Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #ifdef OUTPUT_TEAPOT
  2. // display quaternion values in InvenSense Teapot demo format:
  3. teapotPacket[2] = fifoBuffer[0];
  4. teapotPacket[3] = fifoBuffer[1];
  5. teapotPacket[4] = fifoBuffer[4];
  6. teapotPacket[5] = fifoBuffer[5];
  7. teapotPacket[6] = fifoBuffer[8];
  8. teapotPacket[7] = fifoBuffer[9];
  9. teapotPacket[8] = fifoBuffer[12];
  10. teapotPacket[9] = fifoBuffer[13];
  11. Serial.write(teapotPacket, 14); //Serial.write(buf, len)
  12. teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
  13. #endif
  14.  
  15. #ifdef OUTPUT_ACCEL_STR_RAW
  16. mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  17.  
  18. String accelGyroRaw = "STX,";
  19. accelGyroRaw += ax;
  20. accelGyroRaw += ',';
  21. accelGyroRaw += ay;
  22. accelGyroRaw += ',';
  23. accelGyroRaw += az;
  24. accelGyroRaw += ',';
  25. accelGyroRaw += gx;
  26. accelGyroRaw += ',';
  27. accelGyroRaw += gy;
  28. accelGyroRaw += ',';
  29. accelGyroRaw += gz;
  30. accelGyroRaw += ',';
  31. accelGyroRaw += "ETX";
  32.  
  33. Serial.println(accelGyroRaw);
  34.  
  35. #endif
  36.  
  37. class Program
  38. {
  39. static SerialPort port = new SerialPort("COM7", 115200);
  40. //static int serialCount = 0;
  41. //static int aligned = 0;
  42. //static char[] teapotPacket = new char[14];
  43. //static float[] q = new float[4];
  44.  
  45. static void Main(string[] args)
  46. {
  47.  
  48. Console.WriteLine("****** Serial Console Read ********");
  49. port.Open();
  50. port.DataReceived += port_DataReceived;
  51.  
  52. Console.Read();
  53. }
  54.  
  55. static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
  56. {
  57.  
  58. string s = port.ReadLine();
  59. string[] accelGyroVals = s.Split(',');
  60. string[] accl = new string[3];
  61. string[] gyro = new string[3];
  62.  
  63. if (accelGyroVals[0] == "STX" && accelGyroVals[accelGyroVals.Length - 1] == "ETXr")
  64. {
  65. accl[0] = accelGyroVals[1];
  66. accl[1] = accelGyroVals[2];
  67. accl[2] = accelGyroVals[3];
  68.  
  69. gyro[0] = accelGyroVals[4];
  70. gyro[1] = accelGyroVals[5];
  71. gyro[2] = accelGyroVals[6];
  72.  
  73. Console.WriteLine("a : " + accl[0] + " , " + accl[1] + " , " + accl[2] + "t g : " + gyro[0] + " , " + gyro[1] + " , " + gyro[2]);
  74. }
  75.  
  76. }
  77.  
  78. static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  79. {
  80. if (port.IsOpen)
  81. {
  82. port.Close();
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement