From c2c96e53914a7e64dbedd3a7afbfe2410e83c8b2 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 24 Dec 2016 15:58:04 +0100 Subject: [PATCH] read and compare measurements --- src/tests/system-tests/trk_system_test.cc | 262 ++++++++++++++-------- 1 file changed, 171 insertions(+), 91 deletions(-) diff --git a/src/tests/system-tests/trk_system_test.cc b/src/tests/system-tests/trk_system_test.cc index d223229f7..6af4a87fd 100644 --- a/src/tests/system-tests/trk_system_test.cc +++ b/src/tests/system-tests/trk_system_test.cc @@ -321,7 +321,6 @@ int Trk_System_Test::run_receiver() { std::cout << "STD exception: " << ex.what(); } - // Get the name of the RINEX obs file generated by the receiver FILE *fp; std::string argum2 = std::string("/bin/ls *O | tail -1"); @@ -339,62 +338,58 @@ int Trk_System_Test::run_receiver() } generated_rinex_obs = std::string(without_trailing); pclose(fp); + return 0; } void Trk_System_Test::check_results() { - std::vector> > pseudorange_ref(33); - std::vector> > carrierphase_ref(33); + std::vector> > pseudorange_ref(33); + std::vector> > carrierphase_ref(33); - std::vector> > pseudorange_meas(33); - std::vector> > carrierphase_meas(33); + std::vector> > pseudorange_meas(33); + std::vector> > carrierphase_meas(33); - // Open reference RINEX observables file + // Open and read reference RINEX observables file try { - gpstk::Rinex3ObsStream r_ref(FLAGS_filename_rinex_obs); - r_ref.exceptions(std::ios::failbit); - gpstk::Rinex3ObsData r_ref_data; - gpstk::Rinex3ObsHeader r_ref_header; + gpstk::Rinex3ObsStream r_ref(FLAGS_filename_rinex_obs); + r_ref.exceptions(std::ios::failbit); + gpstk::Rinex3ObsData r_ref_data; + gpstk::Rinex3ObsHeader r_ref_header; - gpstk::RinexDatum dataobj; + gpstk::RinexDatum dataobj; - r_ref >> r_ref_header; + r_ref >> r_ref_header; - while (r_ref >> r_ref_data) - { - for (int myprn = 1; myprn < 33; myprn++) - { - gpstk::SatID prn( myprn, gpstk::SatID::systemGPS ); - //std::cout << " PRN " << myprn << std::endl; - gpstk::CommonTime time = r_ref_data.time; - //std::cout << time << " " << std::endl; - double sow(static_cast(time).sow); - //std::cout << "Time: " << sow << std::endl; - - gpstk::Rinex3ObsData::DataMap::iterator pointer = r_ref_data.obs.find(prn); - if( pointer == r_ref_data.obs.end() ) + while (r_ref >> r_ref_data) { - // PRN not present; do nothing - } - else - { - dataobj = r_ref_data.getObs(prn, "P1", r_ref_header); - double P1 = dataobj.data; - std::map pseudo; - pseudo[sow] = P1; - pseudorange_ref.at(myprn).push_back(pseudo); + for (int myprn = 1; myprn < 33; myprn++) + { + gpstk::SatID prn( myprn, gpstk::SatID::systemGPS ); + gpstk::CommonTime time = r_ref_data.time; + double sow(static_cast(time).sow); - dataobj = r_ref_data.getObs(prn, "L1C", r_ref_header); - double L1 = dataobj.data; - std::map carrier; - carrier[sow]= L1; - carrierphase_ref.at(myprn).push_back(carrier); - } // End of 'if( pointer == roe.obs.end() )' - } // end for - } // end while + gpstk::Rinex3ObsData::DataMap::iterator pointer = r_ref_data.obs.find(prn); + if( pointer == r_ref_data.obs.end() ) + { + // PRN not present; do nothing + } + else + { + dataobj = r_ref_data.getObs(prn, "P1", r_ref_header); + double P1 = dataobj.data; + std::pair pseudo(sow,P1); + pseudorange_ref.at(myprn).push_back(pseudo); + + dataobj = r_ref_data.getObs(prn, "L1C", r_ref_header); + double L1 = dataobj.data; + std::pair carrier(sow, L1); + carrierphase_ref.at(myprn).push_back(carrier); + } // End of 'if( pointer == roe.obs.end() )' + } // end for + } // end while } // End of 'try' block catch(gpstk::FFStreamError& e) { @@ -413,58 +408,54 @@ void Trk_System_Test::check_results() } // Example: count observations per sat: - std::vector> >::iterator iter; + /* std::vector> >::iterator iter; int prn_id=0; for(iter = pseudorange_ref.begin(); iter != pseudorange_ref.end(); iter++) - { - double size_v = iter->size(); - std::cout << "Size for sat " << prn_id << ": " << size_v << std::endl; - prn_id++; - } + { + double size_v = iter->size(); + std::cout << "Size for sat " << prn_id << ": " << size_v << std::endl; + prn_id++; + }*/ - // Open GNSS-SDR-generated RINEX observables file + // Open and read GNSS-SDR-generated RINEX observables file try { - std::string arg2_gen = std::string("./") + generated_rinex_obs; - gpstk::Rinex3ObsStream r_meas(arg2_gen); - gpstk::Rinex3ObsData r_meas_data; - gpstk::Rinex3ObsHeader r_meas_header; - gpstk::RinexDatum dataobj; + std::string arg2_gen = std::string("./") + generated_rinex_obs; + gpstk::Rinex3ObsStream r_meas(arg2_gen); + r_meas.exceptions(std::ios::failbit); + gpstk::Rinex3ObsData r_meas_data; + gpstk::Rinex3ObsHeader r_meas_header; + gpstk::RinexDatum dataobj; - r_meas >> r_meas_header; + r_meas >> r_meas_header; - while (r_meas >> r_meas_data) - { - for (int myprn = 1; myprn < 33; myprn++) - { - gpstk::SatID prn( myprn, gpstk::SatID::systemGPS ); - //std::cout << " PRN " << myprn << std::endl; - gpstk::CommonTime time = r_meas_data.time; - //std::cout << time << " " << std::endl; - double sow(static_cast(time).sow); - //std::cout << "Time: " << sow << std::endl; - - gpstk::Rinex3ObsData::DataMap::iterator pointer = r_meas_data.obs.find(prn); - if( pointer == r_meas_data.obs.end() ) + while (r_meas >> r_meas_data) { - // PRN not present; do nothing - } - else - { - dataobj = r_meas_data.getObs(prn, "C1", r_meas_header); - double P1 = dataobj.data; - std::map pseudo; - pseudo[sow] = P1; - pseudorange_meas.at(myprn).push_back(pseudo); + for (int myprn = 1; myprn < 33; myprn++) + { + gpstk::SatID prn( myprn, gpstk::SatID::systemGPS ); + gpstk::CommonTime time = r_meas_data.time; + double sow(static_cast(time).sow); - dataobj = r_meas_data.getObs(prn, "L1C", r_meas_header); - double L1 = dataobj.data; - std::map carrier; - carrier[sow]= L1; - carrierphase_meas.at(myprn).push_back(carrier); - } // End of 'if( pointer == roe.obs.end() )' - } // end for - } // end while + gpstk::Rinex3ObsData::DataMap::iterator pointer = r_meas_data.obs.find(prn); + if( pointer == r_meas_data.obs.end() ) + { + // PRN not present; do nothing + } + else + { + dataobj = r_meas_data.getObs(prn, "C1", r_meas_header); + double P1 = dataobj.data; + std::pair pseudo(sow, P1); + pseudorange_meas.at(myprn).push_back(pseudo); + + dataobj = r_meas_data.getObs(prn, "L1C", r_meas_header); + double L1 = dataobj.data; + std::pair carrier(sow,L1); + carrierphase_meas.at(myprn).push_back(carrier); + } // End of 'if( pointer == roe.obs.end() )' + } // end for + } // end while } // End of 'try' block catch(gpstk::FFStreamError& e) { @@ -482,19 +473,108 @@ void Trk_System_Test::check_results() exit(1); } - // Time alignment! + // Time alignment + std::vector> > pseudorange_ref_aligned(33); + std::vector> > carrierphase_ref_aligned(33); - // Read reference pseudoranges from a given satellite + std::vector> >::iterator iter; + std::vector>::iterator it; + std::vector>::iterator it2; - // Read obtained pseudoranges from a given satellite + std::vector> pr_diff(33); + std::vector> cp_diff(33); + + std::vector>::iterator iter_diff; + std::vector::iterator iter_v; + + int prn_id = 0; + for(iter = pseudorange_ref.begin(); iter != pseudorange_ref.end(); iter++) + { + for(it = iter->begin(); it != iter->end(); it++) + { + // If a measure exists for this sow, store it + for(it2 = pseudorange_meas.at(prn_id).begin(); it2 != pseudorange_meas.at(prn_id).end(); it2++) + { + if(std::abs(it->first - it2->first) < 0.001) // store measures closer than 1 ms. + { + pseudorange_ref_aligned.at(prn_id).push_back(*it); + pr_diff.at(prn_id).push_back(it->second - it2->second ); + } + } + } + prn_id++; + } + + prn_id = 0; + for(iter = carrierphase_ref.begin(); iter != carrierphase_ref.end(); iter++) + { + for(it = iter->begin(); it != iter->end(); it++) + { + // If a measure exists for this sow, store it + for(it2 = carrierphase_meas.at(prn_id).begin(); it2 != carrierphase_meas.at(prn_id).end(); it2++) + { + if(std::abs(it->first - it2->first) < 0.001) // store measures closer than 1 ms. + { + carrierphase_ref_aligned.at(prn_id).push_back(*it); + cp_diff.at(prn_id).push_back(it->second - it2->second ); + } + } + } + prn_id++; + } // Compute pseudorange error + prn_id = 0; + for(iter_diff = pr_diff.begin(); iter_diff != pr_diff.end(); iter_diff++) + { + // For each satellite with reference and measurements aligned in time + int number_obs = 0; + double mean_diff = 0.0; + for(iter_v = iter_diff->begin(); iter_v != iter_diff->end(); iter_v++) + { + //std::cout << *iter_v << std::endl; + mean_diff = mean_diff + *iter_v; + number_obs = number_obs + 1; + } + if(number_obs > 0) + { + mean_diff = mean_diff / number_obs; + std::cout << "-- Mean pseudorange difference for sat " << prn_id << ": " << mean_diff << std::endl; + } + else + { + mean_diff = 0.0; + } - // Read reference carrier phase from a given satellite - - // Read obtained carrier phase from a given satellite + prn_id++; + } // Compute carrier phase error + prn_id = 0; + for(iter_diff = cp_diff.begin(); iter_diff != cp_diff.end(); iter_diff++) + { + // For each satellite with reference and measurements aligned in time + int number_obs = 0; + double mean_diff = 0.0; + for(iter_v = iter_diff->begin(); iter_v != iter_diff->end(); iter_v++) + { + //std::cout << *iter_v << std::endl; + mean_diff = mean_diff + *iter_v; + number_obs = number_obs + 1; + } + if(number_obs > 0) + { + mean_diff = mean_diff / number_obs; + std::cout << "-- Mean carrier phase difference for sat " << prn_id << ": " << mean_diff << std::endl; + } + else + { + mean_diff = 0.0; + } + + prn_id++; + } + //return 0; }