{"action":"created","issue":{"url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/26","labels_url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/26/comments","events_url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/26/events","html_url":"https://github.com/michaelcheng1991/Golf-Training-Aid-/issues/26","id":115693832,"number":26,"title":"your code","user":{"login":"michaelcheng1991","id":7731020,"avatar_url":"https://avatars.githubusercontent.com/u/7731020?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelcheng1991","html_url":"https://github.com/michaelcheng1991","followers_url":"https://api.github.com/users/michaelcheng1991/followers","following_url":"https://api.github.com/users/michaelcheng1991/following{/other_user}","gists_url":"https://api.github.com/users/michaelcheng1991/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelcheng1991/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelcheng1991/subscriptions","organizations_url":"https://api.github.com/users/michaelcheng1991/orgs","repos_url":"https://api.github.com/users/michaelcheng1991/repos","events_url":"https://api.github.com/users/michaelcheng1991/events{/privacy}","received_events_url":"https://api.github.com/users/michaelcheng1991/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-07T21:40:12Z","updated_at":"2015-11-07T21:41:31Z","closed_at":null,"body":"//this is the arduino 3 IMU output code\r\n\r\n#include <SPI.h> //add arduino SPI library;\r\n//list of all register's binary addresses;\r\n\r\nbyte ACT_THS              = 0B00000100;\r\nbyte ACT_DUR              = 0B00000101;\r\nbyte INT_GEN_CFG_XL       = 0B00000110;\r\nbyte INT_GEN_THS_X_XL     = 0B00000111;\r\nbyte INT_GEN_THS_Y_XL     = 0B00001000;\r\nbyte INT_GEN_THS_Z_XL     = 0B00001001;\r\nbyte INT_GEN_DUR_XL       = 0B00001010;\r\nbyte REFERENCE_G          = 0B00001011;\r\nbyte INT1_CTRL            = 0B00001100;\r\nbyte INT2_CTRL            = 0B00001101;\r\n\r\nbyte WHO_AM_I             = 0B00001111;\r\nbyte CTRL_REG1_G          = 0B00010000;\r\nbyte CTRL_REG2_G          = 0B00010001;\r\nbyte CTRL_REG3_G          = 0B00010010;\r\nbyte ORIENT_CFG_G         = 0B00010011;\r\nbyte INT_GEN_SRC_G        = 0B00010100;\r\nbyte OUT_TEMP_L           = 0B00010101;\r\nbyte OUT_TEMP_H           = 0B00010110;\r\nbyte STATUS_REG0          = 0B00010111;\r\nbyte OUT_X_L_G            = 0B00011000;\r\nbyte OUT_X_H_G            = 0B00011001;\r\nbyte OUT_Y_L_G            = 0B00011010;\r\nbyte OUT_Y_H_G            = 0B00011011;\r\nbyte OUT_Z_L_G            = 0B00011100;\r\nbyte OUT_Z_H_G            = 0B00011101;\r\nbyte CTRL_REG4            = 0B00011110;\r\nbyte CTRL_REG5_XL         = 0B00011111;\r\nbyte CTRL_REG6_XL         = 0B00100000;\r\nbyte CTRL_REG7_XL         = 0B00100001;\r\nbyte CTRL_REG8            = 0B00100010;\r\nbyte CTRL_REG9            = 0B00100011;\r\nbyte CTRL_REG10           = 0B00100100;\r\n\r\nbyte INT_GEN_SRC_XL       = 0B00100110;\r\nbyte STATUS_REG           = 0B00100111;\r\nbyte OUT_X_L_XL           = 0B00101000;\r\nbyte OUT_X_H_XL           = 0B00101001;\r\nbyte OUT_Y_L_XL           = 0B00101010;\r\nbyte OUT_Y_H_XL           = 0B00101011;\r\nbyte OUT_Z_L_XL           = 0B00101100;\r\nbyte OUT_Z_H_XL           = 0B00101101;\r\nbyte FIFO_CTRL            = 0B00101110;\r\nbyte FIFO_SRC             = 0B00101111;\r\nbyte INT_GEN_CFG_G        = 0B00110000;\r\nbyte INT_GEN_THS_XH_G     = 0B00110001;\r\nbyte INT_GEN_THS_XL_G     = 0B00110010;\r\nbyte INT_GEN_THS_YH_G     = 0B00110011;\r\nbyte INT_GEN_THS_YL_G     = 0B00110100;\r\nbyte INT_GEN_THS_ZH_G     = 0B00110101;\r\nbyte INT_GEN_THS_ZL_G     = 0B00110110;\r\nbyte INT_GEN_DUR_G        = 0B00110111;\r\n\r\n\r\nbyte OFFSET_X_REG_L_M     = 0B00000101;\r\nbyte OFFSET_X_REG_H_M     = 0B00000110;\r\nbyte OFFSET_Y_REG_L_M     = 0B00000111;\r\nbyte OFFSET_Y_REG_H_M     = 0B00001000;\r\nbyte OFFSET_Z_REG_L_M     = 0B00001001;\r\nbyte OFFSET_Z_REG_H_M     = 0B00001010;\r\n\r\n//byte WHO_AM_I_M           = 0B00001111;\r\n\r\nbyte CTRL_REG1_M          = 0B00100000;\r\nbyte CTRL_REG2_M          = 0B00100001;\r\nbyte CTRL_REG3_M          = 0B00100010;\r\nbyte CTRL_REG4_M          = 0B00100011;\r\nbyte CTRL_REG5_M          = 0B00100100;\r\n\r\nbyte STATUS_REG_M         = 0B00100111;\r\nbyte OUT_X_L_M            = 0B00101000;\r\nbyte OUT_X_H_M            = 0B00101001;\r\nbyte OUT_Y_L_M            = 0B00101010;\r\nbyte OUT_Y_H_M            = 0B00101011;\r\nbyte OUT_Z_L_M            = 0B00101100;\r\nbyte OUT_Z_H_M            = 0B00101101;\r\n\r\nbyte INT_CFG_M            = 0B00110000;\r\nbyte INT_SRC_M            = 0B00110001;\r\nbyte INT_THS_L_M          = 0B00110010;\r\nbyte INT_THS_H_M          = 0B00110011;\r\nbyte Read  = 0B10000000;\r\nbyte Write = 0B00000000;\r\n\r\n\r\n\r\n//chip select pin on arduino;\r\n const int CS_AG = 7;\r\n const int CS_M =  8;\r\n const int CS_AG_1 = 9; \r\n const int CS_M_1 = 10; \r\n const int CS_AG_2 = 11; \r\n const int CS_M_2 = 12; \r\n \r\n\r\n\r\nvoid setup() {  \r\n  Serial.begin(115200);\r\n  //start the SPI library;\r\n  SPI.begin();\r\n  SPI.setClockDivider(1);    //starts with 16MHz \r\n  //https://www.arduino.cc/en/Reference/SPISettings\r\n  \r\n  \r\n  //initalize the chip select pins;\r\n  pinMode(CS_AG, OUTPUT);\r\n  pinMode(CS_M, OUTPUT);\r\n  pinMode(CS_AG_1,OUTPUT);\r\n  pinMode(CS_M_1,OUTPUT); \r\n  pinMode(CS_AG_2,OUTPUT);\r\n  pinMode(CS_M_2,OUTPUT); \r\n  \r\n  \r\n  digitalWrite(CS_AG, HIGH);\r\n  digitalWrite(CS_M,HIGH);\r\n  digitalWrite(CS_AG_1,HIGH);\r\n  digitalWrite(CS_M_1,HIGH);\r\n  digitalWrite(CS_AG_2,HIGH);\r\n  digitalWrite(CS_M_2,HIGH);\r\n\r\n  \r\n\r\n  //Make sure you know odr is changed\r\n  WriteRegister_AG(CTRL_REG4,0B00111000);  //enable gyro axis\r\n  WriteRegister_AG(CTRL_REG5_XL,0B00111000); //enable accelerometer\r\n  WriteRegister_AG(CTRL_REG1_G,0B01000000); //gyro/accel odr and bw gonna change 001 to 010\r\n  WriteRegister_M(CTRL_REG3_M,0B00000000); //enable mag continuous\r\n\r\n  WriteRegister_AG_1(CTRL_REG4,0B00111000);  //enable gyro axis\r\n  WriteRegister_AG_1(CTRL_REG5_XL,0B00111000); //enable accelerometer\r\n  WriteRegister_AG_1(CTRL_REG1_G,0B01000000); //gyro/accel odr and bw gonna change 001 to 010\r\n  WriteRegister_M_1(CTRL_REG3_M,0B00000000); //enable mag continuous\r\n\r\n  WriteRegister_AG_2(CTRL_REG4,0B00111000);  //enable gyro axis\r\n  WriteRegister_AG_2(CTRL_REG5_XL,0B00111000); //enable accelerometer\r\n  WriteRegister_AG_2(CTRL_REG1_G,0B00100000); //gyro/accel odr and bw\r\n  WriteRegister_M_2(CTRL_REG3_M,0B00000000); //enable mag continuous\r\n\r\n  delay(200);\r\n\r\n}\r\n\r\n  \r\nvoid loop() {\r\n  //this is to show how long a loop takes \r\n  unsigned long millisStart = millis();\r\n\r\n  \r\n  //alloff();  //NOTE: ALL OFF IS COMMENTED OUT\r\n\r\n  //This section is for IMU 1 CS: 9,10 \r\n  //byte WHOAMI = ReadRegister_AG(WHO_AM_I);\r\n  \r\n  //this section is for IMU 2 CS : 7,8\r\n  //byte WHOAMI_1 = ReadRegister_AG_1(WHO_AM_I);\r\n  \r\n  //this section is for IMU 3 CS : 11,12\r\n  //byte WHOAMI_2 = ReadRegister_AG_2(WHO_AM_I);\r\n  \r\n  //gyro \r\n  byte X_L = ReadRegister_AG(OUT_X_L_G);\r\n  byte X_H = ReadRegister_AG(OUT_X_H_G);\r\n  byte Y_L = ReadRegister_AG(OUT_Y_L_G);\r\n  byte Y_H = ReadRegister_AG(OUT_Y_H_G);\r\n  byte Z_L = ReadRegister_AG(OUT_Z_L_G);\r\n  byte Z_H = ReadRegister_AG(OUT_Z_H_G);\r\n  \r\n  int X_AXIs = X_H <<8 | X_L;\r\n  int Y_AXIs = Y_H <<8 | Y_L;\r\n  int Z_AXIs = Z_H <<8 | Z_L;\r\n  \r\n  //accelerameter \r\n  byte X_L_A = ReadRegister_AG(OUT_X_L_XL);\r\n  byte X_H_A = ReadRegister_AG(OUT_X_H_XL);\r\n  byte Y_L_A = ReadRegister_AG(OUT_Y_L_XL);\r\n  byte Y_H_A = ReadRegister_AG(OUT_Y_H_XL);\r\n  byte Z_L_A = ReadRegister_AG(OUT_Z_L_XL);\r\n  byte Z_H_A = ReadRegister_AG(OUT_Z_H_XL);\r\n  \r\n  int X_AXIS_A = X_H_A <<8 | X_L_A;\r\n  int Y_AXIS_A = Y_H_A <<8 | Y_L_A;\r\n  int Z_AXIS_A = Z_H_A <<8 | Z_L_A;\r\n  \r\n  //.000061+.022 may need recalibration\r\n  float x = X_AXIS_A*0.000061+.022;\r\n  float y = Y_AXIS_A*0.000061+.0017;\r\n  float z = Z_AXIS_A*0.000061-.022;\r\n  float pitch = atan(x/sqrt((y*y)+(z*z)))*(180/PI);\r\n  float roll = atan(y/sqrt((x*x)+(z*z)))*(180/PI);\r\n  float yaw = atan(z/sqrt((x*x)+(y*y)))*(180/PI);\r\n  \r\n  //magnetometer\r\n  byte X_L_M = ReadRegister_M(OUT_X_L_M);\r\n  byte X_H_M = ReadRegister_M(OUT_X_H_M);\r\n  byte Y_L_M = ReadRegister_M(OUT_Y_L_M);\r\n  byte Y_H_M = ReadRegister_M(OUT_Y_H_M);\r\n  byte Z_L_M = ReadRegister_M(OUT_Z_L_M);\r\n  byte Z_H_M = ReadRegister_M(OUT_Z_H_M);\r\n  \r\n  int X_AXIS_M = X_H_M <<8 | X_L_M;\r\n  int Y_AXIS_M = Y_H_M <<8 | Y_L_M;\r\n  int Z_AXIS_M = Z_H_M <<8 | Z_L_M;\r\n  \r\n  \r\n  \r\n  //Serial.println(\"Port 1\");\r\n  \r\n  //Serial.print(\"X-Axis: \");  //.00875 is from the datasheet and my settings when i writeregister\r\n  Serial.print(0.00875*(X_AXIs+110), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Y-Axis: \");                   \r\n  Serial.print(0.00875*(Y_AXIs+190), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Z-Axis: \");                   \r\n  Serial.print(0.00875*(Z_AXIs+115), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  \r\n  //Serial.print(\"X-Axis_A: \");\r\n  Serial.print(X_AXIS_A*0.000061, DEC); // .000061 comes from the datasheet and my settings for the accelerometer.\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Y-Axis_A: \");             // output will be in g's.\r\n  Serial.print(Y_AXIS_A*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Z-Axis_A: \");\r\n  Serial.print(Z_AXIS_A*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\"); \r\n \r\n  //Serial.print(\"X-Axis_M: \");\r\n  Serial.print(X_AXIS_M*0.00014, DEC); // 0.00014 comes from the datasheet and my settings for the magnetometer\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Y-Axis_M: \");            // output will be in gauss\r\n  Serial.print(Y_AXIS_M*0.00014, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Z-Axis_M: \");\r\n  Serial.print(Z_AXIS_M*0.00014, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  \r\n  \r\n  \r\n  /*\r\n  Serial.println(\"IMU1\");\r\n  Serial.print(\"roll:\"); Serial.println(roll); \r\n  Serial.print(\"pitch:\"); Serial.println(pitch);\r\n  Serial.print(\"yaw:\"); Serial.println(yaw);\r\n  */\r\n  \r\n  \r\n  //IMU2\r\n  //gyro \r\n  byte X_L_1 = ReadRegister_AG_1(OUT_X_L_G);\r\n  byte X_H_1 = ReadRegister_AG_1(OUT_X_H_G);\r\n  byte Y_L_1 = ReadRegister_AG_1(OUT_Y_L_G);\r\n  byte Y_H_1 = ReadRegister_AG_1(OUT_Y_H_G);\r\n  byte Z_L_1 = ReadRegister_AG_1(OUT_Z_L_G);\r\n  byte Z_H_1 = ReadRegister_AG_1(OUT_Z_H_G);\r\n  \r\n  int X_AXIs_1 = X_H_1 <<8 | X_L_1;\r\n  int Y_AXIs_1 = Y_H_1 <<8 | Y_L_1;\r\n  int Z_AXIs_1 = Z_H_1 <<8 | Z_L_1;\r\n  \r\n  //acelerometer\r\n  byte X_L_A_1 = ReadRegister_AG_1(OUT_X_L_XL);\r\n  byte X_H_A_1 = ReadRegister_AG_1(OUT_X_H_XL);\r\n  byte Y_L_A_1 = ReadRegister_AG_1(OUT_Y_L_XL);\r\n  byte Y_H_A_1 = ReadRegister_AG_1(OUT_Y_H_XL);\r\n  byte Z_L_A_1 = ReadRegister_AG_1(OUT_Z_L_XL);\r\n  byte Z_H_A_1 = ReadRegister_AG_1(OUT_Z_H_XL);\r\n  \r\n  \r\n  int X_AXIS_A_1 = X_H_A_1 <<8 | X_L_A_1;\r\n  int Y_AXIS_A_1 = Y_H_A_1 <<8 | Y_L_A_1;\r\n  int Z_AXIS_A_1 = Z_H_A_1 <<8 | Z_L_A_1;\r\n  \r\n  //.000061+.022 may need recalibration\r\n  float x_1 = X_AXIS_A_1*0.000061+.022;\r\n  float y_1 = Y_AXIS_A_1*0.000061+.0017;\r\n  float z_1 = Z_AXIS_A_1*0.000061-.022;\r\n  float pitch_1 = atan(x_1/sqrt((y_1*y_1)+(z_1*z_1)))*(180/PI);\r\n  float roll_1 = atan(y_1/sqrt((x_1*x_1)+(z_1*z_1)))*(180/PI);\r\n  float yaw_1 = atan(z_1/sqrt((x_1*x_1)+(y_1*y_1)))*(180/PI);\r\n  \r\n  //magnetometer\r\n  byte X_L_M_1 = ReadRegister_M_1(OUT_X_L_M);\r\n  byte X_H_M_1 = ReadRegister_M_1(OUT_X_H_M);\r\n  byte Y_L_M_1 = ReadRegister_M_1(OUT_Y_L_M);\r\n  byte Y_H_M_1 = ReadRegister_M_1(OUT_Y_H_M);\r\n  byte Z_L_M_1 = ReadRegister_M_1(OUT_Z_L_M);\r\n  byte Z_H_M_1 = ReadRegister_M_1(OUT_Z_H_M);\r\n  \r\n  int X_AXIS_M_1 = X_H_M_1 <<8 | X_L_M_1;\r\n  int Y_AXIS_M_1 = Y_H_M_1 <<8 | Y_L_M_1;\r\n  int Z_AXIS_M_1 = Z_H_M_1 <<8 | Z_L_M_1;\r\n  \r\n  \r\n  //Serial.println(\"Port 2\");\r\n  //Serial.print(\"X-Axis: \");  //.00875 is from the datasheet and my settings when i writeregister\r\n  Serial.print(0.00875*(X_AXIs_1+110), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Y-Axis: \");                   \r\n  Serial.print(0.00875*(Y_AXIs_1+190), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Z-Axis: \");                   \r\n  Serial.print(0.00875*(Z_AXIs_1+115), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  \r\n  \r\n  //Serial.print(\"X-Axis_A: \");\r\n  Serial.print(X_AXIS_A_1*0.000061, DEC); // .000061 comes from the datasheet and my settings for the accelerometer.\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Y-Axis_A: \");             // output will be in g's.\r\n  Serial.print(Y_AXIS_A_1*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Z-Axis_A: \");\r\n  Serial.print(Z_AXIS_A_1*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  \r\n  //Serial.print(\"X-Axis_M: \");\r\n  Serial.print(X_AXIS_M_1*0.00014, DEC); // 0.00014 comes from the datasheet and my settings for the magnetometer\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Y-Axis_M: \");            // output will be in gauss\r\n  Serial.print(Y_AXIS_M_1*0.00014, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Z-Axis_M: \");\r\n  Serial.print(Z_AXIS_M_1*0.00014, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  \r\n  /*\r\n  Serial.println(\"IMU2\");\r\n  Serial.print(\"roll:\");  Serial.println(roll_1); \r\n  Serial.print(\"pitch:\"); Serial.println(pitch_1);\r\n  Serial.print(\"yaw:\");   Serial.println(yaw_1);\r\n  */\r\n  \r\n  //IMU 3\r\n  //gyro \r\n  byte X_L_2 = ReadRegister_AG_2(OUT_X_L_G);\r\n  byte X_H_2 = ReadRegister_AG_2(OUT_X_H_G);\r\n  byte Y_L_2 = ReadRegister_AG_2(OUT_Y_L_G);\r\n  byte Y_H_2 = ReadRegister_AG_2(OUT_Y_H_G);\r\n  byte Z_L_2 = ReadRegister_AG_2(OUT_Z_L_G);\r\n  byte Z_H_2 = ReadRegister_AG_2(OUT_Z_H_G);\r\n  \r\n  int X_AXIs_2 = X_H_2 <<8 | X_L_2;\r\n  int Y_AXIs_2 = Y_H_2 <<8 | Y_L_2;\r\n  int Z_AXIs_2 = Z_H_2 <<8 | Z_L_2;\r\n  \r\n  //accelerameter \r\n  byte X_L_A_2 = ReadRegister_AG_2(OUT_X_L_XL);\r\n  byte X_H_A_2 = ReadRegister_AG_2(OUT_X_H_XL);\r\n  byte Y_L_A_2 = ReadRegister_AG_2(OUT_Y_L_XL);\r\n  byte Y_H_A_2 = ReadRegister_AG_2(OUT_Y_H_XL);\r\n  byte Z_L_A_2 = ReadRegister_AG_2(OUT_Z_L_XL);\r\n  byte Z_H_A_2 = ReadRegister_AG_2(OUT_Z_H_XL);\r\n  \r\n  int X_AXIS_A_2 = X_H_A_2 <<8 | X_L_A_2;\r\n  int Y_AXIS_A_2 = Y_H_A_2 <<8 | Y_L_A_2;\r\n  int Z_AXIS_A_2 = Z_H_A_2 <<8 | Z_L_A_2;\r\n  \r\n  //.000061+.022 may need recalibration\r\n  float x_2 = X_AXIS_A_2*0.000061+.022;\r\n  float y_2 = Y_AXIS_A_2*0.000061+.0017;\r\n  float z_2 = Z_AXIS_A_2*0.000061-.022;\r\n  float pitch_2 = atan(x_2/sqrt((y_2*y_2)+(z_2*z_2)))*(180/PI);\r\n  float roll_2 = atan(y_2/sqrt((x_2*x_2)+(z_2*z_2)))*(180/PI);\r\n  float yaw_2 = atan(z_2/sqrt((x_2*x_2)+(y_2*y_2)))*(180/PI);\r\n  \r\n  //magnetometer\r\n  byte X_L_M_2 = ReadRegister_M_2(OUT_X_L_M);\r\n  byte X_H_M_2 = ReadRegister_M_2(OUT_X_H_M);\r\n  byte Y_L_M_2 = ReadRegister_M_2(OUT_Y_L_M);\r\n  byte Y_H_M_2 = ReadRegister_M_2(OUT_Y_H_M);\r\n  byte Z_L_M_2 = ReadRegister_M_2(OUT_Z_L_M);\r\n  byte Z_H_M_2 = ReadRegister_M_2(OUT_Z_H_M);\r\n  \r\n  int X_AXIS_M_2 = X_H_M_2 <<8 | X_L_M_2;\r\n  int Y_AXIS_M_2 = Y_H_M_2 <<8 | Y_L_M_2;\r\n  int Z_AXIS_M_2 = Z_H_M_2 <<8 | Z_L_M_2;\r\n  \r\n  \r\n  \r\n  //Serial.println(\"Port 3\");\r\n  //Serial.print(\"X-Axis: \");  //.00875 is from the datasheet and my settings when i writeregister\r\n  Serial.print(0.00875*(X_AXIs_2+110), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Y-Axis: \");                   \r\n  Serial.print(0.00875*(Y_AXIs_2+190), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  //Serial.print(\"Z-Axis: \");                   \r\n  Serial.print(0.00875*(Z_AXIs_2+115), DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" dps\");\r\n  \r\n  \r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"X-Axis_A: \");\r\n  Serial.print(X_AXIS_A_2*0.000061, DEC); // .000061 comes from the datasheet and my settings for the accelerometer.\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Y-Axis_A: \");             // output will be in g's.\r\n  Serial.print(Y_AXIS_A_2*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" G\");\r\n  //Serial.print(\"Z-Axis_A: \");\r\n  Serial.print(Z_AXIS_A_2*0.000061, DEC);\r\n  Serial.print(\"\\t\");\r\n  \r\n  //Serial.print(\"X-Axis_M: \");\r\n  Serial.print(X_AXIS_M_2*0.00014, DEC); // 0.00014 comes from the datasheet and my settings for the magnetometer\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Y-Axis_M: \");            // output will be in gauss\r\n  Serial.print(Y_AXIS_M_2*0.00014, DEC);\r\n  Serial.print(\"\\t\");\r\n  //Serial.println(\" Gauss\");\r\n  //Serial.print(\"Z-Axis_M: \");\r\n  Serial.print(Z_AXIS_M_2*0.00014, DEC);\r\n  Serial.println();\r\n  //Serial.println(\" Gauss\");\r\n  \r\n  \r\n  \r\n  /*\r\n  Serial.println(\"IMU3\");\r\n  Serial.print(\"roll:\"); Serial.println(roll_2); \r\n  Serial.print(\"pitch:\"); Serial.println(pitch_2);\r\n  Serial.print(\"yaw:\"); Serial.println(yaw_2);\r\n  */\r\n  \r\n\r\n  \r\n  //delay(50);\r\n}\r\n\r\n\r\nvoid alloff()\r\n{\r\n  WriteRegister_AG(CS_AG,255);\r\n  WriteRegister_M(CS_M,255);\r\n  WriteRegister_AG_1(CS_AG_1,255);\r\n  WriteRegister_M_1(CS_M_1,255);\r\n}\r\n\r\nbyte ReadRegister_M(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_M, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  digitalWrite(CS_M, HIGH);\r\n  return(result);  \r\n}\r\n\r\nbyte ReadRegister_AG(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_AG, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  //Serial.print(Address, BIN);\r\n  //Serial.print(\" : \");\r\n  //Serial.println(result, BIN); \r\n  digitalWrite(CS_AG, HIGH);\r\n  return(result);  \r\n}\r\n\r\nvoid WriteRegister_M(byte Address, byte Value){\r\n  digitalWrite(CS_M, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_M, HIGH);  \r\n}\r\n\r\n\r\nvoid WriteRegister_AG(byte Address, byte Value){\r\n  digitalWrite(CS_AG, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_AG, HIGH);  \r\n}\r\n\r\nbyte ReadRegister_M_1(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_M_1, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  digitalWrite(CS_M_1, HIGH);\r\n  return(result);  \r\n}\r\n\r\n\r\nbyte ReadRegister_AG_1(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_AG_1, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  //Serial.print(Address, BIN);\r\n  //Serial.print(\" : \");\r\n  //Serial.println(result, BIN); \r\n  digitalWrite(CS_AG_1, HIGH);\r\n  return(result);  \r\n}\r\n\r\n\r\nvoid WriteRegister_M_1(byte Address, byte Value){\r\n  digitalWrite(CS_M_1, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_M_1, HIGH);  \r\n}\r\n\r\nvoid WriteRegister_AG_1(byte Address, byte Value){\r\n  digitalWrite(CS_AG_1, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_AG_1, HIGH);  \r\n}\r\n\r\nbyte ReadRegister_M_2(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_M_2, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  digitalWrite(CS_M_2, HIGH);\r\n  return(result);  \r\n}\r\n\r\nbyte ReadRegister_AG_2(byte Address){\r\n  byte result = 0;\r\n  digitalWrite(CS_AG_2, LOW); \r\n  SPI.transfer(Read | Address);\r\n  result = SPI.transfer(0x00);\r\n  //Serial.print(Address, BIN);\r\n  //Serial.print(\" : \");\r\n  //Serial.println(result, BIN); \r\n  digitalWrite(CS_AG_2, HIGH);\r\n  return(result);  \r\n}\r\n\r\nvoid WriteRegister_M_2(byte Address, byte Value){\r\n  digitalWrite(CS_M_2, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_M_2, HIGH);  \r\n}\r\n\r\n\r\nvoid WriteRegister_AG_2(byte Address, byte Value){\r\n  digitalWrite(CS_AG_2, LOW); \r\n  SPI.transfer(Write | Address);\r\n  SPI.transfer(Value);\r\n  digitalWrite(CS_AG_2, HIGH);  \r\n}"},"comment":{"url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/comments/154753886","html_url":"https://github.com/michaelcheng1991/Golf-Training-Aid-/issues/26#issuecomment-154753886","issue_url":"https://api.github.com/repos/michaelcheng1991/Golf-Training-Aid-/issues/26","id":154753886,"user":{"login":"michaelcheng1991","id":7731020,"avatar_url":"https://avatars.githubusercontent.com/u/7731020?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelcheng1991","html_url":"https://github.com/michaelcheng1991","followers_url":"https://api.github.com/users/michaelcheng1991/followers","following_url":"https://api.github.com/users/michaelcheng1991/following{/other_user}","gists_url":"https://api.github.com/users/michaelcheng1991/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelcheng1991/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelcheng1991/subscriptions","organizations_url":"https://api.github.com/users/michaelcheng1991/orgs","repos_url":"https://api.github.com/users/michaelcheng1991/repos","events_url":"https://api.github.com/users/michaelcheng1991/events{/privacy}","received_events_url":"https://api.github.com/users/michaelcheng1991/received_events","type":"User","site_admin":false},"created_at":"2015-11-07T21:41:31Z","updated_at":"2015-11-07T21:41:31Z","body":"%MatLab KVest result code \r\n\r\n%%this script attempt to integrate Gait tracking and arduino data \r\n\r\n%1. inport Data from IMU (5000 sets of data)\r\n%2. use script.m \r\n\r\n\r\naddpath('Quaternions');\r\naddpath('ximu_matlab_library');\r\n\r\ndelete (instrfindall);\r\ns = serial ('/dev/tty.usbmodem1411');\r\nset(s,'BaudRate', 115200);\r\nfopen(s);\r\ns.ReadAsyncMode='continuous';\r\n\r\ns.BytesAvailable\r\n\r\n%Start asynchronous reading\r\nreadasync(s);\r\nwhile(s.BytesAvailable <=0)     % sometimes program terminates here \r\n       \r\nend\r\n\r\ns.BytesAvailable\r\n    \r\n\r\nnumofData = 100;\r\nmData = zeros(numofData,27); \r\n\r\n\r\ntic;\r\nfor i = 1: numofData\r\n    sSerialData=fscanf(s);          \r\n    t=strsplit(sSerialData,'\\t');\r\n    for j= 1:27\r\n      mData(i,j) = str2double(t(j));\r\n    end\r\nend\r\ntoc;\r\n\r\nstopasync(s);\r\nfclose(s);\r\n\r\n%export data to excel \r\nfilename = 'swingdatanum1.csv';\r\ncsvwrite(filename,mData);\r\n\r\n% Import data\r\nsamplePeriod = 1/256; %original is 1/256\r\n%xIMUdata = xIMUdataClass(filePath, 'InertialMagneticSampleRate', 1/samplePeriod);\r\ntime = 1:numofData;\r\ngyrX = mData(:,1);\r\ngyrY = mData(:,2);\r\ngyrZ = mData(:,3);\r\naccX = mData(:,4);\r\naccY = mData(:,5);\r\naccZ = mData(:,6);\r\ngyrX_1 = mData(:,10);\r\ngyrY_1 = mData(:,11);\r\ngyrZ_1 = mData(:,12);\r\naccX_1 = mData(:,13);\r\naccY_1 = mData(:,14);\r\naccZ_1 = mData(:,15);\r\ngyrX_2 = mData(:,19);\r\ngyrY_2 = mData(:,20);\r\ngyrZ_2 = mData(:,21);\r\naccX_2 = mData(:,22);\r\naccY_2 = mData(:,23);\r\naccZ_2 = mData(:,24);\r\n%%clear('xIMUdata');\r\n\r\nfigure \r\nhold on \r\nplot(time,gyrX);\r\nplot(time,gyrX_1);\r\nplot(time,gyrX_2);\r\nplot(time,gyrY);\r\nplot(time,gyrY_1);\r\nplot(time,gyrY_2);\r\nplot(time,gyrZ);\r\nplot(time,gyrZ_1);\r\nplot(time,gyrZ_2);\r\nhold off\r\n\r\n"}}