Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit eff3d24

Browse files
committed
add raim_flag to gnss_solution, clarify dgnss_baseline
1 parent f9d21e4 commit eff3d24

File tree

6 files changed

+62
-19
lines changed

6 files changed

+62
-19
lines changed

include/libswiftnav/dgnss_management.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ s8 dgnss_iar_get_single_hyp(double *hyp);
6262
void dgnss_reset_iar(void);
6363
void dgnss_init_known_baseline(u8 num_sats, sdiff_t *sdiffs, double receiver_ecef[3], double b[3]);
6464
void dgnss_update_ambiguity_state(ambiguity_state_t *s);
65+
u8 baseline_flag(s8 ret, bool fixed);
6566
s8 dgnss_baseline(u8 num_sdiffs, const sdiff_t *sdiffs,
6667
const double ref_ecef[3], const ambiguity_state_t *s,
6768
u8 *num_used, double b[3],

include/libswiftnav/pvt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ typedef struct __attribute__((packed)) {
7777
u8 valid;
7878
/* Number of channels used in the soluton. */
7979
u8 n_used;
80+
/* bit 0: raim available?
81+
* bit 1: raim repair used?
82+
*/
83+
u8 raim_flag;
8084
} gnss_solution;
8185

8286
s8 calc_PVT(const u8 n_used,

src/dgnss_management.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,23 @@ void dgnss_update_ambiguity_state(ambiguity_state_t *s)
395395
}
396396
}
397397

