From eaa35208c1b9b500c41231ae840c8532b2cfb2bf Mon Sep 17 00:00:00 2001
From: Emilio Corigliano <emilio.corigliano@skywarder.eu>
Date: Mon, 2 Sep 2024 10:51:03 +0200
Subject: [PATCH] [MEA] Added correction factor for cd estimation

---
 src/shared/algorithms/MEA/MEA.cpp | 9 +++++----
 src/shared/algorithms/MEA/MEA.h   | 5 +++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/shared/algorithms/MEA/MEA.cpp b/src/shared/algorithms/MEA/MEA.cpp
index 0408f3d51..494bcaab6 100644
--- a/src/shared/algorithms/MEA/MEA.cpp
+++ b/src/shared/algorithms/MEA/MEA.cpp
@@ -63,9 +63,10 @@ MEA::MEA(const Config &config)
       baroR{config.baroR}, P{config.P}, x{0, 0, config.initialMass},
       mass{config.initialMass}, accelThresh{config.accelThresh},
       speedThresh{config.speedThresh}, Kt{config.Kt}, alpha{config.alpha},
-      c{config.c}, coeffs{config.coeffs}, crossSection{config.crossSection},
-      ae{config.ae}, p0{config.p0}, minMass{config.minMass}, maxMass{
-                                                                 config.maxMass}
+      c{config.c}, coeffs{config.coeffs},
+      crossSection{config.crossSection}, ae{config.ae}, p0{config.p0},
+      minMass{config.minMass}, maxMass{config.maxMass},
+      cdCorrectionFactor(config.cdCorrectionFactor)
 {
     updateState();
 }
@@ -113,7 +114,7 @@ void MEA::computeForce(const Step &step)
     mach = Aeroutils::computeMach(-step.mslAltitude, step.verticalSpeed,
                                   Constants::MSL_TEMPERATURE);
 
-    cd  = Aeroutils::computeCd(coeffs, mach);
+    cd  = cdCorrectionFactor * Aeroutils::computeCd(coeffs, mach);
     rho = Aeroutils::computeRho(-step.mslAltitude, Constants::MSL_TEMPERATURE);
 
     // Dynamic pressure
diff --git a/src/shared/algorithms/MEA/MEA.h b/src/shared/algorithms/MEA/MEA.h
index 795761e43..fbe18c7e6 100644
--- a/src/shared/algorithms/MEA/MEA.h
+++ b/src/shared/algorithms/MEA/MEA.h
@@ -64,6 +64,9 @@ public:
 
         float minMass;  //< Minimum mass used for predicted apogee
         float maxMass;  //< Maximum mass used for predicted apogee
+
+        float cdCorrectionFactor;  // Factor to account for extra drag generated
+                                   // by the plume
     };
 
     struct Step
@@ -147,6 +150,8 @@ private:
     float minMass;
     float maxMass;
 
+    float cdCorrectionFactor;
+
     MEAState state;
 };
 
-- 
GitLab