@@ -78,10 +78,6 @@ FAST_DATA_ZERO_INIT uint32_t targetPidLooptime;
78
78
FAST_DATA_ZERO_INIT pidAxisData_t pidData [XYZ_AXIS_COUNT ];
79
79
FAST_DATA_ZERO_INIT pidRuntime_t pidRuntime ;
80
80
81
- #if defined(USE_ABSOLUTE_CONTROL )
82
- STATIC_UNIT_TESTED FAST_DATA_ZERO_INIT float axisError [XYZ_AXIS_COUNT ];
83
- #endif
84
-
85
81
#if defined(USE_THROTTLE_BOOST )
86
82
FAST_DATA_ZERO_INIT float throttleBoost ;
87
83
pt1Filter_t throttleLpf ;
@@ -160,18 +156,14 @@ void resetPidProfile(pidProfile_t *pidProfile)
160
156
.itermLimit = 400 ,
161
157
.throttle_boost = 5 ,
162
158
.throttle_boost_cutoff = 15 ,
163
- .iterm_rotation = false ,
159
+ .iterm_rotation = true ,
164
160
.iterm_relax = ITERM_RELAX_RP ,
165
161
.iterm_relax_cutoff = ITERM_RELAX_CUTOFF_DEFAULT ,
166
162
.iterm_relax_type = ITERM_RELAX_SETPOINT ,
167
163
.acro_trainer_angle_limit = 20 ,
168
164
.acro_trainer_lookahead_ms = 50 ,
169
165
.acro_trainer_debug_axis = FD_ROLL ,
170
166
.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 ,
175
167
.antiGravityMode = ANTI_GRAVITY_SMOOTH ,
176
168
.dterm_lpf1_static_hz = DTERM_LPF1_DYN_MIN_HZ_DEFAULT ,
177
169
// NOTE: dynamic lpf is enabled by default so this setting is actually
@@ -285,9 +277,6 @@ void pidResetIterm(void)
285
277
{
286
278
for (int axis = 0 ; axis < 3 ; axis ++ ) {
287
279
pidData [axis ].I = 0.0f ;
288
- #if defined(USE_ABSOLUTE_CONTROL )
289
- axisError [axis ] = 0.0f ;
290
- #endif
291
280
}
292
281
}
293
282
@@ -614,47 +603,29 @@ static float accelerationLimit(int axis, float currentPidSetpoint)
614
603
return currentPidSetpoint ;
615
604
}
616
605
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 )
618
610
{
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 ;
628
621
}
629
622
630
- STATIC_UNIT_TESTED void rotateItermAndAxisError ()
623
+ STATIC_UNIT_TESTED void rotateIterm ()
631
624
{
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 );
657
627
}
628
+
658
629
}
659
630
660
631
#ifdef USE_RC_SMOOTHING_FILTER
@@ -675,46 +646,6 @@ float FAST_CODE applyRcSmoothingFeedforwardFilter(int axis, float pidSetpointDel
675
646
#endif // USE_RC_SMOOTHING_FILTER
676
647
677
648
#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
-
718
649
STATIC_UNIT_TESTED void applyItermRelax (const int axis , const float iterm ,
719
650
const float gyroRate , float * itermErrorRate , float * currentPidSetpoint )
720
651
{
@@ -742,10 +673,6 @@ STATIC_UNIT_TESTED void applyItermRelax(const int axis, const float iterm,
742
673
DEBUG_SET (DEBUG_ITERM_RELAX , 2 , lrintf (* itermErrorRate ));
743
674
}
744
675
}
745
-
746
- #if defined(USE_ABSOLUTE_CONTROL )
747
- applyAbsoluteControl (axis , gyroRate , currentPidSetpoint , itermErrorRate );
748
- #endif
749
676
}
750
677
}
751
678
#endif
@@ -926,7 +853,7 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
926
853
gyroRateDterm [axis ] = pidRuntime .dtermLowpass2ApplyFn ((filter_t * ) & pidRuntime .dtermLowpass2 [axis ], gyroRateDterm [axis ]);
927
854
}
928
855
929
- rotateItermAndAxisError ();
856
+ rotateIterm ();
930
857
931
858
#ifdef USE_RPM_FILTER
932
859
rpmFilterUpdate ();
@@ -1002,19 +929,13 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
1002
929
1003
930
const float previousIterm = pidData [axis ].I ;
1004
931
float itermErrorRate = errorRate ;
1005
- #ifdef USE_ABSOLUTE_CONTROL
1006
- float uncorrectedSetpoint = currentPidSetpoint ;
1007
- #endif
1008
932
1009
933
#if defined(USE_ITERM_RELAX )
1010
934
if (!launchControlActive && !pidRuntime .inCrashRecoveryMode ) {
1011
935
applyItermRelax (axis , previousIterm , gyroRate , & itermErrorRate , & currentPidSetpoint );
1012
936
errorRate = currentPidSetpoint - gyroRate ;
1013
937
}
1014
938
#endif
1015
- #ifdef USE_ABSOLUTE_CONTROL
1016
- float setpointCorrection = currentPidSetpoint - uncorrectedSetpoint ;
1017
- #endif
1018
939
1019
940
// --------low-level gyro-based PID based on 2DOF PID controller. ----------
1020
941
// 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
1114
1035
previousGyroRateDterm [axis ] = gyroRateDterm [axis ];
1115
1036
1116
1037
// -----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
-
1123
1038
// no feedforward in launch control
1124
1039
float feedforwardGain = launchControlActive ? 0.0f : pidRuntime .pidCoefficient [axis ].Kf ;
1125
1040
if (feedforwardGain > 0 ) {
1126
1041
// halve feedforward in Level mode since stick sensitivity is weaker by about half
1127
1042
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
1129
1044
float feedForward = feedforwardGain * pidSetpointDelta * pidRuntime .pidFrequency ;
1130
1045
1131
1046
#ifdef USE_FEEDFORWARD
0 commit comments