398+
/** Formats flag bits for sbp.
399+
* bit positions:
400+
* -`0`: fixed mode?
401+
* -`3`: RAIM available?
402+
* -`4`: RAIM repair used?
403+
*
404+
* \param ret return code from baseline()
405+
* \param fixed 1 for fixed, 0 for float
406+
* \return formatted flag value
407+
*/
408+
u8 baseline_flag(s8 ret, bool fixed)
409+
{
410+
return (ret == 1) << 4 /* RAIM repair? */
411+
| (ret != 2) << 3 /* RAIM available? */
412+
| fixed; /* Fixed mode? */
413+
}
414+
398415
/** Finds the baseline using low latency sdiffs.
399416
* The low latency sdiffs are not guaranteed to match up with either the
400417
* amb_test's or the float sdiffs, and thus care must be taken to transform them
@@ -410,37 +427,43 @@ void dgnss_update_ambiguity_state(ambiguity_state_t *s)
410427
* \param b Output baseline.
411428
* \param disable_raim Flag to turn off raim checks/repair.
412429
* \param raim_threshold raim check threshold
413-
* \return 1 if we are using an IAR resolved baseline.
414-
* 2 if we are using a float baseline.
415-
* -1 if we can't give a baseline.
430+
* \return positive value: SBP baseline msg flags
431+
* negative value: baseline error code
416432
*/
417433
s8 dgnss_baseline(u8 num_sdiffs, const sdiff_t *sdiffs,
418434
const double ref_ecef[3], const ambiguity_state_t *s,
419435
u8 *num_used, double b[3],
420436
bool disable_raim, double raim_threshold)
421437
{
422-
s8 ret = baseline(num_sdiffs, sdiffs, ref_ecef, &s->fixed_ambs, num_used, b,
438+
s8 ret;
439+
440+
/* Try IAR resolved baseline */
441+
ret = baseline(num_sdiffs, sdiffs, ref_ecef, &s->fixed_ambs, num_used, b,
423442
disable_raim, raim_threshold);
424443
if (ret >= 0) {
425-
if (ret == 1) /* TODO: Export this rather than just printing */
444+
if (ret == 1)
426445
log_warn("dgnss_baseline: Fixed baseline RAIM repair");
427446
log_debug("fixed solution");
428447
DEBUG_EXIT();
429-
return 1;
448+
return baseline_flag(ret, true);
430449
}
450+
431451
/* We weren't able to get an IAR resolved baseline, check if we can get a
432452
* float baseline. */
433-
if ((ret = baseline(num_sdiffs, sdiffs, ref_ecef, &s->float_ambs, num_used, b,
434-
disable_raim, raim_threshold))
435-
>= 0) {
436-
if (ret == 1) /* TODO: Export this rather than just printing */
453+
ret = baseline(num_sdiffs, sdiffs, ref_ecef, &s->float_ambs, num_used, b,
454+
disable_raim, raim_threshold);
455+
if (ret >= 0) {
456+
if (ret == 1)
437457
log_warn("dgnss_baseline: Float baseline RAIM repair");
438458
log_debug("float solution");
439459
DEBUG_EXIT();
440-
return 2;
460+
return baseline_flag(ret, false);
441461
}
442462
log_debug("no baseline solution");
443463
DEBUG_EXIT();
464+
465+
/* Must be negative! */
466+
assert(ret < 0);
444467
return ret;
445468
}
446469

src/pvt.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,26 @@ s8 calc_PVT(const u8 n_used,
536536
soln->n_used = n_used; // Keep track of number of working channels
537537

538538
u8 removed_prn = -1;
539-
s8 raim_flag = pvt_solve_raim(rx_state, n_used, nav_meas, disable_raim,
540-
H, &removed_prn, 0);
539+
s8 code = pvt_solve_raim(rx_state, n_used, nav_meas, disable_raim,
540+
H, &removed_prn, 0);
541541

542-
if (raim_flag < 0) {
542+
if (code < 0) {
543543
/* Didn't converge or least squares integrity check failed. */
544-
return raim_flag - 3;
544+
return code - 3;
545545
}
546546

547+
soln->raim_flag = 0;
548+
547549
/* Initial solution failed, but repair was successful. */
548-
if (raim_flag == 1) {
550+
if (code == 1) {
549551
soln->n_used--;
552+
soln->raim_flag = (1 << 1) | 1; /* 11 */
553+
} else if (code == 2) {
554+
soln->raim_flag = 0; /* 00 */
555+
} else if (code == 0) {
556+
soln->raim_flag = 1; /* 01 */
557+
} else {
558+
log_error("Invalid pvt_solve_raim return code: %d\n", code);
550559
}
551560

552561
/* Compute various dilution of precision metrics. */
@@ -597,6 +606,6 @@ s8 calc_PVT(const u8 n_used,
597606

598607
soln->valid = 1;
599608

600-
return raim_flag;
609+
return code;
601610
}
602611

tests/check_dgnss_management.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ START_TEST(test_dgnss_baseline_1)
212212
s.fixed_ambs.n = 0;
213213
s8 valid = dgnss_baseline(num_sdiffs, sdiffs, ref_ecef, &s, &num_used, b,
214214
false, DEFAULT_RAIM_THRESHOLD);
215-
fail_unless(valid == 2);
215+
/* baseline_flag(initial solution ok, float mode) */
216+
fail_unless(valid == baseline_flag(0, false));
216217
fail_unless(num_used == 5);
217218
fail_unless(within_epsilon(b[0], -0.742242));
218219
fail_unless(within_epsilon(b[1], -0.492905));
@@ -222,7 +223,8 @@ START_TEST(test_dgnss_baseline_1)
222223
s.fixed_ambs.n = 4;
223224
valid = dgnss_baseline(num_sdiffs, sdiffs, ref_ecef, &s, &num_used, b,
224225
false, DEFAULT_RAIM_THRESHOLD);
225-
fail_unless(valid == 1);
226+
/* baseline_flag(initial solution ok, fixed mode) */
227+
fail_unless(valid == baseline_flag(0, true));
226228
fail_unless(num_used == 5);
227229
fail_unless(within_epsilon(b[0], -0.417486));
228230
fail_unless(within_epsilon(b[1], -0.358386));

tests/check_pvt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ START_TEST(test_pvt_repair)
8686
s8 code = calc_PVT(n_used, nms, false, &soln, &dops);
8787
fail_unless(code == 1,
8888
"Return code should be 1 (pvt repair). Saw: %d\n", code);
89+
fail_unless(soln.raim_flag == 3,
90+
"raim_flag should be 11, saw: %d\n", soln.raim_flag);
8991
fail_unless(soln.n_used == n_used - 1,
9092
"PVT solver failed to repair solution.");
9193
}
@@ -104,6 +106,8 @@ START_TEST(test_disable_pvt_raim)
104106
s8 code = calc_PVT(n_used, nms, true, &soln, &dops);
105107
fail_unless(code == 2,
106108
"Return code should be 2 (raim not used). Saw: %d\n", code);
109+
fail_unless(soln.raim_flag == 0,
110+
"raim_flag should be 00, saw: %d\n", soln.raim_flag);
107111
fail_unless(soln.valid == 1,
108112
"Solution should be valid!");
109113
}

0 commit comments

Comments
 (0)