@@ -78,10 +78,6 @@ FAST_DATA_ZERO_INIT uint32_t targetPidLooptime;
7878FAST_DATA_ZERO_INIT pidAxisData_t pidData [XYZ_AXIS_COUNT ];
7979FAST_DATA_ZERO_INIT pidRuntime_t pidRuntime ;
8080
81- #if defined(USE_ABSOLUTE_CONTROL )
82- STATIC_UNIT_TESTED FAST_DATA_ZERO_INIT float axisError [XYZ_AXIS_COUNT ];
83- #endif
84-
8581#if defined(USE_THROTTLE_BOOST )
8682FAST_DATA_ZERO_INIT float throttleBoost ;
8783pt1Filter_t throttleLpf ;
@@ -160,18 +156,14 @@ void resetPidProfile(pidProfile_t *pidProfile)
160156 .itermLimit = 400 ,
161157 .throttle_boost = 5 ,
162158 .throttle_boost_cutoff = 15 ,
163- .iterm_rotation = false ,
159+ .iterm_rotation = true ,
164160 .iterm_relax = ITERM_RELAX_RP ,
165161 .iterm_relax_cutoff = ITERM_RELAX_CUTOFF_DEFAULT ,
166162 .iterm_relax_type = ITERM_RELAX_SETPOINT ,
167163 .acro_trainer_angle_limit = 20 ,
168164 .acro_trainer_lookahead_ms = 50 ,
169165 .acro_trainer_debug_axis = FD_ROLL ,
170166 .acro_trainer_gain = 75 ,
171- .abs_control_gain = 0 ,
172- .abs_control_limit = 90 ,
173- .abs_control_error_limit = 20 ,
174- .abs_control_cutoff = 11 ,
175167 .antiGravityMode = ANTI_GRAVITY_SMOOTH ,
176168 .dterm_lpf1_static_hz = DTERM_LPF1_DYN_MIN_HZ_DEFAULT ,
177169 // NOTE: dynamic lpf is enabled by default so this setting is actually
@@ -285,9 +277,6 @@ void pidResetIterm(void)
285277{
286278 for (int axis = 0 ; axis < 3 ; axis ++ ) {
287279 pidData [axis ].I = 0.0f ;
288- #if defined(USE_ABSOLUTE_CONTROL )
289- axisError [axis ] = 0.0f ;
290- #endif
291280 }
292281}
293282
@@ -614,47 +603,29 @@ static float accelerationLimit(int axis, float currentPidSetpoint)
614603 return currentPidSetpoint ;
615604}
616605
617- static void rotateVector (float v [XYZ_AXIS_COUNT ], float rotation [XYZ_AXIS_COUNT ])
606+ #define SIN2 (R ) ((R)-(R)*(R)*(R)/6)
607+ #define COS2 (R ) (1.0f-(R)*(R)/2)
608+
609+ static inline void rotateAroundYaw (float * x , float * y , float r )
618610{
619- // rotate v around rotation vector rotation
620- // rotation in radians, all elements must be small
621- for (int i = 0 ; i < XYZ_AXIS_COUNT ; i ++ ) {
622- int i_1 = (i + 1 ) % 3 ;
623- int i_2 = (i + 2 ) % 3 ;
624- float newV = v [i_1 ] + v [i_2 ] * rotation [i ];
625- v [i_2 ] -= v [i_1 ] * rotation [i ];
626- v [i_1 ] = newV ;
627- }
611+ float a ,b ,s ,c ;
612+
613+ s = SIN2 (r );
614+ c = COS2 (r );
615+
616+ a = x [0 ]* c + y [0 ]* s ;
617+ b = y [0 ]* c - x [0 ]* s ;
618+
619+ x [0 ] = a ;
620+ y [0 ] = b ;
628621}
629622
630- STATIC_UNIT_TESTED void rotateItermAndAxisError ()
623+ STATIC_UNIT_TESTED void rotateIterm ()
631624{
632- if (pidRuntime .itermRotation
633- #if defined(USE_ABSOLUTE_CONTROL )
634- || pidRuntime .acGain > 0 || debugMode == DEBUG_AC_ERROR
635- #endif
636- ) {
637- const float gyroToAngle = pidRuntime .dT * RAD ;
638- float rotationRads [XYZ_AXIS_COUNT ];
639- for (int i = FD_ROLL ; i <= FD_YAW ; i ++ ) {
640- rotationRads [i ] = gyro .gyroADCf [i ] * gyroToAngle ;
641- }
642- #if defined(USE_ABSOLUTE_CONTROL )
643- if (pidRuntime .acGain > 0 || debugMode == DEBUG_AC_ERROR ) {
644- rotateVector (axisError , rotationRads );
645- }
646- #endif
647- if (pidRuntime .itermRotation ) {
648- float v [XYZ_AXIS_COUNT ];
649- for (int i = 0 ; i < XYZ_AXIS_COUNT ; i ++ ) {
650- v [i ] = pidData [i ].I ;
651- }
652- rotateVector (v , rotationRads );
653- for (int i = 0 ; i < XYZ_AXIS_COUNT ; i ++ ) {
654- pidData [i ].I = v [i ];
655- }
656- }
625+ if (pidRuntime .itermRotation ) {
626+ rotateAroundYaw (& pidData [FD_ROLL ].I , & pidData [FD_ROLL ].I , gyro .gyroADCf [FD_YAW ] * pidRuntime .dT * RAD );
657627 }
628+
658629}
659630
660631#ifdef USE_RC_SMOOTHING_FILTER
@@ -675,46 +646,6 @@ float FAST_CODE applyRcSmoothingFeedforwardFilter(int axis, float pidSetpointDel
675646#endif // USE_RC_SMOOTHING_FILTER
676647
677648#if defined(USE_ITERM_RELAX )
678- #if defined(USE_ABSOLUTE_CONTROL )
679- STATIC_UNIT_TESTED void applyAbsoluteControl (const int axis , const float gyroRate , float * currentPidSetpoint , float * itermErrorRate )
680- {
681- if (pidRuntime .acGain > 0 || debugMode == DEBUG_AC_ERROR ) {
682- const float setpointLpf = pt1FilterApply (& pidRuntime .acLpf [axis ], * currentPidSetpoint );
683- const float setpointHpf = fabsf (* currentPidSetpoint - setpointLpf );
684- float acErrorRate = 0 ;
685- const float gmaxac = setpointLpf + 2 * setpointHpf ;
686- const float gminac = setpointLpf - 2 * setpointHpf ;
687- if (gyroRate >= gminac && gyroRate <= gmaxac ) {
688- const float acErrorRate1 = gmaxac - gyroRate ;
689- const float acErrorRate2 = gminac - gyroRate ;
690- if (acErrorRate1 * axisError [axis ] < 0 ) {
691- acErrorRate = acErrorRate1 ;
692- } else {
693- acErrorRate = acErrorRate2 ;
694- }
695- if (fabsf (acErrorRate * pidRuntime .dT ) > fabsf (axisError [axis ]) ) {
696- acErrorRate = - axisError [axis ] * pidRuntime .pidFrequency ;
697- }
698- } else {
699- acErrorRate = (gyroRate > gmaxac ? gmaxac : gminac ) - gyroRate ;
700- }
701-
702- if (isAirmodeActivated ()) {
703- axisError [axis ] = constrainf (axisError [axis ] + acErrorRate * pidRuntime .dT ,
704- - pidRuntime .acErrorLimit , pidRuntime .acErrorLimit );
705- const float acCorrection = constrainf (axisError [axis ] * pidRuntime .acGain , - pidRuntime .acLimit , pidRuntime .acLimit );
706- * currentPidSetpoint += acCorrection ;
707- * itermErrorRate += acCorrection ;
708- DEBUG_SET (DEBUG_AC_CORRECTION , axis , lrintf (acCorrection * 10 ));
709- if (axis == FD_ROLL ) {
710- DEBUG_SET (DEBUG_ITERM_RELAX , 3 , lrintf (acCorrection * 10 ));
711- }
712- }
713- DEBUG_SET (DEBUG_AC_ERROR , axis , lrintf (axisError [axis ] * 10 ));
714- }
715- }
716- #endif
717-
718649STATIC_UNIT_TESTED void applyItermRelax (const int axis , const float iterm ,
719650 const float gyroRate , float * itermErrorRate , float * currentPidSetpoint )
720651{
@@ -742,10 +673,6 @@ STATIC_UNIT_TESTED void applyItermRelax(const int axis, const float iterm,
742673 DEBUG_SET (DEBUG_ITERM_RELAX , 2 , lrintf (* itermErrorRate ));
743674 }
744675 }
745-
746- #if defined(USE_ABSOLUTE_CONTROL )
747- applyAbsoluteControl (axis , gyroRate , currentPidSetpoint , itermErrorRate );
748- #endif
749676 }
750677}
751678#endif
@@ -926,7 +853,7 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
926853 gyroRateDterm [axis ] = pidRuntime .dtermLowpass2ApplyFn ((filter_t * ) & pidRuntime .dtermLowpass2 [axis ], gyroRateDterm [axis ]);
927854 }
928855
929- rotateItermAndAxisError ();
856+ rotateIterm ();
930857
931858#ifdef USE_RPM_FILTER
932859 rpmFilterUpdate ();
@@ -1002,19 +929,13 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
1002929
1003930 const float previousIterm = pidData [axis ].I ;
1004931 float itermErrorRate = errorRate ;
1005- #ifdef USE_ABSOLUTE_CONTROL
1006- float uncorrectedSetpoint = currentPidSetpoint ;
1007- #endif
1008932
1009933#if defined(USE_ITERM_RELAX )
1010934 if (!launchControlActive && !pidRuntime .inCrashRecoveryMode ) {
1011935 applyItermRelax (axis , previousIterm , gyroRate , & itermErrorRate , & currentPidSetpoint );
1012936 errorRate = currentPidSetpoint - gyroRate ;
1013937 }
1014938#endif
1015- #ifdef USE_ABSOLUTE_CONTROL
1016- float setpointCorrection = currentPidSetpoint - uncorrectedSetpoint ;
1017- #endif
1018939
1019940 // --------low-level gyro-based PID based on 2DOF PID controller. ----------
1020941 // 2-DOF PID controller with optional filter on derivative term.
@@ -1114,18 +1035,12 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
11141035 previousGyroRateDterm [axis ] = gyroRateDterm [axis ];
11151036
11161037 // -----calculate feedforward component
1117- #ifdef USE_ABSOLUTE_CONTROL
1118- // include abs control correction in feedforward
1119- pidSetpointDelta += setpointCorrection - pidRuntime .oldSetpointCorrection [axis ];
1120- pidRuntime .oldSetpointCorrection [axis ] = setpointCorrection ;
1121- #endif
1122-
11231038 // no feedforward in launch control
11241039 float feedforwardGain = launchControlActive ? 0.0f : pidRuntime .pidCoefficient [axis ].Kf ;
11251040 if (feedforwardGain > 0 ) {
11261041 // halve feedforward in Level mode since stick sensitivity is weaker by about half
11271042 feedforwardGain *= FLIGHT_MODE (ANGLE_MODE ) ? 0.5f : 1.0f ;
1128- // transition now calculated in feedforward.c when new RC data arrives
1043+ // transition now calculated in feedforward.c when new RC data arrives
11291044 float feedForward = feedforwardGain * pidSetpointDelta * pidRuntime .pidFrequency ;
11301045
11311046#ifdef USE_FEEDFORWARD
0 commit comments