From 501151925d9b530ad4090b2aaeec63e6f0a3adaf Mon Sep 17 00:00:00 2001
From: Petri Mattila <petri.t.j.mattila@gmail.com>
Date: Tue, 6 Aug 2024 10:51:00 +0100
Subject: [PATCH] Add gov_ff_exponent

	100 = angle^1.0
	150 = angle^1.5
---
 src/main/cli/settings.c    | 1 +
 src/main/flight/governor.c | 5 ++++-
 src/main/pg/pid.c          | 1 +
 src/main/pg/pid.h          | 1 +
 4 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c
index be84843afb..96e42eb803 100644
--- a/src/main/cli/settings.c
+++ b/src/main/cli/settings.c
@@ -1162,6 +1162,7 @@ const clivalue_t valueTable[] = {
     { "gov_yaw_ff_weight",          VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.yaw_ff_weight) },
     { "gov_cyclic_ff_weight",       VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.cyclic_ff_weight) },
     { "gov_collective_ff_weight",   VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.collective_ff_weight) },
+    { "gov_ff_exponent",            VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.ff_exponent) },
     { "gov_max_throttle",           VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.max_throttle) },
     { "gov_min_pid_throttle",       VAR_UINT8  |  PROFILE_VALUE,  .config.minmaxUnsigned = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, governor.min_pid_throttle) },
 
diff --git a/src/main/flight/governor.c b/src/main/flight/governor.c
index 5f6dc0ae90..d4b1e5d004 100644
--- a/src/main/flight/governor.c
+++ b/src/main/flight/governor.c
@@ -158,6 +158,7 @@ typedef struct {
     float           yawWeight;
     float           cyclicWeight;
     float           collectiveWeight;
+    float           FFExponent;
     filter_t        FFFilter;
 
     // Tail Torque Assist
@@ -341,7 +342,7 @@ static inline float idleMap(float throttle)
 
 static inline float angleDrag(float angle)
 {
-    return angle * sqrtf(angle); // angle ^ 1.5
+    return pow_approx(angle, gov.FFExponent);
 }
 
 static inline void govChangeState(govState_e futureState)
@@ -1010,6 +1011,8 @@ void governorInitProfile(const pidProfile_t *pidProfile)
         gov.cyclicWeight = pidProfile->governor.cyclic_ff_weight / 100.0f;
         gov.collectiveWeight = pidProfile->governor.collective_ff_weight / 100.0f;
 
+        gov.FFExponent = pidProfile->governor.ff_exponent / 100.0f;
+
         gov.maxThrottle = pidProfile->governor.max_throttle / 100.0f;
         gov.minPIDThrottle = pidProfile->governor.min_pid_throttle / 100.0f;
 
diff --git a/src/main/pg/pid.c b/src/main/pg/pid.c
index bca2c1aeb8..07d9067dc8 100644
--- a/src/main/pg/pid.c
+++ b/src/main/pg/pid.c
@@ -125,6 +125,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
         .governor.tta_limit = 20,
         .governor.cyclic_ff_weight = 40,
         .governor.collective_ff_weight = 100,
+        .governor.ff_exponent = 100,
         .governor.max_throttle = 100,
         .governor.min_pid_throttle = 30,
     );
diff --git a/src/main/pg/pid.h b/src/main/pg/pid.h
index 578d03cb65..6fca400552 100644
--- a/src/main/pg/pid.h
+++ b/src/main/pg/pid.h
@@ -88,6 +88,7 @@ typedef struct {
     uint8_t     yaw_ff_weight;
     uint8_t     cyclic_ff_weight;
     uint8_t     collective_ff_weight;
+    uint8_t     ff_exponent;
     uint8_t     max_throttle;
     uint8_t     min_pid_throttle;
 } governorProfile_t;