RichieHard

Untitled

Apr 21st, 2020
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. //Accelerometer Calibration Matrix A and vector b from matlab
  2.  
  3. const int N = 3; //Dimensions of Matrix A and vector b
  4. float A[N][N] = {
  5. {0.6077, 0.0014, -0.0021}, //A[0][0], A[0][1], A[0][2]
  6. {0.0, 0.6077, -0.0002 }, //A[1][0], A[1][1], A[1][2]
  7. {0.0, 0.0, 0.6033 } //A[2][0], A[2][1], A[2][2]
  8. };
  9.  
  10. //b[0][0], b[0][1], b[0][2]
  11. float b[N] = {-543.9129, 273.3477, 241.1651};
  12.  
  13. //Useful Matrix and vectors
  14. float F[N][N] = {
  15. {0.0000, 0.0000, 0.0000},
  16. {0.0000, 0.0000, 0.0000},
  17. {0.0000, 0.0000, 0.0000}
  18. };
  19.  
  20. float cal[N] = {0.0000, 0.0000, 0.0000}; //calibrated Values
  21. float raw[N] = {0.15210, 0.00232, 1.115302}; //raw values
  22. float dif[N] = {0.0000, 0.0000, 0.0000}; //difference (raw-b) vector
  23.  
  24. void setup() {
  25. Serial.begin(115200);
  26. }
  27.  
  28. void loop() {
  29.  
  30. //cal = 1.0e-04*A*(raw-b);
  31.  
  32. //Difference (raw-b)
  33.  
  34. for (int j = 0; j < N; j++){
  35. dif[j] = raw[j] - b[j];
  36. }
  37.  
  38.  
  39. // Serial.print(dif[0],4);
  40. // Serial.print(" ");
  41. // Serial.print(dif[1],4);
  42. // Serial.print(" ");
  43. // Serial.println(dif[2],4);
  44.  
  45.  
  46.  
  47. //Moltiplication 1.0e-04 *A*dif
  48.  
  49.  
  50. for (int j = 0; j < N; j++){
  51. for(int k = 0; k < N; k++)
  52. {
  53. F[j][k] = A[j][k] * dif[k];
  54. }
  55. }
  56. for(int j = 0; j < N; j++)
  57. {
  58. cal[j] = 0.0001*(F[j][N-3]+F[j][N-2]+F[j][N-1]);
  59. }
  60.  
  61. // Serial.print(cal[0],4);
  62. // Serial.print(" ");
  63. // Serial.print(cal[1],4);
  64. // Serial.print(" ");
  65. // Serial.println(cal[2],4);
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment