ekfPDR.c 16 KB

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