From f022d49709930ff9913f1cee95f1b4d5efabff07 Mon Sep 17 00:00:00 2001 From: Javier Arribas Date: Mon, 9 Apr 2018 16:45:05 +0200 Subject: [PATCH 1/8] Revert "Modify observables history" --- src/algorithms/libs/gnss_circular_deque.h | 213 ------------------ .../observables/adapters/CMakeLists.txt | 1 - .../gnuradio_blocks/CMakeLists.txt | 6 +- .../gnuradio_blocks/hybrid_observables_cc.cc | 122 +++------- .../gnuradio_blocks/hybrid_observables_cc.h | 11 +- 5 files changed, 41 insertions(+), 312 deletions(-) delete mode 100644 src/algorithms/libs/gnss_circular_deque.h diff --git a/src/algorithms/libs/gnss_circular_deque.h b/src/algorithms/libs/gnss_circular_deque.h deleted file mode 100644 index f453be3d2..000000000 --- a/src/algorithms/libs/gnss_circular_deque.h +++ /dev/null @@ -1,213 +0,0 @@ -/*! - * \file gnss_circular_deque.h - * \brief This class implements a circular deque for Gnss_Synchro - * - * \author Luis Esteve, 2018. antonio.ramos(at)cttc.es - * - * Detailed description of the file here if needed. - * - * ------------------------------------------------------------------------- - * - * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) - * - * GNSS-SDR is a software defined Global Navigation - * Satellite Systems receiver - * - * This file is part of GNSS-SDR. - * - * GNSS-SDR is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GNSS-SDR is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNSS-SDR. If not, see . - * - * ------------------------------------------------------------------------- - */ - -#ifndef GNSS_SDR_CIRCULAR_DEQUE_H_ -#define GNSS_SDR_CIRCULAR_DEQUE_H_ - -template -class Gnss_circular_deque -{ -public: - Gnss_circular_deque(); - Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann); - ~Gnss_circular_deque(); - unsigned int size(const unsigned int ch); - T& at(const unsigned int ch, const unsigned int pos); - T& front(const unsigned int ch); - T& back(const unsigned int ch); - void push_back(const unsigned int ch, const T& new_data); - T pop_front(const unsigned int ch); - void clear(const unsigned int ch); - T* get_vector(const unsigned int ch); - -private: - T** d_history; - T d_return_void; // Void object for avoid compiler errors - unsigned int* d_index_pop; - unsigned int* d_index_push; - unsigned int* d_size; - unsigned int d_max_size; - unsigned int d_nchannels; -}; - - -template -Gnss_circular_deque::Gnss_circular_deque() -{ - d_max_size = 0; - d_nchannels = 0; - d_size = nullptr; - d_index_pop = nullptr; - d_index_push = nullptr; - d_history = nullptr; -} - -template -Gnss_circular_deque::Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann) -{ - d_max_size = max_size; - d_nchannels = nchann; - if (d_max_size > 0 and d_nchannels > 0) - { - d_size = new unsigned int[d_nchannels]; - d_index_pop = new unsigned int[d_nchannels]; - d_index_push = new unsigned int[d_nchannels]; - d_history = new T*[d_nchannels]; - for (unsigned int i = 0; i < d_nchannels; i++) - { - d_size[i] = 0; - d_index_pop[i] = 0; - d_index_push[i] = 0; - d_history[i] = new T[d_max_size]; - } - } -} - -template -Gnss_circular_deque::~Gnss_circular_deque() -{ - if (d_max_size > 0 and d_nchannels > 0) - { - delete[] d_size; - delete[] d_index_pop; - delete[] d_index_push; - for (unsigned int i = 0; i < d_nchannels; i++) - { - delete[] d_history[i]; - } - delete[] d_history; - } -} - -template -unsigned int Gnss_circular_deque::size(const unsigned int ch) -{ - return d_size[ch]; -} - -template -T& Gnss_circular_deque::back(const unsigned int ch) -{ - if (d_size[ch] > 0) - { - unsigned int index = 0; - if (d_index_push[ch] > 0) - { - index = d_index_push[ch] - 1; - } - else - { - index = d_max_size; - } - return d_history[ch][index]; - } - else - { - return d_return_void; - } -} - -template -T& Gnss_circular_deque::front(const unsigned int ch) -{ - if (d_size[ch] > 0) - { - return d_history[ch][d_index_pop[ch]]; - } - else - { - return d_return_void; - } -} - -template -T& Gnss_circular_deque::at(const unsigned int ch, const unsigned int pos) -{ - if (d_size[ch] > 0 and pos < d_size[ch]) - { - unsigned int index = (d_index_pop[ch] + pos) % d_max_size; - return d_history[ch][index]; - } - else - { - return d_return_void; - } -} - -template -void Gnss_circular_deque::clear(const unsigned int ch) -{ - d_size[ch] = 0; - d_index_pop[ch] = 0; - d_index_push[ch] = 0; -} - -template -T Gnss_circular_deque::pop_front(const unsigned int ch) -{ - T result; - if (d_size[ch] > 0) - { - d_size[ch]--; - result = d_history[ch][d_index_pop[ch]]; - d_index_pop[ch]++; - d_index_pop[ch] %= d_max_size; - } - return result; -} - -template -void Gnss_circular_deque::push_back(const unsigned int ch, const T& new_data) -{ - d_history[ch][d_index_push[ch]] = new_data; - d_index_push[ch]++; - d_index_push[ch] %= d_max_size; - if (d_size[ch] < d_max_size) - { - d_size[ch]++; - } - else - { - d_index_pop[ch]++; - d_index_pop[ch] %= d_max_size; - } -} - -template -T* Gnss_circular_deque::get_vector(const unsigned int ch) -{ - return d_history[ch]; -} - - -#endif /* GNSS_SDR_CIRCULAR_DEQUE_H_ */ diff --git a/src/algorithms/observables/adapters/CMakeLists.txt b/src/algorithms/observables/adapters/CMakeLists.txt index 882b22d83..5129e4157 100644 --- a/src/algorithms/observables/adapters/CMakeLists.txt +++ b/src/algorithms/observables/adapters/CMakeLists.txt @@ -26,7 +26,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/receiver ${CMAKE_SOURCE_DIR}/src/algorithms/observables/gnuradio_blocks - ${CMAKE_SOURCE_DIR}/src/algorithms/libs ${CMAKE_SOURCE_DIR}/src/algorithms/PVT/libs ${GLOG_INCLUDE_DIRS} ${GFlags_INCLUDE_DIRS} diff --git a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt index e3db8ebcf..98b8213d8 100644 --- a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt @@ -39,8 +39,8 @@ list(SORT OBS_GR_BLOCKS_HEADERS) add_library(obs_gr_blocks ${OBS_GR_BLOCKS_SOURCES} ${OBS_GR_BLOCKS_HEADERS}) source_group(Headers FILES ${OBS_GR_BLOCKS_HEADERS}) if(MATIO_FOUND) - add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) + add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) else(MATIO_FOUND) - add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) + add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) endif(MATIO_FOUND) -target_link_libraries(obs_gr_blocks gnss_sp_libs ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) +target_link_libraries(obs_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 4b03988aa..6e95da824 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -66,7 +66,11 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, max_delta = 0.15; // 150 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; - d_gnss_synchro_history = Gnss_circular_deque(200, d_nchannels); + + for (unsigned int i = 0; i < d_nchannels; i++) + { + d_gnss_synchro_history.push_back(std::deque()); + } // ############# ENABLE DATA FILE LOG ################# if (d_dump) @@ -298,37 +302,15 @@ int hybrid_observables_cc::save_matfile() } -bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned int &ch, const double &ti) +bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, std::deque &data, const double &ti) { - if ((ti < d_gnss_synchro_history.front(ch).RX_time) or (ti > d_gnss_synchro_history.back(ch).RX_time)) + if ((ti < data.front().RX_time) or (ti > data.back().RX_time)) { return false; } - std::pair ind = find_interp_elements(ch, ti); + std::deque::iterator it; - double m = 0.0; - double c = 0.0; - - // CARRIER PHASE INTERPOLATION - - m = (d_gnss_synchro_history.at(ch, ind.first).Carrier_phase_rads - d_gnss_synchro_history.at(ch, ind.second).Carrier_phase_rads) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); - c = d_gnss_synchro_history.at(ch, ind.first).Carrier_phase_rads - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; - out.Carrier_phase_rads = m * ti + c; - - // CARRIER DOPPLER INTERPOLATION - m = (d_gnss_synchro_history.at(ch, ind.first).Carrier_Doppler_hz - d_gnss_synchro_history.at(ch, ind.second).Carrier_Doppler_hz) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); - c = d_gnss_synchro_history.at(ch, ind.first).Carrier_Doppler_hz - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; - out.Carrier_Doppler_hz = m * ti + c; - - // TOW INTERPOLATION - m = (d_gnss_synchro_history.at(ch, ind.first).TOW_at_current_symbol_s - d_gnss_synchro_history.at(ch, ind.second).TOW_at_current_symbol_s) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); - c = d_gnss_synchro_history.at(ch, ind.first).TOW_at_current_symbol_s - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; - out.TOW_at_current_symbol_s = m * ti + c; - - return true; - - /* - arma::vec t = arma::vec(d_gnss_synchro_history.size(ch)); + arma::vec t = arma::vec(data.size()); arma::vec dop = t; arma::vec cph = t; arma::vec tow = t; @@ -354,7 +336,6 @@ bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned i out.TOW_at_current_symbol_s = result(0); return result.is_finite(); - */ } @@ -370,48 +351,6 @@ double hybrid_observables_cc::compute_T_rx_s(const Gnss_Synchro &a) } } -std::pair hybrid_observables_cc::find_interp_elements(const unsigned int &ch, const double &ti) -{ - unsigned int closest = 0; - double dif = std::numeric_limits::max(); - double dt = 0.0; - for (unsigned int i = 0; i < d_gnss_synchro_history.size(ch); i++) - { - dt = std::fabs(ti - d_gnss_synchro_history.at(ch, i).RX_time); - if (dt < dif) - { - dif = dt; - closest = i; - } - } - unsigned int index1; - unsigned int index2; - if (closest == 0) - { - index1 = 0; - index2 = 1; - } - else if (closest == (d_gnss_synchro_history.size(ch) - 1)) - { - index1 = d_gnss_synchro_history.size(ch) - 2; - index2 = d_gnss_synchro_history.size(ch) - 1; - } - else - { - if (d_gnss_synchro_history.at(ch, closest).RX_time < ti) - { - index1 = closest; - index2 = closest + 1; - } - else - { - index1 = closest - 1; - index2 = closest; - } - } - return std::pair(index1, index2); -} - void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items_required) @@ -424,13 +363,13 @@ void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), } -void hybrid_observables_cc::clean_history(Gnss_circular_deque &data, unsigned int pos) +void hybrid_observables_cc::clean_history(std::deque &data) { - while (data.size(pos) > 0) + while (data.size() > 0) { - if ((T_rx_s - data.front(pos).RX_time) > max_delta) + if ((T_rx_s - data.front().RX_time) > max_delta) { - data.pop_front(pos); + data.pop_front(); } else { @@ -515,9 +454,11 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } ////////////////////////////////////////////////////////////////////////// + std::vector>::iterator it; if (total_input_items > 0) { - for (unsigned int i = 0; i < d_nchannels; i++) + i = 0; + for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) { if (ninput_items[i] > 0) { @@ -526,25 +467,26 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (in[i][aux].Flag_valid_word) { - d_gnss_synchro_history.push_back(i, in[i][aux]); - d_gnss_synchro_history.back(i).RX_time = compute_T_rx_s(in[i][aux]); + it->push_back(in[i][aux]); + it->back().RX_time = compute_T_rx_s(in[i][aux]); // Check if the last Gnss_Synchro comes from the same satellite as the previous ones - if (d_gnss_synchro_history.size(i) > 1) + if (it->size() > 1) { - if (d_gnss_synchro_history.front(i).PRN != d_gnss_synchro_history.back(i).PRN) + if (it->front().PRN != it->back().PRN) { - d_gnss_synchro_history.clear(i); + it->clear(); } } } } consume(i, ninput_items[i]); } + i++; } } for (i = 0; i < d_nchannels; i++) { - if (d_gnss_synchro_history.size(i) > 2) + if (d_gnss_synchro_history.at(i).size() > 2) { valid_channels[i] = true; } @@ -564,8 +506,8 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (valid_channels[i]) { - clean_history(d_gnss_synchro_history, i); - if (d_gnss_synchro_history.size(i) < 2) + clean_history(d_gnss_synchro_history.at(i)); + if (d_gnss_synchro_history.at(i).size() < 2) { valid_channels[i] = false; } @@ -581,12 +523,13 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } std::vector epoch_data; - for (unsigned int i = 0; i < d_nchannels; i++) + i = 0; + for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) { if (valid_channels[i]) { - Gnss_Synchro interpolated_gnss_synchro = d_gnss_synchro_history.back(i); - if (interpolate_data(interpolated_gnss_synchro, i, T_rx_s_out)) + Gnss_Synchro interpolated_gnss_synchro = it->back(); + if (interpolate_data(interpolated_gnss_synchro, *it, T_rx_s_out)) { epoch_data.push_back(interpolated_gnss_synchro); } @@ -595,6 +538,7 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) valid_channels[i] = false; } } + i++; } d_num_valid_channels = valid_channels.count(); if (d_num_valid_channels == 0) @@ -602,14 +546,14 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) return 0; } correct_TOW_and_compute_prange(epoch_data); - std::vector::iterator it = epoch_data.begin(); + std::vector::iterator it2 = epoch_data.begin(); for (i = 0; i < d_nchannels; i++) { if (valid_channels[i]) { - out[i][0] = (*it); + out[i][0] = (*it2); out[i][0].Flag_valid_pseudorange = true; - it++; + it2++; } else { diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h index 298a9a0bb..aedba43ab 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h @@ -35,12 +35,12 @@ #define GNSS_SDR_HYBRID_OBSERVABLES_CC_H #include "gnss_synchro.h" -#include "gnss_circular_deque.h" #include #include #include #include -#include +#include +#include class hybrid_observables_cc; @@ -65,15 +65,14 @@ private: friend hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); hybrid_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); - void clean_history(Gnss_circular_deque& data, unsigned int pos); + void clean_history(std::deque& data); double compute_T_rx_s(const Gnss_Synchro& a); - bool interpolate_data(Gnss_Synchro& out, const unsigned int& ch, const double& ti); - std::pair find_interp_elements(const unsigned int& ch, const double& ti); + bool interpolate_data(Gnss_Synchro& out, std::deque& data, const double& ti); void correct_TOW_and_compute_prange(std::vector& data); int save_matfile(); //Tracking observable history - Gnss_circular_deque d_gnss_synchro_history; + std::vector> d_gnss_synchro_history; boost::dynamic_bitset<> valid_channels; double T_rx_s; double T_rx_step_s; From 2a62d868ab60d1600d3ab8cad9a500b51cb9400d Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 9 Apr 2018 18:18:06 +0200 Subject: [PATCH 2/8] Clean code --- .../observables/gnuradio_blocks/hybrid_observables_cc.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 3ee00cbaf..6a87b156c 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -86,7 +86,6 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, } } } - std::cout << "SALIDA CONST HO. ()" << std::endl; } From f350174fd8e7450793e4fd87b679b0c26ba0a0ab Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 10 Apr 2018 15:37:07 +0200 Subject: [PATCH 3/8] Fix bugs --- src/algorithms/libs/gnss_circular_deque.h | 53 ++++++++++++++----- .../gnuradio_blocks/hybrid_observables_cc.cc | 17 ++---- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/algorithms/libs/gnss_circular_deque.h b/src/algorithms/libs/gnss_circular_deque.h index f453be3d2..12a8e64c0 100644 --- a/src/algorithms/libs/gnss_circular_deque.h +++ b/src/algorithms/libs/gnss_circular_deque.h @@ -33,6 +33,7 @@ #ifndef GNSS_SDR_CIRCULAR_DEQUE_H_ #define GNSS_SDR_CIRCULAR_DEQUE_H_ +#include template class Gnss_circular_deque @@ -89,6 +90,10 @@ Gnss_circular_deque::Gnss_circular_deque(const unsigned int max_size, const u d_index_pop[i] = 0; d_index_push[i] = 0; d_history[i] = new T[d_max_size]; + for (unsigned int ii = 0; ii < d_max_size; ii++) + { + d_history[i][ii] = d_return_void; + } } } } @@ -127,12 +132,14 @@ T& Gnss_circular_deque::back(const unsigned int ch) } else { - index = d_max_size; + index = d_max_size - 1; } return d_history[ch][index]; } else { + std::exception ex; + throw ex; return d_return_void; } } @@ -146,6 +153,8 @@ T& Gnss_circular_deque::front(const unsigned int ch) } else { + std::exception ex; + throw ex; return d_return_void; } } @@ -155,11 +164,13 @@ T& Gnss_circular_deque::at(const unsigned int ch, const unsigned int pos) { if (d_size[ch] > 0 and pos < d_size[ch]) { - unsigned int index = (d_index_pop[ch] + pos) % d_max_size; + unsigned int index = ((d_index_pop[ch] + pos) % d_max_size); return d_history[ch][index]; } else { + std::exception ex; + throw ex; return d_return_void; } } @@ -175,31 +186,45 @@ void Gnss_circular_deque::clear(const unsigned int ch) template T Gnss_circular_deque::pop_front(const unsigned int ch) { - T result; if (d_size[ch] > 0) { d_size[ch]--; - result = d_history[ch][d_index_pop[ch]]; - d_index_pop[ch]++; - d_index_pop[ch] %= d_max_size; + T result = d_history[ch][d_index_pop[ch]]; + if (d_size[ch] > 0) + { + d_index_pop[ch]++; + d_index_pop[ch] %= d_max_size; + } + else + { + clear(ch); + } + return result; + } + else + { + std::exception ex; + throw ex; + return d_return_void; } - return result; } template void Gnss_circular_deque::push_back(const unsigned int ch, const T& new_data) { + bool increment_pop = true; + if (d_size[ch] < d_max_size) + { + increment_pop = false; + d_size[ch]++; + } + d_history[ch][d_index_push[ch]] = new_data; d_index_push[ch]++; d_index_push[ch] %= d_max_size; - if (d_size[ch] < d_max_size) + if (increment_pop) { - d_size[ch]++; - } - else - { - d_index_pop[ch]++; - d_index_pop[ch] %= d_max_size; + d_index_pop[ch] = d_index_push[ch]; } } diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 6a87b156c..603b28c8e 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -307,6 +307,7 @@ bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned i } std::pair ind = find_interp_elements(ch, ti); + //Linear interpolation parameters: y(t) = m * t + c double m = 0.0; double c = 0.0; @@ -378,8 +379,8 @@ std::pair hybrid_observables_cc::find_interp_element double dt = 0.0; for (unsigned int i = 0; i < d_gnss_synchro_history->size(ch); i++) { - dt = std::fabs(ti - d_gnss_synchro_history->at(ch, i).RX_time); - if (dt < dif) + dt = ti - d_gnss_synchro_history->at(ch, i).RX_time; + if (dt < dif and dt > 0.0) { dif = dt; closest = i; @@ -399,16 +400,8 @@ std::pair hybrid_observables_cc::find_interp_element } else { - if (d_gnss_synchro_history->at(ch, closest).RX_time < ti) - { - index1 = closest; - index2 = closest + 1; - } - else - { - index1 = closest - 1; - index2 = closest; - } + index1 = closest; + index2 = closest + 1; } return std::pair(index1, index2); } From 01d41e2f0763bcc3a3ce7ff9de2b623c419332d7 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Tue, 10 Apr 2018 16:05:22 +0200 Subject: [PATCH 4/8] Use boost circular buffers --- src/algorithms/libs/gnss_circular_deque.h | 185 ++++-------------- .../gnuradio_blocks/hybrid_observables_cc.cc | 20 +- 2 files changed, 48 insertions(+), 157 deletions(-) diff --git a/src/algorithms/libs/gnss_circular_deque.h b/src/algorithms/libs/gnss_circular_deque.h index 12a8e64c0..e1b73c87d 100644 --- a/src/algorithms/libs/gnss_circular_deque.h +++ b/src/algorithms/libs/gnss_circular_deque.h @@ -33,206 +33,103 @@ #ifndef GNSS_SDR_CIRCULAR_DEQUE_H_ #define GNSS_SDR_CIRCULAR_DEQUE_H_ -#include +#include +#include template class Gnss_circular_deque { public: - Gnss_circular_deque(); - Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann); - ~Gnss_circular_deque(); - unsigned int size(const unsigned int ch); - T& at(const unsigned int ch, const unsigned int pos); - T& front(const unsigned int ch); - T& back(const unsigned int ch); - void push_back(const unsigned int ch, const T& new_data); - T pop_front(const unsigned int ch); - void clear(const unsigned int ch); - T* get_vector(const unsigned int ch); + Gnss_circular_deque(); // Default constructor + Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann); // nchann = number of channels; max_size = channel capacity + unsigned int size(const unsigned int ch); // Returns the number of available elements in a channel + T& at(const unsigned int ch, const unsigned int pos); // Returns a reference to an element + T& front(const unsigned int ch); // Returns a reference to the first element in the deque + T& back(const unsigned int ch); // Returns a reference to the last element in the deque + void push_back(const unsigned int ch, const T& new_data); // Inserts an element at the end of the deque + void pop_front(const unsigned int ch); // Removes the first element of the deque + void clear(const unsigned int ch); // Removes all the elements of the deque (Sets size to 0). Capacity is not modified + void reset(const unsigned int max_size, const unsigned int nchann); // Removes all the elements in all the channels. Re-sets the number of channels and their capacity + void reset(); // Removes all the channels (Sets nchann to 0) private: - T** d_history; - T d_return_void; // Void object for avoid compiler errors - unsigned int* d_index_pop; - unsigned int* d_index_push; - unsigned int* d_size; - unsigned int d_max_size; - unsigned int d_nchannels; + std::vector> d_data; }; template Gnss_circular_deque::Gnss_circular_deque() { - d_max_size = 0; - d_nchannels = 0; - d_size = nullptr; - d_index_pop = nullptr; - d_index_push = nullptr; - d_history = nullptr; + reset(); } template Gnss_circular_deque::Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann) { - d_max_size = max_size; - d_nchannels = nchann; - if (d_max_size > 0 and d_nchannels > 0) - { - d_size = new unsigned int[d_nchannels]; - d_index_pop = new unsigned int[d_nchannels]; - d_index_push = new unsigned int[d_nchannels]; - d_history = new T*[d_nchannels]; - for (unsigned int i = 0; i < d_nchannels; i++) - { - d_size[i] = 0; - d_index_pop[i] = 0; - d_index_push[i] = 0; - d_history[i] = new T[d_max_size]; - for (unsigned int ii = 0; ii < d_max_size; ii++) - { - d_history[i][ii] = d_return_void; - } - } - } -} - -template -Gnss_circular_deque::~Gnss_circular_deque() -{ - if (d_max_size > 0 and d_nchannels > 0) - { - delete[] d_size; - delete[] d_index_pop; - delete[] d_index_push; - for (unsigned int i = 0; i < d_nchannels; i++) - { - delete[] d_history[i]; - } - delete[] d_history; - } + reset(max_size, nchann); } template unsigned int Gnss_circular_deque::size(const unsigned int ch) { - return d_size[ch]; + return d_data.at(ch).size(); } template T& Gnss_circular_deque::back(const unsigned int ch) { - if (d_size[ch] > 0) - { - unsigned int index = 0; - if (d_index_push[ch] > 0) - { - index = d_index_push[ch] - 1; - } - else - { - index = d_max_size - 1; - } - return d_history[ch][index]; - } - else - { - std::exception ex; - throw ex; - return d_return_void; - } + return d_data.at(ch).back(); } + template T& Gnss_circular_deque::front(const unsigned int ch) { - if (d_size[ch] > 0) - { - return d_history[ch][d_index_pop[ch]]; - } - else - { - std::exception ex; - throw ex; - return d_return_void; - } + return d_data.at(ch).front(); } + template T& Gnss_circular_deque::at(const unsigned int ch, const unsigned int pos) { - if (d_size[ch] > 0 and pos < d_size[ch]) - { - unsigned int index = ((d_index_pop[ch] + pos) % d_max_size); - return d_history[ch][index]; - } - else - { - std::exception ex; - throw ex; - return d_return_void; - } + return d_data.at(ch).at(pos); } template void Gnss_circular_deque::clear(const unsigned int ch) { - d_size[ch] = 0; - d_index_pop[ch] = 0; - d_index_push[ch] = 0; + d_data.at(ch).clear(); } template -T Gnss_circular_deque::pop_front(const unsigned int ch) +void Gnss_circular_deque::reset(const unsigned int max_size, const unsigned int nchann) { - if (d_size[ch] > 0) + d_data.clear(); + if (max_size > 0 and nchann > 0) { - d_size[ch]--; - T result = d_history[ch][d_index_pop[ch]]; - if (d_size[ch] > 0) + for (unsigned int i = 0; i < nchann; i++) { - d_index_pop[ch]++; - d_index_pop[ch] %= d_max_size; + d_data.push_back(boost::circular_buffer(max_size)); } - else - { - clear(ch); - } - return result; - } - else - { - std::exception ex; - throw ex; - return d_return_void; } } +template +void Gnss_circular_deque::reset() +{ + d_data.clear(); +} + +template +void Gnss_circular_deque::pop_front(const unsigned int ch) +{ + d_data.at(ch).pop_front(); +} + template void Gnss_circular_deque::push_back(const unsigned int ch, const T& new_data) { - bool increment_pop = true; - if (d_size[ch] < d_max_size) - { - increment_pop = false; - d_size[ch]++; - } - - d_history[ch][d_index_push[ch]] = new_data; - d_index_push[ch]++; - d_index_push[ch] %= d_max_size; - if (increment_pop) - { - d_index_pop[ch] = d_index_push[ch]; - } + d_data.at(ch).push_back(new_data); } -template -T* Gnss_circular_deque::get_vector(const unsigned int ch) -{ - return d_history[ch]; -} - - #endif /* GNSS_SDR_CIRCULAR_DEQUE_H_ */ diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 603b28c8e..0566e86f9 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -66,7 +66,7 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, max_delta = 0.15; // 150 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; - d_gnss_synchro_history = new Gnss_circular_deque(200, d_nchannels); + d_gnss_synchro_history = new Gnss_circular_deque(1000, d_nchannels); // ############# ENABLE DATA FILE LOG ################# if (d_dump) @@ -307,25 +307,19 @@ bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned i } std::pair ind = find_interp_elements(ch, ti); - //Linear interpolation parameters: y(t) = m * t + c - double m = 0.0; - double c = 0.0; + //Linear interpolation: y(t) = y(t1) + (y(t2) - y(t1)) * (t - t1) / (t2 - t1) // CARRIER PHASE INTERPOLATION - m = (d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads - d_gnss_synchro_history->at(ch, ind.second).Carrier_phase_rads) / (d_gnss_synchro_history->at(ch, ind.first).RX_time - d_gnss_synchro_history->at(ch, ind.second).RX_time); - c = d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads - m * d_gnss_synchro_history->at(ch, ind.first).RX_time; - out.Carrier_phase_rads = m * ti + c; + out.Carrier_phase_rads = d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads + (d_gnss_synchro_history->at(ch, ind.second).Carrier_phase_rads - d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); // CARRIER DOPPLER INTERPOLATION - m = (d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz - d_gnss_synchro_history->at(ch, ind.second).Carrier_Doppler_hz) / (d_gnss_synchro_history->at(ch, ind.first).RX_time - d_gnss_synchro_history->at(ch, ind.second).RX_time); - c = d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz - m * d_gnss_synchro_history->at(ch, ind.first).RX_time; - out.Carrier_Doppler_hz = m * ti + c; + + out.Carrier_Doppler_hz = d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz + (d_gnss_synchro_history->at(ch, ind.second).Carrier_Doppler_hz - d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); // TOW INTERPOLATION - m = (d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s - d_gnss_synchro_history->at(ch, ind.second).TOW_at_current_symbol_s) / (d_gnss_synchro_history->at(ch, ind.first).RX_time - d_gnss_synchro_history->at(ch, ind.second).RX_time); - c = d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s - m * d_gnss_synchro_history->at(ch, ind.first).RX_time; - out.TOW_at_current_symbol_s = m * ti + c; + + out.TOW_at_current_symbol_s = d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s + (d_gnss_synchro_history->at(ch, ind.second).TOW_at_current_symbol_s - d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); return true; From 2e15b16660df0d83e10b88215afe91411243afc1 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Wed, 11 Apr 2018 11:26:24 +0200 Subject: [PATCH 5/8] Change std::deque to boost::circular_buffer The circular buffer (fixed memory) increases the performance of the receiver --- .../gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc | 7 ++----- .../gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.h | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc index 580bc8bdc..09f4e2621 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.cc @@ -105,6 +105,8 @@ gps_l1_ca_telemetry_decoder_cc::gps_l1_ca_telemetry_decoder_cc( flag_PLL_180_deg_phase_locked = false; d_preamble_time_samples = 0; d_TOW_at_current_symbol_ms = 0; + d_symbol_history.resize(GPS_CA_PREAMBLE_LENGTH_SYMBOLS + 1); // Change fixed buffer size + d_symbol_history.clear(); // Clear all the elements in the buffer } @@ -395,11 +397,6 @@ int gps_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribute__ } } - // remove used symbols from history - if (d_symbol_history.size() > required_symbols) - { - d_symbol_history.pop_front(); - } //3. Make the output (copy the object contents to the GNURadio reserved memory) *out[0] = current_symbol; diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.h b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.h index 8904f7e85..22a9526a2 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.h +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_cc.h @@ -36,9 +36,9 @@ #include "gnss_satellite.h" #include "gnss_synchro.h" #include -#include #include #include +#include class gps_l1_ca_telemetry_decoder_cc; @@ -79,7 +79,7 @@ private: bool d_flag_frame_sync; // symbols - std::deque d_symbol_history; + boost::circular_buffer d_symbol_history; double d_symbol_accumulator; short int d_symbol_accumulator_counter; From 385055e884374f8cd75c47b75c5d3fcce45d9757 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Wed, 11 Apr 2018 12:49:22 +0200 Subject: [PATCH 6/8] Increase buffer size --- .../gnuradio_blocks/hybrid_observables_cc.cc | 36 +++---------------- .../gnuradio_blocks/hybrid_observables_cc.h | 1 + 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 0566e86f9..1b4d3ab62 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -63,10 +63,11 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, d_dump_filename = dump_filename; T_rx_s = 0.0; T_rx_step_s = 0.001; // 1 ms - max_delta = 0.15; // 150 ms + max_delta = 2.5; // 2.5 s + d_latency = 0.08; // 80 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; - d_gnss_synchro_history = new Gnss_circular_deque(1000, d_nchannels); + d_gnss_synchro_history = new Gnss_circular_deque(static_cast(max_delta * 1000.0), d_nchannels); // ############# ENABLE DATA FILE LOG ################# if (d_dump) @@ -322,35 +323,6 @@ bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned i out.TOW_at_current_symbol_s = d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s + (d_gnss_synchro_history->at(ch, ind.second).TOW_at_current_symbol_s - d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); return true; - - /* - arma::vec t = arma::vec(d_gnss_synchro_history.size(ch)); - arma::vec dop = t; - arma::vec cph = t; - arma::vec tow = t; - arma::vec tiv = arma::vec(1); - arma::vec result; - tiv(0) = ti; - - unsigned int aux = 0; - for (it = data.begin(); it != data.end(); it++) - { - t(aux) = it->RX_time; - dop(aux) = it->Carrier_Doppler_hz; - cph(aux) = it->Carrier_phase_rads; - tow(aux) = it->TOW_at_current_symbol_s; - - aux++; - } - arma::interp1(t, dop, tiv, result); - out.Carrier_Doppler_hz = result(0); - arma::interp1(t, cph, tiv, result); - out.Carrier_phase_rads = result(0); - arma::interp1(t, tow, tiv, result); - out.TOW_at_current_symbol_s = result(0); - - return result.is_finite(); - */ } @@ -562,7 +534,7 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) // Check if there is any valid channel after computing the time distance between the Gnss_Synchro data and the receiver time d_num_valid_channels = valid_channels.count(); - double T_rx_s_out = T_rx_s - (max_delta / 2.0); + double T_rx_s_out = T_rx_s - d_latency; if ((d_num_valid_channels == 0) or (T_rx_s_out < 0.0)) { return 0; diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h index c5557963b..64f929857 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h @@ -78,6 +78,7 @@ private: double T_rx_s; double T_rx_step_s; double max_delta; + double d_latency; bool d_dump; unsigned int d_nchannels; unsigned int d_num_valid_channels; From 2eea1a66aaec477bd5cade49ff9afef66c1b0041 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Wed, 11 Apr 2018 12:56:15 +0200 Subject: [PATCH 7/8] Solve conflicts --- .../observables/gnuradio_blocks/hybrid_observables_cc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 1b4d3ab62..a7142d635 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -63,7 +63,7 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, d_dump_filename = dump_filename; T_rx_s = 0.0; T_rx_step_s = 0.001; // 1 ms - max_delta = 2.5; // 2.5 s + max_delta = 3.0; // 3 s d_latency = 0.08; // 80 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; From b606e1d71fb797df1c0d7c875d77c4e15fdb1b13 Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Wed, 11 Apr 2018 13:35:01 +0200 Subject: [PATCH 8/8] Solve more conflicts --- .../observables/adapters/CMakeLists.txt | 1 + .../gnuradio_blocks/CMakeLists.txt | 6 +- .../gnuradio_blocks/hybrid_observables_cc.cc | 126 ++++++++++-------- .../gnuradio_blocks/hybrid_observables_cc.h | 11 +- 4 files changed, 80 insertions(+), 64 deletions(-) diff --git a/src/algorithms/observables/adapters/CMakeLists.txt b/src/algorithms/observables/adapters/CMakeLists.txt index 5129e4157..882b22d83 100644 --- a/src/algorithms/observables/adapters/CMakeLists.txt +++ b/src/algorithms/observables/adapters/CMakeLists.txt @@ -26,6 +26,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/receiver ${CMAKE_SOURCE_DIR}/src/algorithms/observables/gnuradio_blocks + ${CMAKE_SOURCE_DIR}/src/algorithms/libs ${CMAKE_SOURCE_DIR}/src/algorithms/PVT/libs ${GLOG_INCLUDE_DIRS} ${GFlags_INCLUDE_DIRS} diff --git a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt index 98b8213d8..e3db8ebcf 100644 --- a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt @@ -39,8 +39,8 @@ list(SORT OBS_GR_BLOCKS_HEADERS) add_library(obs_gr_blocks ${OBS_GR_BLOCKS_SOURCES} ${OBS_GR_BLOCKS_HEADERS}) source_group(Headers FILES ${OBS_GR_BLOCKS_HEADERS}) if(MATIO_FOUND) - add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) + add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) else(MATIO_FOUND) - add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) + add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) endif(MATIO_FOUND) -target_link_libraries(obs_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) +target_link_libraries(obs_gr_blocks gnss_sp_libs ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index a60318772..4b6ccfb1d 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -63,15 +63,11 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, d_dump_filename = dump_filename; T_rx_s = 0.0; T_rx_step_s = 0.001; // 1 ms - max_delta = 3.0; // 3 s + max_delta = 3.5; // 3.5 s d_latency = 0.08; // 80 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; - - for (unsigned int i = 0; i < d_nchannels; i++) - { - d_gnss_synchro_history.push_back(std::deque()); - } + d_gnss_synchro_history = new Gnss_circular_deque(static_cast(max_delta * 1000.0), d_nchannels); // ############# ENABLE DATA FILE LOG ################# if (d_dump) @@ -304,40 +300,29 @@ int hybrid_observables_cc::save_matfile() } -bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, std::deque &data, const double &ti) +bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned int &ch, const double &ti) { - if ((ti < data.front().RX_time) or (ti > data.back().RX_time)) + if ((ti < d_gnss_synchro_history->front(ch).RX_time) or (ti > d_gnss_synchro_history->back(ch).RX_time)) { return false; } - std::deque::iterator it; + std::pair ind = find_interp_elements(ch, ti); - arma::vec t = arma::vec(data.size()); - arma::vec dop = t; - arma::vec cph = t; - arma::vec tow = t; - arma::vec tiv = arma::vec(1); - arma::vec result; - tiv(0) = ti; + //Linear interpolation: y(t) = y(t1) + (y(t2) - y(t1)) * (t - t1) / (t2 - t1) - unsigned int aux = 0; - for (it = data.begin(); it != data.end(); it++) - { - t(aux) = it->RX_time; - dop(aux) = it->Carrier_Doppler_hz; - cph(aux) = it->Carrier_phase_rads; - tow(aux) = it->TOW_at_current_symbol_s; + // CARRIER PHASE INTERPOLATION - aux++; - } - arma::interp1(t, dop, tiv, result); - out.Carrier_Doppler_hz = result(0); - arma::interp1(t, cph, tiv, result); - out.Carrier_phase_rads = result(0); - arma::interp1(t, tow, tiv, result); - out.TOW_at_current_symbol_s = result(0); + out.Carrier_phase_rads = d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads + (d_gnss_synchro_history->at(ch, ind.second).Carrier_phase_rads - d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); - return result.is_finite(); + // CARRIER DOPPLER INTERPOLATION + + out.Carrier_Doppler_hz = d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz + (d_gnss_synchro_history->at(ch, ind.second).Carrier_Doppler_hz - d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); + + // TOW INTERPOLATION + + out.TOW_at_current_symbol_s = d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s + (d_gnss_synchro_history->at(ch, ind.second).TOW_at_current_symbol_s - d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time); + + return true; } @@ -353,6 +338,40 @@ double hybrid_observables_cc::compute_T_rx_s(const Gnss_Synchro &a) } } +std::pair hybrid_observables_cc::find_interp_elements(const unsigned int &ch, const double &ti) +{ + unsigned int closest = 0; + double dif = std::numeric_limits::max(); + double dt = 0.0; + for (unsigned int i = 0; i < d_gnss_synchro_history->size(ch); i++) + { + dt = ti - d_gnss_synchro_history->at(ch, i).RX_time; + if (dt < dif and dt > 0.0) + { + dif = dt; + closest = i; + } + } + unsigned int index1; + unsigned int index2; + if (closest == 0) + { + index1 = 0; + index2 = 1; + } + else if (closest == (d_gnss_synchro_history->size(ch) - 1)) + { + index1 = d_gnss_synchro_history->size(ch) - 2; + index2 = d_gnss_synchro_history->size(ch) - 1; + } + else + { + index1 = closest; + index2 = closest + 1; + } + return std::pair(index1, index2); +} + void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items_required) @@ -365,13 +384,13 @@ void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), } -void hybrid_observables_cc::clean_history(std::deque &data) +void hybrid_observables_cc::clean_history(unsigned int pos) { - while (data.size() > 0) + while (d_gnss_synchro_history->size(pos) > 0) { - if ((T_rx_s - data.front().RX_time) > max_delta) + if ((T_rx_s - d_gnss_synchro_history->front(pos).RX_time) > max_delta) { - data.pop_front(); + d_gnss_synchro_history->pop_front(pos); } else { @@ -456,11 +475,9 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } ////////////////////////////////////////////////////////////////////////// - std::vector>::iterator it; if (total_input_items > 0) { - i = 0; - for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) + for (i = 0; i < d_nchannels; i++) { if (ninput_items[i] > 0) { @@ -469,26 +486,25 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (in[i][aux].Flag_valid_word) { - it->push_back(in[i][aux]); - it->back().RX_time = compute_T_rx_s(in[i][aux]); + d_gnss_synchro_history->push_back(i, in[i][aux]); + d_gnss_synchro_history->back(i).RX_time = compute_T_rx_s(in[i][aux]); // Check if the last Gnss_Synchro comes from the same satellite as the previous ones - if (it->size() > 1) + if (d_gnss_synchro_history->size(i) > 1) { - if (it->front().PRN != it->back().PRN) + if (d_gnss_synchro_history->front(i).PRN != d_gnss_synchro_history->back(i).PRN) { - it->clear(); + d_gnss_synchro_history->clear(i); } } } } consume(i, ninput_items[i]); } - i++; } } for (i = 0; i < d_nchannels; i++) { - if (d_gnss_synchro_history.at(i).size() > 2) + if (d_gnss_synchro_history->size(i) > 2) { valid_channels[i] = true; } @@ -508,8 +524,8 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (valid_channels[i]) { - clean_history(d_gnss_synchro_history.at(i)); - if (d_gnss_synchro_history.at(i).size() < 2) + clean_history(i); + if (d_gnss_synchro_history->size(i) < 2) { valid_channels[i] = false; } @@ -525,13 +541,12 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } std::vector epoch_data; - i = 0; - for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) + for (i = 0; i < d_nchannels; i++) { if (valid_channels[i]) { - Gnss_Synchro interpolated_gnss_synchro = it->back(); - if (interpolate_data(interpolated_gnss_synchro, *it, T_rx_s_out)) + Gnss_Synchro interpolated_gnss_synchro = d_gnss_synchro_history->back(i); + if (interpolate_data(interpolated_gnss_synchro, i, T_rx_s_out)) { epoch_data.push_back(interpolated_gnss_synchro); } @@ -540,7 +555,6 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) valid_channels[i] = false; } } - i++; } d_num_valid_channels = valid_channels.count(); if (d_num_valid_channels == 0) @@ -548,14 +562,14 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) return 0; } correct_TOW_and_compute_prange(epoch_data); - std::vector::iterator it2 = epoch_data.begin(); + std::vector::iterator it = epoch_data.begin(); for (i = 0; i < d_nchannels; i++) { if (valid_channels[i]) { - out[i][0] = (*it2); + out[i][0] = (*it); out[i][0].Flag_valid_pseudorange = true; - it2++; + it++; } else { diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h index 8d48fc3fa..64f929857 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h @@ -35,12 +35,12 @@ #define GNSS_SDR_HYBRID_OBSERVABLES_CC_H #include "gnss_synchro.h" +#include "gnss_circular_deque.h" #include #include #include #include -#include -#include +#include class hybrid_observables_cc; @@ -65,14 +65,15 @@ private: friend hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); hybrid_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); - void clean_history(std::deque& data); + void clean_history(unsigned int pos); double compute_T_rx_s(const Gnss_Synchro& a); - bool interpolate_data(Gnss_Synchro& out, std::deque& data, const double& ti); + bool interpolate_data(Gnss_Synchro& out, const unsigned int& ch, const double& ti); + std::pair find_interp_elements(const unsigned int& ch, const double& ti); void correct_TOW_and_compute_prange(std::vector& data); int save_matfile(); //Tracking observable history - std::vector> d_gnss_synchro_history; + Gnss_circular_deque* d_gnss_synchro_history; boost::dynamic_bitset<> valid_channels; double T_rx_s; double T_rx_step_s;