From 3071aa1fcdeae57b03885db2dbf9951c264fb2b2 Mon Sep 17 00:00:00 2001 From: Cillian O'Driscoll Date: Mon, 4 Nov 2019 17:16:20 +0000 Subject: [PATCH] [WIP] Simplifying acquisition config --- .../adapters/gps_l1_ca_pcps_acquisition.cc | 111 ++++------------- src/algorithms/acquisition/libs/acq_conf.cc | 112 ++++++++++++++++-- src/algorithms/acquisition/libs/acq_conf.h | 16 ++- 3 files changed, 139 insertions(+), 100 deletions(-) diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc index 7e85ad3c6..4ed4e9c2d 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc @@ -33,11 +33,11 @@ * ------------------------------------------------------------------------- */ -#include "gps_l1_ca_pcps_acquisition.h" #include "GPS_L1_CA.h" #include "acq_conf.h" #include "configuration_interface.h" #include "gnss_sdr_flags.h" +#include "gps_l1_ca_pcps_acquisition.h" #include "gps_sdr_signal_processing.h" #include #include @@ -54,92 +54,25 @@ GpsL1CaPcpsAcquisition::GpsL1CaPcpsAcquisition( out_streams_(out_streams) { configuration_ = configuration; - std::string default_item_type = "gr_complex"; - std::string default_dump_filename = "./acquisition.mat"; + acq_parameters_.ms_per_code = 1; + acq_parameters_.SetFromConfiguration( configuration_, role, GPS_L1_CA_CODE_RATE_CPS, GPS_L1_CA_OPT_ACQ_FS_SPS ); DLOG(INFO) << "role " << role; - item_type_ = configuration_->property(role + ".item_type", default_item_type); - int64_t fs_in_deprecated = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000); - fs_in_ = configuration_->property("GNSS-SDR.internal_fs_sps", fs_in_deprecated); - acq_parameters_.fs_in = fs_in_; - dump_ = configuration_->property(role + ".dump", false); - acq_parameters_.dump = dump_; - acq_parameters_.dump_channel = configuration_->property(role + ".dump_channel", 0); - blocking_ = configuration_->property(role + ".blocking", true); - acq_parameters_.blocking = blocking_; - doppler_max_ = configuration_->property(role + ".doppler_max", 5000); - if (FLAGS_doppler_max != 0) - { - doppler_max_ = FLAGS_doppler_max; - } - acq_parameters_.doppler_max = doppler_max_; - sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1); - acq_parameters_.sampled_ms = sampled_ms_; - acq_parameters_.ms_per_code = 1; - bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false); - acq_parameters_.bit_transition_flag = bit_transition_flag_; - use_CFAR_algorithm_flag_ = configuration_->property(role + ".use_CFAR_algorithm", true); // will be false in future versions - acq_parameters_.use_CFAR_algorithm_flag = use_CFAR_algorithm_flag_; - max_dwells_ = configuration_->property(role + ".max_dwells", 1); - acq_parameters_.max_dwells = max_dwells_; - dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); - acq_parameters_.dump_filename = dump_filename_; - acq_parameters_.num_doppler_bins_step2 = configuration_->property(role + ".second_nbins", 4); - acq_parameters_.doppler_step2 = configuration_->property(role + ".second_doppler_step", 125.0); - acq_parameters_.make_2_steps = configuration_->property(role + ".make_two_steps", false); - acq_parameters_.use_automatic_resampler = configuration_->property("GNSS-SDR.use_acquisition_resampler", false); - if (acq_parameters_.use_automatic_resampler == true and item_type_ != "gr_complex") - { - LOG(WARNING) << "GPS L1 CA acquisition disabled the automatic resampler feature because its item_type is not set to gr_complex"; - acq_parameters_.use_automatic_resampler = false; - } - if (acq_parameters_.use_automatic_resampler) - { - if (acq_parameters_.fs_in > GPS_L1_CA_OPT_ACQ_FS_SPS) - { - acq_parameters_.resampler_ratio = floor(static_cast(acq_parameters_.fs_in) / GPS_L1_CA_OPT_ACQ_FS_SPS); - uint32_t decimation = acq_parameters_.fs_in / GPS_L1_CA_OPT_ACQ_FS_SPS; - while (acq_parameters_.fs_in % decimation > 0) - { - decimation--; - }; - acq_parameters_.resampler_ratio = decimation; - acq_parameters_.resampled_fs = acq_parameters_.fs_in / static_cast(acq_parameters_.resampler_ratio); - } - // -- Find number of samples per spreading code ------------------------- - code_length_ = static_cast(std::floor(static_cast(acq_parameters_.resampled_fs) / (GPS_L1_CA_CODE_RATE_CPS / GPS_L1_CA_CODE_LENGTH_CHIPS))); - acq_parameters_.samples_per_ms = static_cast(acq_parameters_.resampled_fs) * 0.001; - acq_parameters_.samples_per_chip = static_cast(ceil(GPS_L1_CA_CHIP_PERIOD_S * static_cast(acq_parameters_.resampled_fs))); - } - else - { - acq_parameters_.resampled_fs = fs_in_; - // -- Find number of samples per spreading code ------------------------- - code_length_ = static_cast(std::floor(static_cast(fs_in_) / (GPS_L1_CA_CODE_RATE_CPS / GPS_L1_CA_CODE_LENGTH_CHIPS))); - acq_parameters_.samples_per_ms = static_cast(fs_in_) * 0.001; - acq_parameters_.samples_per_chip = static_cast(ceil(GPS_L1_CA_CHIP_PERIOD_S * static_cast(acq_parameters_.fs_in))); - } + if (FLAGS_doppler_max != 0) doppler_max_ = FLAGS_doppler_max; - acq_parameters_.samples_per_code = acq_parameters_.samples_per_ms * static_cast(GPS_L1_CA_CODE_PERIOD_S * 1000.0); + code_length_ = static_cast(std::floor(static_cast(acq_parameters_.resampled_fs) / (GPS_L1_CA_CODE_RATE_CPS / GPS_L1_CA_CODE_LENGTH_CHIPS))); vector_length_ = std::floor(acq_parameters_.sampled_ms * acq_parameters_.samples_per_ms) * (acq_parameters_.bit_transition_flag ? 2 : 1); code_ = std::vector>(vector_length_); - if (item_type_ == "cshort") - { - item_size_ = sizeof(lv_16sc_t); - } - else - { - item_size_ = sizeof(gr_complex); - } + sampled_ms_ = acq_parameters_.sampled_ms; - acq_parameters_.it_size = item_size_; - acq_parameters_.blocking_on_standby = configuration_->property(role + ".blocking_on_standby", false); acquisition_ = pcps_make_acquisition(acq_parameters_); DLOG(INFO) << "acquisition(" << acquisition_->unique_id() << ")"; - if (item_type_ == "cbyte") + item_type_ = acq_parameters_.item_type; + + if (item_type_ == "ic8") { cbyte_to_float_x2_ = make_complex_byte_to_float_x2(); float_to_complex_ = gr::blocks::float_to_complex::make(); @@ -240,7 +173,7 @@ void GpsL1CaPcpsAcquisition::set_local_code() } else { - gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_, 0); + gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, acq_parameters_.fs_in, 0); } gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) @@ -286,15 +219,15 @@ float GpsL1CaPcpsAcquisition::calculate_threshold(float pfa) void GpsL1CaPcpsAcquisition::connect(gr::top_block_sptr top_block) { - if (item_type_ == "gr_complex") + if (item_type_ == "fc32") { // nothing to connect } - else if (item_type_ == "cshort") + else if (item_type_ == "ic16") { // nothing to connect } - else if (item_type_ == "cbyte") + else if (item_type_ == "ic8") { // Since a byte-based acq implementation is not available, // we just convert cshorts to gr_complex @@ -304,22 +237,22 @@ void GpsL1CaPcpsAcquisition::connect(gr::top_block_sptr top_block) } else { - LOG(WARNING) << item_type_ << " unknown acquisition item type"; + LOG(WARNING) << item_type_ << " unknown acquisition item type: " << item_type_; } } void GpsL1CaPcpsAcquisition::disconnect(gr::top_block_sptr top_block) { - if (item_type_ == "gr_complex") + if (item_type_ == "fc32") { // nothing to disconnect } - else if (item_type_ == "cshort") + else if (item_type_ == "ic16") { // nothing to disconnect } - else if (item_type_ == "cbyte") + else if (item_type_ == "ic8") { top_block->disconnect(cbyte_to_float_x2_, 0, float_to_complex_, 0); top_block->disconnect(cbyte_to_float_x2_, 1, float_to_complex_, 1); @@ -327,27 +260,27 @@ void GpsL1CaPcpsAcquisition::disconnect(gr::top_block_sptr top_block) } else { - LOG(WARNING) << item_type_ << " unknown acquisition item type"; + LOG(WARNING) << item_type_ << " unknown acquisition item type" << item_type_; } } gr::basic_block_sptr GpsL1CaPcpsAcquisition::get_left_block() { - if (item_type_ == "gr_complex") + if (item_type_ == "fc32") { return acquisition_; } - if (item_type_ == "cshort") + if (item_type_ == "ic16") { return acquisition_; } - if (item_type_ == "cbyte") + if (item_type_ == "ic8") { return cbyte_to_float_x2_; } - LOG(WARNING) << item_type_ << " unknown acquisition item type"; + LOG(WARNING) << item_type_ << " unknown acquisition item type" << item_type_; return nullptr; } diff --git a/src/algorithms/acquisition/libs/acq_conf.cc b/src/algorithms/acquisition/libs/acq_conf.cc index ec0a1c62b..a5e958cb8 100644 --- a/src/algorithms/acquisition/libs/acq_conf.cc +++ b/src/algorithms/acquisition/libs/acq_conf.cc @@ -30,31 +30,123 @@ */ #include "acq_conf.h" +#include "item_type_helpers.h" +#include +#include Acq_Conf::Acq_Conf() { /* PCPS acquisition configuration */ - sampled_ms = 0U; - ms_per_code = 0U; - max_dwells = 0U; - samples_per_chip = 0U; - doppler_max = 0U; - num_doppler_bins_step2 = 0U; - doppler_step2 = 0.0; + sampled_ms = 1U; + ms_per_code = 1U; + max_dwells = 1U; + samples_per_chip = 2U; + chips_per_second = 1023000; + doppler_max = 5000; + doppler_min = -5000; + num_doppler_bins_step2 = 4U; + doppler_step2 = 125.0; + pfa = 0.0; + pfa2 = 0.0; fs_in = 0LL; samples_per_ms = 0.0; samples_per_code = 0.0; bit_transition_flag = false; - use_CFAR_algorithm_flag = false; + use_CFAR_algorithm_flag = true; dump = false; - blocking = false; + blocking = true; make_2_steps = false; dump_filename = ""; dump_channel = 0U; - it_size = sizeof(char); + it_size = sizeof(gr_complex); + item_type = "fc32"; blocking_on_standby = false; use_automatic_resampler = false; resampler_ratio = 1.0; resampled_fs = 0LL; resampler_latency_samples = 0U; } + +void Acq_Conf::SetFromConfiguration( ConfigurationInterface *configuration, + const std::string &role, double chip_rate, double opt_freq ) +{ + item_type = configuration->property(role + ".item_type", item_type); + item_type = external_item_type_to_internal( item_type ); + if( !item_type_valid( item_type ) ) + { + throw std::invalid_argument( "Unknown item type: " + item_type ); + } + + chips_per_second = chip_rate; + + int64_t fs_in_deprecated = configuration->property("GNSS-SDR.internal_fs_hz", fs_in); + fs_in = configuration->property("GNSS-SDR.internal_fs_sps", fs_in_deprecated); + doppler_max = configuration->property(role + ".doppler_max", doppler_max); + sampled_ms = configuration->property(role + ".sampled_ms", sampled_ms); + bit_transition_flag = configuration->property(role + ".bit_transition_flag", bit_transition_flag); + use_CFAR_algorithm_flag = configuration->property(role + ".use_CFAR_algorithm", use_CFAR_algorithm_flag); //will be false in future versions + //acquire_pilot = configuration->property(role + ".acquire_pilot", acquire_pilot); //will be true in future versions + max_dwells = configuration->property(role + ".max_dwells", max_dwells); + dump = configuration->property(role + ".dump", dump); + dump_channel = configuration->property(role + ".dump_channel", dump_channel); + blocking = configuration->property(role + ".blocking", blocking); + dump_filename = configuration->property(role + ".dump_filename", dump_filename); + + use_automatic_resampler = configuration->property("GNSS-SDR.use_acquisition_resampler", use_automatic_resampler); + + if ((sampled_ms % ms_per_code) != 0) + { + LOG(WARNING) << "Parameter coherent_integration_time_ms should be a multiple of " + << ms_per_code << ". Setting it to " << ms_per_code; + sampled_ms = ms_per_code; + } + + resampled_fs = fs_in; + + if( use_automatic_resampler ) + { + ConfigureAutomaticResampler( opt_freq ); + } + + it_size = item_type_size(item_type); + num_doppler_bins_step2 = configuration->property(role + ".second_nbins", num_doppler_bins_step2); + doppler_step2 = configuration->property(role + ".second_doppler_step", doppler_step2); + doppler_step = configuration->property(role + ".doppler_step", doppler_step); + pfa = configuration->property(role + ".pfa", pfa); + pfa2 = configuration->property(role + ".pfa_second_step", pfa2); + if( pfa2 <= 0.0 ) + pfa2 = pfa; + make_2_steps = configuration->property(role + ".make_two_steps", make_2_steps); + blocking_on_standby = configuration->property(role + ".blocking_on_standby", blocking_on_standby); + + SetDerivedParams(); + +} + +void Acq_Conf::ConfigureAutomaticResampler( double opt_freq ) +{ + if (use_automatic_resampler) + { + if (fs_in > opt_freq) + { + resampler_ratio = floor(static_cast(fs_in) / opt_freq); + uint32_t decimation = fs_in / opt_freq; + while (fs_in % decimation > 0) + { + decimation--; + }; + resampler_ratio = decimation; + resampled_fs = fs_in / static_cast(resampler_ratio); + } + //--- Find number of samples per spreading code ------------------------- + SetDerivedParams(); + } +} + +void Acq_Conf::SetDerivedParams() +{ + samples_per_ms = static_cast(resampled_fs) * 0.001; + samples_per_chip = static_cast(ceil(static_cast(resampled_fs)/chips_per_second)); + samples_per_code = samples_per_ms * ms_per_code; +} + diff --git a/src/algorithms/acquisition/libs/acq_conf.h b/src/algorithms/acquisition/libs/acq_conf.h index ae449a88f..ed18c3d5c 100644 --- a/src/algorithms/acquisition/libs/acq_conf.h +++ b/src/algorithms/acquisition/libs/acq_conf.h @@ -32,6 +32,7 @@ #ifndef GNSS_SDR_ACQ_CONF_H_ #define GNSS_SDR_ACQ_CONF_H_ +#include "configuration_interface.h" #include #include #include @@ -43,10 +44,15 @@ public: uint32_t sampled_ms; uint32_t ms_per_code; uint32_t samples_per_chip; + uint32_t chips_per_second; uint32_t max_dwells; - uint32_t doppler_max; + int32_t doppler_max; + int32_t doppler_min; + float doppler_step; uint32_t num_doppler_bins_step2; float doppler_step2; + float pfa; + float pfa2; int64_t fs_in; float samples_per_ms; float samples_per_code; @@ -63,8 +69,16 @@ public: std::string dump_filename; uint32_t dump_channel; size_t it_size; + std::string item_type; Acq_Conf(); + + void SetFromConfiguration( ConfigurationInterface *configuration, const std::string &role, double chip_rate, double opt_freq ); + +private: + void SetDerivedParams(); + + void ConfigureAutomaticResampler( double opt_freq ); }; #endif