ekfPDR.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. #include "ekfPDR.h"
  2. void invert3x3(float * src, float * dst)
  3. {
  4. float det;
  5. /* Compute adjoint: */
  6. dst[0] = +src[4] * src[8] - src[5] * src[7];
  7. dst[1] = -src[1] * src[8] + src[2] * src[7];
  8. dst[2] = +src[1] * src[5] - src[2] * src[4];
  9. dst[3] = -src[3] * src[8] + src[5] * src[6];
  10. dst[4] = +src[0] * src[8] - src[2] * src[6];
  11. dst[5] = -src[0] * src[5] + src[2] * src[3];
  12. dst[6] = +src[3] * src[7] - src[4] * src[6];
  13. dst[7] = -src[0] * src[7] + src[1] * src[6];
  14. dst[8] = +src[0] * src[4] - src[1] * src[3];
  15. /* Compute determinant: */
  16. det = src[0] * dst[0] + src[1] * dst[3] + src[2] * dst[6];
  17. /* Multiply adjoint with reciprocal of determinant: */
  18. det = 1.0f / det;
  19. dst[0] *= det;
  20. dst[1] *= det;
  21. dst[2] *= det;
  22. dst[3] *= det;
  23. dst[4] *= det;
  24. dst[5] *= det;
  25. dst[6] *= det;
  26. dst[7] *= det;
  27. dst[8] *= det;
  28. }
  29. void multiply3x3(float *a, float *b, float *dst)
  30. {
  31. dst[0] = a[0] * b[0] + a[1] * b[3] + a[2] * b[6];
  32. dst[1] = a[0] * b[1] + a[1] * b[4] + a[2] * b[7];
  33. dst[2] = a[0] * b[2] + a[1] * b[5] + a[2] * b[8];
  34. dst[3] = a[3] * b[0] + a[4] * b[3] + a[5] * b[6];
  35. dst[4] = a[3] * b[1] + a[4] * b[4] + a[5] * b[7];
  36. dst[5] = a[3] * b[2] + a[4] * b[5] + a[5] * b[8];
  37. dst[6] = a[6] * b[0] + a[7] * b[3] + a[8] * b[6];
  38. dst[7] = a[6] * b[1] + a[7] * b[4] + a[8] * b[7];
  39. dst[8] = a[6] * b[2] + a[7] * b[5] + a[8] * b[8];
  40. }
  41. void multiply3x1(float *a, float *b, float *dst)
  42. {
  43. dst[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  44. dst[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  45. dst[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  46. }
  47. void init_attitude_matrix(float *C, float *acc, float g)
  48. {
  49. float pitch = asin(-acc[0] / g);
  50. float roll = atan2(acc[1], acc[2]);
  51. float pitch_sin = sin(pitch);
  52. float pitch_cos = cos(pitch);
  53. float roll_sin = sin(roll);
  54. float roll_cos = cos(roll);
  55. C[0] = cos(pitch);
  56. C[1] = pitch_sin * roll_sin;
  57. C[2] = pitch_sin * roll_cos;
  58. C[4] = roll_cos;
  59. C[5] = -roll_sin;
  60. C[6] = -pitch_sin;
  61. C[7] = pitch_cos * roll_sin;
  62. C[8] = pitch_cos * roll_cos;
  63. }
  64. void reset_yaw_C(float *C)
  65. {
  66. float pitch = asin(-C[6]);
  67. float roll = atan2(C[7], C[8]);
  68. float pitch_sin = sin(pitch);
  69. float pitch_cos = cos(pitch);
  70. float roll_sin = sin(roll);
  71. float roll_cos = cos(roll);
  72. C[0] = pitch_cos;
  73. C[1] = pitch_sin * roll_sin;
  74. C[2] = pitch_sin * roll_cos;
  75. C[3] = 0.0;
  76. C[4] = roll_cos;
  77. C[5] = -roll_sin;
  78. }
  79. // F * P * F'
  80. void State_covariance_matrix_update(float *P, float *acc_n, float dt)
  81. {
  82. // P2 + P3*dt,
  83. P[3] = P[3] + P[6] * dt;
  84. P[4] = P[4] + P[7] * dt;
  85. P[5] = P[5] + P[8] * dt;
  86. P[12] = P[12] + P[15] * dt;
  87. P[13] = P[13] + P[16] * dt;
  88. P[14] = P[14] + P[17] * dt;
  89. P[21] = P[21] + P[24] * dt;
  90. P[22] = P[22] + P[25] * dt;
  91. P[23] = P[23] + P[26] * dt;
  92. //P4 + P7*dt,
  93. P[27] = P[27] + P[54] * dt;
  94. P[28] = P[28] + P[55] * dt;
  95. P[29] = P[29] + P[56] * dt;
  96. P[36] = P[36] + P[63] * dt;
  97. P[37] = P[37] + P[64] * dt;
  98. P[38] = P[38] + P[65] * dt;
  99. P[45] = P[45] + P[72] * dt;
  100. P[46] = P[46] + P[73] * dt;
  101. P[47] = P[47] + P[74] * dt;
  102. // P5 + P8*dt + dt*(P6 + P9*dt)
  103. P[30] = P[30] + P[57] * dt + dt * (P[33] + P[60] * dt);
  104. P[31] = P[31] + P[58] * dt + dt * (P[34] + P[61] * dt);
  105. P[32] = P[32] + P[59] * dt + dt * (P[35] + P[62] * dt);
  106. P[39] = P[39] + P[66] * dt + dt * (P[42] + P[69] * dt);
  107. P[40] = P[40] + P[67] * dt + dt * (P[43] + P[70] * dt);
  108. P[41] = P[41] + P[68] * dt + dt * (P[44] + P[71] * dt);
  109. P[48] = P[48] + P[75] * dt + dt * (P[51] + P[78] * dt);
  110. P[49] = P[49] + P[76] * dt + dt * (P[52] + P[79] * dt);
  111. P[50] = P[50] + P[77] * dt + dt * (P[53] + P[80] * dt);
  112. //P6 + P9*dt + matr*(P4 + P7*dt)
  113. P[33] = P[33] + P[60] * dt + acc_n[2] * dt * P[28] - acc_n[1] * dt * P[29];
  114. P[34] = P[34] + P[61] * dt - acc_n[2] * dt * P[27] + acc_n[0] * dt * P[29];
  115. P[35] = P[35] + P[62] * dt + acc_n[1] * dt * P[27] - acc_n[0] * dt * P[28];
  116. P[42] = P[42] + P[69] * dt + acc_n[2] * dt * P[37] - acc_n[1] * dt * P[38];
  117. P[43] = P[43] + P[70] * dt - acc_n[2] * dt * P[36] + acc_n[0] * dt * P[38];
  118. P[44] = P[44] + P[71] * dt + acc_n[1] * dt * P[36] - acc_n[0] * dt * P[37];
  119. P[51] = P[51] + P[78] * dt + acc_n[2] * dt * P[46] - acc_n[1] * dt * P[47];
  120. P[52] = P[52] + P[79] * dt - acc_n[2] * dt * P[45] + acc_n[0] * dt * P[47];
  121. P[53] = P[53] + P[80] * dt + acc_n[1] * dt * P[45] - acc_n[0] * dt * P[46];
  122. //P7 + P1*matr
  123. P[54] = P[54] + P[9] * acc_n[2] * dt - P[18] * acc_n[1] * dt;
  124. P[55] = P[55] + P[10] * acc_n[2] * dt - P[19] * acc_n[1] * dt;
  125. P[56] = P[56] + P[11] * acc_n[2] * dt - P[20] * acc_n[1] * dt;
  126. P[63] = P[63] - P[0] * acc_n[2] * dt + P[18] * acc_n[0] * dt;
  127. P[64] = P[64] - P[1] * acc_n[2] * dt + P[19] * acc_n[0] * dt;
  128. P[65] = P[65] - P[2] * acc_n[2] * dt + P[20] * acc_n[0] * dt;
  129. P[72] = P[72] + P[0] * acc_n[1] * dt - P[9] * acc_n[0] * dt;
  130. P[73] = P[73] + P[1] * acc_n[1] * dt - P[10] * acc_n[0] * dt;
  131. P[74] = P[74] + P[2] * acc_n[1] * dt - P[11] * acc_n[0] * dt;
  132. //P8 + P2*matr + dt*(P9 + P3*matr),
  133. P[57] = P[57] + dt * P[60] + P[12] * acc_n[2] * dt - P[21] * acc_n[1] * dt;
  134. P[58] = P[58] + dt * P[61] + P[13] * acc_n[2] * dt - P[22] * acc_n[1] * dt;
  135. P[59] = P[59] + dt * P[62] + P[14] * acc_n[2] * dt - P[23] * acc_n[1] * dt;
  136. P[66] = P[66] + dt * P[69] - P[3] * acc_n[2] * dt + P[21] * acc_n[0] * dt;
  137. P[67] = P[67] + dt * P[70] - P[4] * acc_n[2] * dt + P[22] * acc_n[0] * dt;
  138. P[68] = P[68] + dt * P[71] - P[5] * acc_n[2] * dt + P[23] * acc_n[0] * dt;
  139. P[75] = P[75] + dt * P[78] + P[3] * acc_n[1] * dt - P[12] * acc_n[0] * dt;
  140. P[76] = P[76] + dt * P[79] + P[4] * acc_n[1] * dt - P[13] * acc_n[0] * dt;
  141. P[77] = P[77] + dt * P[80] + P[5] * acc_n[1] * dt - P[14] * acc_n[0] * dt;
  142. // P9 + P3*matr + matr*(P7 + P1*matr)
  143. P[60] = P[60] + P[15] * acc_n[2] * dt - P[24] * acc_n[1] * dt + acc_n[2] * dt * P[55] - acc_n[1] * dt * P[56];
  144. P[61] = P[61] + P[16] * acc_n[2] * dt - P[25] * acc_n[1] * dt - acc_n[2] * dt * P[54] + acc_n[0] * dt * P[56];
  145. P[62] = P[62] + P[17] * acc_n[2] * dt - P[26] * acc_n[1] * dt + acc_n[1] * dt * P[54] - acc_n[0] * dt * P[55];
  146. P[69] = P[69] - P[6] * acc_n[2] * dt + P[24] * acc_n[0] * dt + acc_n[2] * dt * P[64] - acc_n[1] * dt * P[65];
  147. P[70] = P[70] - P[7] * acc_n[2] * dt + P[25] * acc_n[0] * dt - acc_n[2] * dt * P[63] + acc_n[0] * dt * P[65];
  148. P[71] = P[71] - P[8] * acc_n[2] * dt + P[26] * acc_n[0] * dt + acc_n[1] * dt * P[63] - acc_n[0] * dt * P[64];
  149. P[78] = P[78] + P[6] * acc_n[1] * dt - P[15] * acc_n[0] * dt + acc_n[2] * dt * P[73] - acc_n[1] * dt * P[74];
  150. P[79] = P[79] + P[7] * acc_n[1] * dt - P[16] * acc_n[0] * dt - acc_n[2] * dt * P[72] + acc_n[0] * dt * P[74];
  151. P[80] = P[80] + P[8] * acc_n[1] * dt - P[17] * acc_n[0] * dt + acc_n[1] * dt * P[72] - acc_n[0] * dt * P[73];
  152. //P3 + P1 * matr
  153. P[6] = P[6] + P[1] * acc_n[2] * dt - P[2] * acc_n[1] * dt;
  154. P[7] = P[7] - P[0] * acc_n[2] * dt + P[2] * acc_n[0] * dt;
  155. P[8] = P[8] + P[0] * acc_n[1] * dt - P[1] * acc_n[0] * dt;
  156. P[15] = P[15] + P[10] * acc_n[2] * dt - P[11] * acc_n[1] * dt;
  157. P[16] = P[16] - P[9] * acc_n[2] * dt + P[11] * acc_n[0] * dt;
  158. P[17] = P[17] + P[9] * acc_n[1] * dt - P[10] * acc_n[0] * dt;
  159. P[24] = P[24] + P[19] * acc_n[2] * dt - P[20] * acc_n[1] * dt;
  160. P[25] = P[25] - P[18] * acc_n[2] * dt + P[20] * acc_n[0] * dt;
  161. P[26] = P[26] + P[18] * acc_n[1] * dt - P[19] * acc_n[0] * dt;
  162. float noise = SIGMA * SIGMA * dt *dt;
  163. for (int i = 0; i < 3; i++)
  164. {
  165. P[i * 9 + i] += noise*0.5f;
  166. }
  167. for (int i = 6; i < 9; i++)
  168. {
  169. P[i * 9 + i] += noise;
  170. }
  171. }
  172. void Kalfman_gain_angle(float *P, float *Temporary_array, float *Temporary_array1, float *K)
  173. {
  174. Temporary_array[0] = P[0] + SIGMA_V * SIGMA_V;
  175. Temporary_array[1] = P[1];
  176. Temporary_array[2] = P[2];
  177. Temporary_array[3] = P[9];
  178. Temporary_array[4] = P[10] + SIGMA_V * SIGMA_V;
  179. Temporary_array[5] = P[11];
  180. Temporary_array[6] = P[18];
  181. Temporary_array[7] = P[19];
  182. Temporary_array[8] = P[20] + SIGMA_V * SIGMA_V;
  183. invert3x3(Temporary_array, Temporary_array1);
  184. memcpy(Temporary_array, Temporary_array1, 9 * sizeof(float));
  185. K[0] = P[0] * Temporary_array[0] + P[1] * Temporary_array[3] + P[2] * Temporary_array[6];
  186. K[1] = P[0] * Temporary_array[1] + P[1] * Temporary_array[4] + P[2] * Temporary_array[7];
  187. K[2] = P[0] * Temporary_array[2] + P[1] * Temporary_array[5] + P[2] * Temporary_array[8];
  188. K[3] = P[9] * Temporary_array[0] + P[10] * Temporary_array[3] + P[11] * Temporary_array[6];
  189. K[4] = P[9] * Temporary_array[1] + P[10] * Temporary_array[4] + P[11] * Temporary_array[7];
  190. K[5] = P[9] * Temporary_array[2] + P[10] * Temporary_array[5] + P[11] * Temporary_array[8];
  191. K[6] = P[18] * Temporary_array[0] + P[19] * Temporary_array[3] + P[20] * Temporary_array[6];
  192. K[7] = P[18] * Temporary_array[1] + P[19] * Temporary_array[4] + P[20] * Temporary_array[7];
  193. K[8] = P[18] * Temporary_array[2] + P[19] * Temporary_array[5] + P[20] * Temporary_array[8];
  194. K[9] = P[27] * Temporary_array[0] + P[28] * Temporary_array[3] + P[29] * Temporary_array[6];
  195. K[10] = P[27] * Temporary_array[1] + P[28] * Temporary_array[4] + P[29] * Temporary_array[7];
  196. K[11] = P[27] * Temporary_array[2] + P[28] * Temporary_array[5] + P[29] * Temporary_array[8];
  197. K[12] = P[36] * Temporary_array[0] + P[37] * Temporary_array[3] + P[38] * Temporary_array[6];
  198. K[13] = P[36] * Temporary_array[1] + P[37] * Temporary_array[4] + P[38] * Temporary_array[7];
  199. K[14] = P[36] * Temporary_array[2] + P[37] * Temporary_array[5] + P[38] * Temporary_array[8];
  200. K[15] = P[45] * Temporary_array[0] + P[46] * Temporary_array[3] + P[47] * Temporary_array[6];
  201. K[16] = P[45] * Temporary_array[1] + P[46] * Temporary_array[4] + P[47] * Temporary_array[7];
  202. K[17] = P[45] * Temporary_array[2] + P[46] * Temporary_array[5] + P[47] * Temporary_array[8];
  203. K[18] = P[54] * Temporary_array[0] + P[55] * Temporary_array[3] + P[56] * Temporary_array[6];
  204. K[19] = P[54] * Temporary_array[1] + P[55] * Temporary_array[4] + P[56] * Temporary_array[7];
  205. K[20] = P[54] * Temporary_array[2] + P[55] * Temporary_array[5] + P[56] * Temporary_array[8];
  206. K[21] = P[63] * Temporary_array[0] + P[64] * Temporary_array[3] + P[65] * Temporary_array[6];
  207. K[22] = P[63] * Temporary_array[1] + P[64] * Temporary_array[4] + P[65] * Temporary_array[7];
  208. K[23] = P[63] * Temporary_array[2] + P[64] * Temporary_array[5] + P[65] * Temporary_array[8];
  209. K[24] = P[72] * Temporary_array[0] + P[73] * Temporary_array[3] + P[74] * Temporary_array[6];
  210. K[25] = P[72] * Temporary_array[1] + P[73] * Temporary_array[4] + P[74] * Temporary_array[7];
  211. K[26] = P[72] * Temporary_array[2] + P[73] * Temporary_array[5] + P[74] * Temporary_array[8];
  212. }
  213. void Kalfman_gain(float *P, float *Temporary_array, float *Temporary_array1, float *K)
  214. {
  215. Temporary_array[0] = P[60] + SIGMA_V * SIGMA_V ;
  216. Temporary_array[1] = P[61];
  217. Temporary_array[2] = P[62];
  218. Temporary_array[3] = P[69];
  219. Temporary_array[4] = P[70] + SIGMA_V * SIGMA_V ;
  220. Temporary_array[5] = P[71];
  221. Temporary_array[6] = P[78];
  222. Temporary_array[7] = P[79];
  223. Temporary_array[8] = P[80] + SIGMA_V * SIGMA_V;
  224. invert3x3(Temporary_array, Temporary_array1);
  225. memcpy(Temporary_array, Temporary_array1, 9 * sizeof(float));
  226. K[0] = P[6] * Temporary_array[0] + P[7] * Temporary_array[3] + P[8] * Temporary_array[6];
  227. K[1] = P[6] * Temporary_array[1] + P[7] * Temporary_array[4] + P[8] * Temporary_array[7];
  228. K[2] = P[6] * Temporary_array[2] + P[7] * Temporary_array[5] + P[8] * Temporary_array[8];
  229. K[3] = P[15] * Temporary_array[0] + P[16] * Temporary_array[3] + P[17] * Temporary_array[6];
  230. K[4] = P[15] * Temporary_array[1] + P[16] * Temporary_array[4] + P[17] * Temporary_array[7];
  231. K[5] = P[15] * Temporary_array[2] + P[16] * Temporary_array[5] + P[17] * Temporary_array[8];
  232. K[6] = P[24] * Temporary_array[0] + P[25] * Temporary_array[3] + P[26] * Temporary_array[6];
  233. K[7] = P[24] * Temporary_array[1] + P[25] * Temporary_array[4] + P[26] * Temporary_array[7];
  234. K[8] = P[24] * Temporary_array[2] + P[25] * Temporary_array[5] + P[26] * Temporary_array[8];
  235. K[9] = P[33] * Temporary_array[0] + P[34] * Temporary_array[3] + P[35] * Temporary_array[6];
  236. K[10] = P[33] * Temporary_array[1] + P[34] * Temporary_array[4] + P[35] * Temporary_array[7];
  237. K[11] = P[33] * Temporary_array[2] + P[34] * Temporary_array[5] + P[35] * Temporary_array[8];
  238. K[12] = P[42] * Temporary_array[0] + P[43] * Temporary_array[3] + P[44] * Temporary_array[6];
  239. K[13] = P[42] * Temporary_array[1] + P[43] * Temporary_array[4] + P[44] * Temporary_array[7];
  240. K[14] = P[42] * Temporary_array[2] + P[43] * Temporary_array[5] + P[44] * Temporary_array[8];
  241. K[15] = P[51] * Temporary_array[0] + P[52] * Temporary_array[3] + P[53] * Temporary_array[6];
  242. K[16] = P[51] * Temporary_array[1] + P[52] * Temporary_array[4] + P[53] * Temporary_array[7];
  243. K[17] = P[51] * Temporary_array[2] + P[52] * Temporary_array[5] + P[53] * Temporary_array[8];
  244. K[18] = P[60] * Temporary_array[0] + P[61] * Temporary_array[3] + P[62] * Temporary_array[6];
  245. K[19] = P[60] * Temporary_array[1] + P[61] * Temporary_array[4] + P[62] * Temporary_array[7];
  246. K[20] = P[60] * Temporary_array[2] + P[61] * Temporary_array[5] + P[62] * Temporary_array[8];
  247. K[21] = P[69] * Temporary_array[0] + P[70] * Temporary_array[3] + P[71] * Temporary_array[6];
  248. K[22] = P[69] * Temporary_array[1] + P[70] * Temporary_array[4] + P[71] * Temporary_array[7];
  249. K[23] = P[69] * Temporary_array[2] + P[70] * Temporary_array[5] + P[71] * Temporary_array[8];
  250. K[24] = P[78] * Temporary_array[0] + P[79] * Temporary_array[3] + P[80] * Temporary_array[6];
  251. K[25] = P[78] * Temporary_array[1] + P[79] * Temporary_array[4] + P[80] * Temporary_array[7];
  252. K[26] = P[78] * Temporary_array[2] + P[79] * Temporary_array[5] + P[80] * Temporary_array[8];
  253. }
  254. void multiply9x3(float *K, float *vel_n, float* delta_x)
  255. {
  256. int i = 0;
  257. for (i = 0; i < 9; i++)
  258. {
  259. delta_x[i] = K[i * 3] * vel_n[0] + K[i * 3 + 1] * vel_n[1] + K[i * 3 + 2] * vel_n[2];
  260. }
  261. }
  262. void State_covariance_matrix_corr(float *P, float *P_tmp, float *K)
  263. {
  264. int i = 0;
  265. int j = 0;
  266. for (i = 0; i < 9; i++) {
  267. for (j = 0; j < 9; j++) {
  268. P_tmp[i * 9 + j] = P[i * 9 + j] - K[3 * i] * P[54 + j] - K[3 * i + 1] * P[63 + j] - K[3 * i + 2] * P[72 + j];
  269. }
  270. }
  271. memcpy(P, P_tmp, 81 * sizeof(float));
  272. }
  273. void State_covariance_matrix_corr_angle(float *P, float *P_tmp, float *K)
  274. {
  275. int i = 0;
  276. int j = 0;
  277. for (i = 0; i < 9; i++) {
  278. for (j = 0; j < 9; j++) {
  279. P_tmp[i * 9 + j] = P[i * 9 + j] - K[3 * i] * P[j] - K[3 * i + 1] * P[9 + j] - K[3 * i + 2] * P[18 + j];
  280. }
  281. }
  282. memcpy(P, P_tmp, 81 * sizeof(float));
  283. }
  284. void Att_matrix_corr(float *C, float *C_prev, float *Temporary_array, float *Temporary_array1, float *delta_x)
  285. {
  286. Temporary_array[0] = 2.0;
  287. Temporary_array[1] = -delta_x[2];
  288. Temporary_array[2] = delta_x[1];
  289. Temporary_array[3] = delta_x[2];
  290. Temporary_array[4] = 2.0;
  291. Temporary_array[5] = -delta_x[0];
  292. Temporary_array[6] = -delta_x[1];
  293. Temporary_array[7] = delta_x[0];
  294. Temporary_array[8] = 2.0;
  295. invert3x3(Temporary_array, Temporary_array1);
  296. Temporary_array[0] = 2.0;
  297. Temporary_array[1] = delta_x[2];
  298. Temporary_array[2] = -delta_x[1];
  299. Temporary_array[3] = -delta_x[2];
  300. Temporary_array[4] = 2.0;
  301. Temporary_array[5] = delta_x[0];
  302. Temporary_array[6] = delta_x[1];
  303. Temporary_array[7] = -delta_x[0];
  304. Temporary_array[8] = 2.0;
  305. multiply3x3(Temporary_array, Temporary_array1, C_prev);
  306. memcpy(Temporary_array, C_prev, 9 * sizeof(float));
  307. multiply3x3(Temporary_array, C, C_prev);
  308. memcpy(C, C_prev, 9 * sizeof(float));
  309. }
  310. void pos_n_corr(float *pos_n, float *delta_x)
  311. {
  312. pos_n[0] -= delta_x[3];
  313. pos_n[1] -= delta_x[4];
  314. pos_n[2] -= delta_x[5];
  315. }
  316. void vel_n_corr(float *vel_n, float *delta_x)
  317. {
  318. vel_n[0] -= delta_x[6];
  319. vel_n[1] -= delta_x[7];
  320. vel_n[2] -= delta_x[8];
  321. }
  322. void State_covariance_matrix_orthogonalization(float *P)
  323. {
  324. int i = 0;
  325. int j = 0;
  326. float temp;
  327. for (i = 0; i < 9; i++)
  328. for (j = i + 1; j < 9; j++)
  329. {
  330. temp = 0.5f*(P[i * 9 + j] + P[j * 9 + i]);
  331. P[i * 9 + j] = temp;
  332. P[j * 9 + i] = temp;
  333. }
  334. }