Skip to content

Commit 1d90fac

Browse files
Quick-FlashnerdCopter
authored andcommitted
remove absolute control, update iterm rotation
1 parent 7015291 commit 1d90fac

File tree

9 files changed

+23
-165
lines changed

9 files changed

+23
-165
lines changed

src/main/blackbox/blackbox.c

-3
Original file line numberDiff line numberDiff line change
@@ -1379,9 +1379,6 @@ static bool blackboxWriteSysinfo(void)
13791379
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ANTI_GRAVITY_MODE, "%d", currentPidProfile->antiGravityMode);
13801380
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ANTI_GRAVITY_THRESHOLD, "%d", currentPidProfile->itermThrottleThreshold);
13811381
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ANTI_GRAVITY_GAIN, "%d", currentPidProfile->itermAcceleratorGain);
1382-
#ifdef USE_ABSOLUTE_CONTROL
1383-
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_ABS_CONTROL_GAIN, "%d", currentPidProfile->abs_control_gain);
1384-
#endif
13851382
#ifdef USE_INTEGRATED_YAW_CONTROL
13861383
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_USE_INTEGRATED_YAW, "%d", currentPidProfile->use_integrated_yaw);
13871384
#endif

src/main/cli/settings.c

-7
Original file line numberDiff line numberDiff line change
@@ -1142,13 +1142,6 @@ const clivalue_t valueTable[] = {
11421142
{ "horizon_tilt_effect", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, horizon_tilt_effect) },
11431143
{ "horizon_tilt_expert_mode", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, horizon_tilt_expert_mode) },
11441144

1145-
#if defined(USE_ABSOLUTE_CONTROL)
1146-
{ PARAM_NAME_ABS_CONTROL_GAIN, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 20 }, PG_PID_PROFILE, offsetof(pidProfile_t, abs_control_gain) },
1147-
{ "abs_control_limit", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 255 }, PG_PID_PROFILE, offsetof(pidProfile_t, abs_control_limit) },
1148-
{ "abs_control_error_limit", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 1, 45 }, PG_PID_PROFILE, offsetof(pidProfile_t, abs_control_error_limit) },
1149-
{ "abs_control_cutoff", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 1, 45 }, PG_PID_PROFILE, offsetof(pidProfile_t, abs_control_cutoff) },
1150-
#endif
1151-
11521145
#ifdef USE_INTEGRATED_YAW_CONTROL
11531146
{ PARAM_NAME_USE_INTEGRATED_YAW, VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = {TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, use_integrated_yaw) },
11541147
{ "integrated_yaw_relax", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 255 }, PG_PID_PROFILE, offsetof(pidProfile_t, integrated_yaw_relax) },

src/main/flight/pid.c

+21-106
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ FAST_DATA_ZERO_INIT uint32_t targetPidLooptime;
7878
FAST_DATA_ZERO_INIT pidAxisData_t pidData[XYZ_AXIS_COUNT];
7979
FAST_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)
8682
FAST_DATA_ZERO_INIT float throttleBoost;
8783
pt1Filter_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-
718649
STATIC_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

src/main/flight/pid.h

-13
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ typedef struct pidProfile_s {
175175
uint8_t acro_trainer_debug_axis; // The axis for which record debugging values are captured 0=roll, 1=pitch
176176
uint8_t acro_trainer_gain; // The strength of the limiting. Raising may reduce overshoot but also lead to oscillation around the angle limit
177177
uint16_t acro_trainer_lookahead_ms; // The lookahead window in milliseconds used to reduce overshoot
178-
uint8_t abs_control_gain; // How strongly should the absolute accumulated error be corrected for
179-
uint8_t abs_control_limit; // Limit to the correction
180-
uint8_t abs_control_error_limit; // Limit to the accumulated error
181-
uint8_t abs_control_cutoff; // Cutoff frequency for path estimation in abs control
182178
uint8_t dterm_lpf2_type; // Filter type for 2nd dterm lowpass
183179
uint16_t dterm_lpf1_dyn_min_hz; // Dterm lowpass filter 1 min hz when in dynamic mode
184180
uint16_t dterm_lpf1_dyn_max_hz; // Dterm lowpass filter 1 max hz when in dynamic mode
@@ -319,15 +315,6 @@ typedef struct pidRuntime_s {
319315
uint8_t itermRelaxCutoff;
320316
#endif
321317

322-
#ifdef USE_ABSOLUTE_CONTROL
323-
float acCutoff;
324-
float acGain;
325-
float acLimit;
326-
float acErrorLimit;
327-
pt1Filter_t acLpf[XYZ_AXIS_COUNT];
328-
float oldSetpointCorrection[XYZ_AXIS_COUNT];
329-
#endif
330-
331318
#ifdef USE_D_MIN
332319
pt2Filter_t dMinRange[XYZ_AXIS_COUNT];
333320
pt2Filter_t dMinLowpass[XYZ_AXIS_COUNT];

src/main/flight/pid_init.c

-20
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,6 @@ void pidInitFilters(const pidProfile_t *pidProfile)
210210
}
211211
#endif
212212

213-
#if defined(USE_ABSOLUTE_CONTROL)
214-
if (pidRuntime.itermRelax) {
215-
for (int i = 0; i < XYZ_AXIS_COUNT; i++) {
216-
pt1FilterInit(&pidRuntime.acLpf[i], pt1FilterGain(pidRuntime.acCutoff, pidRuntime.dT));
217-
}
218-
}
219-
#endif
220-
221213
#if defined(USE_D_MIN)
222214
// Initialize the filters for all axis even if the d_min[axis] value is 0
223215
// Otherwise if the pidProfile->d_min_xxx parameters are ever added to
@@ -338,17 +330,6 @@ void pidInitConfig(const pidProfile_t *pidProfile)
338330
pidRuntime.acroTrainerGain = (float)pidProfile->acro_trainer_gain / 10.0f;
339331
#endif // USE_ACRO_TRAINER
340332

341-
#if defined(USE_ABSOLUTE_CONTROL)
342-
pidRuntime.acGain = (float)pidProfile->abs_control_gain;
343-
pidRuntime.acLimit = (float)pidProfile->abs_control_limit;
344-
pidRuntime.acErrorLimit = (float)pidProfile->abs_control_error_limit;
345-
pidRuntime.acCutoff = (float)pidProfile->abs_control_cutoff;
346-
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
347-
float iCorrection = -pidRuntime.acGain * PTERM_SCALE / ITERM_SCALE * pidRuntime.pidCoefficient[axis].Kp;
348-
pidRuntime.pidCoefficient[axis].Ki = MAX(0.0f, pidRuntime.pidCoefficient[axis].Ki + iCorrection);
349-
}
350-
#endif
351-
352333
#ifdef USE_DYN_LPF
353334
if (pidProfile->dterm_lpf1_dyn_min_hz > 0) {
354335
switch (pidProfile->dterm_lpf1_type) {
@@ -440,4 +421,3 @@ void pidCopyProfile(uint8_t dstPidProfileIndex, uint8_t srcPidProfileIndex)
440421
memcpy(pidProfilesMutable(dstPidProfileIndex), pidProfilesMutable(srcPidProfileIndex), sizeof(pidProfile_t));
441422
}
442423
}
443-

