check_dgnss_management.c
Go to the documentation of this file.
00001 
00002 #include <check.h>
00003 #include <stdio.h>
00004 #include "linear_algebra.h"
00005 #include "check_utils.h"
00006 #include "dgnss_management.h"
00007 #include "ambiguity_test.h"
00008 
00009 extern sats_management_t sats_management;
00010 extern nkf_t nkf;
00011 extern ambiguity_test_t ambiguity_test;
00012 
00013 sdiff_t sdiffs[6];
00014 double ref_ecef[3];
00015 
00016 void check_dgnss_management_setup()
00017 {
00018   memset(ref_ecef, 0, sizeof(double) * 3);
00019 
00020   sdiffs[0].prn = 1;
00021   sdiffs[0].sat_pos[0] = 1;
00022   sdiffs[0].sat_pos[1] = 1;
00023   sdiffs[0].sat_pos[2] = 0;
00024   sdiffs[0].carrier_phase = 1;
00025 
00026   sdiffs[1].prn = 2;
00027   sdiffs[1].sat_pos[0] = 1;
00028   sdiffs[1].sat_pos[1] = 0;
00029   sdiffs[1].sat_pos[2] = 0;
00030   sdiffs[1].carrier_phase = 2;
00031 
00032   sdiffs[2].prn = 3;
00033   sdiffs[2].sat_pos[0] = 0;
00034   sdiffs[2].sat_pos[1] = 1;
00035   sdiffs[2].sat_pos[2] = 0;
00036   sdiffs[2].carrier_phase = 3;
00037 
00038   sdiffs[3].prn = 4;
00039   sdiffs[3].sat_pos[0] = 0;
00040   sdiffs[3].sat_pos[1] = 1;
00041   sdiffs[3].sat_pos[2] = 1;
00042   sdiffs[3].carrier_phase = 4;
00043 
00044   sdiffs[4].prn = 5;
00045   sdiffs[4].sat_pos[0] = 0;
00046   sdiffs[4].sat_pos[1] = 0;
00047   sdiffs[4].sat_pos[2] = 1;
00048   sdiffs[4].carrier_phase = 5;
00049 
00050   sdiffs[5].prn = 99;
00051 
00052   memset(nkf.state_mean, 0, sizeof(double) * 5);
00053   nkf.state_dim = 4;
00054   nkf.obs_dim = 8;
00055 
00056   create_ambiguity_test(&ambiguity_test);
00057 }
00058 
00059 void check_dgnss_management_teardown()
00060 {}
00061 
00069 void matrix_eye_s32(u32 n, s32 *M)
00070 {
00071   /* NOTE: This function has been bounds checked. Please check again if
00072    * modifying. */
00073   memset(M, 0, n * n * sizeof(s32));
00074   for (u32 i=0; i<n; i++) {
00075     M[i*n + i] = 1;
00076   }
00077 }
00078 
00079 /* Check that it works with the first sdiff as the reference sat.
00080  * This should verify that the loop can start correctly.*/
00081 START_TEST(test_dgnss_low_latency_float_baseline_ref_first) {
00082   sats_management.num_sats = 5;
00083   sats_management.prns[0] = 1;
00084   sats_management.prns[1] = 2;
00085   sats_management.prns[2] = 3;
00086   sats_management.prns[3] = 4;
00087   sats_management.prns[4] = 5;
00088 
00089   double b[3];
00090   u8 num_used;
00091   u8 num_sdiffs = 6;
00092 
00093   s8 valid = _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00094                                  ref_ecef, &num_used, b);
00095 
00096   fail_unless(valid == 0);
00097   fail_unless(within_epsilon(b[0], -0.742242));
00098   fail_unless(within_epsilon(b[1], -0.492905));
00099   fail_unless(within_epsilon(b[2], -0.0533294));
00100 }
00101 END_TEST
00102 
00103 /* Check that it works with a middle sdiff as the reference sat.
00104  * This should verify that the induction works. */
00105 START_TEST(test_dgnss_low_latency_float_baseline_ref_middle) {
00106   sats_management.num_sats = 5;
00107   sats_management.prns[0] = 2;
00108   sats_management.prns[1] = 1;
00109   sats_management.prns[2] = 3;
00110   sats_management.prns[3] = 4;
00111   sats_management.prns[4] = 5;
00112 
00113   double b[3];
00114   u8 num_used;
00115   u8 num_sdiffs = 6;
00116 
00117   s8 valid = _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00118                                  ref_ecef, &num_used, b);
00119 
00120   fail_unless(valid == 0);
00121   fail_unless(within_epsilon(b[0], -0.622609));
00122   fail_unless(within_epsilon(b[1], -0.432371));
00123   fail_unless(within_epsilon(b[2], -0.00461595));
00124 }
00125 END_TEST
00126 
00127 /* Check that it works with the last sdiff as the reference sat.
00128  * This should verify that the loop can terminate correctly.*/
00129 START_TEST(test_dgnss_low_latency_float_baseline_ref_end) {
00130   sats_management.num_sats = 5;
00131   sats_management.prns[0] = 5;
00132   sats_management.prns[1] = 1;
00133   sats_management.prns[2] = 2;
00134   sats_management.prns[3] = 3;
00135   sats_management.prns[4] = 4;
00136 
00137   double b[3];
00138   u8 num_used;
00139   u8 num_sdiffs = 5;
00140 
00141   s8 valid = _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00142                                  ref_ecef, &num_used, b);
00143 
00144   fail_unless(valid == 0);
00145   fail_unless(within_epsilon(b[0], -0.589178));
00146   fail_unless(within_epsilon(b[1], -0.35166));
00147   fail_unless(within_epsilon(b[2], 0.0288157));
00148 }
00149 END_TEST
00150 
00151 /* Check that measurements generated from a baseline result in an estimate
00152  * matching the baseline. */
00153 START_TEST(test_dgnss_low_latency_float_baseline_fixed_point) {
00154   sats_management.num_sats = 5;
00155   sats_management.prns[0] = 5;
00156   sats_management.prns[1] = 1;
00157   sats_management.prns[2] = 2;
00158   sats_management.prns[3] = 3;
00159   sats_management.prns[4] = 4;
00160 
00161   double b_orig[3];
00162   b_orig[0] = 1;
00163   b_orig[1] = 1;
00164   b_orig[2] = 1;
00165 
00166   ref_ecef[0] = 0; /* Done so that we can just do the vector operations on  */
00167   ref_ecef[1] = 0; /*  the sat_pos vectors themselves, instead of computing */
00168   ref_ecef[2] = 0; /*  the line of sight vectors for each sdiff.            */
00169 
00170   sdiffs[0].carrier_phase = vector_dot(3, b_orig, sdiffs[0].sat_pos) /
00171                             vector_norm(3, sdiffs[0].sat_pos) /
00172                             GPS_L1_LAMBDA_NO_VAC;
00173   sdiffs[1].carrier_phase = vector_dot(3, b_orig, sdiffs[1].sat_pos) /
00174                             vector_norm(3, sdiffs[1].sat_pos) /
00175                             GPS_L1_LAMBDA_NO_VAC;
00176   sdiffs[2].carrier_phase = vector_dot(3, b_orig, sdiffs[2].sat_pos) /
00177                             vector_norm(3, sdiffs[2].sat_pos) /
00178                             GPS_L1_LAMBDA_NO_VAC;
00179   sdiffs[3].carrier_phase = vector_dot(3, b_orig, sdiffs[3].sat_pos) /
00180                             vector_norm(3, sdiffs[3].sat_pos) /
00181                             GPS_L1_LAMBDA_NO_VAC;
00182   sdiffs[4].carrier_phase = vector_dot(3, b_orig, sdiffs[4].sat_pos) /
00183                             vector_norm(3, sdiffs[4].sat_pos) /
00184                             GPS_L1_LAMBDA_NO_VAC;
00185 
00186   double b[3];
00187   u8 num_used;
00188   u8 num_sdiffs = 6;
00189 
00190   s8 valid = _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00191                                  ref_ecef, &num_used, b);
00192 
00193   fail_unless(valid == 0);
00194   fail_unless(within_epsilon(b[0], b_orig[0]));
00195   fail_unless(within_epsilon(b[1], b_orig[1]));
00196   fail_unless(within_epsilon(b[2], b_orig[2]));
00197 }
00198 END_TEST
00199 
00200 START_TEST(test_dgnss_low_latency_float_baseline_few_sats) {
00201   sats_management.prns[0] = 5;
00202   sats_management.num_sats = 1;
00203 
00204   double b[3];
00205   u8 num_used;
00206   u8 num_sdiffs = 6;
00207 
00208   s8 valid = _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00209                                               ref_ecef, &num_used, b);
00210 
00211   fail_unless(valid == -1);
00212 
00213   sats_management.num_sats = 0;
00214 
00215   _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00216                                    ref_ecef, &num_used, b);
00217 
00218   fail_unless(valid == -1);
00219 }
00220 END_TEST
00221 
00222 
00223 /* Check that it works with the first sdiff as the reference sat.
00224  * This should verify that the loop can start correctly.*/
00225 START_TEST(test_dgnss_low_latency_IAR_baseline_ref_first) {
00226   u8 prns[4];
00227   prns[0] = 2;
00228   prns[1] = 3;
00229   prns[2] = 4;
00230   prns[3] = 5;
00231   s32 lower[4];
00232   s32 upper[4];
00233   memset(lower, 0, sizeof(s32) * 4);
00234   memset(upper, 0, sizeof(s32) * 4);
00235 
00236   s32 Z_inv[16];
00237   matrix_eye_s32(4, Z_inv);
00238 
00239   add_sats(&ambiguity_test,
00240            1,
00241            4, prns,
00242            lower, upper,
00243            Z_inv);
00244 
00245   ambiguity_test.amb_check.initialized = 1;
00246   ambiguity_test.amb_check.num_matching_ndxs = 4;
00247   ambiguity_test.amb_check.matching_ndxs[0] = 0;
00248   ambiguity_test.amb_check.matching_ndxs[1] = 1;
00249   ambiguity_test.amb_check.matching_ndxs[2] = 2;
00250   ambiguity_test.amb_check.matching_ndxs[3] = 3;
00251   memset(ambiguity_test.amb_check.ambs, 0, sizeof(s32) * 5);
00252 
00253   double b[3];
00254   u8 num_used;
00255   u8 num_sdiffs = 6;
00256 
00257   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00258                                  ref_ecef, &num_used, b);
00259 
00260   fail_unless(valid == 0);
00261   fail_unless(within_epsilon(b[0], -0.742242));
00262   fail_unless(within_epsilon(b[1], -0.492905));
00263   fail_unless(within_epsilon(b[2], -0.0533294));
00264 }
00265 END_TEST
00266 
00267 /* Check that it works with a middle sdiff as the reference sat.
00268  * This should verify that the induction works. */
00269 START_TEST(test_dgnss_low_latency_IAR_baseline_ref_middle) {
00270   u8 ref_prn = 2;
00271   u8 prns[4];
00272   prns[0] = 1;
00273   prns[1] = 3;
00274   prns[2] = 4;
00275   prns[3] = 5;
00276   s32 lower[4];
00277   s32 upper[4];
00278   memset(lower, 0, sizeof(s32) * 4);
00279   memset(upper, 0, sizeof(s32) * 4);
00280 
00281   s32 Z_inv[16];
00282   matrix_eye_s32(4, Z_inv);
00283 
00284   add_sats(&ambiguity_test,
00285            ref_prn,
00286            4, prns,
00287            lower, upper,
00288            Z_inv);
00289 
00290   ambiguity_test.amb_check.initialized = 1;
00291   ambiguity_test.amb_check.num_matching_ndxs = 4;
00292   ambiguity_test.amb_check.matching_ndxs[0] = 0;
00293   ambiguity_test.amb_check.matching_ndxs[1] = 1;
00294   ambiguity_test.amb_check.matching_ndxs[2] = 2;
00295   ambiguity_test.amb_check.matching_ndxs[3] = 3;
00296   memset(ambiguity_test.amb_check.ambs, 0, sizeof(s32) * 5);
00297 
00298   double b[3];
00299   u8 num_used;
00300   u8 num_sdiffs = 6;
00301 
00302   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00303                                  ref_ecef, &num_used, b);
00304 
00305   fail_unless(valid == 0);
00306   fail_unless(within_epsilon(b[0], -0.622609));
00307   fail_unless(within_epsilon(b[1], -0.432371));
00308   fail_unless(within_epsilon(b[2], -0.00461595));
00309 }
00310 END_TEST
00311 
00312 /* Check that it works with the last sdiff as the reference sat.
00313  * This should verify that the loop can terminate correctly.*/
00314 START_TEST(test_dgnss_low_latency_IAR_baseline_ref_end) {
00315   u8 ref_prn = 5;
00316   u8 prns[4];
00317   prns[0] = 1;
00318   prns[1] = 2;
00319   prns[2] = 3;
00320   prns[3] = 4;
00321   s32 lower[4];
00322   s32 upper[4];
00323   memset(lower, 0, sizeof(s32) * 4);
00324   memset(upper, 0, sizeof(s32) * 4);
00325 
00326   s32 Z_inv[16];
00327   matrix_eye_s32(4, Z_inv);
00328 
00329   add_sats(&ambiguity_test,
00330            ref_prn,
00331            4, prns,
00332            lower, upper,
00333            Z_inv);
00334 
00335   ambiguity_test.amb_check.initialized = 1;
00336   ambiguity_test.amb_check.num_matching_ndxs = 4;
00337   ambiguity_test.amb_check.matching_ndxs[0] = 0;
00338   ambiguity_test.amb_check.matching_ndxs[1] = 1;
00339   ambiguity_test.amb_check.matching_ndxs[2] = 2;
00340   ambiguity_test.amb_check.matching_ndxs[3] = 3;
00341   memset(ambiguity_test.amb_check.ambs, 0, sizeof(s32) * 5);
00342 
00343   double b[3];
00344   u8 num_used;
00345   u8 num_sdiffs = 5;
00346 
00347   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00348                                  ref_ecef, &num_used, b);
00349 
00350   fail_unless(valid == 0);
00351   fail_unless(within_epsilon(b[0], -0.589178));
00352   fail_unless(within_epsilon(b[1], -0.35166));
00353   fail_unless(within_epsilon(b[2], 0.0288157));
00354 }
00355 END_TEST
00356 
00357 /* Check that measurements generated from a baseline result in an estimate
00358  * matching the baseline. */
00359 START_TEST(test_dgnss_low_latency_IAR_baseline_fixed_point) {
00360   u8 ref_prn = 5;
00361   u8 prns[4];
00362   prns[0] = 1;
00363   prns[1] = 2;
00364   prns[2] = 3;
00365   prns[3] = 4;
00366   s32 lower[4];
00367   s32 upper[4];
00368   memset(lower, 0, sizeof(s32) * 4);
00369   memset(upper, 0, sizeof(s32) * 4);
00370 
00371   s32 Z_inv[16];
00372   matrix_eye_s32(4, Z_inv);
00373 
00374   add_sats(&ambiguity_test,
00375            ref_prn,
00376            4, prns,
00377            lower, upper,
00378            Z_inv);
00379 
00380   ambiguity_test.amb_check.initialized = 1;
00381   ambiguity_test.amb_check.num_matching_ndxs = 4;
00382   ambiguity_test.amb_check.matching_ndxs[0] = 0;
00383   ambiguity_test.amb_check.matching_ndxs[1] = 1;
00384   ambiguity_test.amb_check.matching_ndxs[2] = 2;
00385   ambiguity_test.amb_check.matching_ndxs[3] = 3;
00386   memset(ambiguity_test.amb_check.ambs, 0, sizeof(s32) * 5);
00387 
00388   double b_orig[3];
00389   b_orig[0] = 1;
00390   b_orig[1] = 1;
00391   b_orig[2] = 1;
00392 
00393   ref_ecef[0] = 0; /* Done so that we can just do the vector operations on  */
00394   ref_ecef[1] = 0; /*  the sat_pos vectors themselves, instead of computing */
00395   ref_ecef[2] = 0; /*  the line of sight vectors for each sdiff.            */
00396 
00397   sdiffs[0].carrier_phase = vector_dot(3, b_orig, sdiffs[0].sat_pos) /
00398                             vector_norm(3, sdiffs[0].sat_pos) /
00399                             GPS_L1_LAMBDA_NO_VAC;
00400   sdiffs[1].carrier_phase = vector_dot(3, b_orig, sdiffs[1].sat_pos) /
00401                             vector_norm(3, sdiffs[1].sat_pos) /
00402                             GPS_L1_LAMBDA_NO_VAC;
00403   sdiffs[2].carrier_phase = vector_dot(3, b_orig, sdiffs[2].sat_pos) /
00404                             vector_norm(3, sdiffs[2].sat_pos) /
00405                             GPS_L1_LAMBDA_NO_VAC;
00406   sdiffs[3].carrier_phase = vector_dot(3, b_orig, sdiffs[3].sat_pos) /
00407                             vector_norm(3, sdiffs[3].sat_pos) /
00408                             GPS_L1_LAMBDA_NO_VAC;
00409   sdiffs[4].carrier_phase = vector_dot(3, b_orig, sdiffs[4].sat_pos) /
00410                             vector_norm(3, sdiffs[4].sat_pos) /
00411                             GPS_L1_LAMBDA_NO_VAC;
00412 
00413   double b[3];
00414   u8 num_used;
00415   u8 num_sdiffs = 6;
00416 
00417   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00418                                  ref_ecef, &num_used, b);
00419 
00420   fail_unless(valid == 0);
00421   fail_unless(within_epsilon(b[0], b_orig[0]));
00422   fail_unless(within_epsilon(b[1], b_orig[1]));
00423   fail_unless(within_epsilon(b[2], b_orig[2]));
00424 }
00425 END_TEST
00426 
00427 START_TEST(test_dgnss_low_latency_IAR_baseline_few_sats) {
00428   ambiguity_test.amb_check.initialized = 1;
00429   ambiguity_test.amb_check.num_matching_ndxs = 1;
00430 
00431   double b[3];
00432   u8 num_used;
00433   u8 num_sdiffs = 6;
00434 
00435 
00436   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00437                                               ref_ecef, &num_used, b);
00438   fail_unless(valid == -1);
00439 
00440   ambiguity_test.amb_check.num_matching_ndxs = 0;
00441 
00442   _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00443                                    ref_ecef, &num_used, b);
00444   fail_unless(valid == -1);
00445 
00446   ambiguity_test.amb_check.initialized = 0;
00447   ambiguity_test.amb_check.num_matching_ndxs = 4;
00448 
00449   _dgnss_low_latency_float_baseline(num_sdiffs, sdiffs,
00450                                    ref_ecef, &num_used, b);
00451   fail_unless(valid == -1);
00452 }
00453 END_TEST
00454 
00455 START_TEST(test_dgnss_low_latency_IAR_baseline_uninitialized) {
00456   ambiguity_test.amb_check.initialized = 0;
00457   ambiguity_test.amb_check.num_matching_ndxs = 5;
00458 
00459   double b[3];
00460   u8 num_used;
00461   u8 num_sdiffs = 6;
00462 
00463 
00464   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00465                                               ref_ecef, &num_used, b);
00466   fail_unless(valid == -1);
00467 }
00468 END_TEST
00469 
00470 START_TEST(test_dgnss_low_latency_baseline_uninitialized) {
00471   ambiguity_test.amb_check.initialized = 0;
00472   ambiguity_test.amb_check.num_matching_ndxs = 5;
00473 
00474   double b[3];
00475   u8 num_used;
00476   u8 num_sdiffs = 6;
00477 
00478 
00479   s8 valid = _dgnss_low_latency_IAR_baseline(num_sdiffs, sdiffs,
00480                                               ref_ecef, &num_used, b);
00481   fail_unless(valid == -1);
00482 }
00483 END_TEST
00484 
00485 Suite* dgnss_management_test_suite(void)
00486 {
00487   Suite *s = suite_create("DGNSS Management");
00488 
00489   TCase *tc_core = tcase_create("Core");
00490   tcase_add_checked_fixture (tc_core, check_dgnss_management_setup,
00491                                       check_dgnss_management_teardown);
00492   tcase_add_test(tc_core, test_dgnss_low_latency_float_baseline_ref_first);
00493   tcase_add_test(tc_core, test_dgnss_low_latency_float_baseline_ref_middle);
00494   tcase_add_test(tc_core, test_dgnss_low_latency_float_baseline_ref_end);
00495   tcase_add_test(tc_core, test_dgnss_low_latency_float_baseline_fixed_point);
00496   tcase_add_test(tc_core, test_dgnss_low_latency_float_baseline_few_sats);
00497 
00498   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_ref_first);
00499   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_ref_middle);
00500   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_ref_end);
00501   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_fixed_point);
00502   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_few_sats);
00503   tcase_add_test(tc_core, test_dgnss_low_latency_IAR_baseline_uninitialized);
00504   tcase_add_test(tc_core, test_dgnss_low_latency_baseline_uninitialized);
00505   suite_add_tcase(s, tc_core);
00506 
00507   return s;
00508 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:28