From 38c02ea29a9e997eb6d69cf830b4c91bb9adea15 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 11 Jul 2022 11:39:09 -0400 Subject: [PATCH] wind_estimator: cmake add symforce generation helper target (wind_estimator_generate_airspeed_fusion) --- Tools/astyle/files_to_check_code_style.sh | 1 + src/lib/wind_estimator/CMakeLists.txt | 9 +++++++++ src/lib/wind_estimator/python/derivation.py | 1 - src/lib/wind_estimator/python/generated/.gitignore | 1 + src/lib/wind_estimator/python/generated/fuse_airspeed.h | 4 ++-- 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/lib/wind_estimator/python/generated/.gitignore diff --git a/Tools/astyle/files_to_check_code_style.sh b/Tools/astyle/files_to_check_code_style.sh index 6f77a514ab..33a98569ae 100755 --- a/Tools/astyle/files_to_check_code_style.sh +++ b/Tools/astyle/files_to_check_code_style.sh @@ -17,6 +17,7 @@ exec find boards msg src platforms test \ -path src/lib/crypto/monocypher -prune -o \ -path src/lib/events/libevents -prune -o \ -path src/lib/parameters/uthash -prune -o \ + -path src/lib/wind_estimator/python/generated -prune -o \ -path src/modules/ekf2/EKF -prune -o \ -path src/modules/gyro_fft/CMSIS_5 -prune -o \ -path src/modules/mavlink/mavlink -prune -o \ diff --git a/src/lib/wind_estimator/CMakeLists.txt b/src/lib/wind_estimator/CMakeLists.txt index 78c94f104c..8c47f08c2d 100644 --- a/src/lib/wind_estimator/CMakeLists.txt +++ b/src/lib/wind_estimator/CMakeLists.txt @@ -36,3 +36,12 @@ add_library(wind_estimator WindEstimator.hpp ) add_dependencies(wind_estimator prebuild_targets) + +add_custom_target(wind_estimator_generate_airspeed_fusion + COMMAND ${PYTHON_EXECUTABLE} derivation.py + #DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/python/derivation.py + #BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/python/generated/fuse_airspeed.h + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python + COMMENT "Generating fuse_airspeed" + USES_TERMINAL +) diff --git a/src/lib/wind_estimator/python/derivation.py b/src/lib/wind_estimator/python/derivation.py index 643cf2a1a0..c5948eb422 100644 --- a/src/lib/wind_estimator/python/derivation.py +++ b/src/lib/wind_estimator/python/derivation.py @@ -44,7 +44,6 @@ import fileinput with fileinput.FileInput(os.path.abspath(metadata.generated_files[0]), inplace=True, backup='.bak') as file: for line in file: line = line.replace("std::max", "math::max") - line = line.replace("std", "matrix") line = line.replace("Eigen", "matrix") line = line.replace("matrix/Dense", "matrix/math.hpp") print(line, end='') diff --git a/src/lib/wind_estimator/python/generated/.gitignore b/src/lib/wind_estimator/python/generated/.gitignore new file mode 100644 index 0000000000..751553b3ac --- /dev/null +++ b/src/lib/wind_estimator/python/generated/.gitignore @@ -0,0 +1 @@ +*.bak diff --git a/src/lib/wind_estimator/python/generated/fuse_airspeed.h b/src/lib/wind_estimator/python/generated/fuse_airspeed.h index 89babbe870..54b63ffaca 100644 --- a/src/lib/wind_estimator/python/generated/fuse_airspeed.h +++ b/src/lib/wind_estimator/python/generated/fuse_airspeed.h @@ -43,8 +43,8 @@ void FuseAirspeed(const matrix::Matrix& v_local, // Intermediate terms (11) const Scalar _tmp0 = -state(0, 0) + v_local(0, 0); const Scalar _tmp1 = -state(1, 0) + v_local(1, 0); - const Scalar _tmp2 = matrix::sqrt(Scalar(matrix::pow(_tmp0, Scalar(2)) + matrix::pow(_tmp1, Scalar(2)) + - epsilon + matrix::pow(v_local(2, 0), Scalar(2)))); + const Scalar _tmp2 = std::sqrt(Scalar(std::pow(_tmp0, Scalar(2)) + std::pow(_tmp1, Scalar(2)) + + epsilon + std::pow(v_local(2, 0), Scalar(2)))); const Scalar _tmp3 = state(2, 0) / _tmp2; const Scalar _tmp4 = _tmp0 * _tmp3; const Scalar _tmp5 = _tmp1 * _tmp3;