1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-02-19 04:20:08 +00:00

Completing tracking unit test with simulator-in-the-loop

This commit is contained in:
Javier Arribas 2017-02-02 18:10:24 +01:00
parent dc910bca4e
commit 37d78d3f12
2 changed files with 313 additions and 22 deletions

View File

@ -39,7 +39,6 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <numeric>
#include <armadillo>
#include <gnuradio/top_block.h>
#include <gnuradio/blocks/file_source.h>
@ -57,7 +56,6 @@
#include "tracking_interface.h"
#include "telemetry_decoder_interface.h"
#include "in_memory_configuration.h"
#include "gnss_sdr_valve.h"
#include "gnss_synchro.h"
#include "gps_l1_ca_telemetry_decoder.h"
@ -202,7 +200,6 @@ public:
std::string filename_rinex_obs = FLAGS_filename_rinex_obs;
std::string filename_raw_data = FLAGS_filename_raw_data;
std::string generated_rinex_obs;
int configure_generator();
int generate_signal();
@ -321,9 +318,15 @@ void GpsL1CATelemetryDecoderTest::check_results(arma::vec true_time_s,
double error_mean=arma::mean(err);
double error_var=arma::var(err);
//4. report
// 4. Peaks
double max_error=arma::max(err);
double min_error=arma::min(err);
std::cout<< std::setprecision(10)<<"Telemetry reported TOW RMSE="<<rmse<<" [s], mean="<<error_mean<<" [s], stdev="<<sqrt(error_var)<<" [s]."<<std::endl;
//5. report
std::cout<< std::setprecision(10)<<"TLM TOW RMSE="
<<rmse<<", mean="<<error_mean
<<", stdev="<<sqrt(error_var)<<" (max,min)="<<max_error<<","<<min_error<<" [Chips]"<<std::endl;
}

View File

