From 8d424a13b67cb2168737b718867c7443e9369c5e Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 12 Jun 2019 20:39:29 +0200 Subject: [PATCH 1/4] Replace boost::filesystem by std::experimental::filesystem when the later is available --- CMakeLists.txt | 4 +-- .../PVT/gnuradio_blocks/CMakeLists.txt | 3 ++ .../PVT/gnuradio_blocks/rtklib_pvt_gs.cc | 9 +++-- src/algorithms/PVT/libs/CMakeLists.txt | 3 ++ src/algorithms/PVT/libs/geojson_printer.cc | 22 ++++++------ src/algorithms/PVT/libs/gpx_printer.cc | 22 ++++++------ src/algorithms/PVT/libs/kml_printer.cc | 22 ++++++------ src/algorithms/PVT/libs/nmea_printer.cc | 22 ++++++------ src/algorithms/PVT/libs/rinex_printer.cc | 22 ++++++------ src/algorithms/PVT/libs/rtcm_printer.cc | 23 ++++++------ .../gnuradio_blocks/CMakeLists.txt | 3 ++ .../gnuradio_blocks/pcps_acquisition.cc | 8 +++++ .../pcps_acquisition_fine_doppler_cc.cc | 8 +++++ src/algorithms/libs/CMakeLists.txt | 6 ++++ .../libs/gnss_sdr_create_directory.cc | 20 ++++++----- src/algorithms/libs/gnss_sdr_flags.cc | 14 ++++---- .../gnuradio_blocks/CMakeLists.txt | 3 ++ .../gnuradio_blocks/hybrid_observables_gs.cc | 6 ++++ .../tracking/gnuradio_blocks/CMakeLists.txt | 3 ++ .../gnuradio_blocks/dll_pll_veml_tracking.cc | 5 +++ .../dll_pll_veml_tracking_fpga.cc | 5 +++ src/main/CMakeLists.txt | 3 ++ src/main/main.cc | 35 ++++++++++--------- src/tests/CMakeLists.txt | 24 +++++++++++++ .../unit-tests/arithmetic/fft_length_test.cc | 5 +++ .../acquisition/acq_performance_test.cc | 12 +++++-- .../beidou_b1i_pcps_acquisition_test.cc | 5 +++ .../beidou_b3i_pcps_acquisition_test.cc | 5 +++ ...ileo_e1_pcps_ambiguous_acquisition_test.cc | 6 ++++ .../gps_l1_ca_pcps_acquisition_test.cc | 5 +++ .../gps_l2_m_pcps_acquisition_test.cc | 5 +++ .../gps_l1_ca_dll_pll_tracking_test.cc | 5 +++ .../tracking/gps_l1_ca_kf_tracking_test.cc | 5 +++ .../tracking/tracking_pull-in_test.cc | 5 +++ .../tracking/tracking_pull-in_test_fpga.cc | 18 ++++++++-- src/utils/front-end-cal/CMakeLists.txt | 3 ++ 36 files changed, 271 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c405d0c58..039742c14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -763,7 +763,7 @@ if(NOT (GNURADIO_VERSION VERSION_LESS 3.8)) cmake_policy(SET CMP0057 NEW) endif() if(NOT ENABLE_UNIT_TESTING_EXTRA) # Workaround for GPSTk - find_package(FILESYSTEM) + find_package(FILESYSTEM COMPONENTS Final Experimental) set_package_properties(FILESYSTEM PROPERTIES URL "https://en.cppreference.com/w/cpp/filesystem" DESCRIPTION "Provides facilities for performing operations on file systems and their components" @@ -894,8 +894,6 @@ endif() - - ################################################################################ # VOLK - Vector-Optimized Library of Kernels ################################################################################ diff --git a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt index 060318af0..081a1ab49 100644 --- a/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/PVT/gnuradio_blocks/CMakeLists.txt @@ -30,6 +30,9 @@ add_library(pvt_gr_blocks ${PVT_GR_BLOCKS_SOURCES} ${PVT_GR_BLOCKS_HEADERS}) if(${FILESYSTEM_FOUND}) target_compile_definitions(pvt_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(pvt_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(pvt_gr_blocks PRIVATE std::filesystem) else() target_link_libraries(pvt_gr_blocks PRIVATE Boost::filesystem Boost::system) diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc index 3a8bfc697..2af4082b6 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc @@ -83,10 +83,15 @@ #include // for msgctl #if HAS_STD_FILESYSTEM -#include #include -namespace fs = std::filesystem; namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif #else #include #include // for error_code diff --git a/src/algorithms/PVT/libs/CMakeLists.txt b/src/algorithms/PVT/libs/CMakeLists.txt index 92e1aec04..6850f3515 100644 --- a/src/algorithms/PVT/libs/CMakeLists.txt +++ b/src/algorithms/PVT/libs/CMakeLists.txt @@ -63,6 +63,9 @@ add_library(pvt_libs ${PVT_LIB_SOURCES} ${PVT_LIB_HEADERS}) if(${FILESYSTEM_FOUND}) target_compile_definitions(pvt_libs PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(pvt_libs PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(pvt_libs PRIVATE std::filesystem) else() target_link_libraries(pvt_libs PRIVATE Boost::filesystem Boost::system) diff --git a/src/algorithms/PVT/libs/geojson_printer.cc b/src/algorithms/PVT/libs/geojson_printer.cc index 6f9dcffe4..f15d9efef 100644 --- a/src/algorithms/PVT/libs/geojson_printer.cc +++ b/src/algorithms/PVT/libs/geojson_printer.cc @@ -33,15 +33,6 @@ #include "geojson_printer.h" #include "pvt_solution.h" #include -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_code -#endif #include #include // for remove #include // for tm @@ -51,9 +42,20 @@ #include // for stringstream #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/PVT/libs/gpx_printer.cc b/src/algorithms/PVT/libs/gpx_printer.cc index 8925f281a..0cc7ded4b 100644 --- a/src/algorithms/PVT/libs/gpx_printer.cc +++ b/src/algorithms/PVT/libs/gpx_printer.cc @@ -33,15 +33,6 @@ #include "gpx_printer.h" #include "rtklib_solver.h" #include -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_code -#endif #include #include // for remove #include // for tm @@ -51,9 +42,20 @@ #include // for stringstream #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/PVT/libs/kml_printer.cc b/src/algorithms/PVT/libs/kml_printer.cc index 335fc0fee..f726531e0 100644 --- a/src/algorithms/PVT/libs/kml_printer.cc +++ b/src/algorithms/PVT/libs/kml_printer.cc @@ -33,15 +33,6 @@ #include "kml_printer.h" #include "rtklib_solver.h" #include -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_code -#endif #include #include // for remove #include // for mkstemp @@ -55,9 +46,20 @@ #include //for mode_t #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc index 0e7127003..c70deb403 100644 --- a/src/algorithms/PVT/libs/nmea_printer.cc +++ b/src/algorithms/PVT/libs/nmea_printer.cc @@ -36,15 +36,6 @@ #include "nmea_printer.h" #include "rtklib_solution.h" #include "rtklib_solver.h" -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_code -#endif #include #include #include @@ -53,9 +44,20 @@ #include #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/PVT/libs/rinex_printer.cc b/src/algorithms/PVT/libs/rinex_printer.cc index 7da65c565..e8a5e2e9c 100644 --- a/src/algorithms/PVT/libs/rinex_printer.cc +++ b/src/algorithms/PVT/libs/rinex_printer.cc @@ -53,15 +53,6 @@ #include #include #include -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_code -#endif #include #include // for min and max #include // for floor @@ -76,9 +67,20 @@ #include #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/PVT/libs/rtcm_printer.cc b/src/algorithms/PVT/libs/rtcm_printer.cc index bccec8dce..1ced95bfc 100644 --- a/src/algorithms/PVT/libs/rtcm_printer.cc +++ b/src/algorithms/PVT/libs/rtcm_printer.cc @@ -39,16 +39,6 @@ #include "gps_cnav_ephemeris.h" #include "gps_ephemeris.h" #include "rtcm.h" -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include -#include // for create_directories, exists -#include // for path, operator<< -#include // for filesystem -#include // for error_codes -#endif #include #include // for remove #include // for tm @@ -59,9 +49,20 @@ #include // for close, write #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt index dfec5b089..79d6eeb64 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt @@ -68,6 +68,9 @@ add_library(acquisition_gr_blocks ${ACQ_GR_BLOCKS_SOURCES} ${ACQ_GR_BLOCKS_HEADE if(${FILESYSTEM_FOUND}) target_compile_definitions(acquisition_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(acquisition_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(acquisition_gr_blocks PRIVATE std::filesystem) else() target_link_libraries(acquisition_gr_blocks PRIVATE Boost::filesystem) diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc index abb00ea79..3cf3564d5 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc @@ -40,7 +40,11 @@ #include "gnss_sdr_create_directory.h" #include "gnss_synchro.h" #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +#else #include +#endif #else #include #endif @@ -58,7 +62,11 @@ #include #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +namespace fs = std::experimental::filesystem; +#else namespace fs = std::filesystem; +#endif #else namespace fs = boost::filesystem; #endif diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc index 051c81130..aa5af66c9 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc @@ -35,7 +35,11 @@ #include "gnss_sdr_create_directory.h" #include "gps_sdr_signal_processing.h" #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +#else #include +#endif #else #include #endif @@ -48,7 +52,11 @@ #include #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +namespace fs = std::experimental::filesystem; +#else namespace fs = std::filesystem; +#endif #else namespace fs = boost::filesystem; #endif diff --git a/src/algorithms/libs/CMakeLists.txt b/src/algorithms/libs/CMakeLists.txt index 4dc71a6bb..c00cb1081 100644 --- a/src/algorithms/libs/CMakeLists.txt +++ b/src/algorithms/libs/CMakeLists.txt @@ -90,6 +90,9 @@ add_library(algorithms_libs ${GNSS_SPLIBS_SOURCES} ${GNSS_SPLIBS_HEADERS}) if(${FILESYSTEM_FOUND}) target_compile_definitions(algorithms_libs PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(algorithms_libs PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(algorithms_libs PRIVATE std::filesystem) else() target_link_libraries(algorithms_libs PRIVATE Boost::filesystem Boost::system) @@ -141,6 +144,9 @@ add_library(gnss_sdr_flags gnss_sdr_flags.cc gnss_sdr_flags.h) if(${FILESYSTEM_FOUND}) target_compile_definitions(gnss_sdr_flags PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + add_definitions(-DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(gnss_sdr_flags PRIVATE std::filesystem) else() target_link_libraries(gnss_sdr_flags PRIVATE Boost::filesystem) diff --git a/src/algorithms/libs/gnss_sdr_create_directory.cc b/src/algorithms/libs/gnss_sdr_create_directory.cc index 325f5ebac..e147d3a39 100644 --- a/src/algorithms/libs/gnss_sdr_create_directory.cc +++ b/src/algorithms/libs/gnss_sdr_create_directory.cc @@ -29,22 +29,24 @@ */ #include "gnss_sdr_create_directory.h" +#include // for exception +#include // for ofstream + #if HAS_STD_FILESYSTEM -#include #include +namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif #else #include // for create_directories, exists #include // for path, operator<< #include // for filesystem #include // for error_code -#endif -#include // for exception -#include // for ofstream - -#if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; -namespace errorlib = std; -#else namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/algorithms/libs/gnss_sdr_flags.cc b/src/algorithms/libs/gnss_sdr_flags.cc index 756d428f4..056ff14c7 100644 --- a/src/algorithms/libs/gnss_sdr_flags.cc +++ b/src/algorithms/libs/gnss_sdr_flags.cc @@ -30,18 +30,20 @@ #include "gnss_sdr_flags.h" -#if HAS_STD_FILESYSTEM -#include -#else -#include // for exists -#endif #include #include #include #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include namespace fs = boost::filesystem; #endif diff --git a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt index c1d7bd7dc..85edd75a9 100644 --- a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt @@ -30,6 +30,9 @@ add_library(obs_gr_blocks ${OBS_GR_BLOCKS_SOURCES} ${OBS_GR_BLOCKS_HEADERS}) if(${FILESYSTEM_FOUND}) target_compile_definitions(obs_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(obs_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(obs_gr_blocks PRIVATE std::filesystem) else() target_link_libraries(obs_gr_blocks PRIVATE Boost::filesystem) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.cc index 36d977fdd..935f01f5c 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_gs.cc @@ -46,13 +46,19 @@ #include // for move #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; #endif + hybrid_observables_gs_sptr hybrid_observables_gs_make(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, bool dump_mat, std::string dump_filename) { return hybrid_observables_gs_sptr(new hybrid_observables_gs(nchannels_in, nchannels_out, dump, dump_mat, std::move(dump_filename))); diff --git a/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt b/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt index 7544c2f4a..7f5c63bf6 100644 --- a/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt @@ -78,6 +78,9 @@ add_library(tracking_gr_blocks if(${FILESYSTEM_FOUND}) target_compile_definitions(tracking_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(tracking_gr_blocks PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(tracking_gr_blocks PRIVATE std::filesystem) else() target_link_libraries(tracking_gr_blocks PRIVATE Boost::filesystem) 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 2e9610bf5..90f1b3d55 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -67,8 +67,13 @@ #include #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; 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 5ee4bee2a..d555aecb8 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 @@ -60,8 +60,13 @@ #include #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 96e1d3c97..dac5a6eed 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -21,6 +21,9 @@ add_executable(gnss-sdr ${CMAKE_CURRENT_SOURCE_DIR}/main.cc) if(${FILESYSTEM_FOUND}) target_compile_definitions(gnss-sdr PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(gnss-sdr PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(gnss-sdr PRIVATE std::filesystem) else() target_link_libraries(gnss-sdr PRIVATE Boost::filesystem Boost::system) diff --git a/src/main/main.cc b/src/main/main.cc index cf01b30b5..7aba038c4 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -46,21 +46,13 @@ #include // for diagnostic_informatio #include // for exception #include // for thread_resource_error -#if HAS_STD_FILESYSTEM -#include -#include -#else -#include // for create_directories, exists -#include // for path, operator<< -#include // for error_code -#endif -#include // for ShutDownCommandLineFlags -#include // for FLAGS_log_dir -#include // for time_point -#include // for exception -#include // for operator<<, endl -#include // for unique_ptr -#include // for string +#include // for ShutDownCommandLineFlags +#include // for FLAGS_log_dir +#include // for time_point +#include // for exception +#include // for operator<<, endl +#include // for unique_ptr +#include // for string #if CUDA_GPU_ACCEL // For the CUDA runtime routines (prefixed with "cuda_") @@ -68,9 +60,20 @@ #endif #if HAS_STD_FILESYSTEM -namespace fs = std::filesystem; +#include namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; #else +#include +namespace fs = std::filesystem; +#endif +#else +#include // for create_directories, exists +#include // for path, operator<< +#include // for filesystem +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 4bb206ad0..266d33b9d 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -356,6 +356,9 @@ if(ENABLE_UNIT_TESTING) add_executable(run_tests ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cc) if(${FILESYSTEM_FOUND}) target_compile_definitions(run_tests PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(run_tests PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(run_tests PRIVATE std::filesystem) else() target_link_libraries(run_tests PRIVATE Boost::filesystem Boost::system) @@ -447,6 +450,9 @@ if(ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(gps_l1_ca_dll_pll_tracking_test_fpga PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(gps_l1_ca_dll_pll_tracking_test_fpga PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(gps_l1_ca_dll_pll_tracking_test_fpga PRIVATE std::filesystem) else() target_link_libraries(gps_l1_ca_dll_pll_tracking_test_fpga PRIVATE Boost::filesystem Boost::system) @@ -492,6 +498,9 @@ function(add_system_test executable) add_executable(${executable} ${SYSTEM_TEST_SOURCES}) if(${FILESYSTEM_FOUND}) target_compile_definitions(${executable} PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(${executable} PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(${executable} PRIVATE std::filesystem) else() target_link_libraries(${executable} PRIVATE Boost::filesystem Boost::system) @@ -585,6 +594,9 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(flowgraph_test PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(flowgraph_test PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(flowgraph_test PRIVATE std::filesystem) else() target_link_libraries(flowgraph_test PRIVATE Boost::filesystem Boost::system) @@ -634,6 +646,9 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(gnss_block_test PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(gnss_block_test PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(gnss_block_test PRIVATE std::filesystem) else() target_link_libraries(gnss_block_test PRIVATE Boost::filesystem Boost::system) @@ -681,6 +696,9 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(gnuradio_block_test PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(gnuradio_block_test PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(gnuradio_block_test PRIVATE std::filesystem) else() target_link_libraries(gnuradio_block_test PRIVATE Boost::filesystem Boost::system) @@ -784,6 +802,9 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(trk_test PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(trk_test PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(trk_test PRIVATE std::filesystem) else() target_link_libraries(trk_test PRIVATE Boost::filesystem Boost::system) @@ -825,6 +846,9 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA) ) if(${FILESYSTEM_FOUND}) target_compile_definitions(control_thread_test PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(control_thread_test PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(control_thread_test PRIVATE std::filesystem) else() target_link_libraries(control_thread_test PRIVATE Boost::filesystem Boost::system) diff --git a/src/tests/unit-tests/arithmetic/fft_length_test.cc b/src/tests/unit-tests/arithmetic/fft_length_test.cc index 5b2583758..ed4aff8b7 100644 --- a/src/tests/unit-tests/arithmetic/fft_length_test.cc +++ b/src/tests/unit-tests/arithmetic/fft_length_test.cc @@ -38,8 +38,13 @@ #include #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/acq_performance_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/acq_performance_test.cc index 82b0fdcfd..73e09e9ec 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/acq_performance_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/acq_performance_test.cc @@ -55,17 +55,23 @@ #include #if HAS_STD_FILESYSTEM -#include #include -namespace fs = std::filesystem; namespace errorlib = std; +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif #else #include -#include +#include // for error_code namespace fs = boost::filesystem; namespace errorlib = boost::system; #endif + DEFINE_string(config_file_ptest, std::string(""), "File containing alternative configuration parameters for the acquisition performance test."); DEFINE_string(acq_test_input_file, std::string(""), "File containing raw signal data, must be in int8_t format. The signal generator will not be used."); DEFINE_string(acq_test_implementation, std::string("GPS_L1_CA_PCPS_Acquisition"), "Acquisition block implementation under test. Alternatives: GPS_L1_CA_PCPS_Acquisition, GPS_L1_CA_PCPS_Acquisition_Fine_Doppler, Galileo_E1_PCPS_Ambiguous_Acquisition, GLONASS_L1_CA_PCPS_Acquisition, GLONASS_L2_CA_PCPS_Acquisition, GPS_L2_M_PCPS_Acquisition, Galileo_E5a_Pcps_Acquisition, GPS_L5i_PCPS_Acquisition"); diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b1i_pcps_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b1i_pcps_acquisition_test.cc index efb923137..c2658889a 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b1i_pcps_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b1i_pcps_acquisition_test.cc @@ -59,8 +59,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b3i_pcps_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b3i_pcps_acquisition_test.cc index 8d39ac2ff..725135d5b 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b3i_pcps_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/beidou_b3i_pcps_acquisition_test.cc @@ -59,8 +59,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test.cc index 204acbb14..58fa9b8e6 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/galileo_e1_pcps_ambiguous_acquisition_test.cc @@ -60,13 +60,19 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; #endif + // ######## GNURADIO BLOCK MESSAGE RECEVER ######### class GalileoE1PcpsAmbiguousAcquisitionTest_msg_rx; diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test.cc index 42fe90a6b..01f424eb8 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l1_ca_pcps_acquisition_test.cc @@ -59,8 +59,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l2_m_pcps_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l2_m_pcps_acquisition_test.cc index ae50d3bb0..de7bc4e27 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l2_m_pcps_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/gps_l2_m_pcps_acquisition_test.cc @@ -60,8 +60,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc index 3e33bc3bf..411221e1e 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_dll_pll_tracking_test.cc @@ -61,8 +61,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_kf_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_kf_tracking_test.cc index 0b16279f7..89c1cb591 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_kf_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/gps_l1_ca_kf_tracking_test.cc @@ -60,8 +60,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc index 21567e373..e7aa0676f 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc @@ -76,8 +76,13 @@ #endif #if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else #include namespace fs = std::filesystem; +#endif #else #include namespace fs = boost::filesystem; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc index a2546b400..bf997d7b4 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc @@ -47,7 +47,6 @@ #include "tracking_tests_flags.h" #include "tracking_true_obs_reader.h" #include -#include #include #include #include @@ -60,6 +59,19 @@ #include #include +#if HAS_STD_FILESYSTEM +#if HAS_STD_FILESYSTEM_EXPERIMENTAL +#include +namespace fs = std::experimental::filesystem; +#else +#include +namespace fs = std::filesystem; +#endif +#else +#include +namespace fs = boost::filesystem; +#endif + // threads #include // for open, O_RDWR, O_SYNC #include // for cout, endl @@ -1131,8 +1143,8 @@ TEST_F(TrackingPullInTestFpga, ValidationOfResults) { try { - boost::filesystem::path p(gnuplot_executable); - boost::filesystem::path dir = p.parent_path(); + fs::path p(gnuplot_executable); + fs::path dir = p.parent_path(); const std::string& gnuplot_path = dir.native(); Gnuplot::set_GNUPlotPath(gnuplot_path); auto decimate = static_cast(FLAGS_plot_decimate); diff --git a/src/utils/front-end-cal/CMakeLists.txt b/src/utils/front-end-cal/CMakeLists.txt index 80f05cc2b..303b4640d 100644 --- a/src/utils/front-end-cal/CMakeLists.txt +++ b/src/utils/front-end-cal/CMakeLists.txt @@ -58,6 +58,9 @@ add_executable(front-end-cal ${CMAKE_CURRENT_SOURCE_DIR}/main.cc) if(${FILESYSTEM_FOUND}) target_compile_definitions(front-end-cal PRIVATE -DHAS_STD_FILESYSTEM=1) + if(${find_experimental}) + target_compile_definitions(front-end-cal PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1) + endif() target_link_libraries(front-end-cal PRIVATE std::filesystem) else() target_link_libraries(front-end-cal PRIVATE Boost::filesystem Boost::system) From 46979c2197507c9af703e65a6352b8c510a234d1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 12 Jun 2019 20:52:40 +0200 Subject: [PATCH 2/4] Fix test when std::filesystem is available --- .../tracking/tracking_pull-in_test_fpga.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc index a2546b400..aee343587 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test_fpga.cc @@ -47,7 +47,6 @@ #include "tracking_tests_flags.h" #include "tracking_true_obs_reader.h" #include -#include #include #include #include @@ -60,6 +59,14 @@ #include #include +#if HAS_STD_FILESYSTEM +#include +namespace fs = std::filesystem; +#else +#include +namespace fs = boost::filesystem; +#endif + // threads #include // for open, O_RDWR, O_SYNC #include // for cout, endl @@ -1131,8 +1138,8 @@ TEST_F(TrackingPullInTestFpga, ValidationOfResults) { try { - boost::filesystem::path p(gnuplot_executable); - boost::filesystem::path dir = p.parent_path(); + fs::path p(gnuplot_executable); + fs::path dir = p.parent_path(); const std::string& gnuplot_path = dir.native(); Gnuplot::set_GNUPlotPath(gnuplot_path); auto decimate = static_cast(FLAGS_plot_decimate); From e285da589924c1b7ee9c3d88c31776d214317891 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 13 Jun 2019 15:33:01 +0200 Subject: [PATCH 3/4] Replace boost::filesystem by std::experimental::filesystem when the later is available --- CMakeLists.txt | 34 +++++++++++++-------------- cmake/Modules/FindLOG4CPP.cmake | 14 +++++++++++ src/algorithms/libs/gnss_sdr_flags.cc | 2 +- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 039742c14..66ae4894a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -752,11 +752,27 @@ endif() +################################################################################ +# Log4cpp - http://log4cpp.sourceforge.net/ +################################################################################ +find_package(LOG4CPP) +set_package_properties(LOG4CPP PROPERTIES + URL "http://log4cpp.sourceforge.net/" + DESCRIPTION "Library of C++ classes for flexible logging to files" + PURPOSE "Required by GNU Radio." + TYPE REQUIRED +) +if(NOT LOG4CPP_FOUND) + message(FATAL_ERROR "*** Log4cpp is required to build gnss-sdr") +endif() + + + ################################################################################ # Dectect availability of std::filesystem ################################################################################ set(FILESYSTEM_FOUND FALSE) -if(NOT (GNURADIO_VERSION VERSION_LESS 3.8)) +if(NOT (GNURADIO_VERSION VERSION_LESS 3.8) AND LOG4CPP_READY_FOR_CXX17) # Check if we have std::filesystem if(NOT (CMAKE_VERSION VERSION_LESS 3.8)) if(POLICY CMP0057) @@ -910,22 +926,6 @@ endif() -################################################################################ -# Log4cpp - http://log4cpp.sourceforge.net/ -################################################################################ -find_package(LOG4CPP) -set_package_properties(LOG4CPP PROPERTIES - URL "http://log4cpp.sourceforge.net/" - DESCRIPTION "Library of C++ classes for flexible logging to files" - PURPOSE "Required by GNU Radio." - TYPE REQUIRED -) -if(NOT LOG4CPP_FOUND) - message(FATAL_ERROR "*** Log4cpp is required to build gnss-sdr") -endif() - - - ################################################################################ # volk_gnsssdr module - GNSS-SDR's own VOLK library ################################################################################ diff --git a/cmake/Modules/FindLOG4CPP.cmake b/cmake/Modules/FindLOG4CPP.cmake index 29c7308fa..784d1f2d0 100644 --- a/cmake/Modules/FindLOG4CPP.cmake +++ b/cmake/Modules/FindLOG4CPP.cmake @@ -39,6 +39,20 @@ find_path(LOG4CPP_INCLUDE_DIR log4cpp/Category.hh $ENV{LOG4CPP_ROOT}/include ) +if(LOG4CPP_INCLUDE_DIR) + file(STRINGS ${LOG4CPP_INCLUDE_DIR}/log4cpp/Priority.hh _log4cpp_Priority) + set(_log4cpp_cxx17 TRUE) + foreach(_loop_var IN LISTS _log4cpp_Priority) + string(STRIP "${_loop_var}" _file_line) + if("throw(std::invalid_argument);" STREQUAL "${_file_line}") + set(_log4cpp_cxx17 FALSE) + endif() + endforeach() + if(${_log4cpp_cxx17}) + set(LOG4CPP_READY_FOR_CXX17 TRUE) + endif() +endif() + set(LOG4CPP_NAMES log4cpp) find_library(LOG4CPP_LIBRARY NAMES ${LOG4CPP_NAMES} diff --git a/src/algorithms/libs/gnss_sdr_flags.cc b/src/algorithms/libs/gnss_sdr_flags.cc index 056ff14c7..66429e415 100644 --- a/src/algorithms/libs/gnss_sdr_flags.cc +++ b/src/algorithms/libs/gnss_sdr_flags.cc @@ -43,7 +43,7 @@ namespace fs = std::experimental::filesystem; namespace fs = std::filesystem; #endif #else -#include +#include // for exists namespace fs = boost::filesystem; #endif From dd2198fd0063b5250618db797ae4b995c4e636c1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 13 Jun 2019 17:37:32 +0200 Subject: [PATCH 4/4] Apply code formatting --- .../tracking/libs/cubature_filter.cc | 75 +++++++++++-------- .../tracking/libs/cubature_filter.h | 2 +- .../tracking/cubature_filter_test.cc | 52 +++++++------ 3 files changed, 71 insertions(+), 58 deletions(-) diff --git a/src/algorithms/tracking/libs/cubature_filter.cc b/src/algorithms/tracking/libs/cubature_filter.cc index 05b346a7c..cd7e3bb83 100644 --- a/src/algorithms/tracking/libs/cubature_filter.cc +++ b/src/algorithms/tracking/libs/cubature_filter.cc @@ -6,7 +6,7 @@ * Filter, which uses multidimensional cubature rules to estimate the * time evolution of a nonlinear system. * - * [1] I Arasaratnam and S Haykin. Cubature kalman filters. IEEE + * [1] I Arasaratnam and S Haykin. Cubature kalman filters. IEEE * Transactions on Automatic Control, 54(6):1254–1269,2009. * * \authors
    @@ -51,6 +51,7 @@ Cubature_filter::Cubature_filter() P_x_est = P_x_pred_out; } + Cubature_filter::Cubature_filter(int nx) { x_pred_out = arma::zeros(nx, 1); @@ -60,6 +61,7 @@ Cubature_filter::Cubature_filter(int nx) P_x_est = P_x_pred_out; } + Cubature_filter::Cubature_filter(const arma::vec& x_pred_0, const arma::mat& P_x_pred_0) { x_pred_out = x_pred_0; @@ -69,8 +71,10 @@ Cubature_filter::Cubature_filter(const arma::vec& x_pred_0, const arma::mat& P_x P_x_est = P_x_pred_out; } + Cubature_filter::~Cubature_filter() = default; + void Cubature_filter::initialize(const arma::mat& x_pred_0, const arma::mat& P_x_pred_0) { x_pred_out = x_pred_0; @@ -91,37 +95,38 @@ void Cubature_filter::predict_sequential(const arma::vec& x_post, const arma::ma int np = 2 * nx; // Generator Matrix - arma::mat gen_one = arma::join_horiz(arma::eye(nx,nx),-1.0*arma::eye(nx,nx)); + arma::mat gen_one = arma::join_horiz(arma::eye(nx, nx), -1.0 * arma::eye(nx, nx)); // Initialize predicted mean and covariance - arma::vec x_pred = arma::zeros(nx,1); - arma::mat P_x_pred = arma::zeros(nx,nx); + arma::vec x_pred = arma::zeros(nx, 1); + arma::mat P_x_pred = arma::zeros(nx, nx); // Factorize posterior covariance arma::mat Sm_post = arma::chol(P_x_post, "lower"); - + // Propagate and evaluate cubature points arma::vec Xi_post; arma::vec Xi_pred; for (uint8_t i = 0; i < np; i++) - { - Xi_post = Sm_post * (std::sqrt(((float) np) / 2.0) * gen_one.col(i)) + x_post; - Xi_pred = (*transition_fcn)(Xi_post); - - x_pred = x_pred + Xi_pred; - P_x_pred = P_x_pred + Xi_pred*Xi_pred.t(); - } - + { + Xi_post = Sm_post * (std::sqrt(static_cast(np) / 2.0) * gen_one.col(i)) + x_post; + Xi_pred = (*transition_fcn)(Xi_post); + + x_pred = x_pred + Xi_pred; + P_x_pred = P_x_pred + Xi_pred * Xi_pred.t(); + } + // Estimate predicted state and error covariance - x_pred = x_pred / ((float) np); - P_x_pred = P_x_pred / ((float) np) - x_pred*x_pred.t() + noise_covariance; + x_pred = x_pred / static_cast(np); + P_x_pred = P_x_pred / static_cast(np) - x_pred * x_pred.t() + noise_covariance; // Store predicted state and error covariance x_pred_out = x_pred; P_x_pred_out = P_x_pred; } + /* * Perform the update step of the cubature Kalman filter */ @@ -133,12 +138,12 @@ void Cubature_filter::update_sequential(const arma::vec& z_upd, const arma::vec& int np = 2 * nx; // Generator Matrix - arma::mat gen_one = arma::join_horiz(arma::eye(nx,nx),-1.0*arma::eye(nx,nx)); + arma::mat gen_one = arma::join_horiz(arma::eye(nx, nx), -1.0 * arma::eye(nx, nx)); // Evaluate predicted measurement and covariances - arma::mat z_pred = arma::zeros(nz,1); - arma::mat P_zz_pred = arma::zeros(nz,nz); - arma::mat P_xz_pred = arma::zeros(nx,nz); + arma::mat z_pred = arma::zeros(nz, 1); + arma::mat P_zz_pred = arma::zeros(nz, nz); + arma::mat P_xz_pred = arma::zeros(nx, nz); // Factorize predicted covariance arma::mat Sm_pred = arma::chol(P_x_pred, "lower"); @@ -147,43 +152,47 @@ void Cubature_filter::update_sequential(const arma::vec& z_upd, const arma::vec& arma::vec Xi_pred; arma::vec Zi_pred; for (uint8_t i = 0; i < np; i++) - { - Xi_pred = Sm_pred * (std::sqrt(((float) np) / 2.0) * gen_one.col(i)) + x_pred; - Zi_pred = (*measurement_fcn)(Xi_pred); - - z_pred = z_pred + Zi_pred; - P_zz_pred = P_zz_pred + Zi_pred*Zi_pred.t(); - P_xz_pred = P_xz_pred + Xi_pred*Zi_pred.t(); - } + { + Xi_pred = Sm_pred * (std::sqrt(static_cast(np) / 2.0) * gen_one.col(i)) + x_pred; + Zi_pred = (*measurement_fcn)(Xi_pred); + + z_pred = z_pred + Zi_pred; + P_zz_pred = P_zz_pred + Zi_pred * Zi_pred.t(); + P_xz_pred = P_xz_pred + Xi_pred * Zi_pred.t(); + } // Estimate measurement covariance and cross covariances - z_pred = z_pred / ((float) np); - P_zz_pred = P_zz_pred / ((float) np) - z_pred*z_pred.t() + noise_covariance; - P_xz_pred = P_xz_pred / ((float) np) - x_pred*z_pred.t(); + z_pred = z_pred / static_cast(np); + P_zz_pred = P_zz_pred / static_cast(np) - z_pred * z_pred.t() + noise_covariance; + P_xz_pred = P_xz_pred / static_cast(np) - x_pred * z_pred.t(); // Estimate cubature Kalman gain - arma::mat W_k = P_xz_pred*arma::inv(P_zz_pred); + arma::mat W_k = P_xz_pred * arma::inv(P_zz_pred); // Estimate and store the updated state and error covariance - x_est = x_pred + W_k*(z_upd - z_pred); - P_x_est = P_x_pred - W_k*P_zz_pred*W_k.t(); + x_est = x_pred + W_k * (z_upd - z_pred); + P_x_est = P_x_pred - W_k * P_zz_pred * W_k.t(); } + arma::mat Cubature_filter::get_x_pred() const { return x_pred_out; } + arma::mat Cubature_filter::get_P_x_pred() const { return P_x_pred_out; } + arma::mat Cubature_filter::get_x_est() const { return x_est; } + arma::mat Cubature_filter::get_P_x_est() const { return P_x_est; diff --git a/src/algorithms/tracking/libs/cubature_filter.h b/src/algorithms/tracking/libs/cubature_filter.h index 6a0806e0e..87f45bcdd 100644 --- a/src/algorithms/tracking/libs/cubature_filter.h +++ b/src/algorithms/tracking/libs/cubature_filter.h @@ -6,7 +6,7 @@ * Filter, which uses multidimensional cubature rules to estimate the * time evolution of a nonlinear system. * - * [1] I Arasaratnam and S Haykin. Cubature kalman filters. IEEE + * [1] I Arasaratnam and S Haykin. Cubature kalman filters. IEEE * Transactions on Automatic Control, 54(6):1254–1269,2009. * * \authors
      diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/cubature_filter_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/cubature_filter_test.cc index a86d5dd7c..948e5cc69 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/cubature_filter_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/cubature_filter_test.cc @@ -35,20 +35,24 @@ #define CUBATURE_TEST_N_TRIALS 1000 -class Transition_Model : public Model_Function { - public: - Transition_Model(arma::mat kf_F) {coeff_mat = kf_F;}; - virtual arma::vec operator() (arma::vec input) {return coeff_mat*input;}; - private: - arma::mat coeff_mat; +class Transition_Model : public Model_Function +{ +public: + Transition_Model(arma::mat kf_F) { coeff_mat = kf_F; }; + virtual arma::vec operator()(arma::vec input) { return coeff_mat * input; }; + +private: + arma::mat coeff_mat; }; -class Measurement_Model : public Model_Function { - public: - Measurement_Model(arma::mat kf_H) {coeff_mat = kf_H;}; - virtual arma::vec operator() (arma::vec input) {return coeff_mat*input;}; - private: - arma::mat coeff_mat; +class Measurement_Model : public Model_Function +{ +public: + Measurement_Model(arma::mat kf_H) { coeff_mat = kf_H; }; + virtual arma::vec operator()(arma::vec input) { return coeff_mat * input; }; + +private: + arma::mat coeff_mat; }; TEST(CubatureFilterComputationTest, CubatureFilterTest) @@ -101,21 +105,21 @@ TEST(CubatureFilterComputationTest, CubatureFilterTest) nx = std::rand() % 5 + 1; ny = std::rand() % 5 + 1; - kf_x = arma::randn(nx,1); + kf_x = arma::randn(nx, 1); - kf_P_x_post = 5.0 * arma::diagmat(arma::randu(nx,1)); + kf_P_x_post = 5.0 * arma::diagmat(arma::randu(nx, 1)); kf_x_post = arma::mvnrnd(kf_x, kf_P_x_post); kf_cubature.initialize(kf_x_post, kf_P_x_post); // Prediction Step - kf_F = arma::randu(nx,nx); - kf_Q = arma::diagmat(arma::randu(nx,1)); + kf_F = arma::randu(nx, nx); + kf_Q = arma::diagmat(arma::randu(nx, 1)); transition_function = new Transition_Model(kf_F); arma::mat ttx = (*transition_function)(kf_x_post); - kf_cubature.predict_sequential(kf_x_post,kf_P_x_post,transition_function,kf_Q); + kf_cubature.predict_sequential(kf_x_post, kf_P_x_post, transition_function, kf_Q); ckf_x_pre = kf_cubature.get_x_pred(); ckf_P_x_pre = kf_cubature.get_P_x_pred(); @@ -127,16 +131,16 @@ TEST(CubatureFilterComputationTest, CubatureFilterTest) EXPECT_TRUE(arma::approx_equal(ckf_P_x_pre, kf_P_x_pre, "absdiff", 0.01)); // Update Step - kf_H = arma::randu(ny,nx); - kf_R = arma::diagmat(arma::randu(ny,1)); + kf_H = arma::randu(ny, nx); + kf_R = arma::diagmat(arma::randu(ny, 1)); - eta = arma::mvnrnd(arma::zeros(nx,1),kf_Q); - nu = arma::mvnrnd(arma::zeros(ny,1),kf_R); + eta = arma::mvnrnd(arma::zeros(nx, 1), kf_Q); + nu = arma::mvnrnd(arma::zeros(ny, 1), kf_R); - kf_y = kf_H*(kf_F*kf_x + eta) + nu; + kf_y = kf_H * (kf_F * kf_x + eta) + nu; measurement_function = new Measurement_Model(kf_H); - kf_cubature.update_sequential(kf_y,kf_x_pre,kf_P_x_pre,measurement_function,kf_R); + kf_cubature.update_sequential(kf_y, kf_x_pre, kf_P_x_pre, measurement_function, kf_R); ckf_x_post = kf_cubature.get_x_est(); ckf_P_x_post = kf_cubature.get_P_x_est(); @@ -145,7 +149,7 @@ TEST(CubatureFilterComputationTest, CubatureFilterTest) kf_K = (kf_P_x_pre * kf_H.t()) * arma::inv(kf_P_y); kf_x_post = kf_x_pre + kf_K * (kf_y - kf_H * kf_x_pre); - kf_P_x_post = (arma::eye(nx,nx) - kf_K * kf_H) * kf_P_x_pre; + kf_P_x_post = (arma::eye(nx, nx) - kf_K * kf_H) * kf_P_x_pre; EXPECT_TRUE(arma::approx_equal(ckf_x_post, kf_x_post, "absdiff", 0.01)); EXPECT_TRUE(arma::approx_equal(ckf_P_x_post, kf_P_x_post, "absdiff", 0.01));