Beispiel #1
0
void dgnss_update(u8 num_sats, sdiff_t *sdiffs, double receiver_ecef[3],
                  bool disable_raim, double raim_threshold)
{
  DEBUG_ENTRY();
  if (DEBUG) {
    printf("sdiff[*].prn = {");
    for (u8 i=0; i < num_sats; i++) {
      printf("%u, ", sdiffs[i].sid.sat);
    }
    printf("}\n");
  }

  if (num_sats <= 1) {
    sats_management.num_sats = num_sats;
    if (num_sats == 1) {
      sats_management.sids[0] = sdiffs[0].sid;
    }
    create_ambiguity_test(&ambiguity_test);
    DEBUG_EXIT();
    return;
  }

  if (sats_management.num_sats <= 1) {
    dgnss_init(num_sats, sdiffs, receiver_ecef);
  }

  sdiff_t sdiffs_with_ref_first[num_sats];

  gnss_signal_t old_sids[MAX_CHANNELS];
  memcpy(old_sids, sats_management.sids, sats_management.num_sats * sizeof(gnss_signal_t));

  /* rebase globals to a new reference sat
   * (permutes sdiffs_with_ref_first accordingly) */
  dgnss_rebase_ref(num_sats, sdiffs, receiver_ecef, old_sids, sdiffs_with_ref_first);

  double dd_measurements[2*(num_sats-1)];
  make_measurements(num_sats-1, sdiffs_with_ref_first, dd_measurements);

  /* all the added/dropped sat stuff */
  dgnss_update_sats(num_sats, receiver_ecef, sdiffs_with_ref_first, dd_measurements);

  /* Unless the KF says otherwise, DONT TRUST THE MEASUREMENTS */
  u8 is_bad_measurement = true;

  double ref_ecef[3];
  if (num_sats >= 5) {
    double b2[3];
    s8 code = least_squares_solve_b_external_ambs(nkf.state_dim, nkf.state_mean,
        sdiffs_with_ref_first, dd_measurements, receiver_ecef, b2,
        disable_raim, raim_threshold);

    if (code < 0) {
      log_warn("dgnss_update. baseline estimate error: %d", code);
      /* Use b = 0, continue */
      memset(b2, 0, sizeof(b2));
    }

    double ref_ecef[3];

    vector_add_sc(3, receiver_ecef, b2, 0.5, ref_ecef);

    /* TODO: make a common DE and use it instead. */

    set_nkf_matrices(&nkf,
                     dgnss_settings.phase_var_kf, dgnss_settings.code_var_kf,
                     sats_management.num_sats, sdiffs_with_ref_first, ref_ecef);

    is_bad_measurement = nkf_update(&nkf, dd_measurements);
  }

  u8 changed_sats = ambiguity_update_sats(&ambiguity_test, num_sats, sdiffs,
                                          &sats_management, nkf.state_mean,
                                          nkf.state_cov_U, nkf.state_cov_D,
                                          is_bad_measurement);

  /* TODO: Refactor - looks like ref_ecef can be passed in uninitialized */
  if (!is_bad_measurement) {
    update_ambiguity_test(ref_ecef,
                          dgnss_settings.phase_var_test,
                          dgnss_settings.code_var_test,
                          &ambiguity_test, nkf.state_dim,
                          sdiffs, changed_sats);
  }

  update_unanimous_ambiguities(&ambiguity_test);

  DEBUG_EXIT();
}
void dgnss_update(u8 num_sats, sdiff_t *sdiffs, double reciever_ecef[3])
{
  DEBUG_ENTRY();
  if (DEBUG) {
    printf("sdiff[*].prn = {");
    for (u8 i=0; i < num_sats; i++) {
      printf("%u, ",sdiffs[i].prn);
    }
    printf("}\n");
  }

  if (num_sats <= 1) {
    sats_management.num_sats = num_sats;
    if (num_sats == 1) {
      sats_management.prns[0] = sdiffs[0].prn;
    }
    create_ambiguity_test(&ambiguity_test);
    DEBUG_EXIT();
    return;
  }

  if (sats_management.num_sats <= 1) {
    dgnss_init(num_sats, sdiffs, reciever_ecef);
  }

  sdiff_t sdiffs_with_ref_first[num_sats];

  u8 old_prns[MAX_CHANNELS];
  memcpy(old_prns, sats_management.prns, sats_management.num_sats * sizeof(u8));

  /* rebase globals to a new reference sat
   * (permutes sdiffs_with_ref_first accordingly) */
  dgnss_rebase_ref(num_sats, sdiffs, reciever_ecef, old_prns, sdiffs_with_ref_first);

  double dd_measurements[2*(num_sats-1)];
  make_measurements(num_sats-1, sdiffs_with_ref_first, dd_measurements);

  /* all the added/dropped sat stuff */
  dgnss_update_sats(num_sats, reciever_ecef, sdiffs_with_ref_first, dd_measurements);

  double ref_ecef[3];
  if (num_sats >= 5) {
    dgnss_incorporate_observation(sdiffs_with_ref_first, dd_measurements, reciever_ecef);

    double b2[3];
    least_squares_solve_b(&nkf, sdiffs_with_ref_first, dd_measurements, reciever_ecef, b2);

    ref_ecef[0] = reciever_ecef[0] + 0.5 * b2[0];
    ref_ecef[1] = reciever_ecef[1] + 0.5 * b2[1];
    ref_ecef[2] = reciever_ecef[2] + 0.5 * b2[2];
  }

  u8 changed_sats = ambiguity_update_sats(&ambiguity_test, num_sats, sdiffs,
                                          &sats_management, nkf.state_mean,
                                          nkf.state_cov_U, nkf.state_cov_D);

  update_ambiguity_test(ref_ecef,
                        dgnss_settings.phase_var_test,
                        dgnss_settings.code_var_test,
                        &ambiguity_test, nkf.state_dim,
                        sdiffs, changed_sats);

  update_unanimous_ambiguities(&ambiguity_test);

  if (DEBUG) {
    if (num_sats >=4) {
      double b3[3];
      least_squares_solve_b(&nkf, sdiffs_with_ref_first, dd_measurements, reciever_ecef, b3);

      ref_ecef[0] = reciever_ecef[0] + 0.5 * b3[0];
      ref_ecef[1] = reciever_ecef[1] + 0.5 * b3[1];
      ref_ecef[2] = reciever_ecef[2] + 0.5 * b3[2];
      double bb[3];
      u8 num_used;
      dgnss_fixed_baseline(num_sats, sdiffs, ref_ecef,
                           &num_used, bb);
      log_debug("\ndgnss_fixed_baseline:\nb = %f, \t%f, \t%f\nnum_used/num_sats = %u/%u\nusing_iar = %u\n\n",
             bb[0], bb[1], bb[2],
             num_used, num_sats,
             ambiguity_iar_can_solve(&ambiguity_test));
    }
  }
  DEBUG_EXIT();
}