From d1331676eaf47268b338f246a17d7636de09f5d1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 24 Apr 2019 00:56:17 +0200 Subject: [PATCH 1/9] Improve CMake messages when Protocol Buffers is not found Fixed building with Ninja when glog, matio or protocol buffers are not found --- CMakeLists.txt | 126 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 106 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea5dc91fb..8ce5e4ca8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1257,6 +1257,19 @@ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/c endif() endif() + set(GLOG_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) + if(GLOG_MAKE_PROGRAM MATCHES "ninja") + find_program(GLOG_MAKE_EXECUTABLE make + HINTS + /usr/bin/ + /usr/local/bin/ + ) + if(NOT GLOG_MAKE_EXECUTABLE) + message(FATAL_ERROR "make is required to build Glog from source.") + endif() + set(GLOG_MAKE_PROGRAM ${GLOG_MAKE_EXECUTABLE}) + endif() + if(CMAKE_VERSION VERSION_LESS 3.2) ExternalProject_Add(glog-${GNSSSDR_GLOG_LOCAL_VERSION} DEPENDS ${TARGET_GFLAGS} @@ -1266,7 +1279,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/c SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION} CONFIGURE_COMMAND ${GLOG_CONFIGURE} --prefix= - BUILD_COMMAND "${CMAKE_MAKE_PROGRAM}" + BUILD_COMMAND "${GLOG_MAKE_PROGRAM}" UPDATE_COMMAND "" PATCH_COMMAND "" INSTALL_COMMAND "" @@ -1280,7 +1293,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/c SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION} CONFIGURE_COMMAND ${GLOG_CONFIGURE} --prefix= - BUILD_COMMAND "${CMAKE_MAKE_PROGRAM}" + BUILD_COMMAND "${GLOG_MAKE_PROGRAM}" BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/.libs/${CMAKE_FIND_LIBRARY_PREFIXES}glog${CMAKE_STATIC_LIBRARY_SUFFIX} UPDATE_COMMAND "" PATCH_COMMAND "" @@ -1664,6 +1677,19 @@ if(NOT MATIO_FOUND OR MATIO_VERSION_STRING VERSION_LESS ${GNSSSDR_MATIO_MIN_VERS endif() endif() + set(MATIO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) + if(MATIO_MAKE_PROGRAM MATCHES "ninja") + find_program(MATIO_MAKE_EXECUTABLE make + HINTS + /usr/bin/ + /usr/local/bin/ + ) + if(NOT MATIO_MAKE_EXECUTABLE) + message(FATAL_ERROR "make is required to build Matio from source.") + endif() + set(MATIO_MAKE_PROGRAM ${MATIO_MAKE_EXECUTABLE}) + endif() + if(CMAKE_VERSION VERSION_LESS 3.2) ExternalProject_Add(matio-${GNSSSDR_MATIO_LOCAL_VERSION} PREFIX ${CMAKE_CURRENT_BINARY_DIR}/matio @@ -1672,7 +1698,7 @@ if(NOT MATIO_FOUND OR MATIO_VERSION_STRING VERSION_LESS ${GNSSSDR_MATIO_MIN_VERS SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION} UPDATE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION}/autogen.sh CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION}/configure --with-hdf5=${HDF5_BASE_DIR} --with-zlib=${ZLIB_BASE_DIR} --with-default-file-ver=7.3 --enable-mat73=yes --prefix= - BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} + BUILD_COMMAND ${MATIO_MAKE_PROGRAM} ) else() ExternalProject_Add(matio-${GNSSSDR_MATIO_LOCAL_VERSION} @@ -1682,8 +1708,8 @@ if(NOT MATIO_FOUND OR MATIO_VERSION_STRING VERSION_LESS ${GNSSSDR_MATIO_MIN_VERS SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION} UPDATE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION}/autogen.sh CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/matio/matio-${GNSSSDR_MATIO_LOCAL_VERSION}/configure --with-hdf5=${HDF5_BASE_DIR} --with-zlib=${ZLIB_BASE_DIR} --with-default-file-ver=7.3 --enable-mat73=yes --prefix= - BUILD_COMMAND $(MAKE) - BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/matio/lib/${CMAKE_FIND_LIBRARY_PREFIXES}matio${CMAKE_STATIC_LIBRARY_SUFFIX} + BUILD_COMMAND ${MATIO_MAKE_PROGRAM} + BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/matio/lib/${CMAKE_FIND_LIBRARY_PREFIXES}matio${CMAKE_SHARED_LIBRARY_SUFFIX} ) endif() set(MATIO_LOCAL true) @@ -1695,8 +1721,8 @@ if(NOT MATIO_FOUND OR MATIO_VERSION_STRING VERSION_LESS ${GNSSSDR_MATIO_MIN_VERS set_target_properties(Matio::matio PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/matio/lib/${CMAKE_FIND_LIBRARY_PREFIXES}matio${CMAKE_SHARED_LIBRARY_SUFFIX}" - INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/matio/include" - INTERFACE_LINK_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/matio/lib/${CMAKE_FIND_LIBRARY_PREFIXES}matio${CMAKE_SHARED_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/matio/include + INTERFACE_LINK_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/matio/lib/${CMAKE_FIND_LIBRARY_PREFIXES}matio${CMAKE_SHARED_LIBRARY_SUFFIX} ) endif() else() @@ -1789,7 +1815,6 @@ endif() ################################################################################ # Protocol Buffers https://github.com/protocolbuffers/protobuf ################################################################################ -set(Protobuf_VERSION "0.0.0") find_package(Protobuf) set_package_properties(Protobuf PROPERTIES URL "https://developers.google.com/protocol-buffers/" @@ -1797,6 +1822,9 @@ set_package_properties(Protobuf PROPERTIES PURPOSE "Used to serialize output data in a way that can be read by other applications." TYPE REQUIRED ) +if(NOT Protobuf_VERSION) + set(Protobuf_VERSION "0.0.0") +endif() if(CMAKE_VERSION VERSION_LESS 3.6) if(PROTOBUF_FOUND) set(Protobuf_FOUND ${PROTOBUF_FOUND}) @@ -1846,8 +1874,8 @@ endif() if(Protobuf_FOUND AND CMAKE_CROSSCOMPILING) find_program(PROTOC_EXECUTABLE protoc HINTS - /usr/local/bin/ - /usr/bin/ + /usr/local/bin/ + /usr/bin/ NO_SYSTEM_ENVIRONMENT_PATH ) if(PROTOC_EXECUTABLE) @@ -1856,7 +1884,7 @@ if(Protobuf_FOUND AND CMAKE_CROSSCOMPILING) IMPORTED_LOCATION ${PROTOC_EXECUTABLE} ) else() - message(FATAL ERROR "Please install the Protocol Buffers compiter v{${Protobuf_VERSION}} in the host machine") + message(FATAL ERROR "Please install the Protocol Buffers compiter v${Protobuf_VERSION} in the host machine") endif() endif() if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSION} VERSION_LESS ${GNSSSDR_PROTOBUF_MIN_VERSION})) @@ -1874,10 +1902,63 @@ if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSI BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX} - ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/bin/protoc + ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/bin/protoc ) endif() else() + if(OS_IS_LINUX) + if(NOT EXISTS "/usr/bin/libtoolize") + message(" libtool has not been found.") + message(" You can try to install it by typing:") + if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") + message(" sudo yum groupinstall 'Development Tools'") + elseif(${LINUX_DISTRIBUTION} MATCHES "openSUSE") + message(" sudo zypper install libtoool") + else() + message(" sudo apt-get install libtool") + endif() + message(FATAL_ERROR "libtool is required to build Protocol Buffers from source") + endif() + if(EXISTS "/usr/bin/aclocal" OR + EXISTS "/usr/bin/aclocal-1.16" OR + EXISTS "/usr/bin/aclocal-1.15" OR + EXISTS "/usr/bin/aclocal-1.14" OR + EXISTS "/usr/bin/aclocal-1.13" OR + EXISTS "/usr/bin/aclocal-1.11" OR + EXISTS "/usr/bin/aclocal-1.10") + message(STATUS "Automake found.") + else() + message(" aclocal has not been found.") + message(" You can try to install it by typing:") + if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") + message(" sudo yum groupinstall 'Development Tools'") + elseif(${LINUX_DISTRIBUTION} MATCHES "openSUSE") + message(" sudo zypper install automake") + else() + message(" sudo apt-get install automake") + endif() + message(FATAL_ERROR "aclocal is required to build Protocol Buffers from source") + endif() + endif() + find_package(CURL REQUIRED) + set_package_properties(CURL PROPERTIES + URL "https://curl.haxx.se/" + DESCRIPTION "Command line tool and library for transferring data with URLs" + PURPOSE "Required to build Protocol Buffers." + TYPE REQUIRED + ) + set(PROTOBUF_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) + if(PROTOBUF_MAKE_PROGRAM MATCHES "ninja") + find_program(MAKE_EXECUTABLE make + HINTS + /usr/bin/ + /usr/local/bin/ + ) + if(NOT MAKE_EXECUTABLE) + message(FATAL_ERROR "make is required to build Protocol Buffers from source.") + endif() + set(PROTOBUF_MAKE_PROGRAM ${MAKE_EXECUTABLE}) + endif() if(CMAKE_VERSION VERSION_LESS 3.2) ExternalProject_Add(protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} PREFIX ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} @@ -1887,8 +1968,8 @@ if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSI BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} UPDATE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/autogen.sh CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} - BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + BUILD_COMMAND ${PROTOBUF_MAKE_PROGRAM} + INSTALL_COMMAND ${PROTOBUF_MAKE_PROGRAM} install ) else() ExternalProject_Add(protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} @@ -1899,10 +1980,10 @@ if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSI BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} UPDATE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/autogen.sh CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} - BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + BUILD_COMMAND ${PROTOBUF_MAKE_PROGRAM} + INSTALL_COMMAND ${PROTOBUF_MAKE_PROGRAM} install BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX} - ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/bin/protoc + ${CMAKE_CURRENT_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/bin/protoc ) endif() @@ -1931,14 +2012,19 @@ if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSI ) if(${Protobuf_VERSION} VERSION_LESS ${GNSSSDR_PROTOBUF_MIN_VERSION}) - set_package_properties(Protobuf PROPERTIES - PURPOSE "Protocol Buffers found (v${Protobuf_VERSION}) is too old (> v${GNSSSDR_PROTOBUF_MIN_VERSION} needed)." - ) + if(NOT (${Protobuf_VERSION} EQUAL "0.0.0")) + set_package_properties(Protobuf PROPERTIES + PURPOSE "Protocol Buffers found (v${Protobuf_VERSION}) is too old (> v${GNSSSDR_PROTOBUF_MIN_VERSION} needed)." + ) + endif() endif() set_package_properties(Protobuf PROPERTIES PURPOSE "Protocol Buffers v${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION} will be downloaded and built when doing '${CMAKE_MAKE_PROGRAM_PRETTY_NAME}'." ) endif() +if(${Protobuf_VERSION} VERSION_EQUAL "0.0.0") + unset(Protobuf_VERSION) +endif() From fa4460038e96ecbf3e05525a54d3e1a6357fcbd0 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 24 Apr 2019 01:19:43 +0200 Subject: [PATCH 2/9] Fix warning: logical not is only applied to the left hand side of this comparison --- .../gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc index e2d93efda..3bc7b0325 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc @@ -488,7 +488,7 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__ // 2. Add the telemetry decoder information if (d_flag_preamble == true) { - if (!d_nav.d_TOW == 0) + if (!(d_nav.d_TOW == 0)) { d_TOW_at_current_symbol_ms = static_cast(d_nav.d_TOW * 1000.0); d_TOW_at_Preamble_ms = static_cast(d_nav.d_TOW * 1000.0); From a44c6e8b59393467fb99eb5b94372fb7a462b60a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 24 Apr 2019 01:30:22 +0200 Subject: [PATCH 3/9] Remove detection of curl since it is not really needed --- CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ce5e4ca8..865a04e2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1940,13 +1940,7 @@ if((NOT Protobuf_FOUND) OR (NOT Protobuf_PROTOC_EXECUTABLE) OR (${Protobuf_VERSI message(FATAL_ERROR "aclocal is required to build Protocol Buffers from source") endif() endif() - find_package(CURL REQUIRED) - set_package_properties(CURL PROPERTIES - URL "https://curl.haxx.se/" - DESCRIPTION "Command line tool and library for transferring data with URLs" - PURPOSE "Required to build Protocol Buffers." - TYPE REQUIRED - ) + set(PROTOBUF_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) if(PROTOBUF_MAKE_PROGRAM MATCHES "ninja") find_program(MAKE_EXECUTABLE make From 52ae97ed4e95606ef860c41b2853924702da3ad4 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 24 Apr 2019 15:50:53 +0200 Subject: [PATCH 4/9] Fix serialization --- src/core/monitor/serdes_gnss_synchro.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/monitor/serdes_gnss_synchro.h b/src/core/monitor/serdes_gnss_synchro.h index cbab0bd48..ee79ce993 100644 --- a/src/core/monitor/serdes_gnss_synchro.h +++ b/src/core/monitor/serdes_gnss_synchro.h @@ -97,8 +97,8 @@ public: obs->set_flag_valid_symbol_output(gs.Flag_valid_symbol_output); obs->set_correlation_length_ms(gs.correlation_length_ms); - obs->set_fs(gs.Flag_valid_word); - obs->set_fs(gs.TOW_at_current_symbol_ms); + obs->set_flag_valid_word(gs.Flag_valid_word); + obs->set_tow_at_current_symbol_ms(gs.TOW_at_current_symbol_ms); obs->set_pseudorange_m(gs.Pseudorange_m); obs->set_rx_time(gs.RX_time); From 69e6816392ede47b32919727fee86c836376788a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 24 Apr 2019 20:51:01 +0200 Subject: [PATCH 5/9] Make coexistence of different instances of gnss-sdr in the same machine easier If the user forgot to set parameter PVT.rtcm_output_file_enabled to false in the configuration file, this raised up the RTCM server even if flag_rtcm_server was set to false, thus preventing the execution of more than one instance of gnss-sdr in the same machine. By setting the default value of rtcm_output_file_enabled to false, just letting the PVT.flag_rtcm_server parameter to get its default value, which is false, enables more than one instance in the same host machine. This also alleviates by default optional processing load in embedded devices --- src/algorithms/PVT/adapters/rtklib_pvt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index 440036116..ac8c18f48 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -725,7 +725,7 @@ Rtklib_Pvt::Rtklib_Pvt(ConfigurationInterface* configuration, pvt_output_parameters.kml_output_enabled = configuration->property(role + ".kml_output_enabled", default_output_enabled); pvt_output_parameters.xml_output_enabled = configuration->property(role + ".xml_output_enabled", default_output_enabled); pvt_output_parameters.nmea_output_file_enabled = configuration->property(role + ".nmea_output_file_enabled", default_output_enabled); - pvt_output_parameters.rtcm_output_file_enabled = configuration->property(role + ".rtcm_output_file_enabled", default_output_enabled); + pvt_output_parameters.rtcm_output_file_enabled = configuration->property(role + ".rtcm_output_file_enabled", false); std::string default_output_path = configuration->property(role + ".output_path", std::string(".")); pvt_output_parameters.output_path = default_output_path; From 50d4db9c056ef391f10a440b48b538b5c60fa2e6 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 25 Apr 2019 08:50:21 +0200 Subject: [PATCH 6/9] Add a simple CN0 smoother --- .../gnuradio_blocks/dll_pll_veml_tracking.cc | 10 +- .../gnuradio_blocks/dll_pll_veml_tracking.h | 2 + src/algorithms/tracking/libs/CMakeLists.txt | 2 + .../tracking/libs/exponential_smoother.cc | 139 ++++++++++++++++++ .../tracking/libs/exponential_smoother.h | 71 +++++++++ 5 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 src/algorithms/tracking/libs/exponential_smoother.cc create mode 100644 src/algorithms/tracking/libs/exponential_smoother.h diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc index 4ccb3222f..6dd8f1405 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -439,6 +439,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl d_carrier_lock_fail_counter = 0; d_carrier_lock_threshold = trk_parameters.carrier_lock_th; d_Prompt_Data = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_cn0_smoother = Exponential_Smoother(); d_acquisition_gnss_synchro = nullptr; d_channel = 0; @@ -848,9 +849,12 @@ bool dll_pll_veml_tracking::cn0_and_tracking_lock_status(double coh_integration_ d_cn0_estimation_counter++; return true; } - d_cn0_estimation_counter = 0; + + d_Prompt_buffer[d_cn0_estimation_counter % trk_parameters.cn0_samples] = d_P_accu; + d_cn0_estimation_counter++; // Code lock indicator - d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, coh_integration_time_s); + double d_CN0_SNV_dB_Hz_raw = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, coh_integration_time_s); + d_CN0_SNV_dB_Hz = d_cn0_smoother.smooth(d_CN0_SNV_dB_Hz_raw); // Carrier lock indicator d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, trk_parameters.cn0_samples); // Loss of lock detection @@ -1593,7 +1597,7 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused) DLOG(INFO) << "Number of samples between Acquisition and Tracking = " << acq_trk_diff_samples << " ( " << acq_trk_diff_seconds << " s)"; DLOG(INFO) << "PULL-IN Doppler [Hz] = " << d_carrier_doppler_hz << ". PULL-IN Code Phase [samples] = " << d_acq_code_phase_samples; - + d_cn0_smoother.reset(); consume_each(samples_offset); // shift input to perform alignment with local replica return 0; } diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h index 43d95f3f6..1ccb44667 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h @@ -34,6 +34,7 @@ #include "cpu_multicorrelator_real_codes.h" #include "dll_pll_conf.h" +#include "exponential_smoother.h" #include "tracking_FLL_PLL_filter.h" // for PLL/FLL filter #include "tracking_loop_filter.h" // for DLL filter #include @@ -197,6 +198,7 @@ private: double d_carrier_lock_threshold; boost::circular_buffer d_Prompt_circular_buffer; gr_complex *d_Prompt_buffer; + Exponential_Smoother d_cn0_smoother; // file dump std::ofstream d_dump_file; diff --git a/src/algorithms/tracking/libs/CMakeLists.txt b/src/algorithms/tracking/libs/CMakeLists.txt index 7a7951645..763ce9b07 100644 --- a/src/algorithms/tracking/libs/CMakeLists.txt +++ b/src/algorithms/tracking/libs/CMakeLists.txt @@ -43,6 +43,7 @@ set(TRACKING_LIB_SOURCES tracking_loop_filter.cc dll_pll_conf.cc bayesian_estimation.cc + exponential_smoother.cc ) set(TRACKING_LIB_HEADERS @@ -59,6 +60,7 @@ set(TRACKING_LIB_HEADERS tracking_loop_filter.h dll_pll_conf.h bayesian_estimation.h + exponential_smoother.h ) if(ENABLE_FPGA) diff --git a/src/algorithms/tracking/libs/exponential_smoother.cc b/src/algorithms/tracking/libs/exponential_smoother.cc new file mode 100644 index 000000000..16d13fdce --- /dev/null +++ b/src/algorithms/tracking/libs/exponential_smoother.cc @@ -0,0 +1,139 @@ +/*! + * \file exponential_smoother.cc + * \brief Class that implements an exponential smoother + * \authors Carles Fernandez, 2019 cfernandez@cttc.es + * + * Class that implements a first-order exponential smoother. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2019 (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 . + * + * ------------------------------------------------------------------------- + */ + +#include "exponential_smoother.h" +#include /////////////// +#include +#include + +Exponential_Smoother::Exponential_Smoother() +{ + alpha_ = 0.001; + old_value_ = 0.0; + one_minus_alpha_ = 1.0 - alpha_; + samples_for_initialization_ = 500; + initializing_ = true; + init_counter_ = 0; + min_value_ = 25; + offset_ = 9.0; + init_buffer_.reserve(samples_for_initialization_); +} + + +Exponential_Smoother::~Exponential_Smoother() = default; + + +void Exponential_Smoother::set_alpha(float alpha) +{ + alpha_ = alpha; + if (alpha_ < 0) + { + alpha_ = 0; + } + if (alpha_ > 1) + { + alpha_ = 1; + } + one_minus_alpha_ = 1.0 - alpha_; +} + + +void Exponential_Smoother::set_offset(float offset) +{ + offset_ = offset; +} + + +void Exponential_Smoother::set_samples_for_initialization(int num_samples) +{ + int ns = num_samples; + if (ns <= 0) + { + ns = 1; + } + samples_for_initialization_ = num_samples; + init_buffer_.reserve(samples_for_initialization_); +} + + +void Exponential_Smoother::reset() +{ + initializing_ = true; + init_counter_ = 0; + init_buffer_.clear(); +} + + +void Exponential_Smoother::set_min_value(float value) +{ + min_value_ = value; +} + + +double Exponential_Smoother::smooth(double raw) +{ + float raw_f = static_cast(raw); + double smooth_d = static_cast((this)->smooth(raw_f)); + return smooth_d; +} + + +float Exponential_Smoother::smooth(float raw) +{ + float smoothed_value; + if (initializing_ == true) + { + init_counter_++; + smoothed_value = raw; + init_buffer_.push_back(smoothed_value); + if (init_counter_ == samples_for_initialization_) + { + old_value_ = std::accumulate(std::begin(init_buffer_), std::end(init_buffer_), 0.0) / static_cast(init_buffer_.size()); + if (old_value_ < (min_value_ + offset_)) + { + // flush buffer and start again + init_counter_ = 0; + init_buffer_.clear(); + } + else + { + initializing_ = false; + } + } + } + else + { + smoothed_value = alpha_ * raw + one_minus_alpha_ * old_value_; + old_value_ = smoothed_value; + } + return smoothed_value; +} diff --git a/src/algorithms/tracking/libs/exponential_smoother.h b/src/algorithms/tracking/libs/exponential_smoother.h new file mode 100644 index 000000000..327789949 --- /dev/null +++ b/src/algorithms/tracking/libs/exponential_smoother.h @@ -0,0 +1,71 @@ +/*! + * \file exponential_smoother.h + * \brief Class that implements an exponential smoother + * \authors Carles Fernandez, 2019 cfernandez@cttc.es + * + * Class that implements a first-order exponential smoother. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2019 (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_EXPONENTIAL_SMOOTHER_H_ +#define GNSS_SDR_EXPONENTIAL_SMOOTHER_H_ + +#include + +/*! \brief + * Class that implements a first-order exponential smoother. + * + * smoothed_value[k] = alpha * raw + (1-alpha) * smoothed_value[k-1] + * + * The length of the initialization can be controlled with + * set_samples_for_initialization(int num_samples) + */ +class Exponential_Smoother +{ +public: + Exponential_Smoother(); //!< Constructor + ~Exponential_Smoother(); //!< Destructor + void set_alpha(float alpha); //!< 0 < alpha < 1. The higher, the most responsive, but more variance. Default value: 0.0001 + void set_samples_for_initialization(int num_samples); //!< Number of samples averaged for initialization. Default value: + void reset(); + void set_min_value(float value); + void set_offset(float offset); + float smooth(float raw); + double smooth(double raw); +private: + float alpha_; // takes value 0.0001 if not set + int samples_for_initialization_; + float one_minus_alpha_; + float old_value_; + float min_value_; + float offset_; + bool initializing_; + int init_counter_; + std::vector init_buffer_; +}; + +#endif // GNSS_SDR_EXPONENTIAL_SMOOTHER_H_ From f5f255b28d2c412355d8f26cd77ea47a030f567e Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 25 Apr 2019 10:41:57 +0200 Subject: [PATCH 7/9] Fix building with new version of GNU Radio 3.7.13.5 maint --- src/algorithms/input_filter/adapters/CMakeLists.txt | 2 +- src/algorithms/resampler/adapters/CMakeLists.txt | 2 +- src/core/receiver/CMakeLists.txt | 2 +- src/tests/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/algorithms/input_filter/adapters/CMakeLists.txt b/src/algorithms/input_filter/adapters/CMakeLists.txt index 8459dea90..19583570e 100644 --- a/src/algorithms/input_filter/adapters/CMakeLists.txt +++ b/src/algorithms/input_filter/adapters/CMakeLists.txt @@ -62,7 +62,7 @@ target_include_directories(input_filter_adapters ${CMAKE_SOURCE_DIR}/src/core/interfaces ) -if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.13.4") +if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.20") target_compile_definitions(input_filter_adapters PUBLIC -DGR_GREATER_38=1) endif() diff --git a/src/algorithms/resampler/adapters/CMakeLists.txt b/src/algorithms/resampler/adapters/CMakeLists.txt index 18554d352..398187b46 100644 --- a/src/algorithms/resampler/adapters/CMakeLists.txt +++ b/src/algorithms/resampler/adapters/CMakeLists.txt @@ -52,7 +52,7 @@ target_include_directories(resampler_adapters ${CMAKE_SOURCE_DIR}/src/core/interfaces ) -if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.13.4") +if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.20") target_compile_definitions(resampler_adapters PUBLIC -DGR_GREATER_38=1) endif() diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt index d18eaa976..7ce6380c3 100644 --- a/src/core/receiver/CMakeLists.txt +++ b/src/core/receiver/CMakeLists.txt @@ -84,7 +84,7 @@ if(PC_GNURADIO_RUNTIME_VERSION VERSION_GREATER 3.7.3) target_compile_definitions(core_receiver PRIVATE -DMODERN_GNURADIO=1) endif() -if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.13.4") +if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.20") target_compile_definitions(core_receiver PRIVATE -DGR_GREATER_38=1) endif() diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 4509fcf99..4e9e586c1 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -141,7 +141,7 @@ endif() # Definitions ################################################################################ -if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.13.4") +if(${PC_GNURADIO_RUNTIME_VERSION} VERSION_GREATER "3.7.20") add_definitions(-DGR_GREATER_38=1) endif() From 42c0544c4c3033aeaad574f8de3e17da8600edb1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 25 Apr 2019 14:58:30 +0200 Subject: [PATCH 8/9] Accelerate CN0 estimation --- .../tracking/libs/lock_detectors.cc | 22 +++++++++---------- src/algorithms/tracking/libs/lock_detectors.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/algorithms/tracking/libs/lock_detectors.cc b/src/algorithms/tracking/libs/lock_detectors.cc index b66e3a15d..6633b893a 100644 --- a/src/algorithms/tracking/libs/lock_detectors.cc +++ b/src/algorithms/tracking/libs/lock_detectors.cc @@ -65,23 +65,23 @@ * where \f$T_{int}\f$ is the coherent integration time, in seconds. * */ -float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, double coh_integration_time_s) +float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, float coh_integration_time_s) { - double SNR = 0.0; - double SNR_dB_Hz = 0.0; - double Psig = 0.0; - double Ptot = 0.0; + float SNR = 0.0; + float SNR_dB_Hz = 0.0; + float Psig = 0.0; + float Ptot = 0.0; for (int i = 0; i < length; i++) { - Psig += std::abs(static_cast(Prompt_buffer[i].real())); - Ptot += static_cast(Prompt_buffer[i].imag()) * static_cast(Prompt_buffer[i].imag()) + static_cast(Prompt_buffer[i].real()) * static_cast(Prompt_buffer[i].real()); + Psig += std::abs(Prompt_buffer[i].real()); + Ptot += Prompt_buffer[i].imag() * Prompt_buffer[i].imag() + Prompt_buffer[i].real() * Prompt_buffer[i].real(); } - Psig /= static_cast(length); + Psig /= static_cast(length); Psig = Psig * Psig; - Ptot /= static_cast(length); + Ptot /= static_cast(length); SNR = Psig / (Ptot - Psig); - SNR_dB_Hz = 10.0 * log10(SNR) - 10.0 * log10(coh_integration_time_s); - return static_cast(SNR_dB_Hz); + SNR_dB_Hz = 10.0 * std::log10(SNR) - 10.0 * std::log10(coh_integration_time_s); + return SNR_dB_Hz; } diff --git a/src/algorithms/tracking/libs/lock_detectors.h b/src/algorithms/tracking/libs/lock_detectors.h index 90dc90fcb..81d54b651 100644 --- a/src/algorithms/tracking/libs/lock_detectors.h +++ b/src/algorithms/tracking/libs/lock_detectors.h @@ -72,7 +72,7 @@ * IEEE 10th International Symposium on Spread Spectrum Techniques and * Applications, pp.28-30, August 2008. */ -float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, double coh_integration_time_s); +float cn0_svn_estimator(const gr_complex* Prompt_buffer, int length, float coh_integration_time_s); /*! \brief A carrier lock detector From 9d3619990138445434740ab9d4cbba7c9eec7b76 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 25 Apr 2019 15:30:11 +0200 Subject: [PATCH 9/9] Trim CN0 smoother parameters. Add it to the FPGA block --- .../tracking/gnuradio_blocks/dll_pll_veml_tracking.cc | 10 +++++++--- .../gnuradio_blocks/dll_pll_veml_tracking_fpga.cc | 9 ++++++++- .../gnuradio_blocks/dll_pll_veml_tracking_fpga.h | 2 ++ src/algorithms/tracking/libs/exponential_smoother.cc | 9 ++++----- src/algorithms/tracking/libs/exponential_smoother.h | 4 ++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc index 6dd8f1405..57c19c994 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -440,7 +440,10 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl d_carrier_lock_threshold = trk_parameters.carrier_lock_th; d_Prompt_Data = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex), volk_gnsssdr_get_alignment())); d_cn0_smoother = Exponential_Smoother(); - + if (d_code_period > 0.0) + { + d_cn0_smoother.set_samples_for_initialization(200 / static_cast(d_code_period * 1000.0)); + } d_acquisition_gnss_synchro = nullptr; d_channel = 0; d_acq_code_phase_samples = 0.0; @@ -853,7 +856,7 @@ bool dll_pll_veml_tracking::cn0_and_tracking_lock_status(double coh_integration_ d_Prompt_buffer[d_cn0_estimation_counter % trk_parameters.cn0_samples] = d_P_accu; d_cn0_estimation_counter++; // Code lock indicator - double d_CN0_SNV_dB_Hz_raw = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, coh_integration_time_s); + float d_CN0_SNV_dB_Hz_raw = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, static_cast(coh_integration_time_s)); d_CN0_SNV_dB_Hz = d_cn0_smoother.smooth(d_CN0_SNV_dB_Hz_raw); // Carrier lock indicator d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, trk_parameters.cn0_samples); @@ -1593,11 +1596,12 @@ int dll_pll_veml_tracking::general_work(int noutput_items __attribute__((unused) d_acc_carrier_phase_rad -= d_carrier_phase_step_rad * static_cast(samples_offset); d_state = 2; d_sample_counter += samples_offset; // count for the processed samples + d_cn0_smoother.reset(); DLOG(INFO) << "Number of samples between Acquisition and Tracking = " << acq_trk_diff_samples << " ( " << acq_trk_diff_seconds << " s)"; DLOG(INFO) << "PULL-IN Doppler [Hz] = " << d_carrier_doppler_hz << ". PULL-IN Code Phase [samples] = " << d_acq_code_phase_samples; - d_cn0_smoother.reset(); + consume_each(samples_offset); // shift input to perform alignment with local replica return 0; } diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc index 185281684..43cc30e7a 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc @@ -350,6 +350,11 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & d_Prompt_buffer = new gr_complex[trk_parameters.cn0_samples]; d_carrier_lock_test = 1.0; d_CN0_SNV_dB_Hz = 0.0; + d_cn0_smoother = Exponential_Smoother(); + if (d_code_period > 0.0) + { + d_cn0_smoother.set_samples_for_initialization(200 / static_cast(d_code_period * 1000.0)); + } d_carrier_lock_fail_counter = 0; d_carrier_lock_threshold = trk_parameters.carrier_lock_th; d_Prompt_Data = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex), volk_gnsssdr_get_alignment())); @@ -582,7 +587,8 @@ bool dll_pll_veml_tracking_fpga::cn0_and_tracking_lock_status(double coh_integra { d_cn0_estimation_counter = 0; // Code lock indicator - d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, coh_integration_time_s); + float d_CN0_SNV_dB_Hz_raw = cn0_svn_estimator(d_Prompt_buffer, trk_parameters.cn0_samples, static_cast(coh_integration_time_s)); + d_CN0_SNV_dB_Hz = d_cn0_smoother.smooth(d_CN0_SNV_dB_Hz_raw); // Carrier lock indicator d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, trk_parameters.cn0_samples); // Loss of lock detection @@ -1437,6 +1443,7 @@ int dll_pll_veml_tracking_fpga::general_work(int noutput_items __attribute__((un int32_t samples_offset = round(d_acq_code_phase_samples); d_acc_carrier_phase_rad -= d_carrier_phase_step_rad * static_cast(samples_offset); d_state = 2; + d_cn0_smoother.reset(); // DEBUG OUTPUT std::cout << "Tracking of " << systemName << " " << signal_pretty_name << " signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName, d_acquisition_gnss_synchro->PRN) << std::endl; diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h index 388775a7e..0cb708323 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h @@ -33,6 +33,7 @@ #define GNSS_SDR_DLL_PLL_VEML_TRACKING_FPGA_H #include "dll_pll_conf_fpga.h" +#include "exponential_smoother.h" #include "tracking_FLL_PLL_filter.h" // for PLL/FLL filter #include "tracking_loop_filter.h" // for DLL filter #include @@ -201,6 +202,7 @@ private: boost::circular_buffer d_Prompt_circular_buffer; //std::deque d_Prompt_buffer_deque; gr_complex *d_Prompt_buffer; + Exponential_Smoother d_cn0_smoother; // file dump std::ofstream d_dump_file; diff --git a/src/algorithms/tracking/libs/exponential_smoother.cc b/src/algorithms/tracking/libs/exponential_smoother.cc index 16d13fdce..e05ff9c9b 100644 --- a/src/algorithms/tracking/libs/exponential_smoother.cc +++ b/src/algorithms/tracking/libs/exponential_smoother.cc @@ -31,7 +31,6 @@ */ #include "exponential_smoother.h" -#include /////////////// #include #include @@ -40,11 +39,11 @@ Exponential_Smoother::Exponential_Smoother() alpha_ = 0.001; old_value_ = 0.0; one_minus_alpha_ = 1.0 - alpha_; - samples_for_initialization_ = 500; + samples_for_initialization_ = 200; initializing_ = true; init_counter_ = 0; - min_value_ = 25; - offset_ = 9.0; + min_value_ = 25.0; + offset_ = 12.0; init_buffer_.reserve(samples_for_initialization_); } @@ -117,7 +116,7 @@ float Exponential_Smoother::smooth(float raw) init_buffer_.push_back(smoothed_value); if (init_counter_ == samples_for_initialization_) { - old_value_ = std::accumulate(std::begin(init_buffer_), std::end(init_buffer_), 0.0) / static_cast(init_buffer_.size()); + old_value_ = std::accumulate(std::begin(init_buffer_), std::end(init_buffer_), 0.0f) / static_cast(init_buffer_.size()); if (old_value_ < (min_value_ + offset_)) { // flush buffer and start again diff --git a/src/algorithms/tracking/libs/exponential_smoother.h b/src/algorithms/tracking/libs/exponential_smoother.h index 327789949..f8ff21182 100644 --- a/src/algorithms/tracking/libs/exponential_smoother.h +++ b/src/algorithms/tracking/libs/exponential_smoother.h @@ -49,8 +49,8 @@ class Exponential_Smoother public: Exponential_Smoother(); //!< Constructor ~Exponential_Smoother(); //!< Destructor - void set_alpha(float alpha); //!< 0 < alpha < 1. The higher, the most responsive, but more variance. Default value: 0.0001 - void set_samples_for_initialization(int num_samples); //!< Number of samples averaged for initialization. Default value: + void set_alpha(float alpha); //!< 0 < alpha < 1. The higher, the most responsive, but more variance. Default value: 0.001 + void set_samples_for_initialization(int num_samples); //!< Number of samples averaged for initialization. Default value: 200 void reset(); void set_min_value(float value); void set_offset(float offset);