From b0b7ef190c7e9aa220adcd13e22e3a1577c60138 Mon Sep 17 00:00:00 2001 From: Leah Kiner Date: Mon, 10 Jun 2024 16:23:15 -0600 Subject: [PATCH 1/8] Add linear interpolation function --- .../utilities/linearInterpolation.hpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/architecture/utilities/linearInterpolation.hpp diff --git a/src/architecture/utilities/linearInterpolation.hpp b/src/architecture/utilities/linearInterpolation.hpp new file mode 100644 index 0000000000..f7a26ae9b9 --- /dev/null +++ b/src/architecture/utilities/linearInterpolation.hpp @@ -0,0 +1,41 @@ +/* + ISC License + + Copyright (c) 2024, Laboratory for Atmospheric and Space Physics, University of Colorado at Boulder + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + */ + +#ifndef LINEARINTERPOLATION_H +#define LINEARINTERPOLATION_H + +#include + +/*! This function uses linear interpolation to solve for the value of an unknown function of a single variables f(x) + at the point x. +@return double +@param x1 Data point x1 +@param x2 Data point x2 +@param y1 Function value at point x1 +@param y2 Function value at point x2 +@param x Function x coordinate for interpolation +*/ +double linearInterpolation(double x1, double x2, double y1, double y2, double x) { + + assert(x1 < x && x < x2); + + return y1 * (x2 - x) / (x2 - x1) + y2 * (x - x1) / (x2 - x1); +} + +#endif // LINEARINTERPOLATION_H From 81b29e8c8942c8f592b03a95969fb6b0a4cdb32a Mon Sep 17 00:00:00 2001 From: Leah Kiner Date: Mon, 10 Jun 2024 16:23:25 -0600 Subject: [PATCH 2/8] Add bilinear interpolation function --- .../utilities/bilinearInterpolation.hpp | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/architecture/utilities/bilinearInterpolation.hpp diff --git a/src/architecture/utilities/bilinearInterpolation.hpp b/src/architecture/utilities/bilinearInterpolation.hpp new file mode 100644 index 0000000000..4d3360362e --- /dev/null +++ b/src/architecture/utilities/bilinearInterpolation.hpp @@ -0,0 +1,58 @@ +/* + ISC License + + Copyright (c) 2024, Laboratory for Atmospheric and Space Physics, University of Colorado at Boulder + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + */ + +#ifndef BILINEARINTERPOLATION_H +#define BILINEARINTERPOLATION_H + +#include + +/*! This function uses bilinear interpolation to solve for the value of an unknown function of two variables f(x,y) + at the point (x,y). +@return double +@param x1 Data point x1 +@param x2 Data point x2 +@param y1 Data point y1 +@param y2 Data point y2 +@param z11 Function value at point (x1, y1) +@param z12 Function value at point (x1, y2) +@param z21 Function value at point (x2, y1) +@param z22 Function value at point (x2, y2) +@param x Function x coordinate for interpolation +@param y Function y coordinate for interpolation +*/ +double bilinearInterpolation(double x1, + double x2, + double y1, + double y2, + double z11, + double z12, + double z21, + double z22, + double x, + double y) { + + assert(x1 < x && x < x2); + assert(y1 < y && y < y2); + + return 1 / ((x2 - x1) * (y2 - y1)) * (z11 * (x2 - x) * (y2 - y) + z21 * (x - x1) * (y2 - y) + + z12 * (x2 - x) * (y - y1) + + z22 * (x - x1) * (y - y1)); +} + +#endif // BILINEARINTERPOLATION_H From 6022a7c0ba06e61211ee95b07cc3ea95de5045ae Mon Sep 17 00:00:00 2001 From: Leah Kiner Date: Mon, 10 Jun 2024 16:23:39 -0600 Subject: [PATCH 3/8] Add linear interpolation google test file --- .../tests/test_linearInterpolation.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/architecture/utilities/tests/test_linearInterpolation.cpp diff --git a/src/architecture/utilities/tests/test_linearInterpolation.cpp b/src/architecture/utilities/tests/test_linearInterpolation.cpp new file mode 100644 index 0000000000..935d5cf99a --- /dev/null +++ b/src/architecture/utilities/tests/test_linearInterpolation.cpp @@ -0,0 +1,42 @@ +/* + ISC License + + Copyright (c) 2024, Laboratory for Atmospheric and Space Physics, University of Colorado at Boulder + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + */ + +#include "architecture/utilities/linearInterpolation.hpp" +#include +#include + +std::random_device rd; +std::default_random_engine generator(rd()); +std::uniform_real_distribution valueDistribution(-10, 10); +std::uniform_real_distribution boundDistribution(0, 2); + +TEST(LinearInterpolationTest, HandlesNormalInputs) { + double x = valueDistribution(generator); + double x1 = x - boundDistribution(generator); + double x2 = x + boundDistribution(generator); + + double yUnused = valueDistribution(generator); + double y1 = yUnused - boundDistribution(generator); + double y2 = yUnused + boundDistribution(generator); + + // Linearly interpolate to solve for y + double y = y1 * (x2 - x) / (x2 - x1) + y2 * (x - x1) / (x2 - x1); + + EXPECT_EQ(linearInterpolation(x1, x2, y1, y2, x), y); +} From ea3dabbbea92beb8523c0f8ea5c441e55a280142 Mon Sep 17 00:00:00 2001 From: Leah Kiner Date: Mon, 10 Jun 2024 16:23:57 -0600 Subject: [PATCH 4/8] Add bilinear interpolation google test file --- .../tests/test_bilinearInterpolation.cpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/architecture/utilities/tests/test_bilinearInterpolation.cpp diff --git a/src/architecture/utilities/tests/test_bilinearInterpolation.cpp b/src/architecture/utilities/tests/test_bilinearInterpolation.cpp new file mode 100644 index 0000000000..afbeb182f3 --- /dev/null +++ b/src/architecture/utilities/tests/test_bilinearInterpolation.cpp @@ -0,0 +1,49 @@ +/* + ISC License + + Copyright (c) 2024, Laboratory for Atmospheric and Space Physics, University of Colorado at Boulder + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + */ + +#include "architecture/utilities/bilinearInterpolation.hpp" +#include +#include + +std::random_device rd; +std::default_random_engine generator(rd()); +std::uniform_real_distribution valueDistribution(-10, 10); +std::uniform_real_distribution boundDistribution(0, 2); + +TEST(BilinearInterpolationTest, HandlesNormalInputs) { + double x = valueDistribution(generator); + double x1 = x - boundDistribution(generator); + double x2 = x + boundDistribution(generator); + + double y = valueDistribution(generator); + double y1 = y - boundDistribution(generator); + double y2 = y + boundDistribution(generator); + + double z11 = valueDistribution(generator); + double z12 = valueDistribution(generator); + double z21 = valueDistribution(generator); + double z22 = valueDistribution(generator); + + // Bilinearly interpolate to solve for z + double z = 1 / ((x2 - x1) * (y2 - y1)) * (z11 * (x2 - x) * (y2 - y) + z21 * (x - x1) * (y2 - y) + + z12 * (x2 - x) * (y - y1) + + z22 * (x - x1) * (y - y1)); + + EXPECT_EQ(bilinearInterpolation(x1, x2, y1, y2, z11, z12, z21, z22, x, y), z); +} From c23edd42020bfb15b01fe21d1b3c812ed47e8603 Mon Sep 17 00:00:00 2001 From: Leah Kiner Date: Mon, 10 Jun 2024 16:25:51 -0600 Subject: [PATCH 5/8] Add interpolation functions and tests to CMakeLists.txt --- src/architecture/utilities/tests/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/architecture/utilities/tests/CMakeLists.txt b/src/architecture/utilities/tests/CMakeLists.txt index 0145529e2f..1ed3cab235 100644 --- a/src/architecture/utilities/tests/CMakeLists.txt +++ b/src/architecture/utilities/tests/CMakeLists.txt @@ -22,6 +22,14 @@ add_executable(test_avsEigenMRP test_avsEigenMRP.cpp) target_link_libraries(test_avsEigenMRP GTest::gtest_main) target_link_libraries(test_avsEigenMRP ArchitectureUtilities) +add_executable(test_linearInterpolation test_linearInterpolation.cpp) +target_link_libraries(test_linearInterpolation GTest::gtest_main) +target_link_libraries(test_linearInterpolation ArchitectureUtilities) + +add_executable(test_bilinearInterpolation test_bilinearInterpolation.cpp) +target_link_libraries(test_bilinearInterpolation GTest::gtest_main) +target_link_libraries(test_bilinearInterpolation ArchitectureUtilities) + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" AND CMAKE_GENERATOR STREQUAL "Xcode") set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST) endif() @@ -32,3 +40,5 @@ gtest_discover_tests(test_orbitalMotion) gtest_discover_tests(test_saturate) gtest_discover_tests(test_geodeticConversion) gtest_discover_tests(test_avsEigenMRP) +gtest_discover_tests(test_linearInterpolation) +gtest_discover_tests(test_bilinearInterpolation) From e4e4ef5eb05a352888e0c45f83fafa175551b98b Mon Sep 17 00:00:00 2001 From: Hanspeter Schaub Date: Wed, 12 Jun 2024 21:55:49 -0600 Subject: [PATCH 6/8] include *.hpp files in the RST documentation --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d39bab0d63..c2f7d7dc4f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -224,6 +224,7 @@ def __init__(self, newFiles=False): def grabRelevantFiles(self,dir_path): dirs_in_dir = glob(dir_path + '*/') files_in_dir = glob(dir_path + "*.h") + files_in_dir.extend(glob(dir_path + "*.hpp")) files_in_dir.extend(glob(dir_path + "*.c")) files_in_dir.extend(glob(dir_path + "*.cpp")) files_in_dir.extend(glob(dir_path + "*.py")) @@ -346,7 +347,7 @@ def generateAutoDoc(self, path, files_paths): # Sort the files by language py_file_paths = sorted([s for s in files_paths if ".py" in s]) - c_file_paths = sorted([s for s in files_paths if ".c" in s or ".cpp" in s or ".h" in s]) + c_file_paths = sorted([s for s in files_paths if ".c" in s or ".cpp" in s or ".h" in s or ".hpp" in s]) # Create the .rst file for C-Modules @@ -506,4 +507,3 @@ def run(self, srcDir): # Example of how to link C with Breathe # breathe_projects_source = {"BasiliskFSW": ("../../src/fswAlgorithms/attControl/mrpFeedback", ['mrpFeedback.c', 'mrpFeedback.h'])} - From 5f41bfeba851b60a0bc0fd494e7d8145d5a627aa Mon Sep 17 00:00:00 2001 From: Hanspeter Schaub Date: Wed, 12 Jun 2024 21:58:04 -0600 Subject: [PATCH 7/8] avoid documentation issues with similar file names. The issue was that the conf.py script was searching if the base file name was included in a list Thus, the name 'linearTest' was found to be within `bilinearTest`. This resulted in RST documentation issues with one method being shown in the wrong file documentation. --- docs/source/conf.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index c2f7d7dc4f..fb350b7b8c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -399,8 +399,13 @@ def generateAutoDoc(self, path, files_paths): lines += "----\n\n" # Link the path with the modules for Breathe - module_files.extend([s for s in c_file_local_paths if c_file_basename in s]) - module_files_temp.extend([s for s in c_file_local_paths if c_file_basename in s]) + # make sure the list of files match the base name perfectly + # this avoids issues where one file name is contained in another + # file name + c_file_list_coarse = [s for s in c_file_local_paths if c_file_basename in s] + c_file_list = [file_name for file_name in c_file_list_coarse if file_name.rsplit(".", 1)[0] == c_file_basename] + module_files.extend(c_file_list) + module_files_temp.extend(c_file_list) # Populate the module's .rst for module_file in module_files_temp: From 81578c77a04767e34fc14e14041dbba3c0056c8a Mon Sep 17 00:00:00 2001 From: Hanspeter Schaub Date: Wed, 12 Jun 2024 22:00:49 -0600 Subject: [PATCH 8/8] remove defunct documentation related to BSKv1 messaging --- docs/source/conf.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index fb350b7b8c..3efd96654a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -381,11 +381,7 @@ def generateAutoDoc(self, path, files_paths): lines += ".. _" + c_file_basename + pathToFolder.split("/")[-1] + ":\n\n" else: lines += ".. _" + c_file_basename + ":\n\n" - if "fswMessages" in src_path \ - or "simFswInterfaceMessages" in src_path \ - or "simMessages" in src_path\ - or "architecture" in src_path\ - or "utilities" in src_path: + if "architecture" in src_path or "utilities" in src_path: lines += c_file_basename + "\n" + "=" * (len(c_file_basename) + 8) + "\n\n" else: lines += "Module: " + c_file_basename + "\n" + "=" * (len(c_file_basename) + 8) + "\n\n" @@ -492,7 +488,6 @@ def run(self, srcDir): shutil.rmtree(officialDoc) # adjust the fileCrawler path to a local folder to just build a sub-system breathe_projects_source = fileCrawler.run(officialSrc) - # breathe_projects_source = fileCrawler.run(officialSrc+"/fswAlgorithms/fswMessages") # breathe_projects_source = fileCrawler.run(officialSrc+"/fswAlgorithms") # breathe_projects_source = fileCrawler.run(officialSrc+"/simulation/environment") # breathe_projects_source = fileCrawler.run(officialSrc+"/moduleTemplates")