src/main/msp/msp.c

+1-9
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
14181418
sbufWriteU16(dst, (uint16_t)constrain(gpsSol.llh.altCm / 100, 0, UINT16_MAX)); // alt changed from 1m to 0.01m per lsb since MSP API 1.39 by RTH. To maintain backwards compatibility compensate to 1m per lsb in MSP again.
14191419
sbufWriteU16(dst, gpsSol.groundSpeed);
14201420
sbufWriteU16(dst, gpsSol.groundCourse);
1421-
// Added in API version 1.44
1421+
// Added in API version 1.44
14221422
sbufWriteU16(dst, gpsSol.hdop);
14231423
break;
14241424

@@ -1848,11 +1848,7 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
18481848
sbufWriteU8(dst, 0);
18491849
sbufWriteU8(dst, 0);
18501850
#endif
1851-
#if defined(USE_ABSOLUTE_CONTROL)
1852-
sbufWriteU8(dst, currentPidProfile->abs_control_gain);
1853-
#else
18541851
sbufWriteU8(dst, 0);
1855-
#endif
18561852
#if defined(USE_THROTTLE_BOOST)
18571853
sbufWriteU8(dst, currentPidProfile->throttle_boost);
18581854
#else
@@ -2939,11 +2935,7 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
29392935
sbufReadU8(src);
29402936
sbufReadU8(src);
29412937
#endif
2942-
#if defined(USE_ABSOLUTE_CONTROL)
2943-
currentPidProfile->abs_control_gain = sbufReadU8(src);
2944-
#else
29452938
sbufReadU8(src);
2946-
#endif
29472939
#if defined(USE_THROTTLE_BOOST)
29482940
currentPidProfile->throttle_boost = sbufReadU8(src);
29492941
#else

src/main/target/common_post.h

-4
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,6 @@ extern uint8_t __config_end;
397397
#undef USE_DYN_IDLE
398398
#endif
399399

400-
#ifndef USE_ITERM_RELAX
401-
#undef USE_ABSOLUTE_CONTROL
402-
#endif
403-
404400
#if defined(USE_CUSTOM_DEFAULTS)
405401
#define USE_CUSTOM_DEFAULTS_ADDRESS
406402
#endif

src/main/target/common_pre.h

-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ extern uint8_t _dmaram_end__;
399399
#define USE_TELEMETRY_MAVLINK
400400
#define USE_UNCOMMON_MIXERS
401401
#define USE_SIGNATURE
402-
#define USE_ABSOLUTE_CONTROL
403402
#define USE_HOTT_TEXTMODE
404403
#define USE_LED_STRIP_STATUS_MODE
405404
#define USE_VARIO

src/test/Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ scheduler_unittest_SRC := \
280280
$(USER_DIR)/common/streambuf.c
281281

282282
scheduler_unittest_DEFINES := \
283-
USE_OSD=
283+
USE_OSD=
284284

285285
sensor_gyro_unittest_SRC := \
286286
$(USER_DIR)/sensors/gyro.c \
@@ -390,7 +390,6 @@ pid_unittest_SRC := \
390390
pid_unittest_DEFINES := \
391391
USE_ITERM_RELAX= \
392392
USE_RC_SMOOTHING_FILTER= \
393-
USE_ABSOLUTE_CONTROL= \
394393
USE_LAUNCH_CONTROL= \
395394
USE_FEEDFORWARD=
396395

0 commit comments

Comments
 (0)