@ -33,6 +33,8 @@
#include <ctime>
#include <iostream>
#include <unistd.h>
#include <armadillo>
#include <gnuradio/top_block.h>
#include <gnuradio/blocks/file_source.h>
#include <gnuradio/analog/sig_source_waveform.h>
@ -42,14 +44,28 @@
#include <gnuradio/blocks/null_sink.h>
#include <gnuradio/blocks/skiphead.h>
#include <gtest/gtest.h>
#include "GPS_L1_CA.h"
#include "gnss_block_factory.h"
#include "gnss_block_interface.h"
#include "tracking_interface.h"
#include "in_memory_configuration.h"
#include "gnss_sdr_valve.h"
#include "gnss_synchro.h"
#include "gps_l1_ca_dll_pll_tracking.h"
#include "../libs/tracking_true_obs_reader.h"
#include "../libs/tracking_dump_reader.h"
DECLARE_string(generator_binary);
DECLARE_string(rinex_nav_file);
DECLARE_int32(duration);
DECLARE_int32(fs_gen_hz);
DECLARE_string(static_position);
DECLARE_string(dynamic_position);
DECLARE_string(filename_rinex_obs);
DECLARE_string(filename_raw_data);
DECLARE_int32(test_satellite_PRN);
// ######## GNURADIO BLOCK MESSAGE RECEVER #########
class GpsL1CADllPllTrackingTest_msg_rx;
@ -106,7 +122,35 @@ GpsL1CADllPllTrackingTest_msg_rx::~GpsL1CADllPllTrackingTest_msg_rx()
class GpsL1CADllPllTrackingTest: public ::testing::Test
{
protected:
public:
std::string generator_binary;
std::string p1;
std::string p2;
std::string p3;
std::string p4;
std::string p5;
const int baseband_sampling_freq = FLAGS_fs_gen_hz;
std::string filename_rinex_obs = FLAGS_filename_rinex_obs;
std::string filename_raw_data = FLAGS_filename_raw_data;
int configure_generator();
int generate_signal();
void check_results_doppler(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value);
void check_results_acc_carrier_phase(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value);
void check_results_codephase(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value);
GpsL1CADllPllTrackingTest()
{
factory = std::make_shared<GNSSBlockFactory>();
@ -118,7 +162,7 @@ protected:
~GpsL1CADllPllTrackingTest()
{}
void init();
void configure_receiver();
gr::msg_queue::sptr queue;
gr::top_block_sptr top_block;
@ -129,15 +173,59 @@ protected:
};
void GpsL1CADllPllTrackingTest::init()
int GpsL1CADllPllTrackingTest::configure_generator()
{
// Configure signal generator
generator_binary = FLAGS_generator_binary;
p1 = std::string("-rinex_nav_file=") + FLAGS_rinex_nav_file;
if(FLAGS_dynamic_position.empty())
{
p2 = std::string("-static_position=") + FLAGS_static_position + std::string(",") + std::to_string(FLAGS_duration * 10);
}
else
{
p2 = std::string("-obs_pos_file=") + std::string(FLAGS_dynamic_position);
}
p3 = std::string("-rinex_obs_file=") + FLAGS_filename_rinex_obs; // RINEX 2.10 observation file output
p4 = std::string("-sig_out_file=") + FLAGS_filename_raw_data; // Baseband signal output file. Will be stored in int8_t IQ multiplexed samples
p5 = std::string("-sampling_freq=") + std::to_string(baseband_sampling_freq); //Baseband sampling frequency [MSps]
return 0;
}
int GpsL1CADllPllTrackingTest::generate_signal()
{
int child_status;
char *const parmList[] = { &generator_binary[0], &generator_binary[0], &p1[0], &p2[0], &p3[0], &p4[0], &p5[0], NULL };
int pid;
if ((pid = fork()) == -1)
perror("fork err");
else if (pid == 0)
{
execv(&generator_binary[0], parmList);
std::cout << "Return not expected. Must be an execv err." << std::endl;
std::terminate();
}
waitpid(pid, &child_status, 0);
std::cout << "Signal and Observables RINEX and RAW files created." << std::endl;
return 0;
}
void GpsL1CADllPllTrackingTest::configure_receiver()
{
gnss_synchro.Channel_ID = 0;
gnss_synchro.System = 'G';
std::string signal = "1C";
signal.copy(gnss_synchro.Signal, 2, 0);
gnss_synchro.PRN = 1;
gnss_synchro.PRN = FLAGS_test_satellite_PRN;
config->set_property("GNSS-SDR.internal_fs_hz", "2600000");
config->set_property("GNSS-SDR.internal_fs_hz", std::to_string(baseband_sampling_freq));
// Set Tracking
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
config->set_property("Tracking_1C.item_type", "gr_complex");
@ -145,26 +233,158 @@ void GpsL1CADllPllTrackingTest::init()
config->set_property("Tracking_1C.dump", "true");
config->set_property("Tracking_1C.dump_filename", "./tracking_ch_");
config->set_property("Tracking_1C.pll_bw_hz", "30.0");
config->set_property("Tracking_1C.dll_bw_hz", "4.0");
config->set_property("Tracking_1C.dll_bw_hz", "2.0");
config->set_property("Tracking_1C.early_late_space_chips", "0.5");
}
void GpsL1CADllPllTrackingTest::check_results_doppler(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value)
{
//1. True value interpolation to match the measurement times
arma::vec true_value_interp;
arma::interp1(true_time_s,true_value,meas_time_s,true_value_interp);
//2. RMSE
arma::vec err;
err=meas_value-true_value_interp;
arma::vec err2=arma::square(err);
double rmse=sqrt(arma::mean(err2));
//3. Mean err and variance
double error_mean=arma::mean(err);
double error_var=arma::var(err);
// 5. Peaks
double max_error=arma::max(err);
double min_error=arma::min(err);
//5. report
std::cout<< std::setprecision(10)<<"TRK Doppler RMSE="<<rmse
<<", mean="<<error_mean
<<", stdev="<<sqrt(error_var)<<" (max,min)="<<max_error<<","<<min_error<<" [Hz]"<<std::endl;
}
void GpsL1CADllPllTrackingTest::check_results_acc_carrier_phase(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value)
{
//1. True value interpolation to match the measurement times
arma::vec true_value_interp;
arma::interp1(true_time_s,true_value,meas_time_s,true_value_interp);
//2. RMSE
arma::vec err;
err=meas_value-true_value_interp;
arma::vec err2=arma::square(err);
double rmse=sqrt(arma::mean(err2));
//3. Mean err and variance
double error_mean=arma::mean(err);
double error_var=arma::var(err);
// 4. Peaks
double max_error=arma::max(err);
double min_error=arma::min(err);
//5. report
std::cout<< std::setprecision(10)<<"TRK acc carrier phase RMSE="<<rmse
<<", mean="<<error_mean
<<", stdev="<<sqrt(error_var)<<" (max,min)="<<max_error<<","<<min_error<<" [Hz]"<<std::endl;
}
void GpsL1CADllPllTrackingTest::check_results_codephase(arma::vec true_time_s,
arma::vec true_value,
arma::vec meas_time_s,
arma::vec meas_value)
{
//1. True value interpolation to match the measurement times
arma::vec true_value_interp;
arma::interp1(true_time_s,true_value,meas_time_s,true_value_interp);
//2. RMSE
arma::vec err;
err=meas_value-true_value_interp;
arma::vec err2=arma::square(err);
double rmse=sqrt(arma::mean(err2));
//3. Mean err and variance
double error_mean=arma::mean(err);
double error_var=arma::var(err);
// 4. Peaks
double max_error=arma::max(err);
double min_error=arma::min(err);
//5. report
std::cout<< std::setprecision(10)<<"TRK code phase RMSE="<<rmse
<<", mean="<<error_mean
<<", stdev="<<sqrt(error_var)<<" (max,min)="<<max_error<<","<<min_error<<" [Chips]"<<std::endl;
}
TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults)
{
// Configure the signal generator
configure_generator();
// Generate signal raw signal samples and observations RINEX file
generate_signal();
struct timeval tv;
long long int begin = 0;
long long int end = 0;
int fs_in = 2600000;
//int nsamples = fs_in*3;
init();
configure_receiver();
//open true observables log file written by the simulator
tracking_true_obs_reader true_obs_data;
int test_satellite_PRN = FLAGS_test_satellite_PRN;
std::cout<<"Testing satellite PRN="<<test_satellite_PRN<<std::endl;
std::string true_obs_file=std::string("./gps_l1_ca_obs_prn");
true_obs_file.append(std::to_string(test_satellite_PRN));
true_obs_file.append(".dat");
ASSERT_NO_THROW({
if (true_obs_data.open_obs_file(true_obs_file)==false)
{
throw std::exception();
};
})<< "Failure opening true observables file" << std::endl;
queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Tracking test");
std::shared_ptr<TrackingInterface> tracking = std::make_shared<GpsL1CaDllPllTracking>(config.get(), "Tracking_1C", 1, 1);
//std::shared_ptr<TrackingInterface> tracking = std::make_shared<GpsL1CaDllPllCAidTracking>(config.get(), "Tracking_1C", 1, 1);
boost::shared_ptr<GpsL1CADllPllTrackingTest_msg_rx> msg_rx = GpsL1CADllPllTrackingTest_msg_rx_make();
gnss_synchro.Acq_delay_samples = (1023-994.622/1023)*fs_in*1e-3;
gnss_synchro.Acq_doppler_hz = -2583.86;
// load acquisition data based on the first epoch of the true observations
ASSERT_NO_THROW({
if (true_obs_data.read_binary_obs()==false)
{
throw std::exception();
};
})<< "Failure reading true observables file" << std::endl;
//restart the epoch counter
true_obs_data.restart();
std::cout<<"Initial Doppler [Hz]="<<true_obs_data.doppler_l1_hz<<" Initial code delay [Chips]="<<true_obs_data.prn_delay_chips<<std::endl;
gnss_synchro.Acq_delay_samples = (GPS_L1_CA_CODE_LENGTH_CHIPS-true_obs_data.prn_delay_chips/GPS_L1_CA_CODE_LENGTH_CHIPS)*baseband_sampling_freq*GPS_L1_CA_CODE_PERIOD;
gnss_synchro.Acq_doppler_hz = true_obs_data.doppler_l1_hz;
gnss_synchro.Acq_samplestamp_samples = 0;
ASSERT_NO_THROW( {
@ -180,15 +400,12 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults)
}) << "Failure connecting tracking to the top_block." << std::endl;
ASSERT_NO_THROW( {
std::string path = std::string(TEST_PATH);
std::string file = path + "signal_samples/gps_l1ca_prn1_2.6msps.dat";
std::string file = "./" + filename_raw_data;
const char * file_name = file.c_str();
gr::blocks::file_source::sptr file_source = gr::blocks::file_source::make(sizeof(int8_t), file_name, false);
//boost::shared_ptr<gr::block> valve = gnss_sdr_make_valve(sizeof(gr_complex), nsamples, queue);
gr::blocks::interleaved_char_to_complex::sptr gr_interleaved_char_to_complex = gr::blocks::interleaved_char_to_complex::make();
gr::blocks::null_sink::sptr sink = gr::blocks::null_sink::make(sizeof(Gnss_Synchro));
top_block->connect(file_source, 0, gr_interleaved_char_to_complex, 0);
//top_block->connect(gr_interleaved_char_to_complex, 0, valve, 0);
top_block->connect(gr_interleaved_char_to_complex, 0, tracking->get_left_block(), 0);
top_block->connect(tracking->get_right_block(), 0, sink, 0);
top_block->msg_connect(tracking->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events"));
@ -204,7 +421,78 @@ TEST_F(GpsL1CADllPllTrackingTest, ValidationOfResults)
end = tv.tv_sec *1000000 + tv.tv_usec;
}) << "Failure running the top_block." << std::endl;
// TODO: Verify tracking results
//check results
//load the true values
long int nepoch =true_obs_data.num_epochs();
std::cout<<"True observation epochs="<<nepoch<<std::endl;
arma::vec true_timestamp_s=arma::zeros(nepoch,1);
arma::vec true_acc_carrier_phase_cycles=arma::zeros(nepoch,1);
arma::vec true_Doppler_Hz=arma::zeros(nepoch,1);
arma::vec true_prn_delay_chips=arma::zeros(nepoch,1);
arma::vec true_tow_s=arma::zeros(nepoch,1);
long int epoch_counter=0;
while(true_obs_data.read_binary_obs())
{
true_timestamp_s(epoch_counter)=true_obs_data.signal_timestamp_s;
true_acc_carrier_phase_cycles(epoch_counter)=true_obs_data.acc_carrier_phase_cycles;
true_Doppler_Hz(epoch_counter)=true_obs_data.doppler_l1_hz;
true_prn_delay_chips(epoch_counter)=true_obs_data.prn_delay_chips;
true_tow_s(epoch_counter)=true_obs_data.tow;
epoch_counter++;
}
//load the measured values
tracking_dump_reader trk_dump;
ASSERT_NO_THROW({
if (trk_dump.open_obs_file(std::string("./tracking_ch_0.dat"))==false)
{
throw std::exception();
};
})<< "Failure opening tracking dump file" << std::endl;
nepoch =trk_dump.num_epochs();
std::cout<<"Measured observation epochs="<<nepoch<<std::endl;
arma::vec trk_timestamp_s=arma::zeros(nepoch,1);
arma::vec trk_acc_carrier_phase_cycles=arma::zeros(nepoch,1);
arma::vec trk_Doppler_Hz=arma::zeros(nepoch,1);
arma::vec trk_prn_delay_chips=arma::zeros(nepoch,1);
epoch_counter=0;
while(trk_dump.read_binary_obs())
{
trk_timestamp_s(epoch_counter)=static_cast<double>(trk_dump.PRN_start_sample_count)/static_cast<double>(baseband_sampling_freq);
trk_acc_carrier_phase_cycles(epoch_counter)=trk_dump.acc_carrier_phase_rad/GPS_TWO_PI;
trk_Doppler_Hz(epoch_counter)=trk_dump.carrier_doppler_hz;
double delay_chips=GPS_L1_CA_CODE_LENGTH_CHIPS
-GPS_L1_CA_CODE_LENGTH_CHIPS
*(fmod((static_cast<double>(trk_dump.PRN_start_sample_count)+trk_dump.aux1)/static_cast<double>(baseband_sampling_freq),1.0e-3)/1.0e-3);
trk_prn_delay_chips(epoch_counter)=delay_chips;
epoch_counter++;
}
//Align initial measurements and cut the tracking pull-in transitory
double pull_in_offset_s=1.0;
arma::uvec initial_meas_point = arma::find(trk_timestamp_s >= (true_timestamp_s(0)+pull_in_offset_s), 1, "first");
trk_timestamp_s=trk_timestamp_s.subvec(initial_meas_point(0),trk_timestamp_s.size()-1);
trk_acc_carrier_phase_cycles=trk_acc_carrier_phase_cycles.subvec(initial_meas_point(0),trk_acc_carrier_phase_cycles.size()-1);
trk_Doppler_Hz=trk_Doppler_Hz.subvec(initial_meas_point(0),trk_Doppler_Hz.size()-1);
trk_prn_delay_chips=trk_prn_delay_chips.subvec(initial_meas_point(0),trk_prn_delay_chips.size()-1);
check_results_doppler(true_timestamp_s,true_Doppler_Hz,trk_timestamp_s,trk_Doppler_Hz);
check_results_codephase(true_timestamp_s,true_prn_delay_chips,trk_timestamp_s,trk_prn_delay_chips);
check_results_acc_carrier_phase(true_timestamp_s,true_acc_carrier_phase_cycles,trk_timestamp_s,trk_acc_carrier_phase_cycles);
std::cout << "Signal tracking completed in " << (end - begin) << " microseconds" << std::endl;
}